Implementation the Native sequence
This commit is contained in:
parent
e194ec8172
commit
c80f34265e
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -63,7 +63,16 @@ public class MSysConfig extends X_AD_SysConfig
|
|||
private static CLogger s_log = CLogger.getCLogger (MSysConfig.class);
|
||||
/** Cache */
|
||||
private static CCache<String, String> s_cache = new CCache<String, String>(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
|
||||
|
|
|
@ -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<MTable> 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@";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue