Search in sources :

Example 1 with Table

use of cbit.sql.Table in project vcell by virtualcell.

the class MigrateDbManager method main.

public static void main(String[] args) throws SQLException {
    ConnectionFactory conFactory_Oracle = null;
    ConnectionFactory conFactory_Postgres = null;
    try {
        String driverName_Oracle = "oracle.jdbc.driver.OracleDriver";
        String connectionURL_Oracle = "jdbc:oracle:thin:@VCELL-DB.cam.uchc.edu:1521/vcelldborcl.cam.uchc.edu";
        String userid_Oracle = "vcell";
        String password_Oracle = "cbittech";
        conFactory_Oracle = DatabaseService.getInstance().createConnectionFactory(driverName_Oracle, connectionURL_Oracle, userid_Oracle, password_Oracle);
        String driverName_Postgres = "org.postgresql.Driver";
        String connectionURL_Postgres = "jdbc:postgresql://localhost:5432/schaff";
        String userid_Postgres = "schaff";
        String password_Postgres = "cbittech";
        conFactory_Postgres = DatabaseService.getInstance().createConnectionFactory(driverName_Postgres, connectionURL_Postgres, userid_Postgres, password_Postgres);
        int retryCount = 0;
        boolean done = false;
        while (!done && retryCount < 100) {
            try {
                Table[] tables = SQLCreateAllTables.getVCellTables();
                for (Table table : tables) {
                    if (!table.getTableName().toUpperCase().startsWith("VC_")) {
                        continue;
                    }
                    if (table == SimContextStatTable.table || table == SimContextStat2Table.table) {
                        continue;
                    }
                    migrate(table, conFactory_Oracle, conFactory_Postgres);
                }
                done = true;
            } catch (Exception e) {
                e.printStackTrace();
                // sleep 10 seconds
                Thread.sleep(10000);
                retryCount++;
            }
        }
        System.out.println("done");
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    } finally {
        if (conFactory_Oracle != null) {
            conFactory_Oracle.close();
        }
        if (conFactory_Postgres != null) {
            conFactory_Postgres.close();
        }
    }
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) SimContextStatTable(cbit.vcell.modeldb.SimContextStatTable) Table(cbit.sql.Table) SimContextStat2Table(cbit.vcell.modeldb.SimContextStat2Table) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Example 2 with Table

use of cbit.sql.Table in project vcell by virtualcell.

the class GeometryTable method getInfoSQL.

/**
 * This method was created in VisualAge.
 * @return java.lang.String
 */
public String getInfoSQL(User user, String extraConditions, String special, boolean bCheckPermission, DatabaseSyntax dbSyntax) {
    UserTable userTable = UserTable.table;
    GeometryTable gTable = this;
    ExtentTable eTable = ExtentTable.table;
    SoftwareVersionTable swvTable = SoftwareVersionTable.table;
    String sql;
    Field[] f = { userTable.userid, new cbit.sql.StarField(gTable), eTable.extentX, eTable.extentY, eTable.extentZ, swvTable.softwareVersion };
    Table[] t = { gTable, userTable, eTable, swvTable };
    switch(dbSyntax) {
        case ORACLE:
            {
                String condition = // links in the extent table
                eTable.id.getQualifiedColName() + " = " + gTable.extentRef.getQualifiedColName() + " AND " + userTable.id.getQualifiedColName() + " = " + // links in the userTable
                gTable.ownerRef.getQualifiedColName() + " AND " + gTable.id.getQualifiedColName() + " = " + swvTable.versionableRef.getQualifiedColName() + "(+) ";
                if (extraConditions != null && extraConditions.trim().length() > 0) {
                    condition += " AND " + extraConditions;
                }
                sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, special, dbSyntax, bCheckPermission);
                return sql;
            }
        case POSTGRES:
            {
                String condition = // links in the extent table
                eTable.id.getQualifiedColName() + " = " + gTable.extentRef.getQualifiedColName() + " AND " + userTable.id.getQualifiedColName() + " = " + gTable.ownerRef.getQualifiedColName() + // links in the userTable
                " ";
                // " AND " + gTable.id.getQualifiedColName() + " = " + swvTable.versionableRef.getQualifiedColName()+"(+) ";
                if (extraConditions != null && extraConditions.trim().length() > 0) {
                    condition += " AND " + extraConditions;
                }
                OuterJoin outerJoin = new OuterJoin(gTable, swvTable, JoinOp.LEFT_OUTER_JOIN, gTable.id, swvTable.versionableRef);
                sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, outerJoin, condition, special, dbSyntax, bCheckPermission);
                return sql;
            }
        default:
            {
                throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
            }
    }
}
Also used : Table(cbit.sql.Table) Field(cbit.sql.Field) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin)

Example 3 with Table

use of cbit.sql.Table in project vcell by virtualcell.

the class MathDescTable method getInfoSQL.

/**
 * This method was created in VisualAge.
 * @return java.lang.String
 */
public String getInfoSQL(User user, String extraConditions, String special, DatabaseSyntax dbSyntax) {
    UserTable userTable = UserTable.table;
    MathDescTable vTable = MathDescTable.table;
    SoftwareVersionTable swvTable = SoftwareVersionTable.table;
    String sql;
    // Field[] f = {userTable.userid,new cbit.sql.StarField(vTable)};
    Field[] f = new Field[] { vTable.id, userTable.userid, swvTable.softwareVersion };
    f = (Field[]) org.vcell.util.BeanUtils.addElements(f, vTable.versionFields);
    f = (Field[]) org.vcell.util.BeanUtils.addElement(f, vTable.geometryRef);
    Table[] t = { vTable, userTable, swvTable };
    switch(dbSyntax) {
        case ORACLE:
            {
                String condition = // links in the userTable
                userTable.id.getQualifiedColName() + " = " + vTable.ownerRef.getQualifiedColName() + " AND " + vTable.id.getQualifiedColName() + " = " + swvTable.versionableRef.getQualifiedColName() + "(+) ";
                if (extraConditions != null && extraConditions.trim().length() > 0) {
                    condition += " AND " + extraConditions;
                }
                sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, special, dbSyntax);
                return sql;
            }
        case POSTGRES:
            {
                // links in the userTable
                String condition = userTable.id.getQualifiedColName() + " = " + vTable.ownerRef.getQualifiedColName() + " ";
                // " AND " + vTable.id.getQualifiedColName() + " = " + swvTable.versionableRef.getQualifiedColName()+"(+) ";
                if (extraConditions != null && extraConditions.trim().length() > 0) {
                    condition += " AND " + extraConditions;
                }
                OuterJoin outerJoin = new OuterJoin(vTable, swvTable, JoinOp.LEFT_OUTER_JOIN, vTable.id, swvTable.versionableRef);
                sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, outerJoin, condition, special, dbSyntax);
                return sql;
            }
        default:
            {
                throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
            }
    }
}
Also used : Field(cbit.sql.Field) Table(cbit.sql.Table) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin)

Example 4 with Table

use of cbit.sql.Table in project vcell by virtualcell.

the class MathDescriptionDbDriver method getMathDescriptionSQL.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.math.MathDescription
 * @param user cbit.vcell.server.User
 * @param mathDescKey cbit.sql.KeyValue
 */
private MathDescription getMathDescriptionSQL(QueryHashtable dbc, Connection con, User user, KeyValue mathDescKey) throws SQLException, DataAccessException, ObjectNotFoundException {
    String sql;
    Field[] f = { userTable.userid, new cbit.sql.StarField(mathDescTable) };
    Table[] t = { mathDescTable, userTable };
    String condition = mathDescTable.id.getQualifiedColName() + " = " + mathDescKey + " AND " + userTable.id.getQualifiedColName() + " = " + mathDescTable.ownerRef.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
    // System.out.println(sql);
    MathDescription mathDescription = null;
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            // 
            // note: must call mathDescTable.getMathDescription() first (rset.getBytes(language) must be called first)
            // 
            mathDescription = mathDescTable.getMathDescription(rset, con, dbSyntax);
            // 
            // get Geometry reference and assign to mathDescription
            // 
            java.math.BigDecimal bigD = rset.getBigDecimal(MathDescTable.table.geometryRef.toString());
            KeyValue geomRef = null;
            if (!rset.wasNull()) {
                geomRef = new KeyValue(bigD);
            } else {
                throw new DataAccessException("Error:  Geometry Reference Cannot be Null for MathDescription");
            }
            Geometry geom = (Geometry) geomDB.getVersionable(dbc, con, user, VersionableType.Geometry, geomRef, false);
            try {
                mathDescription.setGeometry(geom);
            } catch (java.beans.PropertyVetoException e) {
                e.printStackTrace(System.out);
                throw new DataAccessException("DataAccess Exception: " + e.getMessage());
            }
        } else {
            throw new ObjectNotFoundException("MathDescription id=" + mathDescKey + " not found for user '" + user + "'");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    return mathDescription;
}
Also used : Table(cbit.sql.Table) KeyValue(org.vcell.util.document.KeyValue) MathDescription(cbit.vcell.math.MathDescription) Statement(java.sql.Statement) Geometry(cbit.vcell.geometry.Geometry) Field(cbit.sql.Field) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) ResultSet(java.sql.ResultSet) DataAccessException(org.vcell.util.DataAccessException)

Example 5 with Table

use of cbit.sql.Table in project vcell by virtualcell.

the class MathModelDbDriver method getMathModelMetaDatas.

/**
 * getModel method comment.
 */
MathModelMetaData[] getMathModelMetaDatas(Connection con, User user, boolean bAll) throws SQLException, DataAccessException, ObjectNotFoundException {
    if (user == null) {
        throw new IllegalArgumentException("Improper parameters for getMathModelMetaDatas");
    }
    if (lg.isTraceEnabled())
        lg.trace("MathModelDbDriver.getMathModelMetaData(user=" + user + ", bAll=" + bAll + ")");
    // 
    // to construct a MathModelMetaData as an immutable object, lets collect all keys first
    // (even before authentication).  If the user doesn't authenticate, then throw away the
    // child keys (from link tables).
    // 
    // 
    // get BioModelMetaData object for bioModelKey
    // 
    String sql;
    Field[] f = { new cbit.sql.StarField(mathModelTable), userTable.userid };
    Table[] t = { mathModelTable, userTable };
    String condition = userTable.id.getQualifiedColName() + " = " + mathModelTable.ownerRef.getQualifiedColName();
    if (!bAll) {
        condition += " AND " + userTable.id.getQualifiedColName() + " = " + user.getID();
    }
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax, true);
    // 
    StringBuffer newSQL = new StringBuffer(sql);
    newSQL.insert(7, Table.SQL_GLOBAL_HINT);
    sql = newSQL.toString();
    // 
    Statement stmt = con.createStatement();
    Vector<MathModelMetaData> mathModelMetaDataList = new Vector<MathModelMetaData>();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            MathModelMetaData mathModelMetaData = mathModelTable.getMathModelMetaData(rset, this, con, dbSyntax);
            mathModelMetaDataList.addElement(mathModelMetaData);
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    MathModelMetaData[] mathModelMetaDataArray = new MathModelMetaData[mathModelMetaDataList.size()];
    mathModelMetaDataList.copyInto(mathModelMetaDataArray);
    return mathModelMetaDataArray;
}
Also used : Table(cbit.sql.Table) Statement(java.sql.Statement) MathModelMetaData(cbit.vcell.mathmodel.MathModelMetaData) Field(cbit.sql.Field) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) ResultSet(java.sql.ResultSet) Vector(java.util.Vector)

Aggregations

Table (cbit.sql.Table)22 Field (cbit.sql.Field)20 OuterJoin (cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin)19 Statement (java.sql.Statement)11 ResultSet (java.sql.ResultSet)10 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)8 StarField (cbit.sql.StarField)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)3 DataAccessException (org.vcell.util.DataAccessException)3 KeyValue (org.vcell.util.document.KeyValue)3 BioModelMetaData (cbit.vcell.biomodel.BioModelMetaData)2 Geometry (cbit.vcell.geometry.Geometry)2 MathModelMetaData (cbit.vcell.mathmodel.MathModelMetaData)2 PropertyVetoException (java.beans.PropertyVetoException)2 Vector (java.util.Vector)2 VCImage (cbit.image.VCImage)1 RecordChangedException (cbit.sql.RecordChangedException)1 DBSpeciesTable (cbit.vcell.dictionary.db.DBSpeciesTable)1 GeometryClass (cbit.vcell.geometry.GeometryClass)1