Index: topia/src/java/org/codelutin/topia/persistence/serialization/SerializablePersistenceHelper.java diff -u topia/src/java/org/codelutin/topia/persistence/serialization/SerializablePersistenceHelper.java:1.1 topia/src/java/org/codelutin/topia/persistence/serialization/SerializablePersistenceHelper.java:1.2 --- topia/src/java/org/codelutin/topia/persistence/serialization/SerializablePersistenceHelper.java:1.1 Fri Jun 10 17:16:38 2005 +++ topia/src/java/org/codelutin/topia/persistence/serialization/SerializablePersistenceHelper.java Tue Jun 14 17:03:10 2005 @@ -24,7 +24,7 @@ * Created: 10 juin 2005 * * @author Arnaud Thimel -* @version $Revision: 1.1 $ +* @version $Revision: 1.2 $ */ @@ -39,6 +39,7 @@ import java.io.ObjectOutputStream; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Properties; @@ -48,14 +49,18 @@ import org.codelutin.topia.TopiaException; import org.codelutin.topia.TopiaQuery; import org.codelutin.topia.persistence.AbstractPersistenceHelper; +import org.codelutin.topia.persistence.jdo.Util; +import org.codelutin.util.VersionNumberUtil; public class SerializablePersistenceHelper extends AbstractPersistenceHelper { + public void finalize() { //Au cas oł ca fonctionne... + destroy(); + } + public void destroy() { - System.out.println("------------------------------------------------"); File dbFile = new File(properties.getProperty("topia.persistence.xml.dbfile")); - System.out.println("!!!!!!!!!!!!!!!! " + dbFile); ObjectOutputStream output; try { output = new ObjectOutputStream(new FileOutputStream(dbFile)); @@ -76,6 +81,11 @@ */ public SerializablePersistenceHelper(TopiaContext context, Properties properties) { super(context, properties); + load(); + printEntities(); + } + + private void load() { File dbFile = new File(properties.getProperty("topia.persistence.xml.dbfile")); if (dbFile.exists()) { try { @@ -94,9 +104,12 @@ } } -/* public void finalize() { + public TopiaEntity create(Class entityClass) throws TopiaException { + Class clazz = Util.getClazz(entityClass.getName() + "Impl"); + TopiaEntity entity = (TopiaEntity) Util.getInstance(clazz); + return entity; } -*/ + /* (non-Javadoc) * @see org.codelutin.topia.persistence.PersistenceHelper#makePersistent(org.codelutin.topia.TopiaEntity) */ @@ -109,13 +122,14 @@ doEntity = entity; entities.put(entityId, doEntity); } else { - throw new TopiaException("Can't persist new Entity, topiaId already in use : " + entityId); + throw new TopiaException("Can't persist new entity, topiaId already in use : " + entityId); } } else { if (doEntity == null) { throw new TopiaException("Can't persist entity, can't find entity for topiaId : " + entityId); } else { //TODO Arno : Update ??? + doEntity = entity; entities.put(entityId, doEntity); } } @@ -127,6 +141,9 @@ * @see org.codelutin.topia.persistence.PersistenceHelper#update(org.codelutin.topia.TopiaEntity) */ public TopiaEntity update(TopiaEntity entity) throws TopiaException { + String version = entity.get_topiaVersion_(); + version = VersionNumberUtil.inc(version); + entity.set_topiaVersion_(version); return makePersistent(entity); } @@ -204,4 +221,10 @@ return (TopiaEntity)entities.get(id); } + private void printEntities() { + for (Iterator it = entities.keySet().iterator(); it.hasNext(); ) { + String id = (String)it.next(); + System.out.println("Loaded entity : " + id + " - " + entities.get(id)); + } + } }