IDEMPIERE-5509 Implement readonly query without using Trx - fix issue with native sequences in PostgreSQL (#1815)
This commit is contained in:
parent
61118b8877
commit
07ecea1494
|
@ -61,7 +61,7 @@ public class EnableNativeSequence extends SvrProcess
|
||||||
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 already set");
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the sysconfig key to Y out of trx and reset the cache
|
// update the sysconfig key to Y out of trx and reset the cache
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.adempiere.webui.adwindow.ADWindow;
|
import org.adempiere.webui.adwindow.ADWindow;
|
||||||
import org.adempiere.webui.adwindow.AbstractADWindowContent;
|
import org.adempiere.webui.adwindow.AbstractADWindowContent;
|
||||||
import org.adempiere.webui.apps.AEnv;
|
import org.adempiere.webui.apps.AEnv;
|
||||||
|
@ -642,6 +643,8 @@ public class ValuePreference extends Window implements EventListener<Event>
|
||||||
int Client_ID = cbClient.isChecked() ? m_AD_Client_ID : 0;
|
int Client_ID = cbClient.isChecked() ? m_AD_Client_ID : 0;
|
||||||
int Org_ID = cbOrg.isChecked() ? m_AD_Org_ID : 0;
|
int Org_ID = cbOrg.isChecked() ? m_AD_Org_ID : 0;
|
||||||
int AD_Preference_ID = DB.getNextID(m_ctx, "AD_Preference", null);
|
int AD_Preference_ID = DB.getNextID(m_ctx, "AD_Preference", null);
|
||||||
|
if (AD_Preference_ID < 0)
|
||||||
|
throw new AdempiereException("Cannot obtain sequence for AD_Preference");
|
||||||
//
|
//
|
||||||
StringBuilder sql = new StringBuilder ("INSERT INTO AD_Preference ("
|
StringBuilder sql = new StringBuilder ("INSERT INTO AD_Preference ("
|
||||||
+ "AD_Preference_ID, AD_Preference_UU, AD_Client_ID, AD_Org_ID, IsActive, Created,CreatedBy,Updated,UpdatedBy,"
|
+ "AD_Preference_ID, AD_Preference_UU, AD_Client_ID, AD_Org_ID, IsActive, Created,CreatedBy,Updated,UpdatedBy,"
|
||||||
|
|
|
@ -871,7 +871,24 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNextID(String name, String trxName) {
|
public int getNextID(String name, String trxName) {
|
||||||
int m_sequence_id = DB.getSQLValueEx(trxName, "SELECT nextval('"+name.toLowerCase()+"')");
|
Trx trx = null;
|
||||||
|
int m_sequence_id = -1;
|
||||||
|
try {
|
||||||
|
// avoid cannot execute nextval() in a read-only transaction
|
||||||
|
if (trxName == null) {
|
||||||
|
trxName = Trx.createTrxName("getNextval");
|
||||||
|
trx = Trx.get(trxName, true);
|
||||||
|
}
|
||||||
|
m_sequence_id = DB.getSQLValueEx(trxName, "SELECT nextval('"+name.toLowerCase()+"')");
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (trx != null) {
|
||||||
|
trx.rollback();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (trx != null) {
|
||||||
|
trx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
return m_sequence_id;
|
return m_sequence_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue