use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class XmlReader method getElectricalStimulus.
/**
* This method process Electrical Stimulus, also called Clamps.
* Creation date: (6/6/2002 4:46:18 PM)
* @return cbit.vcell.mapping.ElectricalStimulus
* @param param org.jdom.Element
*/
private ElectricalStimulus getElectricalStimulus(Element param, SimulationContext currentSimulationContext) throws XmlParseException {
ElectricalStimulus clampStimulus = null;
// get name
// String name = unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
// get Electrode
Electrode electrode = getElectrode(param.getChild(XMLTags.ElectrodeTag, vcNamespace), currentSimulationContext);
if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.VoltageClampTag)) {
// is a voltage clamp
clampStimulus = new VoltageClampStimulus(electrode, "voltClampElectrode", new Expression(0.0), currentSimulationContext);
} else if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.CurrentDensityClampTag) || param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.CurrentDensityClampTag_oldName)) {
// is a current density clamp
clampStimulus = new CurrentDensityClampStimulus(electrode, "currDensityClampElectrode", new Expression(0.0), currentSimulationContext);
} else if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.TotalCurrentClampTag)) {
// is a "total" current clamp
clampStimulus = new TotalCurrentClampStimulus(electrode, "totalCurrClampElectrode", new Expression(0.0), currentSimulationContext);
}
try {
// transaction begin flag ... yeah, this is a hack
clampStimulus.reading(true);
// Read all of the parameters
List<Element> list = param.getChildren(XMLTags.ParameterTag, vcNamespace);
// add constants that may be used in the electrical stimulus.
VariableHash varHash = new VariableHash();
Model model = currentSimulationContext.getModel();
addResevedSymbols(varHash, model);
//
for (Element xmlParam : list) {
String paramName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
String role = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
String paramExpStr = xmlParam.getText();
Expression paramExp = unMangleExpression(paramExpStr);
try {
if (varHash.getVariable(paramName) == null) {
Domain domain = null;
varHash.addVariable(new Function(paramName, paramExp, domain));
} else {
if (model.getReservedSymbolByName(paramName) != null) {
varHash.removeVariable(paramName);
Domain domain = null;
varHash.addVariable(new Function(paramName, paramExp, domain));
}
}
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("error reordering parameters according to dependencies:", e);
}
LocalParameter tempParam = null;
if (!role.equals(XMLTags.ParamRoleUserDefinedTag)) {
if (role.equals(XMLTags.ParamRoleTotalCurrentTag)) {
if (clampStimulus instanceof TotalCurrentClampStimulus) {
tempParam = ((TotalCurrentClampStimulus) clampStimulus).getCurrentParameter();
} else {
varHash.removeVariable(paramName);
continue;
}
} else if (role.equals(XMLTags.ParamRoleTotalCurrentDensityTag) || role.equals(XMLTags.ParamRoleTotalCurrentDensityOldNameTag)) {
if (clampStimulus instanceof CurrentDensityClampStimulus) {
tempParam = ((CurrentDensityClampStimulus) clampStimulus).getCurrentDensityParameter();
} else {
varHash.removeVariable(paramName);
continue;
}
} else if (role.equals(XMLTags.ParamRolePotentialDifferenceTag)) {
if (clampStimulus instanceof VoltageClampStimulus) {
tempParam = ((VoltageClampStimulus) clampStimulus).getVoltageParameter();
} else {
varHash.removeVariable(paramName);
continue;
}
}
} else {
continue;
}
if (tempParam == null) {
throw new XmlParseException("parameter with role '" + role + "' not found in electricalstimulus");
}
//
if (!tempParam.getName().equals(paramName)) {
LocalParameter multNameParam = clampStimulus.getLocalParameter(paramName);
int n = 0;
while (multNameParam != null) {
String tempName = paramName + "_" + n++;
clampStimulus.renameParameter(paramName, tempName);
multNameParam = clampStimulus.getLocalParameter(tempName);
}
clampStimulus.renameParameter(tempParam.getName(), paramName);
}
}
//
// create unresolved parameters for all unresolved symbols
//
String unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
while (unresolvedSymbol != null) {
try {
Domain domain = null;
// will turn into an UnresolvedParameter.
varHash.addVariable(new Function(unresolvedSymbol, new Expression(0.0), domain));
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
clampStimulus.addUnresolvedParameter(unresolvedSymbol);
unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
}
Variable[] sortedVariables = varHash.getTopologicallyReorderedVariables();
ModelUnitSystem modelUnitSystem = model.getUnitSystem();
for (int i = sortedVariables.length - 1; i >= 0; i--) {
if (sortedVariables[i] instanceof Function) {
Function paramFunction = (Function) sortedVariables[i];
Element xmlParam = null;
for (int j = 0; j < list.size(); j++) {
Element tempParam = (Element) list.get(j);
if (paramFunction.getName().equals(unMangle(tempParam.getAttributeValue(XMLTags.NameAttrTag)))) {
xmlParam = tempParam;
break;
}
}
if (xmlParam == null) {
// must have been an unresolved parameter
continue;
}
String symbol = xmlParam.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
VCUnitDefinition unit = null;
if (symbol != null) {
unit = modelUnitSystem.getInstance(symbol);
}
LocalParameter tempParam = clampStimulus.getLocalParameter(paramFunction.getName());
if (tempParam == null) {
clampStimulus.addUserDefinedParameter(paramFunction.getName(), paramFunction.getExpression(), unit);
} else {
if (tempParam.getExpression() != null) {
// if the expression is null, it should remain null.
clampStimulus.setParameterValue(tempParam, paramFunction.getExpression());
}
tempParam.setUnitDefinition(unit);
}
}
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while setting parameters for simContext : " + currentSimulationContext.getName(), e);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while settings parameters for simContext : " + currentSimulationContext.getName(), e);
} finally {
clampStimulus.reading(false);
}
return clampStimulus;
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class XmlReader method getPointSubDomain.
private PointSubDomain getPointSubDomain(Element param, MathDescription mathDesc) throws XmlParseException {
// get name
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
// *** create new pointSubDomain object ***
PointSubDomain pointDomain = new PointSubDomain(name);
// add OdeEquations
Iterator<Element> iterator = param.getChildren(XMLTags.OdeEquationTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
try {
pointDomain.addEquation(getOdeEquation(tempElement, mathDesc));
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A MathException was fired when adding an OdeEquation to the FilamentSubDomain " + name, e);
}
}
String temp = param.getChildText(XMLTags.PositionXTag, vcNamespace);
if (temp != null && temp.length() > 0) {
pointDomain.setPositionX(unMangleExpression(temp));
}
temp = param.getChildText(XMLTags.PositionYTag, vcNamespace);
if (temp != null && temp.length() > 0) {
pointDomain.setPositionY(unMangleExpression(temp));
}
temp = param.getChildText(XMLTags.PositionZTag, vcNamespace);
if (temp != null && temp.length() > 0) {
pointDomain.setPositionZ(unMangleExpression(temp));
}
return pointDomain;
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class XmlReader method getFastSystem.
/**
* This method returns a FastSystemImplicit from a XML Element.
* Creation date: (5/18/2001 2:38:56 PM)
* @return cbit.vcell.math.FastSystemImplicit
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private FastSystem getFastSystem(Element param, MathDescription mathDesc) throws XmlParseException {
// Create a new FastSystem
FastSystem fastSystem = new FastSystem(mathDesc);
// Process the FastInvariants
Iterator<Element> iterator = param.getChildren(XMLTags.FastInvariantTag, vcNamespace).iterator();
FastInvariant fastInvariant = null;
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
String temp = tempElement.getText();
try {
Expression newExp = unMangleExpression(temp);
fastInvariant = new FastInvariant(newExp);
fastSystem.addFastInvariant(fastInvariant);
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding the FastInvariant " + fastInvariant + ", to a FastSystem!" + " : ", e);
}
}
// Process the FastRate
iterator = param.getChildren(XMLTags.FastRateTag, vcNamespace).iterator();
FastRate fastRate = null;
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
String temp = tempElement.getText();
try {
Expression newExp = unMangleExpression(temp);
fastRate = new FastRate(newExp);
fastSystem.addFastRate(fastRate);
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding the FastRate " + fastRate + ", to a FastSystem!", e);
}
}
return fastSystem;
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class MathVerifier method testMathGeneration.
public MathGenerationResults testMathGeneration(KeyValue simContextKey) throws SQLException, ObjectNotFoundException, DataAccessException, XmlParseException, MappingException, MathException, MatrixException, ExpressionException, ModelException, PropertyVetoException {
User adminUser = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new org.vcell.util.document.KeyValue(PropertyLoader.ADMINISTRATOR_ID));
if (lg.isTraceEnabled())
lg.trace("Testing SimContext with key '" + simContextKey + "'");
// get biomodel refs
java.sql.Connection con = null;
java.sql.Statement stmt = null;
con = conFactory.getConnection(new Object());
cbit.vcell.modeldb.BioModelSimContextLinkTable bmscTable = cbit.vcell.modeldb.BioModelSimContextLinkTable.table;
cbit.vcell.modeldb.BioModelTable bmTable = cbit.vcell.modeldb.BioModelTable.table;
cbit.vcell.modeldb.UserTable userTable = cbit.vcell.modeldb.UserTable.table;
String sql = "SELECT " + bmscTable.bioModelRef.getQualifiedColName() + "," + bmTable.ownerRef.getQualifiedColName() + "," + userTable.userid.getQualifiedColName() + " FROM " + bmscTable.getTableName() + "," + bmTable.getTableName() + "," + userTable.getTableName() + " WHERE " + bmscTable.simContextRef.getQualifiedColName() + " = " + simContextKey + " AND " + bmTable.id.getQualifiedColName() + " = " + bmscTable.bioModelRef.getQualifiedColName() + " AND " + bmTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
ArrayList<KeyValue> bioModelKeys = new ArrayList<KeyValue>();
stmt = con.createStatement();
User owner = null;
try {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
KeyValue key = new KeyValue(rset.getBigDecimal(bmscTable.bioModelRef.getUnqualifiedColName()));
bioModelKeys.add(key);
KeyValue ownerRef = new KeyValue(rset.getBigDecimal(bmTable.ownerRef.getUnqualifiedColName()));
String userid = rset.getString(userTable.userid.getUnqualifiedColName());
owner = new User(userid, ownerRef);
}
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
// use the first biomodel...
if (bioModelKeys.size() == 0) {
throw new RuntimeException("zombie simContext ... no biomodels");
}
BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(owner, bioModelKeys.get(0));
//
// read in the BioModel from the database
//
BigString bioModelXML = dbServerImpl.getBioModelXML(owner, bioModelInfo.getVersion().getVersionKey());
BioModel bioModelFromDB = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModelFromDB.refreshDependencies();
bioModelNewMath.refreshDependencies();
//
// get all Simulations for this model
//
Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
//
// ---> only for the SimContext we started with...
// recompute mathDescription, and verify it is equivalent
// then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
//
SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
SimulationContext simContextFromDB = null;
SimulationContext simContextNewMath = null;
for (int k = 0; k < simContextsFromDB.length; k++) {
// find it...
if (simContextsFromDB[k].getKey().equals(simContextKey)) {
simContextFromDB = simContextsFromDB[k];
simContextNewMath = simContextsNewMath[k];
break;
}
}
if (simContextFromDB == null) {
throw new RuntimeException("BioModel referred to by this SimContext does not contain this SimContext");
} else {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
try {
if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
//
// updated mathDescription loaded into copy of bioModel, then test for equivalence.
//
cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
MathDescription mathDesc_latest = mathMapping.getMathDescription();
MathMapping_4_8 mathMapping_4_8 = new MathMapping_4_8(simContextNewMath);
MathDescription mathDesc_4_8 = mathMapping_4_8.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):\n");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>\n");
}
issueString = buffer.toString();
}
simContextNewMath.setMathDescription(mathDesc_latest);
MathCompareResults mathCompareResults_latest = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, mathDesc_latest);
MathCompareResults mathCompareResults_4_8 = null;
try {
mathCompareResults_4_8 = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, mathDesc_4_8);
} catch (Exception e) {
e.printStackTrace(System.out);
mathCompareResults_4_8 = new MathCompareResults(Decision.MathDifferent_FAILURE_UNKNOWN, e.getMessage());
}
return new MathGenerationResults(bioModelFromDB, simContextFromDB, origMathDesc, mathDesc_latest, mathCompareResults_latest, mathDesc_4_8, mathCompareResults_4_8);
}
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class MathVerifier method scanBioModels.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
*/
public void scanBioModels(boolean bUpdateDatabase, KeyValue[] bioModelKeys) throws MathException, MappingException, SQLException, DataAccessException, ModelException, ExpressionException {
java.util.Calendar calendar = java.util.GregorianCalendar.getInstance();
// calendar.set(2002,java.util.Calendar.MAY,7+1);
calendar.set(2002, java.util.Calendar.JULY, 1);
final java.util.Date fluxCorrectionOrDisablingBugFixDate = calendar.getTime();
// calendar.set(2001,java.util.Calendar.JUNE,13+1);
calendar.set(2002, java.util.Calendar.JANUARY, 1);
final java.util.Date totalVolumeCorrectionFixDate = calendar.getTime();
User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
for (int i = 0; i < bioModelKeys.length; i++) {
BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(user, bioModelKeys[i]);
if (lg.isTraceEnabled())
lg.trace("Testing bioModel with key '" + bioModelKeys[i] + "'");
java.sql.Connection con = null;
java.sql.Statement stmt = null;
try {
//
// read in the BioModel from the database
//
BigString bioModelXML = dbServerImpl.getBioModelXML(user, bioModelInfo.getVersion().getVersionKey());
BioModel bioModelFromDB = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModelFromDB.refreshDependencies();
bioModelNewMath.refreshDependencies();
//
// get all Simulations for this model
//
Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
//
// for each application, recompute mathDescription, and verify it is equivalent
// then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
//
SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
for (int k = 0; k < simContextsFromDB.length; k++) {
SimulationContext simContextFromDB = simContextsFromDB[k];
Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
SimulationContext simContextNewMath = simContextsNewMath[k];
Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
MathCompareResults mathCompareResults = null;
try {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
// find out if any simulation belonging to this Application has data
//
boolean bApplicationHasData = false;
for (int l = 0; l < modelSimsFromDB.length; l++) {
SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
if (simulationStatus != null && simulationStatus.getHasData()) {
bApplicationHasData = true;
}
}
//
try {
if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
//
// updated mathdescription loaded into copy of biomodel, then test for equivalence.
//
cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
MathDescription newMathDesc = mathMapping.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>");
}
issueString = buffer.toString();
}
simContextNewMath.setMathDescription(newMathDesc);
MathCompareResults testIfSameResults = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
StringBuffer buffer = new StringBuffer();
buffer.append(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults.isEquivalent() + ">>: " + mathCompareResults.toDatabaseStatus());
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + ((issueString != null) ? (", " + SimContextStat2Table.table.comments.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(issueString, 255) + "'") : ("")) + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
//
for (int l = 0; l < appSimsFromDB.length; l++) {
try {
boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults);
if (lg.isTraceEnabled())
lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.decision.description) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
} catch (Throwable e) {
// exception in whole BioModel
lg.error(e.getMessage(), e);
// can't update anything in database, since we don't know what simcontexts are involved
}
}
}
Aggregations