use of cbit.vcell.mapping.StructureMapping in project vcell by virtualcell.
the class SimulationContextDbDriver method assignStructureMappingsSQL.
/**
* This method was created in VisualAge.
* @param simContext cbit.vcell.mapping.SimulationContext
*/
private void assignStructureMappingsSQL(QueryHashtable dbc, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
String sql;
sql = " SELECT " + "*" + " FROM " + structureMappingTable.getTableName() + " WHERE " + structureMappingTable.simContextRef + " = " + simContextKey;
Statement stmt = con.createStatement();
try {
// log.print(sql);
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal subvolumeRefBigDecimal = rset.getBigDecimal(structureMappingTable.subVolumeRef.toString());
KeyValue subVolumeRef = (subvolumeRefBigDecimal == null ? null : new KeyValue(subvolumeRefBigDecimal));
BigDecimal surfaceClassRefBigDecimal = rset.getBigDecimal(structureMappingTable.surfaceClassRef.toString());
KeyValue surfaceClassRef = (surfaceClassRefBigDecimal == null ? null : new KeyValue(surfaceClassRefBigDecimal));
KeyValue structureRef = new KeyValue(rset.getBigDecimal(structureMappingTable.structRef.toString()));
//
// lookup structure and subVolume from SimulationContext by their keys
//
// DBCache will not always give same instance consistently (usually this is
// fixed up later in the ReferenceResolver at the Client).
//
Structure theStructure = null;
Structure[] structureArray = simContext.getModel().getStructures();
for (int i = 0; i < structureArray.length; i++) {
Structure structure = structureArray[i];
if (structure.getKey().compareEqual(structureRef)) {
theStructure = structure;
break;
}
}
if (theStructure == null) {
throw new DataAccessException("Can't match structure and subvolume");
}
GeometryClass theGeometryClass = null;
KeyValue geometryClassKey = (subVolumeRef == null ? surfaceClassRef : subVolumeRef);
if (geometryClassKey != null) {
GeometryClass[] geometryClasses = simContext.getGeometry().getGeometryClasses();
for (int i = 0; i < geometryClasses.length; i++) {
if (geometryClasses[i].getKey().compareEqual(geometryClassKey)) {
theGeometryClass = geometryClasses[i];
break;
}
}
if (theGeometryClass == null) {
throw new DataAccessException("Can't find Geometryclass");
}
}
Expression sizeExpression = null;
String sizeExpressionS = rset.getString(StructureMappingTable.table.sizeExp.getUnqualifiedColName());
if (!rset.wasNull() && sizeExpressionS != null && sizeExpressionS.length() > 0) {
try {
sizeExpressionS = TokenMangler.getSQLRestoredString(sizeExpressionS);
sizeExpression = new Expression(sizeExpressionS);
} catch (ExpressionException e) {
e.printStackTrace();
throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't parse non-null size expression for Structure " + theStructure.getName());
}
}
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(theStructure);
try {
sm.getSizeParameter().setExpression(sizeExpression);
} catch (Exception e1) {
throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't set size expression '" + sizeExpressionS + "'for Structure " + theStructure.getName());
}
try {
sm.setGeometryClass(theGeometryClass);
} catch (PropertyVetoException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
if (sm instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) sm;
String boundaryTypeXmString = rset.getString(structureMappingTable.boundaryTypeXm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeXm(new BoundaryConditionType(boundaryTypeXmString));
}
String boundaryTypeXpString = rset.getString(structureMappingTable.boundaryTypeXp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeXp(new BoundaryConditionType(boundaryTypeXpString));
}
String boundaryTypeYmString = rset.getString(structureMappingTable.boundaryTypeYm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeYm(new BoundaryConditionType(boundaryTypeYmString));
}
String boundaryTypeYpString = rset.getString(structureMappingTable.boundaryTypeYp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeYp(new BoundaryConditionType(boundaryTypeYpString));
}
String boundaryTypeZmString = rset.getString(structureMappingTable.boundaryTypeZm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeZm(new BoundaryConditionType(boundaryTypeZmString));
}
String boundaryTypeZpString = rset.getString(structureMappingTable.boundaryTypeZp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeZp(new BoundaryConditionType(boundaryTypeZpString));
}
String volPerUnitArea = rset.getString(structureMappingTable.volPerUnitAreaExp.toString());
if (!rset.wasNull()) {
try {
fm.getVolumePerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitArea)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String volPerUnitVol = rset.getString(structureMappingTable.volPerUnitVolExp.toString());
if (!rset.wasNull()) {
try {
fm.getVolumePerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitVol)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
} else if (sm instanceof MembraneMapping) {
MembraneMapping mm = (MembraneMapping) sm;
String surfToVolString = rset.getString(structureMappingTable.surfToVolExp.toString());
if (!rset.wasNull()) {
try {
mm.getSurfaceToVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(surfToVolString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String volFractString = rset.getString(structureMappingTable.volFractExp.toString());
if (!rset.wasNull()) {
try {
mm.getVolumeFractionParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volFractString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in volFract expression: " + e.getMessage());
}
}
boolean bCalculateVoltage = rset.getBoolean(structureMappingTable.bCalculateVoltage.toString());
if (!rset.wasNull()) {
mm.setCalculateVoltage(bCalculateVoltage);
}
java.math.BigDecimal specificCapacitance = rset.getBigDecimal(structureMappingTable.specificCap.toString());
if (!rset.wasNull()) {
try {
mm.getSpecificCapacitanceParameter().setExpression(new Expression(specificCapacitance.doubleValue()));
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new DataAccessException("error setting membrane specific capacitance: " + e.getMessage());
}
}
String initialVoltageString = rset.getString(structureMappingTable.initialVoltage.toString());
if (!rset.wasNull()) {
try {
mm.getInitialVoltageParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(initialVoltageString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("database parse error in initial membrane voltage: " + e.getMessage());
}
}
String areaPerUnitArea = rset.getString(structureMappingTable.areaPerUnitAreaExp.toString());
if (!rset.wasNull()) {
try {
mm.getAreaPerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitArea)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String areaPerUnitVol = rset.getString(structureMappingTable.areaPerUnitVolExp.toString());
if (!rset.wasNull()) {
try {
mm.getAreaPerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitVol)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
} else {
throw new DataAccessException("unknown structureMapping type");
}
// System.out.println("Structure Key = " + theStructure + " - " + "SubVolume Key " + theSubVolume.getKey());
}
} finally {
stmt.close();
}
}
use of cbit.vcell.mapping.StructureMapping in project vcell by virtualcell.
the class SimulationContextDbDriver method insertStructureMappingsSQL.
/**
* This method was created in VisualAge.
*/
private void insertStructureMappingsSQL(InsertHashtable hash, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
String sql;
StructureMapping[] structureMappings = simContext.getGeometryContext().getStructureMappings();
for (int i = 0; i < structureMappings.length; i++) {
StructureMapping structureMapping = structureMappings[i];
//
// check for incomplete StructureMappings, this allows partially mapped SimContext to be saved without Exceptions.
// it's ok to have missing StructureMappings in the database, assignStructureMappingsSQL() is tolerant of this.
//
//
KeyValue newStuctureMappingKey = keyFactory.getNewKey(con);
//
sql = "INSERT INTO " + structureMappingTable.getTableName() + " " + structureMappingTable.getSQLColumnList() + " VALUES " + structureMappingTable.getSQLValueList(hash, newStuctureMappingKey, simContextKey, structureMapping);
// System.out.println(sql);
updateCleanSQL(con, sql);
}
}
Aggregations