use of cbit.vcell.model.DBSpecies in project vcell by virtualcell.
the class XmlReader method getDBSpecies.
/**
* This method reads a DBSpecies from a XML representation.
* Creation date: (6/3/2003 8:20:54 PM)
* @return cbit.vcell.dictionary.DBSpecies
* @param dbSpeciesElement org.jdom.Element
*/
private DBSpecies getDBSpecies(Element dbSpeciesElement) throws XmlParseException {
// Read the key
String keystring = dbSpeciesElement.getAttributeValue(XMLTags.KeyValueAttrTag);
KeyValue key = new KeyValue(keystring);
DBSpecies dbSpecies = null;
// read the type
String type = dbSpeciesElement.getAttributeValue(XMLTags.TypeAttrTag);
// Read the DBFormalSpecies
org.jdom.Element formalSpeciesElement = dbSpeciesElement.getChild(XMLTags.DBFormalSpeciesTag, vcNamespace);
if (type.equalsIgnoreCase(XMLTags.CompoundTypeTag)) {
// Create a BoundCompound
dbSpecies = new BoundCompound(key, (FormalCompound) getDBFormalSpecies(formalSpeciesElement));
} else if (type.equalsIgnoreCase(XMLTags.EnzymeTypeTag)) {
// Create a BoundEnzyme
dbSpecies = new BoundEnzyme(key, (FormalEnzyme) getDBFormalSpecies(formalSpeciesElement));
} else if (type.equalsIgnoreCase(XMLTags.ProteinTypeTag)) {
// Create a BoundProtein
dbSpecies = new BoundProtein(key, (FormalProtein) getDBFormalSpecies(formalSpeciesElement));
} else {
throw new XmlParseException("DBSpecies type: " + type + ", not supported yet!");
}
return dbSpecies;
}
use of cbit.vcell.model.DBSpecies in project vcell by virtualcell.
the class ReactStepDbDriver method getSpecies.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.Species
* @param rset java.sql.ResultSet
* @exception java.sql.SQLException The exception description.
*/
private Species getSpecies(QueryHashtable dbc, ResultSet rset, Connection con) throws SQLException, DataAccessException {
//
// look in object cache (don't instantiate a new one if possible)
//
KeyValue speciesKey = new KeyValue(rset.getBigDecimal(speciesTable.id.toString()));
Species species = (Species) dbc.get(speciesKey);
if (species != null) {
return species;
} else {
DBSpecies dbSpeciesRef = null;
KeyValue dbSpeciesKey = null;
java.math.BigDecimal dbSpeciesKeyS = rset.getBigDecimal(speciesTable.dbSpeciesRef.toString());
if (dbSpeciesKeyS != null) {
dbSpeciesKey = new KeyValue(dbSpeciesKeyS);
}
if (dbSpeciesKey != null) {
dbSpeciesRef = (DBSpecies) dbc.get(dbSpeciesKey);
if (dbSpeciesRef == null) {
dbSpeciesRef = dictDB.getDBSpeciesFromKeyValue(dbc, con, dbSpeciesKey);
}
}
species = speciesTable.getSpecies(rset, dbSpeciesRef);
//
// stick new one in cache
//
dbc.put(speciesKey, species);
return species;
}
}
use of cbit.vcell.model.DBSpecies in project vcell by virtualcell.
the class DictionaryDbDriver method getBoundSpecies.
/**
* Insert the method's description here.
* Creation date: (2/26/2003 1:38:19 PM)
* @return cbit.vcell.dictionary.DBSpecies
* @param dbfs cbit.vcell.dictionary.DBFormalSpecies
*/
public DBSpecies getBoundSpecies(Connection con, DBFormalSpecies dbfs) throws SQLException {
// Check if this is already a DBSpecies
if (dbfs instanceof DBSpecies) {
return (DBSpecies) dbfs;
}
int restrictsearch = 0;
if (dbfs.getFormalSpeciesType().equals(FormalSpeciesType.compound)) {
restrictsearch = FormalSpeciesType.COMPOUND_KEGGID;
} else if (dbfs.getFormalSpeciesType().equals(FormalSpeciesType.enzyme)) {
restrictsearch = FormalSpeciesType.ENZYME_ECNUMBER;
} else if (dbfs.getFormalSpeciesType().equals(FormalSpeciesType.protein)) {
restrictsearch = FormalSpeciesType.PROTEIN_SWISSPROTID;
} else {
throw new IllegalArgumentException("DictionaryDbDriver.getBoundSpecies: Unsupported FormalSpeciesType");
}
// Check if binding already exists in database
DBFormalSpecies[] dbfsBound = getDatabaseSpecies(con, null, dbfs.getFormalSpeciesInfo().getFormalID(), true, dbfs.getFormalSpeciesType(), restrictsearch, -1, false);
if (dbfsBound != null) {
if (dbfsBound.length == 1) {
return (DBSpecies) dbfsBound[0];
} else {
throw new RuntimeException("Expecting only 1 result");
}
}
// Create new binding
// Add entry to binding table
KeyValue newKey = keyFactory.getNewKey(con);
String sql = "INSERT INTO " + DBSpeciesTable.table.getTableName() + " VALUES " + DBSpeciesTable.table.getSQLValueList(newKey, dbfs);
DbDriver.updateCleanSQL(con, sql);
// Get new DBSpecies
dbfsBound = getDatabaseSpecies(con, null, dbfs.getFormalSpeciesInfo().getFormalID(), true, dbfs.getFormalSpeciesType(), restrictsearch, -1, false);
if (dbfsBound != null) {
if (dbfsBound.length == 1) {
return (DBSpecies) dbfsBound[0];
} else {
throw new RuntimeException("Expecting only 1 result");
}
}
throw new RuntimeException("Couldn't Get New DBSpecies");
}
use of cbit.vcell.model.DBSpecies in project vcell by virtualcell.
the class DictionaryDbDriver method getDBSpeciesFromKeyValue.
public DBSpecies getDBSpeciesFromKeyValue(QueryHashtable dbc, Connection con, KeyValue argDBSpeciesRef) throws SQLException {
//
// try to get SpeciesReference from the object cache
//
DBSpecies dbSpeciesRef = (DBSpecies) dbc.get(argDBSpeciesRef);
if (dbSpeciesRef != null) {
return dbSpeciesRef;
}
DBSpecies result = null;
String sql;
sql = " SELECT " + " * " + " FROM " + dbSpeciesTable.getTableName() + " WHERE " + dbSpeciesTable.id + " = " + argDBSpeciesRef;
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
DBSpecies dbSpecies = null;
java.math.BigDecimal compoundBD = rset.getBigDecimal(dbSpeciesTable.compoundRef.getUnqualifiedColName());
java.math.BigDecimal enzymeBD = rset.getBigDecimal(dbSpeciesTable.enzymeRef.getUnqualifiedColName());
java.math.BigDecimal proteinBD = rset.getBigDecimal(dbSpeciesTable.proteinRef.getUnqualifiedColName());
if (compoundBD != null) {
dbSpecies = (DBSpecies) getDatabaseSpecies(con, null, compoundBD.toString(), true, FormalSpeciesType.compound, FormalSpeciesType.COMPOUND_ID, -1, false)[0];
} else if (enzymeBD != null) {
dbSpecies = (DBSpecies) getDatabaseSpecies(con, null, enzymeBD.toString(), true, FormalSpeciesType.enzyme, FormalSpeciesType.ENZYME_ID, -1, false)[0];
} else if (proteinBD != null) {
dbSpecies = (DBSpecies) getDatabaseSpecies(con, null, proteinBD.toString(), true, FormalSpeciesType.protein, FormalSpeciesType.PROTEIN_ID, -1, false)[0];
}
result = dbSpecies;
dbc.put(result.getDBSpeciesKey(), result);
}
} finally {
// Release resources include resultset
stmt.close();
}
return result;
}
use of cbit.vcell.model.DBSpecies in project vcell by virtualcell.
the class SpeciesTable method getSpecies.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.ReactionParticipant
* @param rset java.sql.ResultSet
*/
public Species getSpecies(java.sql.ResultSet rset, DBSpecies dbSpecies) throws java.sql.SQLException, DataAccessException {
String annotation = rset.getString(SpeciesTable.table.annotation.toString());
if (annotation != null) {
annotation = org.vcell.util.TokenMangler.getSQLRestoredString(annotation);
}
String cNameStr = TokenMangler.getSQLRestoredString(rset.getString(SpeciesTable.table.commonName.toString()));
Species species = new Species(cNameStr, annotation, dbSpecies);
return species;
}
Aggregations