Search in sources :

Example 6 with Table

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

the class MathModelTable 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;
    MathModelTable vTable = MathModelTable.table;
    SoftwareVersionTable swvTable = SoftwareVersionTable.table;
    String sql;
    Field[] f = { userTable.userid, new cbit.sql.StarField(vTable), swvTable.softwareVersion };
    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, true);
                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, true);
                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 7 with Table

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

the class ModelDbDriver method getModel.

/**
 * getModel method comment.
 */
private cbit.vcell.model.Model getModel(QueryHashtable dbc, Connection con, User user, KeyValue modelKey) throws SQLException, DataAccessException, ObjectNotFoundException {
    if (user == null || modelKey == null) {
        throw new IllegalArgumentException("Improper parameters for getModel");
    }
    // log.print("ModelDbDriver.getModel(user=" + user + ", id=" + modelKey + ")");
    String sql;
    Field[] f = { new cbit.sql.StarField(modelTable), userTable.userid };
    Table[] t = { modelTable, userTable };
    String condition = modelTable.id.getQualifiedColName() + " = " + modelKey + " AND " + userTable.id.getQualifiedColName() + " = " + modelTable.ownerRef.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
    Statement stmt = con.createStatement();
    Model model = null;
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            model = getModel(dbc, rset, con, user);
        } else {
            throw new org.vcell.util.ObjectNotFoundException("Model id=" + modelKey + " not found for user '" + user + "'");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    // GlobalModelParameterTable.table.setModelParameters(con, model);
    return model;
}
Also used : Table(cbit.sql.Table) Statement(java.sql.Statement) Field(cbit.sql.Field) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) Model(cbit.vcell.model.Model) ResultSet(java.sql.ResultSet)

Example 8 with Table

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

the class ModelTable 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;
    ModelTable vTable = ModelTable.table;
    SoftwareVersionTable swvTable = SoftwareVersionTable.table;
    String sql;
    Field[] f = { userTable.userid, new cbit.sql.StarField(vTable), swvTable.softwareVersion };
    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 9 with Table

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

the class SQLCreateAllTables method destroyAndRecreateTables.

/**
 * This method was created in VisualAge.
 */
private static void destroyAndRecreateTables(ConnectionFactory conFactory, KeyFactory keyFactory, DatabaseSyntax dbSyntax) {
    try {
        JPanel panel = new JPanel(new BorderLayout());
        JCheckBox c1 = new JCheckBox("Drop all tables");
        JCheckBox c2 = new JCheckBox("Create all tables");
        JCheckBox c3 = new JCheckBox("initialize User, Group, and Available tables");
        panel.add(c1, BorderLayout.NORTH);
        panel.add(c2, BorderLayout.CENTER);
        panel.add(c3, BorderLayout.SOUTH);
        int ok = JOptionPane.showConfirmDialog(new JFrame(), panel, "Select Action(s)", JOptionPane.OK_CANCEL_OPTION);
        if (ok == JOptionPane.OK_OPTION && (c1.isSelected() || c2.isSelected())) {
            Connection con = null;
            Object lock = new Object();
            try {
                con = conFactory.getConnection(lock);
                System.out.println("connected....");
                Table[] tables = getVCellTables();
                if (c1.isSelected()) {
                    dropTables(con, tables, dbSyntax);
                    dropSequence(con, keyFactory);
                }
                if (c2.isSelected()) {
                    createTables(con, tables, dbSyntax);
                    createSequence(con, keyFactory);
                    // 
                    if (c3.isSelected()) {
                        Statement s = con.createStatement();
                        try {
                            // Add void user
                            s.executeUpdate(cbit.vcell.modeldb.UserTable.getCreateVoidUserSQL());
                            // Add PRIVATE group
                            s.executeUpdate(cbit.vcell.modeldb.GroupTable.getCreateGroupPrivateSQL(keyFactory.getNewKey(con)));
                            // Add PUBLIC group
                            s.executeUpdate(cbit.vcell.modeldb.GroupTable.getCreateGroupPublicSQL(keyFactory.getNewKey(con)));
                            // Add Initial Available Status
                            s.executeUpdate(cbit.vcell.modeldb.AvailableTable.getCreateInitAvailStatusSQL(keyFactory.getNewKey(con)));
                        } finally {
                            s.close();
                        }
                    }
                    // 
                    // Create Indexes
                    // 
                    createIndex(con, "grp_grpid", cbit.vcell.modeldb.GroupTable.table, cbit.vcell.modeldb.GroupTable.table.groupid, dbSyntax);
                    createIndex(con, "browse_imgref", cbit.vcell.modeldb.BrowseImageDataTable.table, cbit.vcell.modeldb.BrowseImageDataTable.table.imageRef, dbSyntax);
                    createIndex(con, "geom_extentref", cbit.vcell.modeldb.GeometryTable.table, cbit.vcell.modeldb.GeometryTable.table.extentRef, dbSyntax);
                    createIndex(con, "geom_imageref", cbit.vcell.modeldb.GeometryTable.table, cbit.vcell.modeldb.GeometryTable.table.imageRef, dbSyntax);
                    createIndex(con, "mathdesc_geomref", cbit.vcell.modeldb.MathDescTable.table, cbit.vcell.modeldb.MathDescTable.table.geometryRef, dbSyntax);
                    createIndex(con, "simcstat_simcref", cbit.vcell.modeldb.SimContextStatTable.table, cbit.vcell.modeldb.SimContextStatTable.table.simContextRef, dbSyntax);
                }
                con.commit();
            } catch (SQLException exc) {
                con.rollback();
                System.out.println(exc.getMessage());
                exc.printStackTrace(System.out);
            } finally {
                conFactory.release(con, lock);
            }
        } else {
            throw new RuntimeException("Aborted by user");
        }
        System.exit(0);
    } catch (Throwable exc) {
        System.out.println(exc.getMessage());
        exc.printStackTrace(System.out);
    }
}
Also used : JPanel(javax.swing.JPanel) Table(cbit.sql.Table) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JCheckBox(javax.swing.JCheckBox) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame)

Example 10 with Table

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

the class DbDriver method insertVersionableChildSummary.

/**
 * This method was created in VisualAge.
 * @return cbit.sql.KeyValue
 * @param versionable cbit.sql.Versionable
 * @param pRef cbit.sql.KeyValue
 * @param bCommit boolean
 */
public static void insertVersionableChildSummary(Connection con, String serialDBChildSummary, VersionableType vType, KeyValue vKey, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
    Table csTable = null;
    Field csLargeCol = null;
    Field csSmallCol = null;
    if (vType.equals(VersionableType.BioModelMetaData)) {
        csTable = BioModelTable.table;
        csLargeCol = BioModelTable.table.childSummaryLarge;
        csSmallCol = BioModelTable.table.childSummarySmall;
    } else if (vType.equals(VersionableType.MathModelMetaData)) {
        csTable = MathModelTable.table;
        csLargeCol = MathModelTable.table.childSummaryLarge;
        csSmallCol = MathModelTable.table.childSummarySmall;
    } else {
        throw new IllegalArgumentException("vType " + vType + " not supported");
    }
    String sql = "UPDATE " + csTable.getTableName() + " SET " + (varchar2_CLOB_is_Varchar2_OK(serialDBChildSummary) ? csLargeCol.toString() + " = null ," + csSmallCol.toString() + " = " + INSERT_VARCHAR2_HERE : csLargeCol.toString() + " = " + INSERT_CLOB_HERE + " , " + csSmallCol.toString() + " = null") + " WHERE " + csTable.id.getUnqualifiedColName() + " = " + vKey.toString();
    varchar2_CLOB_update(con, sql, serialDBChildSummary, csTable, vKey, csLargeCol, csSmallCol, dbSyntax);
}
Also used : StarField(cbit.sql.StarField) Field(cbit.sql.Field) Table(cbit.sql.Table) LoadModelsStatTable(cbit.vcell.modeldb.MathVerifier.LoadModelsStatTable)

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