Index: topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java diff -u topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java:1.3 topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java:1.4 --- topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java:1.3 Mon Jul 25 14:14:48 2005 +++ topia/src/java/org/codelutin/topia/persistence/PersistenceStorageJDBC.java Mon Jul 25 15:19:48 2005 @@ -23,9 +23,9 @@ * Created: 20 juillet 2005 15:25:06 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2005/07/25 14:14:48 $ + * Last update: $Date: 2005/07/25 15:19:48 $ * by : $Author: bpoussin $ */ @@ -142,8 +142,10 @@ "SELECT count(*) FROM management where id='' AND longdate=0;"); SQL_DEFAULT.put(SQL_CREATE_TABLE_MANAGEMENT, "CREATE TABLE management (id text, longdate bigint, class text, isNew boolean, isDeleted boolean, schemaVersion bigint, PRIMARY KEY (id, longdate));"); + // sans doute faire une suppression en cascade lors que la cle(id, date), n'existe plus dans management + // si supporté par toutes les bases cibles SQL_DEFAULT.put(SQL_CREATE_TABLE_DATA, - "CREATE TABLE data (id text, longdate bigint, field text, value bytea, type text, PRIMARY KEY (id, longdate, field));"); + "CREATE TABLE data (id text, longdate bigint, field text, value bytea, type text, PRIMARY KEY (id, longdate, field), FOREIGN KEY (id, longdate) REFERENCES management (id, longdate) ON DELETE CASCADE ON UPDATE CASCADE);"); SQL_DEFAULT.put(SQL_CREATE_INDEX_MANAGEMENT_ID, "CREATE INDEX index_management_id ON management (id);"); SQL_DEFAULT.put(SQL_CREATE_INDEX_MANAGEMENT_DATE, @@ -185,15 +187,15 @@ SQL_MYSQL.setProperty(SQL_CREATE_TABLE_MANAGEMENT, "CREATE TABLE management (id varchar(100), longdate bigint, class text, isNew bool, isDeleted bool, schemaVersion bigint, PRIMARY KEY (id, longdate));"); SQL_MYSQL.put(SQL_CREATE_TABLE_DATA, - "CREATE TABLE data (id varchar(100), longdate bigint, field varchar(100), value longblob, type text, PRIMARY KEY (id, longdate, field));"); + "CREATE TABLE data (id varchar(100), longdate bigint, field varchar(100), value longblob, type text, PRIMARY KEY (id, longdate, field), FOREIGN KEY (id, longdate) REFERENCES management (id, longdate) ON DELETE CASCADE ON UPDATE CASCADE);"); SQL_MCKOI.setProperty(SQL_CREATE_TABLE_DATA, - "CREATE TABLE data (id text, longdate bigint, field text, value longvarbinary, type text, PRIMARY KEY (id, longdate, field));"); + "CREATE TABLE data (id text, longdate bigint, field text, value longvarbinary, type text, PRIMARY KEY (id, longdate, field), FOREIGN KEY (id, longdate) REFERENCES management (id, longdate) ON DELETE CASCADE ON UPDATE CASCADE);"); SQL_ORACLE.setProperty(SQL_CREATE_TABLE_MANAGEMENT, "CREATE TABLE management (id varchar(100), longdate number(21), class varchar(255), isNew number(1), isDeleted number(1), schemaVersion number(21), PRIMARY KEY (id, longdate));"); SQL_ORACLE.put(SQL_CREATE_TABLE_DATA, - "CREATE TABLE data (id varchar(100), longdate number(21), field varchar(100), value blob, type varchar(255), PRIMARY KEY (id, longdate, field));"); + "CREATE TABLE data (id varchar(100), longdate number(21), field varchar(100), value blob, type varchar(255), PRIMARY KEY (id, longdate, field), FOREIGN KEY (id, longdate) REFERENCES management (id, longdate) ON DELETE CASCADE ON UPDATE CASCADE);"); } @@ -766,6 +768,8 @@ } finally { sta.close(); } + // normalement plus besoin avec l'update en cascade + // on le laisse au cas ou sta = conn.prepareStatement(SQL.getProperty(SQL_COMMIT_DATA)); try{ sta.setLong(1, -newtt.getId()); @@ -801,6 +805,10 @@ } finally { sta.close(); } + // normalement pas besoin car suppression en cascade, mais + // par prudence pour l'instant on laisse, surtout + // si plus tard des bases ne supporte pas les suppressions + // en cascade sta = conn.prepareStatement(SQL.getProperty(SQL_ROLLBACK_DATA)); try{ sta.setLong(1, tt.getId()); @@ -855,6 +863,20 @@ */ public void cleanHistory(int depth) throws TopiaPersistenceException { // TODO + // Pour tous les objets plus vieux que la derniere transaction + // - supprimer tous les objets effacés + // delete * from management where isDeleted=true and longdate>0 + // and longdate < + // (select min(longdate) from management where longdate < 0); + // - ne garder que les n(depth) dernier enregistrement de chaque id. + // for(String id: getAllId()){ + // ResultSet rs = SQL_LOAD_HISTORY(id); + // for(int i=0; i 0 and date < rs.longdate; } /**