public interface

EntityEngine

com.atlassian.jira.entity.EntityEngine
Known Indirect Subclasses

Class Overview

Provides methods for working with the DB via Atlassian EntityEngine.

These methods are considered a higher level alternative to the OfBizDelegator and provide two main advantages:

  • They provide a fluent interface that is considered easier to read and understand than the OfBizDelegator methods.
  • They allow the developer to ignore GenericValues and deal directly with proper Data Objects.
    (Provided that an EntityFactory exists for the given Entity)

This interface is still experimental at this stage.

Summary

Nested Classes
interface EntityEngine.SelectFromContext<E>  
interface EntityEngine.WhereContext<E>  
interface EntityEngine.WhereEqualAndContext<E>  
interface EntityEngine.WhereEqualContext<E>  
interface EntityEngine.WhereInContext<E>  
Public Methods
<E> E createValue(EntityFactory<E> entityFactory, E newValue)
Creates a new Entity and auto populates the ID if no ID is explicitly set.
<E> void createValueWithoutId(EntityFactory<E> entityFactory, E newValue)
Creates a new Entity without trying to automatically populate the ID column.
int delete(Delete.DeleteWhereContext deleteContext)
Allows you to execute an SQL DELETE using a fluent interface.
int execute(Update.WhereContext updateContext)
Allows you to execute an UPDATE statement using a fluent interface.
<E> int removeValue(EntityFactory<E> entityFactory, Long id)
Remove the given entity from the DB.
<E> ExecutionContext<E> run(SelectQuery<E> selectQuery)
<E> SelectFromContext<E> selectFrom(EntityFactory<E> entityFactory)
Starts a dialog to run a SELECT query against EntityEngine.
<E> void updateValue(EntityFactory<E> entityFactory, E newValue)

Public Methods

public E createValue (EntityFactory<E> entityFactory, E newValue)

Creates a new Entity and auto populates the ID if no ID is explicitly set.

Use this for entities that include an ID column (most of them).

Parameters
entityFactory the EntityFactory
newValue the entity to be created.
Returns
  • the newly created value (with the newly populated ID in it).

public void createValueWithoutId (EntityFactory<E> entityFactory, E newValue)

Creates a new Entity without trying to automatically populate the ID column.

Use this for entities that don't have a numeric ID column.

Parameters
entityFactory the EntityFactory
newValue the entity to be created.

public int delete (Delete.DeleteWhereContext deleteContext)

Allows you to execute an SQL DELETE using a fluent interface.

You should call this using code that looks like:

     entityEngine.delete(Delete.from(Entity.ISSUE_SECURITY_LEVEL).whereIdEquals(securityLevelId));
 
or:
     entityEngine.delete(
         Delete.from(Entity.ISSUE_SECURITY_LEVEL)
               .whereEqual("scheme", schemeId)
               .andEqual("name", name)
     );
 

Parameters
deleteContext build up a fluent DELETE statement here. Should start with Delete.from(
Returns
  • the number of entities / DB rows deleted.

public int execute (Update.WhereContext updateContext)

Allows you to execute an UPDATE statement using a fluent interface.

See the Update class for an example.

Parameters
updateContext build up a fluent UPDATE statement here. Should start with Update.into(
Returns
  • the number of entities / DB rows deleted.

public int removeValue (EntityFactory<E> entityFactory, Long id)

Remove the given entity from the DB.

Parameters
entityFactory represents the entity type (ie TABLE)
id the id of the row to delete.
Returns
  • number of rows effected by this operation

public ExecutionContext<E> run (SelectQuery<E> selectQuery)

public SelectFromContext<E> selectFrom (EntityFactory<E> entityFactory)

Starts a dialog to run a SELECT query against EntityEngine.

e.g. to run "SELECT * FROM remotelink WHERE id = ?" (and return a single entity value) you could write:

   RemoteIssueLink link = entityEngine.selectFrom(Entity.REMOTE_ISSUE_LINK)
                                 .whereEqual("id", remoteIssueLinkId)
                                 .singleValue();
 
e.g. to run "SELECT * FROM remotelink WHERE issueid = ? AND app = ? ORDER BY type" you could write:
   List remoteIssueLinks =
           entityEngine.selectFrom(Entity.REMOTE_ISSUE_LINK)
                       .whereEqual("issueid", issueId)
                       .andEqual("app", app)
                       .orderBy("type");
 

Parameters
entityFactory that can convert GenericValues into Entity data objects. See Entity for existing factories.
Returns
  • The context that begins a fluent dialog to run a SELECT query.
See Also

public void updateValue (EntityFactory<E> entityFactory, E newValue)