001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.amber.entity;
031:
032: import com.caucho.amber.manager.AmberConnection;
033: import com.caucho.amber.type.EntityType;
034:
035: import java.sql.PreparedStatement;
036: import java.sql.ResultSet;
037: import java.sql.SQLException;
038: import java.util.Map;
039:
040: /**
041: * An entity instance
042: */
043: public interface Entity extends MappedSuperclass {
044: public static final int TRANSIENT = 0;
045: public static final int P_NEW = 1;
046: public static final int P_PERSISTING = 2;
047: public static final int P_PERSISTED = 3;
048: public static final int P_NON_TRANSACTIONAL = 4;
049: public static final int P_TRANSACTIONAL = 5;
050: public static final int P_DELETING = 6;
051: public static final int P_DELETED = 7;
052:
053: /**
054: * Makes the entity persistent.
055: */
056: public boolean __caucho_makePersistent(AmberConnection aConn,
057: EntityType entityType) throws SQLException;
058:
059: /**
060: * Makes the entity persistent.
061: */
062: public void __caucho_makePersistent(AmberConnection aConn,
063: EntityItem item) throws SQLException;
064:
065: /**
066: * Pre-cascades the persist operation to child entities.
067: */
068: public void __caucho_cascadePrePersist(AmberConnection aConn)
069: throws SQLException;
070:
071: /**
072: * Pre-cascades the remove operation to child entities.
073: */
074: public void __caucho_cascadePreRemove(AmberConnection aConn)
075: throws SQLException;
076:
077: /**
078: * Post-cascades the persist operation to child entities.
079: */
080: public void __caucho_cascadePostPersist(AmberConnection aConn)
081: throws SQLException;
082:
083: /**
084: * Post-cascades the remove operation to child entities.
085: */
086: public void __caucho_cascadePostRemove(AmberConnection aConn)
087: throws SQLException;
088:
089: /**
090: * Detatch the entity
091: */
092: public void __caucho_detach();
093:
094: /**
095: * Creates the entity in the database, making it persistent-new.
096: */
097: public boolean __caucho_create(AmberConnection aConn,
098: EntityType entityType) throws SQLException;
099:
100: /**
101: * Changes the entity state to P_PERSISTING, but does not flush to database.
102: */
103: public boolean __caucho_lazy_create(AmberConnection aConn,
104: EntityType entityType) throws SQLException;
105:
106: /**
107: * Sets the __caucho_item.
108: */
109: public void __caucho_setCacheItem(EntityItem item);
110:
111: /**
112: * Updates the cache item after commit.
113: */
114: public void __caucho_updateCacheItem(Entity item);
115:
116: /**
117: * Set the primary key.
118: */
119: public void __caucho_setPrimaryKey(Object key);
120:
121: /**
122: * Get the primary key.
123: */
124: public Object __caucho_getPrimaryKey();
125:
126: /**
127: * Gets the corresponding cache entity referenced by __caucho_item.
128: */
129: public Entity __caucho_getCacheEntity();
130:
131: /**
132: * Gets the __caucho_item.
133: */
134: public EntityItem __caucho_getCacheItem();
135:
136: /**
137: * Get the entity type.
138: */
139: public EntityType __caucho_getEntityType();
140:
141: /**
142: * Get the entity state.
143: */
144: public EntityState __caucho_getEntityState();
145:
146: /**
147: * Sets the entity state.
148: */
149: public void __caucho_setEntityState(EntityState state);
150:
151: /**
152: * Sets the connection.
153: */
154: public void __caucho_setConnection(AmberConnection aConn);
155:
156: /**
157: * Returns the connection.
158: */
159: public AmberConnection __caucho_getConnection();
160:
161: /**
162: * Copies all the dirty mask values from a source entity.
163: */
164: public void __caucho_copyDirtyMaskFrom(Entity sourceEntity);
165:
166: /**
167: * Copies all the load mask values from a source entity.
168: */
169: public void __caucho_copyLoadMaskFrom(Entity sourceEntity);
170:
171: /**
172: * Returns the load mask value for a load group.
173: */
174: public long __caucho_getLoadMask(int loadGroup);
175:
176: /**
177: * Sets the load mask value for a load group.
178: */
179: public void __caucho_setLoadMask(long loadMask, int loadGroup);
180:
181: /**
182: * Returns true if the entity is dirty.
183: */
184: public boolean __caucho_isDirty();
185:
186: /**
187: * Returns true if the entity matches.
188: */
189: public boolean __caucho_match(String className, Object key);
190:
191: /**
192: * Loads the entity from the database.
193: */
194: public EntityItem __caucho_home_find(AmberConnection aConn,
195: AmberEntityHome home, ResultSet rs, int index)
196: throws SQLException;
197:
198: /**
199: * Returns a new entity. In the case of inheritance, needs to query
200: * the database.
201: */
202: public Entity __caucho_home_find(AmberConnection aConn,
203: AmberEntityHome home, Object key);
204:
205: /**
206: * Returns a new entity.
207: */
208: /*
209: public Entity __caucho_home_new(AmberConnection aConn,
210: AmberEntityHome home,
211: Object key)
212: throws SQLException;
213: */
214:
215: /*
216: public Entity __caucho_home_new(AmberConnection aConn,
217: AmberEntityHome home,
218: Object key,
219: boolean loadFromResultSet)
220: throws SQLException;
221: */
222:
223: /**
224: * Returns a new entity.
225: */
226: public Entity __caucho_home_new(AmberEntityHome home, Object key,
227: AmberConnection aConn, EntityItem cacheItem);
228:
229: /**
230: * Creates a new instance based on the current entity.
231: */
232: public Entity __caucho_copy(AmberConnection aConn,
233: EntityItem cacheItem);
234:
235: /**
236: * Copies this entity state to an existing entity.
237: */
238: public Entity __caucho_copyTo(Entity targetEntity,
239: AmberConnection aConn, EntityItem cacheItem);
240:
241: /**
242: * Copies this entity state to an existing entity.
243: */
244: public void __caucho_copyTo(Entity targetEntity,
245: AmberConnection aConn);
246:
247: /**
248: * Copies this entity state to an existing entity.
249: */
250: public void __caucho_copyTo(Entity targetEntity,
251: AmberConnection aConn, boolean isFullMerge);
252:
253: /**
254: * Merges this entity state into an existing entity.
255: */
256: public void __caucho_merge(Entity targetEntity,
257: AmberConnection aConn, boolean isFullMerge);
258:
259: /**
260: * Retrieves data from the data store, including the eager loads.
261: */
262: public void __caucho_retrieve_eager(AmberConnection aConn);
263:
264: /**
265: * Retrieves data from the data store, only loading own fields.
266: */
267: public void __caucho_retrieve_self(AmberConnection aConn);
268:
269: /**
270: * Loads the entity from the database and
271: * returns the number of columns consumed
272: * from the result set.
273: */
274: public int __caucho_load(AmberConnection aConn, ResultSet rs,
275: int index) throws SQLException;
276:
277: /**
278: * Loads the entity key.
279: */
280: public Object __caucho_load_key(AmberConnection aConn,
281: ResultSet rs, int index) throws SQLException;
282:
283: /**
284: * Loads the entity from the database.
285: */
286: public void __caucho_setKey(PreparedStatement pstmt, int index)
287: throws SQLException;
288:
289: /**
290: * Expires data
291: */
292: public void __caucho_expire();
293:
294: /**
295: * Deletes the entity from the database.
296: */
297: public void __caucho_delete();
298:
299: /**
300: * Called when a foreign object is created/deleted.
301: */
302: public void __caucho_invalidate_foreign(String table, Object key);
303:
304: /**
305: * Flushes changes to the backing store.
306: */
307: public boolean __caucho_flush() throws SQLException;
308:
309: /**
310: * After a commit.
311: */
312: public void __caucho_afterCommit();
313:
314: /**
315: * After a rollback.
316: */
317: public void __caucho_afterRollback();
318:
319: /**
320: * Checks entity-relationship consistency and adds information to the log
321: * about relationships from this entity.
322: */
323: public void __caucho_dumpRelationships();
324: }
|