IDEMPIERE-422 Complete Native Sequence feature / Fixing as latest changes on MSequence for IDEMPIERE-332 broke native sequence feature
This commit is contained in:
parent
f22faccda1
commit
988f40d193
|
@ -682,6 +682,25 @@ public class MSequence extends X_AD_Sequence
|
||||||
{
|
{
|
||||||
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue(MSysConfig.SYSTEM_NATIVE_SEQUENCE,false);
|
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);
|
MSequence seq = new MSequence (ctx, 0, trxName);
|
||||||
if (tableID)
|
if (tableID)
|
||||||
seq.setClientOrg(0, 0);
|
seq.setClientOrg(0, 0);
|
||||||
|
@ -697,13 +716,6 @@ public class MSequence extends X_AD_Sequence
|
||||||
}
|
}
|
||||||
seq.setIsTableID(tableID);
|
seq.setIsTableID(tableID);
|
||||||
seq.saveEx();
|
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;
|
return true;
|
||||||
} // createTableSequence
|
} // createTableSequence
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all hardcoded ID used in the code
|
* List all hardcoded ID used in the code
|
||||||
* @author Carlos Ruiz, Nicolas Micoud, ...
|
* @author Carlos Ruiz, Nicolas Micoud, ...
|
||||||
|
@ -146,5 +147,6 @@ public class SystemIDs
|
||||||
public final static int WINDOW_WAREHOUSE_LOCATOR = 139;
|
public final static int WINDOW_WAREHOUSE_LOCATOR = 139;
|
||||||
public final static int WINDOW_WINDOW_TAB_FIELD = 102;
|
public final static int WINDOW_WINDOW_TAB_FIELD = 102;
|
||||||
|
|
||||||
public final static int SYSCONFIG_USER_HASH_PASSWORD = 200013;
|
public final static int SYSCONFIG_USER_HASH_PASSWORD = 200013;
|
||||||
|
public final static int SYSCONFIG_SYSTEM_NATIVE_SEQUENCE = 50016;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -29,12 +31,11 @@ import org.compiere.model.MSequence;
|
||||||
import org.compiere.model.MSysConfig;
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.model.Query;
|
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.model.X_AD_Table;
|
||||||
import org.compiere.process.ProcessInfo;
|
import org.compiere.process.ProcessInfo;
|
||||||
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.Env;
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,16 +54,20 @@ public class EnableNativeSequence extends SvrProcess
|
||||||
{
|
{
|
||||||
} // prepare
|
} // prepare
|
||||||
|
|
||||||
protected String doIt()
|
protected String doIt() throws Exception
|
||||||
{
|
{
|
||||||
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue(MSysConfig.SYSTEM_NATIVE_SEQUENCE,false);
|
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue(MSysConfig.SYSTEM_NATIVE_SEQUENCE,false);
|
||||||
if(SYSTEM_NATIVE_SEQUENCE)
|
if (SYSTEM_NATIVE_SEQUENCE)
|
||||||
{
|
{
|
||||||
throw new AdempiereException("Native Sequence is Actived");
|
throw new AdempiereException("Native Sequence is Actived");
|
||||||
}
|
}
|
||||||
|
|
||||||
setSystemNativeSequence(true);
|
// update the sysconfig key to Y out of trx and reset the cache
|
||||||
boolean ok = false;
|
MSysConfig conf = new MSysConfig(getCtx(), SystemIDs.SYSCONFIG_SYSTEM_NATIVE_SEQUENCE, null);
|
||||||
|
conf.setValue("Y");
|
||||||
|
conf.saveEx();
|
||||||
|
MSysConfig.resetCache();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
createSequence("AD_Sequence", null);
|
createSequence("AD_Sequence", null);
|
||||||
|
@ -77,14 +82,11 @@ public class EnableNativeSequence extends SvrProcess
|
||||||
{
|
{
|
||||||
createSequence(table, get_TrxName());
|
createSequence(table, get_TrxName());
|
||||||
}
|
}
|
||||||
ok = true;
|
} catch (Exception e) {
|
||||||
}
|
// reset to N on exception
|
||||||
finally
|
conf.setValue("N");
|
||||||
{
|
conf.saveEx();
|
||||||
if (!ok)
|
throw e;
|
||||||
{
|
|
||||||
setSystemNativeSequence(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "@OK@";
|
return "@OK@";
|
||||||
|
@ -109,15 +111,6 @@ public class EnableNativeSequence extends SvrProcess
|
||||||
createSequence(MTable.get(getCtx(), tableName), trxName);
|
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
|
* Main test
|
||||||
* @param args
|
* @param args
|
||||||
|
|
Loading…
Reference in New Issue