Search in sources :

Example 1 with DBSpecies

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;
}
Also used : DBSpecies(cbit.vcell.model.DBSpecies) KeyValue(org.vcell.util.document.KeyValue) BoundProtein(cbit.vcell.dictionary.BoundProtein) BoundEnzyme(cbit.vcell.dictionary.BoundEnzyme) FormalProtein(cbit.vcell.dictionary.FormalProtein) BoundCompound(cbit.vcell.dictionary.BoundCompound) Element(org.jdom.Element) FormalCompound(cbit.vcell.dictionary.FormalCompound)

Example 2 with 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;
    }
}
Also used : DBSpecies(cbit.vcell.model.DBSpecies) KeyValue(org.vcell.util.document.KeyValue) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies)

Example 3 with DBSpecies

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");
}
Also used : DBSpecies(cbit.vcell.model.DBSpecies) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) KeyValue(org.vcell.util.document.KeyValue)

Example 4 with 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;
}
Also used : BigDecimal(java.math.BigDecimal) DBSpecies(cbit.vcell.model.DBSpecies) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet)

Example 5 with DBSpecies

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;
}
Also used : DBSpecies(cbit.vcell.model.DBSpecies) Species(cbit.vcell.model.Species)

Aggregations

DBSpecies (cbit.vcell.model.DBSpecies)5 KeyValue (org.vcell.util.document.KeyValue)3 Species (cbit.vcell.model.Species)2 BoundCompound (cbit.vcell.dictionary.BoundCompound)1 BoundEnzyme (cbit.vcell.dictionary.BoundEnzyme)1 BoundProtein (cbit.vcell.dictionary.BoundProtein)1 FormalCompound (cbit.vcell.dictionary.FormalCompound)1 FormalProtein (cbit.vcell.dictionary.FormalProtein)1 DBFormalSpecies (cbit.vcell.model.DBFormalSpecies)1 BigDecimal (java.math.BigDecimal)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Element (org.jdom.Element)1