1008086 - External (non-plugin) 2Pack automation

(NPE potential issue)
This commit is contained in:
Diego Ruiz 2017-06-22 12:27:19 +02:00
parent c42958d700
commit 200eea4344
4 changed files with 49 additions and 29 deletions

View File

@ -21,6 +21,7 @@ import org.compiere.model.MSysConfig;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -68,7 +69,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
public abstract String getName();
public boolean getDBLock() {
public boolean getDBLock() throws AdempiereSystemError {
int timeout = MSysConfig.getIntValue(MSysConfig.AUTOMATIC_PACKIN_TIMEOUT, 120);
int maxAttempts = MSysConfig.getIntValue(MSysConfig.AUTOMATIC_PACKIN_RETRIES, 5);
boolean lockAcquired = false;
@ -86,15 +87,19 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
Trx.get(trxName, false).close();
}
private boolean getDBLock(int timeout) {
private boolean getDBLock(int timeout) throws AdempiereSystemError {
return DB.getDatabase().forUpdate(getLockPO(), timeout);
}
private PO getLockPO() {
private PO getLockPO() throws AdempiereSystemError {
MSysConfig sysconfig = new Query(Env.getCtx(), MSysConfig.Table_Name,
"Name=? AND AD_Client_ID=0", null)
.setParameters(MSysConfig.AUTOMATIC_PACKIN_PROCESSING)
.first();
.firstOnly();
if (sysconfig == null) {
throw new AdempiereSystemError(MSysConfig.AUTOMATIC_PACKIN_PROCESSING + " SysConfig does not exist");
}
trxName = Trx.createTrxName("ActSysTrx");
sysconfig.set_TrxName(trxName);
return sysconfig;

View File

@ -14,6 +14,7 @@ import org.compiere.model.Query;
import org.compiere.model.ServerStateChangeEvent;
import org.compiere.model.ServerStateChangeListener;
import org.compiere.model.X_AD_Package_Imp;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.osgi.framework.BundleContext;
@ -56,6 +57,7 @@ public class AdempiereActivator extends AbstractActivator {
q.setParameters(new Object[] { getName(), version + "%" });
X_AD_Package_Imp pkg = q.first();
if (pkg == null) {
try {
if (getDBLock()) {
System.out.println("Installing " + getName() + " " + version + " ...");
packIn();
@ -65,6 +67,9 @@ public class AdempiereActivator extends AbstractActivator {
} else {
logger.log(Level.SEVERE, "Could not acquire the DB lock to install:" + getName());
}
} catch (AdempiereSystemError e) {
e.printStackTrace();
}
} else {
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + version + " was installed: "
+ pkg.getCreated());

View File

@ -32,6 +32,7 @@ import org.compiere.model.Query;
import org.compiere.model.ServerStateChangeEvent;
import org.compiere.model.ServerStateChangeListener;
import org.compiere.model.X_AD_Package_Imp;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Trx;
@ -184,6 +185,7 @@ public class Incremental2PackActivator extends AbstractActivator {
}
});
try {
if (getDBLock()) {
for(TwoPackEntry entry : list) {
if (!installedVersions.contains(entry.version)) {
@ -197,6 +199,9 @@ public class Incremental2PackActivator extends AbstractActivator {
} else {
logger.log(Level.SEVERE, "Could not acquire the DB lock to install:" + getName());
}
} catch (AdempiereSystemError e) {
e.printStackTrace();
}
}
private String extractVersionString(URL u) {

View File

@ -32,6 +32,7 @@ import org.compiere.model.Query;
import org.compiere.model.ServerStateChangeEvent;
import org.compiere.model.ServerStateChangeListener;
import org.compiere.model.X_AD_Package_Imp;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Util;
@ -157,6 +158,7 @@ public class Version2PackActivator extends AbstractActivator {
}
});
try {
if (getDBLock()) {
for(TwoPackEntry entry : list) {
if (!packIn(entry.url)) {
@ -168,6 +170,9 @@ public class Version2PackActivator extends AbstractActivator {
} else {
logger.log(Level.SEVERE, "Could not acquire the DB lock to install:" + getName());
}
} catch (AdempiereSystemError e) {
e.printStackTrace();
}
}
private String extractVersionString(URL u) {