BF [ 2970200 ] Enable Native Sequences not working
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2970200
This commit is contained in:
parent
1784eebf02
commit
a1942f8043
|
|
@ -1092,8 +1092,8 @@ public class DB_Oracle implements AdempiereDatabase
|
||||||
|
|
||||||
public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start , String trxName)
|
public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start , String trxName)
|
||||||
{
|
{
|
||||||
|
int no = DB.executeUpdate("DROP SEQUENCE "+name.toUpperCase(), trxName);
|
||||||
int no = DB.executeUpdateEx("CREATE SEQUENCE "+name.toUpperCase()
|
no = DB.executeUpdateEx("CREATE SEQUENCE "+name.toUpperCase()
|
||||||
+ " MINVALUE " + minvalue
|
+ " MINVALUE " + minvalue
|
||||||
+ " MAXVALUE " + maxvalue
|
+ " MAXVALUE " + maxvalue
|
||||||
+ " START WITH " + start
|
+ " START WITH " + start
|
||||||
|
|
|
||||||
|
|
@ -776,12 +776,29 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
||||||
|
|
||||||
public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start, String trxName)
|
public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start, String trxName)
|
||||||
{
|
{
|
||||||
|
// Check if Sequence exists
|
||||||
int no = DB.executeUpdate("CREATE SEQUENCE "+name.toUpperCase()
|
final int cnt = DB.getSQLValueEx(trxName, "SELECT COUNT(*) FROM pg_class WHERE UPPER(relname)=? AND relkind='S'", name.toUpperCase());
|
||||||
+ " INCREMENT " + increment
|
final int no;
|
||||||
+ " MINVALUE " + minvalue
|
//
|
||||||
+ " MAXVALUE " + maxvalue
|
// New Sequence
|
||||||
+ " START " + start , trxName);
|
if (cnt == 0)
|
||||||
|
{
|
||||||
|
no = DB.executeUpdate("CREATE SEQUENCE "+name.toUpperCase()
|
||||||
|
+ " INCREMENT " + increment
|
||||||
|
+ " MINVALUE " + minvalue
|
||||||
|
+ " MAXVALUE " + maxvalue
|
||||||
|
+ " START " + start , trxName);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Already existing sequence => ALTER
|
||||||
|
else
|
||||||
|
{
|
||||||
|
no = DB.executeUpdate("ALTER SEQUENCE "+name.toUpperCase()
|
||||||
|
+ " INCREMENT " + increment
|
||||||
|
+ " MINVALUE " + minvalue
|
||||||
|
+ " MAXVALUE " + maxvalue
|
||||||
|
+ " RESTART " + start , trxName);
|
||||||
|
}
|
||||||
if(no == -1 )
|
if(no == -1 )
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -19,23 +19,28 @@ package org.eevolution.process;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
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.MPInstance;
|
||||||
import org.compiere.model.MSequence;
|
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 org.compiere.model.X_AD_Table;
|
import org.compiere.model.X_AD_Table;
|
||||||
|
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.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable Native Sequence
|
* Enable Native Sequence
|
||||||
*
|
*
|
||||||
* @author Victor Perez, e-Evolution, S.C.
|
* @author Victor Perez, e-Evolution, S.C.
|
||||||
|
* @author Teo Sarca, teo.sarca@gmail.com
|
||||||
*/
|
*/
|
||||||
public class EnableNativeSequence extends SvrProcess
|
public class EnableNativeSequence extends SvrProcess
|
||||||
{
|
{
|
||||||
|
|
@ -50,36 +55,67 @@ public class EnableNativeSequence extends SvrProcess
|
||||||
protected String doIt()
|
protected String doIt()
|
||||||
{
|
{
|
||||||
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",false);
|
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",false);
|
||||||
|
|
||||||
if(SYSTEM_NATIVE_SEQUENCE)
|
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);
|
throw new AdempiereException("Native Sequence is Actived");
|
||||||
MSysConfig.resetCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MTable> tables = new Query(getCtx(),X_AD_Table.Table_Name,"", get_TrxName()).list();
|
setSystemNativeSequence(true);
|
||||||
for(MTable table : tables)
|
boolean ok = false;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if(!table.isView())
|
createSequence("AD_Sequence", null);
|
||||||
{
|
createSequence("AD_Issue", null);
|
||||||
if(!MSequence.createTableSequence(getCtx(), table.getTableName(), get_TrxName()))
|
createSequence("AD_ChangeLog", null);
|
||||||
{
|
//
|
||||||
DB.executeUpdateEx("UPDATE AD_SysConfig SET Value='N' WHERE Name='SYSTEM_NATIVE_SEQUENCE'",null);
|
final String whereClause = "TableName NOT IN ('AD_Sequence', 'AD_Issue', 'AD_ChangeLog')";
|
||||||
MSysConfig.resetCache();
|
List<MTable> tables = new Query(getCtx(),X_AD_Table.Table_Name, whereClause, get_TrxName())
|
||||||
new AdempiereException("Can not create Native Sequence");
|
.setOrderBy("TableName")
|
||||||
}
|
.list();
|
||||||
else
|
for(MTable table : tables)
|
||||||
{
|
{
|
||||||
this.addLog("Create Native Sequence for : "+table.getTableName());
|
createSequence(table, get_TrxName());
|
||||||
}
|
}
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
setSystemNativeSequence(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return "@OK@";
|
return "@OK@";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createSequence(MTable table, String trxName)
|
||||||
|
{
|
||||||
|
if(!table.isView())
|
||||||
|
{
|
||||||
|
if(!MSequence.createTableSequence(getCtx(), table.getTableName(), trxName))
|
||||||
|
{
|
||||||
|
throw new AdempiereException("Can not create Native Sequence for table "+table.getTableName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addLog("Create Native Sequence for : "+table.getTableName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void createSequence(String tableName, String 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
|
||||||
|
|
@ -88,15 +124,25 @@ public class EnableNativeSequence extends SvrProcess
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
|
Adempiere.startupEnvironment(true);
|
||||||
try {
|
CLogMgt.setLevel(Level.INFO);
|
||||||
Adempiere.startupEnvironment(true);
|
|
||||||
CLogMgt.setLevel(Level.ALL);
|
Properties ctx = Env.getCtx();
|
||||||
EnableNativeSequence seqs = new EnableNativeSequence();
|
int AD_Process_ID = 53156; // HARDCODED
|
||||||
seqs.doIt();
|
|
||||||
} catch (Exception e) {
|
MPInstance pinstance = new MPInstance(ctx, AD_Process_ID, -1);
|
||||||
// TODO Auto-generated catch block
|
pinstance.saveEx();
|
||||||
e.printStackTrace();
|
|
||||||
|
ProcessInfo pi = new ProcessInfo("", AD_Process_ID, 0, 0);
|
||||||
|
pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
|
||||||
|
pi.setAD_User_ID(Env.getAD_User_ID(ctx));
|
||||||
|
pi.setAD_PInstance_ID(pinstance.getAD_PInstance_ID());
|
||||||
|
//
|
||||||
|
EnableNativeSequence proc = new EnableNativeSequence();
|
||||||
|
proc.startProcess(ctx, pi, null);
|
||||||
|
if (pi.isError())
|
||||||
|
{
|
||||||
|
throw new AdempiereException(pi.getSummary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue