001: package javax.persistence;
002:
003: /**
004: * Interface used to interact with the persistence context.
005: */
006: public interface EntityManager {
007:
008: /**
009: * Make an instance managed, using the unqualified class name as the entity name.
010: *
011: * @param entity
012: */
013: public void persist(Object entity);
014:
015: /**
016: * Merge the state of the given entity into the current persistence context,
017: * using the unqualified class name as the entity name.
018: *
019: * @param entity
020: * @return the instance that the state was merged to
021: *
022: * @throws IllegalArgumentException if not an entity
023: * or entity is in the removed state
024: * @throws TransactionRequiredException if there is
025: * no transaction
026: */
027: public <T> T merge(T entity);
028:
029: /**
030: * Remove the instance.
031: *
032: * @param entity
033: * @throws IllegalArgumentException if not an entity
034: * or entity is in the removed or in * the detached state
035: * @throws TransactionRequiredException if there is
036: * no transaction
037: */
038: public void remove(Object entity);
039:
040: /**
041: * Refresh the state of the instance from the
042: * database.
043: *
044: * @param entity
045: * @throws IllegalArgumentException if not an entity
046: * or entity is not in managed state
047: * @throws TransactionRequiredException if there is
048: * no transaction
049: */
050: public void refresh(Object entity);
051:
052: /**
053: * Find by primary key.
054: *
055: * @param entityName
056: * @param primaryKey
057: * @return the found entity instance
058: * @throws EntityNotFoundException if the entity does not exist
059: * @throws IllegalArgumentException if the first argument does
060: * not denote an entity type or the second
061: * argument is not a valid type for that
062: * entity s primary key
063: */
064: public Object find(String entityName, Object primaryKey);
065:
066: /**
067: * Find by primary key.
068: *
069: * @param entityClass
070: * @param primaryKey
071: * @return the found entity instance
072: * @throws EntityNotFoundException if the entity does not exist
073: * @throws IllegalArgumentException if the first argument does
074: * not denote an entity type or the second
075: * argument is not a valid type for that
076: * entity s primary key
077: */
078: public <T> T find(Class<T> entityClass, Object primaryKey);
079:
080: /**
081: * Synchronize the persistence context with the underlying database.
082: */
083: public void flush();
084:
085: /**
086: * Create an instance of Query for executing an EJBQL query.
087: *
088: * @param ejbqlString an EJBQL query string
089: * @return the new query instance
090: */
091: public Query createQuery(String ejbqlString);
092:
093: /**
094: * Create an instance of Query for executing a named query (in EJBQL or native SQL).
095: *
096: * @param name the name of a query defined in metadata
097: * @return the new query instance
098: */
099: public Query createNamedQuery(String name);
100:
101: /**
102: * Create an instance of Query for executing a native SQL query.
103: *
104: * @param sqlString a native SQL query string
105: * @return the new query instance
106: */
107: public Query createNativeQuery(String sqlString);
108:
109: /**
110: * Create an instance of Query for executing
111: * a native SQL query.
112: *
113: * @param sqlString a native SQL query string
114: * @param resultClass the class of the resulting instances
115: * @return the new query instance
116: * @throws IllegalArgumentException if query string is not valid
117: */
118: public Query createNativeQuery(String sqlString, Class resultClass);
119:
120: /**
121: * Create an instance of Query for executing
122: * a native SQL query.
123: *
124: * @param sqlString a native SQL query string
125: * @param resultSetMapping the name of the result set mapping
126: * @return the new query instance
127: * @throws IllegalArgumentException if query string is not valid
128: */
129: public Query createNativeQuery(String sqlString,
130: String resultSetMapping);
131:
132: /**
133: * Check if the instance belongs to the current persistence context.
134: *
135: * @param entity
136: * @return
137: */
138: public boolean contains(Object entity);
139:
140: }
|