use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class ModelDbDriver method insertModel.
/**
* This method was created in VisualAge.
* @param model cbit.vcell.model.Model
*/
private void insertModel(InsertHashtable hash, Connection con, User user, Model model, Version newVersion) throws SQLException, DataAccessException, RecordChangedException {
//
// insert model record
//
insertModelSQL(con, user, model, newVersion);
hash.put(model, newVersion.getVersionKey());
//
// make sure all species are in the database and the hashtable
//
StructureTopology structureTopology = model.getStructureTopology();
ElectricalTopology electricalTopology = model.getElectricalTopology();
Species[] speciesArray = model.getSpecies();
for (int i = 0; i < speciesArray.length; i++) {
// speciesArray[i].getKey();
KeyValue speciesKey = null;
// if (speciesKey == null) {
speciesKey = reactStepDB.insertSpecies(hash, con, speciesArray[i], user);
// throw new DataAccessException("Database error: species "+species.getName()+" has null key");
// }else if (speciesArray[i].getOwnerKey()!=null && speciesArray[i].getOwnerKey()==user.getID()){
// reactStepDB.updateSpecies(con,speciesArray[i],user);
// }
// if (hash.getDatabaseKey(speciesArray[i])==null){
hash.put(speciesArray[i], speciesKey);
// }
}
//
// make sure all structures are in the database and the hashtable (add entry to link table)
// this does not populate the parent, negativeFeature, and positiveFeature columns ... done later with updateStructureKeys()
//
Structure[] structures = model.getStructures();
for (int i = 0; i < structures.length; i++) {
Structure structure = (Structure) structures[i];
KeyValue structureKey = null;
if (hash.getDatabaseKey(structure) == null) {
structureKey = reactStepDB.insertStructure(hash, con, structure);
}
KeyValue linkKey = keyFactory.getNewKey(con);
insertModelStructLinkSQL(con, linkKey, newVersion.getVersionKey(), /*modelKey*/
hash.getDatabaseKey(structure));
}
//
for (Structure structure : structures) {
KeyValue structKey = hash.getDatabaseKey(structure);
KeyValue parentKey = null;
Structure parentStruct = structureTopology.getParentStructure(structure);
if (parentStruct != null) {
parentKey = hash.getDatabaseKey(parentStruct);
}
KeyValue negKey = null;
KeyValue posKey = null;
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
Feature negFeature = electricalTopology.getNegativeFeature(membrane);
if (negFeature != null) {
negKey = hash.getDatabaseKey(negFeature);
}
Feature posFeature = electricalTopology.getPositiveFeature(membrane);
if (posFeature != null) {
posKey = hash.getDatabaseKey(posFeature);
}
}
StructureKeys structureKeys = new StructureKeys(structKey, parentKey, posKey, negKey);
reactStepDB.updateStructureKeys(con, structureKeys);
}
//
// make sure all speciesContexts are in database and the hashtable
//
SpeciesContext[] speciesContexts = model.getSpeciesContexts();
for (int i = 0; i < speciesContexts.length; i++) {
SpeciesContext sc = speciesContexts[i];
if (hash.getDatabaseKey(sc) == null) {
insertSpeciesContextSQL(hash, con, keyFactory.getNewKey(con), sc, newVersion.getVersionKey());
}
}
//
// insert all reactionSteps
//
ReactionStep[] reactionSteps = model.getReactionSteps();
for (int i = 0; i < reactionSteps.length; i++) {
ReactionStep rs = reactionSteps[i];
if (hash.getDatabaseKey(rs) == null) {
reactStepDB.insertReactionStep(hash, con, user, rs, newVersion.getVersionKey());
}
}
//
// insert diagrams
//
Diagram[] diagrams = model.getDiagrams();
for (int i = 0; i < diagrams.length; i++) {
Diagram diagram = diagrams[i];
KeyValue key = keyFactory.getNewKey(con);
KeyValue structKey = hash.getDatabaseKey(diagram.getStructure());
if (structKey != null) {
insertDiagramSQL(con, key, diagram, newVersion.getVersionKey(), /*modelKey*/
hash.getDatabaseKey(diagram.getStructure()));
} else {
if (lg.isWarnEnabled())
lg.warn("ModelDbDriver.insertModel(), diagram " + diagram.toString() + " is orphaned, check Model logic");
}
}
//
// insert GlobalModelParameters
//
// //-----------------testing remove
// try{
// Model.ModelParameter testParam = model.new ModelParameter("test",new Expression("1.0"),Model.ROLE_UserDefined,VCUnitDefinition.UNIT_molecules);
// model.setModelParameters(new Model.ModelParameter[] {testParam});
// }catch(Exception e){
// e.printStackTrace();
// }
// //-----------------
GlobalModelParameterTable.table.insertModelParameters(con, keyFactory, model.getModelParameters(), newVersion.getVersionKey());
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class ReactStepTable method getReactionStep.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.ReactionParticipant
* @param rset java.sql.ResultSet
*/
public ReactionStep getReactionStep(Structure structure, Model model, KeyValue rsKey, java.sql.ResultSet rset, DatabaseSyntax dbSyntax) throws java.sql.SQLException, DataAccessException {
KeyValue key = rsKey;
if (rset.wasNull()) {
key = null;
}
String reactType = rset.getString(ReactStepTable.table.reactType.toString());
String reactionStepName = null;
String nameString = rset.getString(ReactStepTable.table.name.toString());
if (rset.wasNull()) {
nameString = null;
}
if (nameString != null) {
reactionStepName = TokenMangler.getSQLRestoredString(nameString);
}
ReactionStep rs = null;
try {
if (reactType.equals(ReactStepTable.REACTTYPE_FLUX_REVERSIBLE)) {
rs = new FluxReaction(model, (Membrane) structure, key, reactionStepName, true);
} else if (reactType.equals(ReactStepTable.REACTTYPE_FLUX_IRREVERSIBLE)) {
rs = new FluxReaction(model, (Membrane) structure, key, reactionStepName, false);
} else if (reactType.equals(ReactStepTable.REACTTYPE_SIMPLE_REVERSIBLE)) {
rs = new SimpleReaction(model, structure, key, reactionStepName, true);
} else if (reactType.equals(ReactStepTable.REACTTYPE_SIMPLE_IRREVERSIBLE)) {
rs = new SimpleReaction(model, structure, key, reactionStepName, false);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
//
// if valence is stored as a 'null', it was an error (previous models were updated administratively).
//
int valenceValue = rset.getInt(ReactStepTable.table.chargeValence.toString());
if (rset.wasNull()) {
throw new DataAccessException("unexpected null for chargeValence");
}
//
// New procedure for getting kinetics
//
String kinetics_vcml = DbDriver.varchar2_CLOB_get(rset, ReactStepTable.table.kineticsSmall, ReactStepTable.table.kineticsLarge, dbSyntax);
if (kinetics_vcml == null || kinetics_vcml.length() == 0) {
throw new DataAccessException("no data stored for kinetics");
}
// This isn't needed?
// if (kinetics_vcml.endsWith(";}\n")){
// StringBuffer buffer = new StringBuffer(kinetics_vcml.substring(0,kinetics_vcml.length()-2));
// buffer.append("\n}\n");
// kinetics_vcml = buffer.toString();
// }
org.vcell.util.CommentStringTokenizer tokens = new org.vcell.util.CommentStringTokenizer(kinetics_vcml);
Kinetics kinetics = null;
try {
String token = tokens.nextToken();
if (!token.equalsIgnoreCase(VCMODL.Kinetics)) {
throw new DataAccessException("expected " + VCMODL.Kinetics);
}
token = tokens.nextToken();
KineticsDescription kineticsDescription = KineticsDescription.fromVCMLKineticsName(token);
if (kineticsDescription != null) {
kinetics = kineticsDescription.createKinetics(rs);
} else {
throw new DataAccessException("expected valid kinetics type, read '" + token + "'");
}
kinetics.fromTokens(kinetics_vcml);
//
// for debug purposes only, remove when unresolvedParameters are ok ... when globals exist
//
// if (kinetics.getUnresolvedParameters().length!=0){
// System.out.println("<<<WARNING>>> ReactStepTable.getReactionStep(key="+rsKey+") has "+kinetics.getUnresolvedParameters().length+" UnresolvedParameters");
// for (int i = 0; i < kinetics.getUnresolvedParameters().length; i++){
// System.out.println(">>>>>>>>>>>>> UnresolvedParameter["+i+"] = "+kinetics.getUnresolvedParameters()[i].toString());
// }
// }
KineticsParameter chargeValenceParameter = kinetics.getChargeValenceParameter();
if (chargeValenceParameter != null) {
chargeValenceParameter.setExpression(new cbit.vcell.parser.Expression(valenceValue));
}
} catch (Exception e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
rs.setKinetics(kinetics);
//
// if physicsOptions is stored as a 'null', it was an error (previous models were updated administratively).
//
int physicsOptionsValue = rset.getInt(ReactStepTable.table.physicsOptions.toString());
if (rset.wasNull()) {
throw new DataAccessException("unexpected null for physicsOptions");
}
try {
rs.setPhysicsOptions(physicsOptionsValue);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
}
String annot = rset.getString(ReactStepTable.table.annotation.getUnqualifiedColName());
if (!rset.wasNull()) {
// annot = TokenMangler.getSQLRestoredString(annot);
// rs.setAnnotation(annot);
}
return rs;
}
Aggregations