Search in sources :

Example 81 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class AdminDBTopLevel method insertUserInfo.

/**
 * This method was created in VisualAge.
 * @return cbit.sql.UserInfo
 * @param newUserInfo cbit.sql.UserInfo
 */
KeyValue insertUserInfo(UserInfo newUserInfo, boolean bEnableRetry) throws SQLException, UseridIDExistsException {
    Object lock = new Object();
    Connection con = conFactory.getConnection(lock);
    try {
        if (userDB.getUserFromUserid(con, newUserInfo.userid) != null) {
            throw new UseridIDExistsException("Insert new user failed: username '" + newUserInfo.userid + "' already exists");
        }
        KeyValue key = userDB.insertUserInfo(con, conFactory.getKeyFactory(), newUserInfo);
        con.commit();
        return key;
    } catch (Throwable e) {
        lg.error("failure in insertUserInfo()", e);
        if (e instanceof UseridIDExistsException) {
            throw (UseridIDExistsException) e;
        }
        try {
            con.rollback();
        } catch (Throwable rbe) {
            lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
        }
        if (bEnableRetry && isBadConnection(con)) {
            conFactory.failed(con, lock);
            return insertUserInfo(newUserInfo, false);
        } else {
            handle_SQLException(e);
            // never gets here;
            return null;
        }
    } finally {
        conFactory.release(con, lock);
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Connection(java.sql.Connection) UseridIDExistsException(org.vcell.util.UseridIDExistsException)

Example 82 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class GeomDbDriver method getImageRefKeyFromGeometry.

/**
 * getModel method comment.
 */
private KeyValue getImageRefKeyFromGeometry(Connection con, KeyValue geomKey) throws SQLException, DataAccessException, ObjectNotFoundException {
    if (geomKey == null) {
        throw new IllegalArgumentException("Improper parameters for getImageRefKeyFromGeometry");
    }
    // log.print("GeomDbDriver.getImageRefKeyFromGeometry(id="+geomKey+")");
    String sql;
    sql = " SELECT " + geomTable.imageRef + " FROM " + geomTable.getTableName() + " WHERE " + geomTable.id + " = " + geomKey;
    // System.out.println(sql);
    // Connection con = conFact.getConnection();
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            java.math.BigDecimal iR = rset.getBigDecimal(geomTable.imageRef.toString());
            if (rset.wasNull()) {
                return null;
            }
            return new KeyValue(iR);
        } else {
            throw new ObjectNotFoundException("getSizeKeyFromGeometry for Image id=" + geomKey + " not found");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
}
Also used : BigDecimal(java.math.BigDecimal) KeyValue(org.vcell.util.document.KeyValue) Statement(java.sql.Statement) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResultSet(java.sql.ResultSet)

Example 83 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class GeomDbDriver method insertFilamentsSQL.

/**
 * This method was created in VisualAge.
 * @param vcimage cbit.image.VCImage
 * @param userid java.lang.String
 * @exception java.rmi.RemoteException The exception description.
 */
private void insertFilamentsSQL(Connection con, Geometry geom, KeyValue geomKey) throws SQLException, DataAccessException {
    String sql;
    Filament[] filaments = geom.getGeometrySpec().getFilamentGroup().getFilaments();
    for (int i = 0; i < filaments.length; i++) {
        // Iterate through Filaments
        KeyValue newFilamentKey = keyFactory.getNewKey(con);
        // 
        // Insert Filament
        // 
        Filament currentFilament = filaments[i];
        sql = "INSERT INTO " + filamentTable.getTableName() + " " + filamentTable.getSQLColumnList() + " VALUES " + filamentTable.getSQLValueList(newFilamentKey, currentFilament.getName(), geomKey);
        updateCleanSQL(con, sql);
        // 
        // Insert all Curves for this filament
        // 
        Curve[] curves = currentFilament.getCurves();
        for (int j = 0; j < curves.length; j += 1) {
            KeyValue newCurveKey = keyFactory.getNewKey(con);
            sql = "INSERT INTO " + curveTable.getTableName() + " " + curveTable.getSQLColumnList() + " VALUES " + curveTable.getSQLValueList(newCurveKey, newFilamentKey, dbSyntax);
            // 
            switch(dbSyntax) {
                case ORACLE:
                    {
                        updateCleanSQL(con, sql);
                        updateCleanLOB(con, curveTable.id.toString(), newCurveKey, curveTable.tableName, curveTable.curveData, CurveTable.encodeCurve(curves[j]), dbSyntax);
                        break;
                    }
                case POSTGRES:
                    {
                        updatePreparedCleanSQL(con, sql, CurveTable.encodeCurve(curves[j]));
                        break;
                    }
                default:
                    {
                        throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
                    }
            }
        }
    }
}
Also used : Filament(cbit.vcell.geometry.Filament) KeyValue(org.vcell.util.document.KeyValue) Curve(cbit.vcell.geometry.Curve)

Example 84 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class GeomDbDriver method getExtentRefKeyFromImage.

/**
 * getModel method comment.
 */
private KeyValue getExtentRefKeyFromImage(Connection con, KeyValue imageKey) throws SQLException, DataAccessException, ObjectNotFoundException {
    if (imageKey == null) {
        throw new IllegalArgumentException("Improper parameters for getSizeKeyFromImage");
    }
    // log.print("GeomDbDriver.getSizeRefKeyFromImage(id="+imageKey+")");
    String sql;
    sql = " SELECT " + imageTable.extentRef + " FROM " + imageTable.getTableName() + " WHERE " + imageTable.id + " = " + imageKey;
    // System.out.println(sql);
    // Connection con = conFact.getConnection();
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            return new KeyValue(rset.getBigDecimal(imageTable.extentRef.toString()));
        } else {
            throw new ObjectNotFoundException("getSizeKeyFromImage for Image id=" + imageKey + " not found");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Statement(java.sql.Statement) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResultSet(java.sql.ResultSet)

Example 85 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class GeomDbDriver method deleteGeometrySQL.

/**
 * only the owner can delete a Geometry
 */
private void deleteGeometrySQL(Connection con, User user, KeyValue geomKey) throws SQLException, DataAccessException, DependencyException {
    failOnExternalRefs(con, MathDescTable.table.geometryRef, VersionTable.getVersionTable(VersionableType.MathDescription), geomKey, GeometryTable.table);
    failOnExternalRefs(con, SimContextTable.table.geometryRef, VersionTable.getVersionTable(VersionableType.SimulationContext), geomKey, GeometryTable.table);
    String sql;
    KeyValue imageRefKey = getImageRefKeyFromGeometry(con, geomKey);
    KeyValue extentKey = getExtentRefKeyFromGeometry(con, geomKey);
    // Delete Geometry, all APPROPRIATE children go ON DELETE CASCADE
    sql = DatabasePolicySQL.enforceOwnershipDelete(user, geomTable, GeometryTable.table.id + " = " + geomKey);
    // System.out.println(sql);
    updateCleanSQL(con, sql);
    // Don't have to check if other Geometries are using because Geometries never share sizetable
    if (imageRefKey == null) {
        sql = "DELETE FROM " + extentTable.getTableName() + " WHERE " + extentTable.id + " = " + extentKey;
        // System.out.println(sql);
        updateCleanSQL(con, sql);
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue)

Aggregations

KeyValue (org.vcell.util.document.KeyValue)325 DataAccessException (org.vcell.util.DataAccessException)92 User (org.vcell.util.document.User)68 ResultSet (java.sql.ResultSet)57 Statement (java.sql.Statement)52 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)44 SQLException (java.sql.SQLException)43 BigString (org.vcell.util.BigString)40 BigDecimal (java.math.BigDecimal)38 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)37 BioModel (cbit.vcell.biomodel.BioModel)36 Simulation (cbit.vcell.solver.Simulation)33 XmlParseException (cbit.vcell.xml.XmlParseException)33 PropertyVetoException (java.beans.PropertyVetoException)33 Vector (java.util.Vector)33 Connection (java.sql.Connection)32 ArrayList (java.util.ArrayList)31 File (java.io.File)29 SimulationContext (cbit.vcell.mapping.SimulationContext)28 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)24