use of cbit.vcell.mapping.Electrode in project vcell by virtualcell.
the class SimulationContextDbDriver method assignStimuliSQL.
/**
* This method was created in VisualAge.
* @param simContext cbit.vcell.mapping.SimulationContext
*/
private void assignStimuliSQL(Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
String sql;
sql = " SELECT " + "*" + " FROM " + stimulusTable.getTableName() + " WHERE " + stimulusTable.simContextRef + " = " + simContextKey;
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
try {
// KeyValue key = new KeyValue(rset.getBigDecimal(stimulusTable.id.toString()));
KeyValue structureRef = new KeyValue(rset.getBigDecimal(stimulusTable.structRef.toString()));
// KeyValue simContextRef = new KeyValue(rset.getBigDecimal(stimulusTable.simContextRef.toString()));
//
// lookup structure from SimulationContext by its key
//
// 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;
}
}
String name = rset.getString(stimulusTable.name.toString());
if (rset.wasNull()) {
name = null;
}
int stimulusType = rset.getInt(stimulusTable.stimulusType.toString());
Expression exp = null;
String expString = rset.getString(stimulusTable.expression.toString());
if (rset.wasNull()) {
exp = null;
} else {
exp = new Expression(TokenMangler.getSQLRestoredString(expString));
}
double posX = rset.getBigDecimal(stimulusTable.positionX.toString()).doubleValue();
double posY = rset.getBigDecimal(stimulusTable.positionY.toString()).doubleValue();
double posZ = rset.getBigDecimal(stimulusTable.positionZ.toString()).doubleValue();
org.vcell.util.CommentStringTokenizer paramsCST = null;
String paramsS = rset.getString(StimulusTable.table.params.toString());
if (!rset.wasNull()) {
paramsCST = new org.vcell.util.CommentStringTokenizer(org.vcell.util.TokenMangler.getSQLRestoredString(paramsS));
}
if (stimulusType == StimulusTable.GROUND_ELECTRODE) {
//
// an Electrode (ground)
//
Electrode groundElectrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
simContext.setGroundElectrode(groundElectrode);
} else if (stimulusType == StimulusTable.TOTALCURRENT_CLAMP_STIMULUS) {
Electrode electrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
TotalCurrentClampStimulus stimulus = new TotalCurrentClampStimulus(electrode, name, exp, simContext);
stimulus.parameterVCMLSet(paramsCST);
ElectricalStimulus[] newStimuli = (ElectricalStimulus[]) org.vcell.util.BeanUtils.addElement(simContext.getElectricalStimuli(), stimulus);
simContext.setElectricalStimuli(newStimuli);
} else if (stimulusType == StimulusTable.CURRENTDENSITY_CLAMP_STIMULUS) {
Electrode electrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
CurrentDensityClampStimulus stimulus = new CurrentDensityClampStimulus(electrode, name, exp, simContext);
stimulus.parameterVCMLSet(paramsCST);
ElectricalStimulus[] newStimuli = (ElectricalStimulus[]) org.vcell.util.BeanUtils.addElement(simContext.getElectricalStimuli(), stimulus);
simContext.setElectricalStimuli(newStimuli);
} else if (stimulusType == StimulusTable.VOLTAGE_CLAMP_STIMULUS) {
Electrode electrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
VoltageClampStimulus stimulus = new VoltageClampStimulus(electrode, name, exp, simContext);
stimulus.parameterVCMLSet(paramsCST);
ElectricalStimulus[] newStimuli = (ElectricalStimulus[]) org.vcell.util.BeanUtils.addElement(simContext.getElectricalStimuli(), stimulus);
simContext.setElectricalStimuli(newStimuli);
} else {
throw new DataAccessException("unknown stimulusType <" + stimulusType + ">");
}
} catch (ExpressionException | PropertyVetoException e) {
lg.error(e.getMessage(), e);
}
}
} finally {
stmt.close();
}
}
Aggregations