Index: topia/src/java/org/codelutin/topia/persistence/PersistenceStorage.java diff -u topia/src/java/org/codelutin/topia/persistence/PersistenceStorage.java:1.3 topia/src/java/org/codelutin/topia/persistence/PersistenceStorage.java:1.4 --- topia/src/java/org/codelutin/topia/persistence/PersistenceStorage.java:1.3 Thu Jul 21 16:51:39 2005 +++ topia/src/java/org/codelutin/topia/persistence/PersistenceStorage.java Tue Aug 2 21:03:58 2005 @@ -23,9 +23,9 @@ * Created: 16 juillet 2005 23:40:21 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2005/07/21 16:51:39 $ + * Last update: $Date: 2005/08/02 21:03:58 $ * by : $Author: bpoussin $ */ @@ -37,6 +37,7 @@ import java.util.logging.Logger; import java.util.Properties; import org.codelutin.topia.TopiaQuery; +import org.codelutin.topia.TopiaContext; /** * L'implantation du storage doit prendre en compte qu'il n'y aura qu'une @@ -51,37 +52,37 @@ /** * Demande la sauvegarde de l'entité dans le context de la transaction */ - public void store(TopiaTransaction tt, TopiaPersistenceObject tpo) throws TopiaPersistenceException; + public void store(TopiaContext context, TopiaPersistenceObject tpo) throws TopiaPersistenceException; /** * Demande la restauration de l'entité dans le context de la transaction */ - public void restore(TopiaTransaction tt, TopiaPersistenceObject tpo) throws TopiaPersistenceException; + public void restore(TopiaContext context, TopiaPersistenceObject tpo) throws TopiaPersistenceException; /** * Retourne tous les id de tous les objets encore existant dans le * context de la transaction */ - public Collection getAllId(TopiaTransaction tt) throws TopiaPersistenceException; + public Collection getAllId(TopiaContext context) throws TopiaPersistenceException; /** * Permet d'indiquer au storage le debut d'une transaction */ - public void beginTransaction(TopiaTransaction tt) throws TopiaPersistenceException; + public void beginTransaction(TopiaContext context) throws TopiaPersistenceException; /** * Indique au storage de commiter la transaction passé en paramètre. * @return la nouvelle transaction utilisable pour de futurs appels au storage * car l'ancienne transaction n'est plus valide */ - public TopiaTransaction commitTransaction(TopiaTransaction tt) throws TopiaPersistenceException; + public TopiaTransaction commitTransaction(TopiaContext context) throws TopiaPersistenceException; /** * Indique au storage de faire un rollback de la transaction passé en paramètre. * @return la nouvelle transaction utilisable pour de futurs appels au storage * car l'ancienne transaction n'est plus valide */ - public TopiaTransaction rollbackTransaction(TopiaTransaction tt) throws TopiaPersistenceException; + public TopiaTransaction rollbackTransaction(TopiaContext context) throws TopiaPersistenceException; /** * Indique si le storage implante une methode de recherche rapide @@ -95,12 +96,12 @@ * il faut que haveFindImplemented return false, et que cette méthode * leve l'exception UnsupportedOperationException */ - public List find(TopiaTransaction tt, TopiaQuery query) throws TopiaPersistenceException; + public List find(TopiaContext context, TopiaQuery query) throws TopiaPersistenceException; /** * Retourne l'historique de l'objet ayant l'id passé en paramètre */ - public List getHistory(TopiaTransaction tt, String id) throws TopiaPersistenceException; + public List getHistory(TopiaContext context, String id) throws TopiaPersistenceException; /** * Nettoie l'historique pour ne conserver qu'une profondeur d'historique @@ -113,7 +114,7 @@ /** * Permet de savoir si un id existe encore dans le context de la transaction */ - public boolean exists(TopiaTransaction tt, String id) throws TopiaPersistenceException; + public boolean exists(TopiaContext context, String id) throws TopiaPersistenceException; } // PersistenceStorage Index: topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java diff -u topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java:1.6 topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java:1.7 --- topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java:1.6 Tue Aug 2 15:00:11 2005 +++ topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java Tue Aug 2 21:03:58 2005 @@ -23,9 +23,9 @@ * Created: 20 juillet 2005 15:25:06 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * - * Last update: $Date: 2005/08/02 15:00:11 $ + * Last update: $Date: 2005/08/02 21:03:58 $ * by : $Author: bpoussin $ */ @@ -65,6 +65,7 @@ import org.codelutin.topia.TopiaId; import org.codelutin.topia.TopiaQuery; import org.codelutin.topia.Util; +import org.codelutin.topia.TopiaContext; /** * Storage implante sur JDBC. @@ -314,14 +315,14 @@ public long time_objectToDatabase = 0; public long time_databaseToObject = 0; - public void store(TopiaTransaction tt, Collection tpos) throws TopiaPersistenceException { + public void store(TopiaContext context, Collection tpos) throws TopiaPersistenceException { long time = System.currentTimeMillis(); Connection conn = null; try{ conn = getConnection(); try{ for(TopiaPersistenceObject tpo: tpos){ - store(conn, tt, tpo); + store(conn, context, tpo); } } finally { conn.commit(); @@ -342,13 +343,13 @@ time_storeList += System.currentTimeMillis() - time; } - public void store(TopiaTransaction tt, TopiaPersistenceObject tpo) throws TopiaPersistenceException { + public void store(TopiaContext context, TopiaPersistenceObject tpo) throws TopiaPersistenceException { long time = System.currentTimeMillis(); Connection conn = null; try{ conn = getConnection(); try{ - store(conn, tt, tpo); + store(conn, context, tpo); } finally { conn.commit(); conn.close(); @@ -371,27 +372,27 @@ /** * Demande la sauvegarde de l'entité dans le context de la transaction */ - public void store(Connection conn, TopiaTransaction tt, TopiaPersistenceObject tpo) + public void store(Connection conn, TopiaContext context, TopiaPersistenceObject tpo) throws SQLException, TopiaPersistenceException { long time = System.currentTimeMillis(); // si l'objet n'etait pas encore dans la transaction, on le met - tpo.getManagement().setDate(tt.getId()); + tpo.getManagement().setDate(context.getTransaction().getId()); - boolean exists = managementExists(conn, tt, tpo); + boolean exists = managementExists(conn, context, tpo); if(exists){ // l'objet existait on le met a jour - saveManagement(conn, tt, tpo, false); - saveData(conn, tt, tpo, false); + saveManagement(conn, context, tpo, false); + saveData(conn, context, tpo, false); } else { // l'objet n'existait pas, on le creer - saveManagement(conn, tt, tpo, true); - saveData(conn, tt, tpo, true); + saveManagement(conn, context, tpo, true); + saveData(conn, context, tpo, true); } time_store += System.currentTimeMillis() - time; } - protected boolean managementExists(Connection conn, TopiaTransaction tt, + protected boolean managementExists(Connection conn, TopiaContext context, TopiaPersistenceObject tpo) throws SQLException, TopiaPersistenceException { long time = System.currentTimeMillis(); boolean result = false; @@ -411,7 +412,7 @@ /** * Demande la restauration de l'entité dans le context de la transaction */ - public void restore(TopiaTransaction tt, TopiaPersistenceObject tpo) throws TopiaPersistenceException { + public void restore(TopiaContext context, TopiaPersistenceObject tpo) throws TopiaPersistenceException { if(!(tpo.getManagement().isUnloaded() || tpo.getAskedFields().size() != 0)){ // deja chargé et pas de champs a charger on sort tout de suite return; @@ -422,7 +423,7 @@ PreparedStatement sta = conn.prepareStatement(SQL.getProperty(SQL_LOAD_MANAGEMENT)); try{ sta.setString(1, tpo.getManagement().getId()); - sta.setLong(2, tt.getId()); + sta.setLong(2, context.getTransaction().getId()); ResultSet management = sta.executeQuery(); if(!management.next()){ // on a pas trouve un management specifique pour la @@ -431,14 +432,14 @@ sta.close(); sta = conn.prepareStatement(SQL.getProperty(SQL_LOAD_HISTORY)); sta.setString(1, tpo.getManagement().getId()); - sta.setLong(2, -tt.getId()); - sta.setLong(3, tt.getId()); + sta.setLong(2, -context.getTransaction().getId()); + sta.setLong(3, context.getTransaction().getId()); management = sta.executeQuery(); if(!management.next()){ // on a pas trouvé d'objet sattisfaisant la demande throw new TopiaPersistenceException("This object(" + tpo.getManagement().getId() + ") don't exist in this transaction(" - + tt.getId() + ")"); + + context.getTransaction().getId() + ")"); } } @@ -454,7 +455,7 @@ // tous les champs dans un nouveau TopiaPersistenceObjectData // et on fait un changement de schema dessus. TopiaPersistenceObjectData oldData = new TopiaPersistenceObjectData(); - loadData(conn, tt, tpo, oldData, true); + loadData(conn, context, tpo, oldData, true); // on fait la conversion des données TopiaPersistenceObjectData newData = @@ -473,7 +474,7 @@ delete.close(); // On sauve les nouvelles valeur pour l'objet - saveData(conn, tt, tpo, true); + saveData(conn, context, tpo, true); // on change le numero de schema des données PreparedStatement updateSchema = conn.prepareStatement(SQL.getProperty(SQL_UPDATE_SCHEMAVERSION)); @@ -488,7 +489,7 @@ } else { // pas de changement de schema, on charge directement // dans l'objet data du tpo - loadData(conn, tt, tpo, tpo.getData(), false); + loadData(conn, context, tpo, tpo.getData(), false); } } finally { @@ -590,7 +591,7 @@ * @param forceLoadAllField force le chargement de tous les champs meme ceux * non demandé */ - protected void loadData(Connection conn, TopiaTransaction tt, + protected void loadData(Connection conn, TopiaContext context, TopiaPersistenceObject tpo, TopiaPersistenceObjectData data, boolean forceLoadAllField) throws SQLException, TopiaPersistenceException { @@ -621,7 +622,7 @@ } } - protected void saveManagement(Connection conn, TopiaTransaction tt, + protected void saveManagement(Connection conn, TopiaContext context, TopiaPersistenceObject tpo, boolean forceInsert) throws SQLException, TopiaPersistenceException { long time = System.currentTimeMillis(); @@ -659,7 +660,7 @@ * Sauve tous les champs modifier et vide la liste des champs modifiée * @param forceInsert si vrai fait un insert, sinon fait un update */ - protected void saveData(Connection conn, TopiaTransaction tt, + protected void saveData(Connection conn, TopiaContext context, TopiaPersistenceObject tpo, boolean forceInsert) throws SQLException, TopiaPersistenceException { // TODO supprimer le time apres analyse des perfs @@ -709,17 +710,17 @@ * Retourne tous les id de tous les objets encore existant dans le * context de la transaction */ - public Collection getAllId(TopiaTransaction tt) throws TopiaPersistenceException { + public Collection getAllId(TopiaContext context) throws TopiaPersistenceException { List result = new ArrayList(); try{ Connection conn = getConnection(); try{ PreparedStatement sta = conn.prepareStatement(SQL.getProperty(SQL_GET_ALL_ID)); try{ - sta.setLong(1, tt.getId()); - sta.setLong(2, -tt.getId()); - sta.setLong(3, tt.getId()); - sta.setLong(4, -tt.getId()); + sta.setLong(1, context.getTransaction().getId()); + sta.setLong(2, -context.getTransaction().getId()); + sta.setLong(3, context.getTransaction().getId()); + sta.setLong(4, -context.getTransaction().getId()); ResultSet rr = sta.executeQuery(); while(rr.next()){ result.add(rr.getString("id")); @@ -740,7 +741,7 @@ /** * Permet d'indiquer au storage le debut d'une transaction */ - public void beginTransaction(TopiaTransaction tt) throws TopiaPersistenceException { + public void beginTransaction(TopiaContext context) throws TopiaPersistenceException { // On pourrait conservé l'id de la transaction, et lors d'appel // d'autre methode verifier que cet Id est bien l'id d'une transation // qui a un beginTransaction. @@ -759,15 +760,15 @@ * il sont supprimé on non. Ensuite, il faut supprimer avec les meme requete * que rollback ces objets. */ - public TopiaTransaction commitTransaction(TopiaTransaction tt) throws TopiaPersistenceException { + public TopiaTransaction commitTransaction(TopiaContext context) throws TopiaPersistenceException { try{ - TopiaTransaction newtt = tt.regenerateTransaction(); + TopiaTransaction newtt = context.getTransaction().regenerateTransaction(); Connection conn = getConnection(); try{ PreparedStatement sta = conn.prepareStatement(SQL.getProperty(SQL_COMMIT_MANAGEMENT)); try{ sta.setLong(1, -newtt.getId()); - sta.setLong(2, tt.getId()); + sta.setLong(2, context.getTransaction().getId()); sta.execute(); } finally { sta.close(); @@ -777,7 +778,7 @@ sta = conn.prepareStatement(SQL.getProperty(SQL_COMMIT_DATA)); try{ sta.setLong(1, -newtt.getId()); - sta.setLong(2, tt.getId()); + sta.setLong(2, context.getTransaction().getId()); sta.execute(); } finally { sta.close(); @@ -789,7 +790,7 @@ // peut-etre faire quelque chose comme dans beginTransaction ? return newtt; } catch(SQLException eee){ - throw new TopiaPersistenceException("Erreur durant le rollback transaction: " + tt.getId(), eee); + throw new TopiaPersistenceException("Erreur durant le rollback transaction: " + context.getTransaction().getId(), eee); } } @@ -798,13 +799,13 @@ * @return la nouvelle transaction utilisable pour de futurs appels au storage * car l'ancienne transaction n'est plus valide */ - public TopiaTransaction rollbackTransaction(TopiaTransaction tt) throws TopiaPersistenceException { + public TopiaTransaction rollbackTransaction(TopiaContext context) throws TopiaPersistenceException { try{ Connection conn = getConnection(); try{ PreparedStatement sta = conn.prepareStatement(SQL.getProperty(SQL_ROLLBACK_MANAGEMENT)); try{ - sta.setLong(1, tt.getId()); + sta.setLong(1, context.getTransaction().getId()); sta.execute(); } finally { sta.close(); @@ -815,7 +816,7 @@ // en cascade sta = conn.prepareStatement(SQL.getProperty(SQL_ROLLBACK_DATA)); try{ - sta.setLong(1, tt.getId()); + sta.setLong(1, context.getTransaction().getId()); sta.execute(); } finally { sta.close(); @@ -825,11 +826,11 @@ conn.close(); } // creation d'un nouvelle transation - tt = tt.regenerateTransaction(); + TopiaTransaction tt = context.getTransaction().regenerateTransaction(); // peut-etre faire quelque chose comme dans beginTransaction ? return tt; } catch(SQLException eee){ - throw new TopiaPersistenceException("Erreur durant le rollback transaction: " + tt.getId(), eee); + throw new TopiaPersistenceException("Erreur durant le rollback transaction: " + context.getTransaction().getId(), eee); } } @@ -847,7 +848,7 @@ * il faut que haveFindImplemented return false, et que cette méthode * leve l'exception UnsupportedOperationException */ - public List find(TopiaTransaction tt, TopiaQuery query) throws TopiaPersistenceException { + public List find(TopiaContext context, TopiaQuery query) throws TopiaPersistenceException { TopiaJDBCQueryHelper queryHelper = new TopiaJDBCQueryHelper(); try { queryHelper.setQuery(query.getQueryString()); @@ -856,7 +857,7 @@ } List results = new ArrayList(); try { - String preparedQuery = queryHelper.getPreparedQuery(tt); + String preparedQuery = queryHelper.getPreparedQuery(context.getTransaction()); try { Connection conn = getConnection(); try{ @@ -880,7 +881,7 @@ conn.close(); } } catch (SQLException eee) { - throw new TopiaPersistenceException("Erreur durant le find transaction : " + tt.getId(), eee); + throw new TopiaPersistenceException("Erreur durant le find transaction : " + context.getTransaction().getId(), eee); } } catch (QueryHelperException eee) { throw new TopiaPersistenceException("Execution de la requete impossible, requete source mal formée", eee); @@ -891,7 +892,7 @@ /** * Retourne l'historique de l'objet ayant l'id passé en paramètre */ - public List getHistory(TopiaTransaction tt, String id) throws TopiaPersistenceException { + public List getHistory(TopiaContext context, String id) throws TopiaPersistenceException { // TODO return new ArrayList(); } @@ -923,7 +924,7 @@ /** * Permet de savoir si un id existe encore dans le context de la transaction */ - public boolean exists(TopiaTransaction tt, String id) throws TopiaPersistenceException { + public boolean exists(TopiaContext context, String id) throws TopiaPersistenceException { boolean result = false; try{ Connection conn = getConnection(); @@ -931,8 +932,8 @@ PreparedStatement sta = conn.prepareStatement(SQL.getProperty(SQL_LOAD_HISTORY)); try{ sta.setString(1, id); - sta.setLong(2, -tt.getId()); - sta.setLong(3, tt.getId()); + sta.setLong(2, -context.getTransaction().getId()); + sta.setLong(3, context.getTransaction().getId()); ResultSet rr = sta.executeQuery(); if(rr.next()){ result = !rr.getBoolean("isDeleted"); Index: topia/src/java/org/codelutin/topia/persistence/TopiaPersistenceHelper.java diff -u topia/src/java/org/codelutin/topia/persistence/TopiaPersistenceHelper.java:1.4 topia/src/java/org/codelutin/topia/persistence/TopiaPersistenceHelper.java:1.5 --- topia/src/java/org/codelutin/topia/persistence/TopiaPersistenceHelper.java:1.4 Tue Jul 26 14:32:06 2005 +++ topia/src/java/org/codelutin/topia/persistence/TopiaPersistenceHelper.java Tue Aug 2 21:03:58 2005 @@ -23,9 +23,9 @@ * Created: Jul 16, 2005 * * @author Benjamin POUSSIN - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Last update : $Date: 2005/07/26 14:32:06 $ + * Last update : $Date: 2005/08/02 21:03:58 $ * by : $Author: bpoussin $ */ @@ -96,15 +96,15 @@ } public void beginTransaction() throws TopiaException { - getStorage().beginTransaction(getContext().getTransaction()); + getStorage().beginTransaction(getContext()); } public TopiaTransaction commitTransaction() throws TopiaException { - return getStorage().commitTransaction(getContext().getTransaction()); + return getStorage().commitTransaction(getContext()); } public TopiaTransaction rollbackTransaction() throws TopiaException { - return getStorage().rollbackTransaction(getContext().getTransaction()); + return getStorage().rollbackTransaction(getContext()); } /** @@ -135,7 +135,7 @@ throw new IllegalArgumentException("Null is not a valid entity"); } if(!Proxy.isProxyClass(entity.getClass())){ - if(getStorage().exists(getContext().getTransaction(), entity.get_topiaId_())){ + if(getStorage().exists(getContext(), entity.get_topiaId_())){ throw new IllegalArgumentException("This entity allready exists in Storage."); } result = (A)create(entity.getEntityClass()); @@ -145,7 +145,7 @@ TopiaPersistenceObject tpo = tpp.getObject(); if(tpp.getPersistenceHelper() != this){ - if(getStorage().exists(getContext().getTransaction(), entity.get_topiaId_())){ + if(getStorage().exists(getContext(), entity.get_topiaId_())){ throw new IllegalArgumentException("This entity allready exists in Storage."); } // l'objet venait d'un autre PersistenceHelper, il faut en recreer @@ -161,7 +161,7 @@ // l'objet n'est plus supprimé s'il l'etait tpo.getManagement().setDeleted(false); - getStorage().store(getContext().getTransaction(), tpo); + getStorage().store(getContext(), tpo); return result; } @@ -185,7 +185,7 @@ throw new IllegalArgumentException("This entity is deleted, you can't update it. You must call makePersistent first"); } - getStorage().store(getContext().getTransaction(), tpo); + getStorage().store(getContext(), tpo); return entity; } @@ -206,18 +206,18 @@ TopiaPersistenceObject tpo = tpp.getObject(); tpo.getManagement().setDeleted(true); - getStorage().store(getContext().getTransaction(), tpo); + getStorage().store(getContext(), tpo); } public List find(TopiaQuery query) throws TopiaException { List result = new ArrayList(); if(getStorage().haveFindImplemented()){ - for(String id: getStorage().find(getContext().getTransaction(), query)) { + for(String id: getStorage().find(getContext(), query)) { result.add(findByTopiaId(id)); } } else { List entities = new ArrayList(); - for(String id: getStorage().getAllId(getContext().getTransaction())){ + for(String id: getStorage().getAllId(getContext())){ if(TopiaId.getClassNameAsString(id).equals(query.getFrom())){ entities.add(findByTopiaId(id)); } @@ -240,7 +240,7 @@ public int size(TopiaQuery query) throws TopiaException { List result = null; if(getStorage().haveFindImplemented()){ - result = getStorage().find(getContext().getTransaction(), query); + result = getStorage().find(getContext(), query); } else { result = find(query); } @@ -267,7 +267,7 @@ if(id == null){ return null; } - if(!getStorage().exists(getContext().getTransaction(), id)){ + if(!getStorage().exists(getContext(), id)){ throw new TopiaException("This id don't exist in Storage: " + id); } TopiaEntity result = getCache().get(id); @@ -301,7 +301,7 @@ throw new IllegalArgumentException("This entity is deleted, you can't load it. You must call makePersistent first"); } - getStorage().restore(getContext().getTransaction(), tpo); + getStorage().restore(getContext(), tpo); } } // TopiaPersistenceHelper