From c80f34265e4567d3cd8aa626a71e25281a4a2e1f Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Tue, 2 Dec 2008 18:22:29 +0000 Subject: [PATCH] Implementation the Native sequence --- .../org/compiere/db/AdempiereDatabase.java | 2 +- base/src/org/compiere/db/DB_Oracle.java | 6 +++--- base/src/org/compiere/db/DB_PostgreSQL.java | 4 ++-- base/src/org/compiere/model/MSequence.java | 4 ++-- base/src/org/compiere/model/MSysConfig.java | 9 ++++++++ .../process/EnableNativeSequence.java | 21 ++++++++++++++++--- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/base/src/org/compiere/db/AdempiereDatabase.java b/base/src/org/compiere/db/AdempiereDatabase.java index f63367e9bc..9a7c288d39 100644 --- a/base/src/org/compiere/db/AdempiereDatabase.java +++ b/base/src/org/compiere/db/AdempiereDatabase.java @@ -208,7 +208,7 @@ public interface AdempiereDatabase * Create Native Sequence * @param Sequence Name */ - public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start); + public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start, String trxName); /** Create User commands */ diff --git a/base/src/org/compiere/db/DB_Oracle.java b/base/src/org/compiere/db/DB_Oracle.java index 55efbe10ba..469a92f056 100644 --- a/base/src/org/compiere/db/DB_Oracle.java +++ b/base/src/org/compiere/db/DB_Oracle.java @@ -1090,14 +1090,14 @@ public class DB_Oracle implements AdempiereDatabase return m_sequence_id; } - public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start) + public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start , String trxName) { - int no = DB.executeUpdate("CREATE SEQUENCE "+name.toUpperCase() + int no = DB.executeUpdateEx("CREATE SEQUENCE "+name.toUpperCase() + " INCREMENT BY " + increment + " START WITH " + start + " MIN VALUE " + minvalue - + " MAX VALUE " + maxvalue, null); + + " MAX VALUE " + maxvalue, trxName); if(no == -1 ) return false; else diff --git a/base/src/org/compiere/db/DB_PostgreSQL.java b/base/src/org/compiere/db/DB_PostgreSQL.java index 53ee3a3fbb..325daf2e40 100755 --- a/base/src/org/compiere/db/DB_PostgreSQL.java +++ b/base/src/org/compiere/db/DB_PostgreSQL.java @@ -769,14 +769,14 @@ public class DB_PostgreSQL implements AdempiereDatabase return m_sequence_id; } - public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start) + public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start, String trxName) { int no = DB.executeUpdate("CREATE SEQUENCE "+name.toUpperCase() + " INCREMENT " + increment + " MINVALUE " + minvalue + " MAXVALUE " + maxvalue - + " START " + start , null); + + " START " + start , trxName); if(no == -1 ) return false; else diff --git a/base/src/org/compiere/model/MSequence.java b/base/src/org/compiere/model/MSequence.java index c1bc266ec0..676db011e8 100644 --- a/base/src/org/compiere/model/MSequence.java +++ b/base/src/org/compiere/model/MSequence.java @@ -950,11 +950,11 @@ public class MSequence extends X_AD_Sequence seq.setName(TableName); seq.setDescription("Table " + TableName); seq.setIsTableID(true); - seq.save(); + seq.saveEx(); next_id = 1000000; } - if(CConnection.get().getDatabase().createSequence(TableName+"_SEQ", 1, 0 , 99999999, next_id)) + if(CConnection.get().getDatabase().createSequence(TableName+"_SEQ", 1, 0 , 99999999, next_id, trxName)) return true; return false; diff --git a/base/src/org/compiere/model/MSysConfig.java b/base/src/org/compiere/model/MSysConfig.java index ce3082d88e..74dae11be0 100644 --- a/base/src/org/compiere/model/MSysConfig.java +++ b/base/src/org/compiere/model/MSysConfig.java @@ -63,7 +63,16 @@ public class MSysConfig extends X_AD_SysConfig private static CLogger s_log = CLogger.getCLogger (MSysConfig.class); /** Cache */ private static CCache s_cache = new CCache(Table_Name, 40, 0); + /** resetCache */ + private static boolean resetCache = false; + /** Reset Cache + * + */ + public static void resetCache() + { + s_cache.reset(); + } /** * Get system configuration property of type string * @param Name diff --git a/base/src/org/eevolution/process/EnableNativeSequence.java b/base/src/org/eevolution/process/EnableNativeSequence.java index 20b8b1f5f8..bbdcbda320 100644 --- a/base/src/org/eevolution/process/EnableNativeSequence.java +++ b/base/src/org/eevolution/process/EnableNativeSequence.java @@ -24,11 +24,13 @@ import java.util.logging.Level; import org.adempiere.exceptions.AdempiereException; import org.compiere.Adempiere; import org.compiere.model.MSequence; +import org.compiere.model.MSysConfig; import org.compiere.model.MTable; import org.compiere.model.X_AD_Table; import org.compiere.process.SvrProcess; import org.compiere.util.CLogMgt; import org.compiere.util.DB; +import org.compiere.util.Env; import org.compiere.model.Query; /** @@ -48,14 +50,27 @@ public class EnableNativeSequence extends SvrProcess protected String doIt() { - + boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",true,Env.getAD_Client_ID(Env.getCtx())); + + if(SYSTEM_NATIVE_SEQUENCE) + throw new AdempiereException("Native Sequence is Actived"); + else + { + DB.executeUpdateEx("UPDATE AD_SysConfig SET Value='Y' WHERE Name='SYSTEM_NATIVE_SEQUENCE'",null); + MSysConfig.resetCache(); + } + List tables = new Query(getCtx(),X_AD_Table.Table_Name,"", get_TrxName()).list(); for(MTable table : tables) { if(!table.isView()) { - if(MSequence.createTableSequence(getCtx(), table.getTableName(), get_TrxName())) + if(!MSequence.createTableSequence(getCtx(), table.getTableName(), get_TrxName())) + { + DB.executeUpdateEx("UPDATE AD_SysConfig SET Value='N' WHERE Name='SYSTEM_NATIVE_SEQUENCE'",null); + MSysConfig.resetCache(); new AdempiereException("Can not create Native Sequence"); + } else { this.addLog("Create Native Sequence for : "+table.getTableName()); @@ -63,7 +78,7 @@ public class EnableNativeSequence extends SvrProcess } } - DB.executeUpdateEx("UPDATE AD_SysConfig SET Value='Y' WHERE Name='SYSTEM_NATIVE_SEQUENCE'",null); + return "@OK@"; }