Implementation the Native sequence
This commit is contained in:
parent
e194ec8172
commit
c80f34265e
|
@ -208,7 +208,7 @@ public interface AdempiereDatabase
|
||||||
* Create Native Sequence
|
* Create Native Sequence
|
||||||
* @param Sequence Name
|
* @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 */
|
/** Create User commands */
|
||||||
|
|
|
@ -1090,14 +1090,14 @@ public class DB_Oracle implements AdempiereDatabase
|
||||||
return m_sequence_id;
|
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
|
+ " INCREMENT BY " + increment
|
||||||
+ " START WITH " + start
|
+ " START WITH " + start
|
||||||
+ " MIN VALUE " + minvalue
|
+ " MIN VALUE " + minvalue
|
||||||
+ " MAX VALUE " + maxvalue, null);
|
+ " MAX VALUE " + maxvalue, trxName);
|
||||||
if(no == -1 )
|
if(no == -1 )
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
|
|
@ -769,14 +769,14 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
||||||
return m_sequence_id;
|
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.executeUpdate("CREATE SEQUENCE "+name.toUpperCase()
|
||||||
+ " INCREMENT " + increment
|
+ " INCREMENT " + increment
|
||||||
+ " MINVALUE " + minvalue
|
+ " MINVALUE " + minvalue
|
||||||
+ " MAXVALUE " + maxvalue
|
+ " MAXVALUE " + maxvalue
|
||||||
+ " START " + start , null);
|
+ " START " + start , trxName);
|
||||||
if(no == -1 )
|
if(no == -1 )
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
|
|
@ -950,11 +950,11 @@ public class MSequence extends X_AD_Sequence
|
||||||
seq.setName(TableName);
|
seq.setName(TableName);
|
||||||
seq.setDescription("Table " + TableName);
|
seq.setDescription("Table " + TableName);
|
||||||
seq.setIsTableID(true);
|
seq.setIsTableID(true);
|
||||||
seq.save();
|
seq.saveEx();
|
||||||
next_id = 1000000;
|
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 true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -63,7 +63,16 @@ public class MSysConfig extends X_AD_SysConfig
|
||||||
private static CLogger s_log = CLogger.getCLogger (MSysConfig.class);
|
private static CLogger s_log = CLogger.getCLogger (MSysConfig.class);
|
||||||
/** Cache */
|
/** Cache */
|
||||||
private static CCache<String, String> s_cache = new CCache<String, String>(Table_Name, 40, 0);
|
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
|
* Get system configuration property of type string
|
||||||
* @param Name
|
* @param Name
|
||||||
|
|
|
@ -24,11 +24,13 @@ import java.util.logging.Level;
|
||||||
import org.adempiere.exceptions.AdempiereException;
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.compiere.Adempiere;
|
import org.compiere.Adempiere;
|
||||||
import org.compiere.model.MSequence;
|
import org.compiere.model.MSequence;
|
||||||
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.model.X_AD_Table;
|
import org.compiere.model.X_AD_Table;
|
||||||
import org.compiere.process.SvrProcess;
|
import org.compiere.process.SvrProcess;
|
||||||
import org.compiere.util.CLogMgt;
|
import org.compiere.util.CLogMgt;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
import org.compiere.model.Query;
|
import org.compiere.model.Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,14 +50,27 @@ public class EnableNativeSequence extends SvrProcess
|
||||||
|
|
||||||
protected String doIt()
|
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();
|
List<MTable> tables = new Query(getCtx(),X_AD_Table.Table_Name,"", get_TrxName()).list();
|
||||||
for(MTable table : tables)
|
for(MTable table : tables)
|
||||||
{
|
{
|
||||||
if(!table.isView())
|
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");
|
new AdempiereException("Can not create Native Sequence");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.addLog("Create Native Sequence for : "+table.getTableName());
|
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@";
|
return "@OK@";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue