IDEMPIERE-422 Complete Native Sequence feature / Fixing as latest changes on MSequence for IDEMPIERE-332 broke native sequence feature

This commit is contained in:
Carlos Ruiz 2012-09-20 10:57:45 -05:00
parent f22faccda1
commit 988f40d193
3 changed files with 38 additions and 31 deletions

View File

@ -682,6 +682,25 @@ public class MSequence extends X_AD_Sequence
{
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue(MSysConfig.SYSTEM_NATIVE_SEQUENCE,false);
if (tableID && SYSTEM_NATIVE_SEQUENCE)
{
int next_id = MSequence.getNextID(Env.getAD_Client_ID(ctx), TableName, trxName);
if (next_id == -1)
{
MSequence seq = new MSequence (ctx, 0, trxName);
seq.setClientOrg(0, 0);
seq.setName(TableName);
seq.setDescription("Table " + TableName);
seq.setIsTableID(tableID);
seq.saveEx();
next_id = seq.getCurrentNext();
}
if (! CConnection.get().getDatabase().createSequence(TableName+"_SQ", 1, 0 , 99999999, next_id, trxName))
return false;
return true;
}
MSequence seq = new MSequence (ctx, 0, trxName);
if (tableID)
seq.setClientOrg(0, 0);
@ -698,13 +717,6 @@ public class MSequence extends X_AD_Sequence
seq.setIsTableID(tableID);
seq.saveEx();
if (tableID && SYSTEM_NATIVE_SEQUENCE)
{
int next_id = seq.getCurrentNext();
if (! CConnection.get().getDatabase().createSequence(TableName+"_SQ", 1, 0 , 99999999, next_id, trxName))
return false;
}
return true;
} // createTableSequence

View File

@ -16,6 +16,7 @@
*****************************************************************************/
package org.compiere.model;
/**
* List all hardcoded ID used in the code
* @author Carlos Ruiz, Nicolas Micoud, ...
@ -147,4 +148,5 @@ public class SystemIDs
public final static int WINDOW_WINDOW_TAB_FIELD = 102;
public final static int SYSCONFIG_USER_HASH_PASSWORD = 200013;
public final static int SYSCONFIG_SYSTEM_NATIVE_SEQUENCE = 50016;
}

View File

@ -18,6 +18,8 @@ package org.eevolution.process;
import static org.compiere.model.SystemIDs.PROCESS_AD_NATIVE_SEQUENCE_ENABLE;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -29,12 +31,11 @@ import org.compiere.model.MSequence;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.Query;
import static org.compiere.model.SystemIDs.*;
import org.compiere.model.SystemIDs;
import org.compiere.model.X_AD_Table;
import org.compiere.process.ProcessInfo;
import org.compiere.process.SvrProcess;
import org.compiere.util.CLogMgt;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
@ -53,7 +54,7 @@ public class EnableNativeSequence extends SvrProcess
{
} // prepare
protected String doIt()
protected String doIt() throws Exception
{
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue(MSysConfig.SYSTEM_NATIVE_SEQUENCE,false);
if (SYSTEM_NATIVE_SEQUENCE)
@ -61,8 +62,12 @@ public class EnableNativeSequence extends SvrProcess
throw new AdempiereException("Native Sequence is Actived");
}
setSystemNativeSequence(true);
boolean ok = false;
// update the sysconfig key to Y out of trx and reset the cache
MSysConfig conf = new MSysConfig(getCtx(), SystemIDs.SYSCONFIG_SYSTEM_NATIVE_SEQUENCE, null);
conf.setValue("Y");
conf.saveEx();
MSysConfig.resetCache();
try
{
createSequence("AD_Sequence", null);
@ -77,14 +82,11 @@ public class EnableNativeSequence extends SvrProcess
{
createSequence(table, get_TrxName());
}
ok = true;
}
finally
{
if (!ok)
{
setSystemNativeSequence(false);
}
} catch (Exception e) {
// reset to N on exception
conf.setValue("N");
conf.saveEx();
throw e;
}
return "@OK@";
@ -109,15 +111,6 @@ public class EnableNativeSequence extends SvrProcess
createSequence(MTable.get(getCtx(), tableName), trxName);
}
private void setSystemNativeSequence(boolean value)
{
DB.executeUpdateEx("UPDATE AD_SysConfig SET Value=? WHERE Name='SYSTEM_NATIVE_SEQUENCE'",
new Object[]{value ? "Y" : "N"},
null // trxName
);
MSysConfig.resetCache();
}
/**
* Main test
* @param args