Search in sources :

Example 71 with BioModelInfo

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

the class DbDriver method getVCInfoContainer.

/**
 * Insert the method's description here.
 * Creation date: (9/24/2003 12:54:32 PM)
 * @return cbit.vcell.modeldb.VCInfoContainer
 */
public static VCInfoContainer getVCInfoContainer(User user, Connection con, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
    VCInfoContainer results = null;
    // 
    VCImageInfo[] vcImageInfos = null;
    GeometryInfo[] geometryInfos = null;
    MathModelInfo[] mathModelInfos = null;
    BioModelInfo[] bioModelInfos = null;
    // 
    StringBuffer sql = null;
    String special = null;
    ResultSet rset = null;
    boolean enableSpecial = true;
    boolean enableDistinct = true;
    Statement stmt = con.createStatement();
    try {
        // 
        // BioModelInfos
        // 
        {
            double beginTime = System.currentTimeMillis();
            special = " ORDER BY " + BioModelTable.table.name.getQualifiedColName() + "," + BioModelTable.table.versionBranchID.getQualifiedColName() + "," + BioModelTable.table.versionDate.getQualifiedColName();
            sql = new StringBuffer(BioModelTable.table.getInfoSQL(user, null, (enableSpecial ? special : null), dbSyntax));
            sql.insert(7, Table.SQL_GLOBAL_HINT);
            rset = stmt.executeQuery(sql.toString());
            ArrayList<BioModelInfo> tempInfos = new ArrayList<BioModelInfo>();
            Set<String> distinctV = new HashSet<String>();
            while (rset.next()) {
                BioModelInfo versionInfo = (BioModelInfo) BioModelTable.table.getInfo(rset, con, dbSyntax);
                if (!distinctV.contains(versionInfo.getVersion().getVersionKey().toString())) {
                    tempInfos.add(versionInfo);
                    distinctV.add(versionInfo.getVersion().getVersionKey().toString());
                }
            }
            rset.close();
            if (tempInfos.size() > 0) {
                bioModelInfos = new BioModelInfo[tempInfos.size()];
                tempInfos.toArray(bioModelInfos);
            }
            if (lg.isInfoEnabled()) {
                lg.info("BioModelInfo Time=" + (((double) System.currentTimeMillis() - beginTime) / (double) 1000));
            }
        }
        // 
        // MathModelInfos
        // 
        {
            double beginTime = System.currentTimeMillis();
            special = " ORDER BY " + MathModelTable.table.name.getQualifiedColName() + "," + MathModelTable.table.versionBranchID.getQualifiedColName() + "," + MathModelTable.table.versionDate.getQualifiedColName();
            sql = new StringBuffer(MathModelTable.table.getInfoSQL(user, null, (enableSpecial ? special : null), dbSyntax));
            sql.insert(7, Table.SQL_GLOBAL_HINT);
            rset = stmt.executeQuery(sql.toString());
            ArrayList<MathModelInfo> tempInfos = new ArrayList<MathModelInfo>();
            Set<String> distinctV = new HashSet<String>();
            while (rset.next()) {
                MathModelInfo versionInfo = (MathModelInfo) MathModelTable.table.getInfo(rset, con, dbSyntax);
                if (!distinctV.contains(versionInfo.getVersion().getVersionKey().toString())) {
                    tempInfos.add(versionInfo);
                    distinctV.add(versionInfo.getVersion().getVersionKey().toString());
                }
            }
            rset.close();
            if (tempInfos.size() > 0) {
                mathModelInfos = new MathModelInfo[tempInfos.size()];
                tempInfos.toArray(mathModelInfos);
            }
            if (lg.isInfoEnabled()) {
                lg.info("MathModelInfo Time=" + (((double) System.currentTimeMillis() - beginTime) / (double) 1000));
            }
        }
        // 
        // VCImageInfos
        // 
        {
            double beginTime = System.currentTimeMillis();
            special = " ORDER BY " + ImageTable.table.name.getQualifiedColName() + "," + ImageTable.table.versionBranchID.getQualifiedColName() + "," + ImageTable.table.versionDate.getQualifiedColName();
            sql = new StringBuffer(ImageTable.table.getInfoSQL(user, null, (enableSpecial ? special : null), true, dbSyntax));
            sql.insert(7, Table.SQL_GLOBAL_HINT);
            rset = stmt.executeQuery(sql.toString());
            ArrayList<VCImageInfo> tempInfos = new ArrayList<VCImageInfo>();
            Set<String> distinctV = new HashSet<String>();
            while (rset.next()) {
                VCImageInfo versionInfo = (VCImageInfo) ImageTable.table.getInfo(rset, con, dbSyntax);
                if (!distinctV.contains(versionInfo.getVersion().getVersionKey().toString())) {
                    tempInfos.add(versionInfo);
                    distinctV.add(versionInfo.getVersion().getVersionKey().toString());
                }
            }
            rset.close();
            if (tempInfos.size() > 0) {
                vcImageInfos = new VCImageInfo[tempInfos.size()];
                tempInfos.toArray(vcImageInfos);
            }
            if (lg.isInfoEnabled()) {
                lg.info("ImageInfo Time=" + (((double) System.currentTimeMillis() - beginTime) / (double) 1000));
            }
        }
        // 
        // GeometeryInfos
        // 
        {
            double beginTime = System.currentTimeMillis();
            special = " ORDER BY " + GeometryTable.table.name.getQualifiedColName() + "," + GeometryTable.table.versionBranchID.getQualifiedColName() + "," + GeometryTable.table.versionDate.getQualifiedColName();
            sql = new StringBuffer(GeometryTable.table.getInfoSQL(user, null, (enableSpecial ? special : null), true, dbSyntax));
            sql.insert(7, Table.SQL_GLOBAL_HINT + (enableDistinct ? "DISTINCT " : ""));
            rset = stmt.executeQuery(sql.toString());
            ArrayList<GeometryInfo> tempInfos = new ArrayList<GeometryInfo>();
            Set<String> distinctV = new HashSet<String>();
            while (rset.next()) {
                GeometryInfo versionInfo = (GeometryInfo) GeometryTable.table.getInfo(rset, con);
                if (!distinctV.contains(versionInfo.getVersion().getVersionKey().toString())) {
                    tempInfos.add(versionInfo);
                    distinctV.add(versionInfo.getVersion().getVersionKey().toString());
                }
            }
            rset.close();
            if (tempInfos.size() > 0) {
                geometryInfos = new GeometryInfo[tempInfos.size()];
                tempInfos.toArray(geometryInfos);
            }
            if (lg.isInfoEnabled()) {
                lg.info("GeometryInfo Time=" + (((double) System.currentTimeMillis() - beginTime) / (double) 1000));
            }
        }
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
    results = new VCInfoContainer(user, vcImageInfos, geometryInfos, mathModelInfos, bioModelInfos);
    return results;
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) BioModelInfo(org.vcell.util.document.BioModelInfo) ArrayList(java.util.ArrayList) MathModelInfo(org.vcell.util.document.MathModelInfo) VCInfoContainer(org.vcell.util.document.VCInfoContainer) GeometryInfo(cbit.vcell.geometry.GeometryInfo) ResultSet(java.sql.ResultSet) VCImageInfo(cbit.image.VCImageInfo)

Example 72 with BioModelInfo

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

the class DbDriver method testSuiteOP.

/**
 * Insert the method's description here.
 * Creation date: (10/19/2004 6:55:36 AM)
 * @return cbit.vcell.numericstest.TestSuiteNew
 * @param tsop cbit.vcell.numericstest.TestSuiteOP
 */
public static TestSuiteOPResults testSuiteOP(TestSuiteOP tsop, Connection con, User user, KeyFactory keyFactory) throws SQLException, DataAccessException {
    java.util.TreeSet<BigDecimal> changedTestSuiteKeys = new java.util.TreeSet<BigDecimal>();
    String sql = null;
    Statement stmt = null;
    try {
        if (tsop instanceof ModelGeometryOP) {
            ModelGeometryOP modelGeometryOP = (ModelGeometryOP) tsop;
            if (modelGeometryOP.getVCDocumentInfo() instanceof BioModelInfo) {
                BioModelInfo bioModelInfo = (BioModelInfo) modelGeometryOP.getVCDocumentInfo();
                sql = "SELECT " + SimContextTable.table.geometryRef.getQualifiedColName() + " FROM " + SimContextTable.table.getTableName() + "," + BioModelSimContextLinkTable.table.getTableName() + " WHERE " + SimContextTable.table.name.getQualifiedColName() + " = '" + modelGeometryOP.getBioModelApplicationName() + "'" + " AND " + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + " = " + SimContextTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + " = " + bioModelInfo.getVersion().getVersionKey().toString();
            } else if (modelGeometryOP.getVCDocumentInfo() instanceof MathModelInfo) {
                MathModelInfo mathModelInfo = (MathModelInfo) modelGeometryOP.getVCDocumentInfo();
                sql = "SELECT " + MathDescTable.table.geometryRef.getQualifiedColName() + " FROM " + MathDescTable.table.getTableName() + "," + MathModelTable.table.getTableName() + " WHERE " + MathModelTable.table.id.getQualifiedColName() + " = " + mathModelInfo.getVersion().getVersionKey().toString() + " AND " + MathModelTable.table.mathRef.getQualifiedColName() + " = " + MathDescTable.table.id.getQualifiedColName();
            } else {
                throw new IllegalArgumentException("UnImplemented VCDocumentInfo type=" + modelGeometryOP.getVCDocumentInfo().getClass().getName());
            }
            stmt = con.createStatement();
            ResultSet rset = stmt.executeQuery(sql);
            BigDecimal geometryKey = null;
            if (rset.next()) {
                geometryKey = rset.getBigDecimal(1);
                if (rset.next()) {
                    throw new DataAccessException("Expecting only 1 Geometry but found at least 2");
                }
            } else {
                throw new DataAccessException("No Geometry found using criteria");
            }
            rset.close();
            stmt.close();
            return new ModelGeometryOPResults(new KeyValue(geometryKey));
        } else // 
        if (tsop instanceof LoadTestInfoOP) {
            // 
            if (((LoadTestInfoOP) tsop).getLoadTestOpFlag() == LoadTestOpFlag.delete) {
                // Delete before return details
                LoadTestSoftwareVersionTimeStamp[] deleteTheseVersTimeStamps = ((LoadTestInfoOP) tsop).getLoadTestSoftwareVersionTimeStamps();
                for (int i = 0; i < deleteTheseVersTimeStamps.length; i++) {
                    sql = "DELETE FROM " + LoadModelsStatTable.table.getTableName() + " WHERE " + LoadModelsStatTable.table.softwareVers + " = " + "'" + deleteTheseVersTimeStamps[i].getSoftwareVersion() + "'" + " AND " + LoadModelsStatTable.table.timeStamp + " = " + "'" + deleteTheseVersTimeStamps[i].getRunTimeStamp() + "'";
                    DbDriver.updateCleanSQL(con, sql);
                }
                return null;
            }
            // Check if Date info is requested
            if (((LoadTestInfoOP) tsop).getLoadTestOpFlag() == LoadTestOpFlag.info && ((LoadTestInfoOP) tsop).getBeginDate() != null) {
                final String YMD_FORMAT_STRING = "yyyy-MM-dd";
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YMD_FORMAT_STRING);
                final String BETWEEN_CONDITION = " BETWEEN " + " TO_DATE('" + simpleDateFormat.format(((LoadTestInfoOP) tsop).getBeginDate()) + " 00:00:00', '" + YMD_FORMAT_STRING + " HH24:MI:SS') " + " AND " + " TO_DATE('" + simpleDateFormat.format(((LoadTestInfoOP) tsop).getEndDate()) + " 23:59:59', '" + YMD_FORMAT_STRING + " HH24:MI:SS') ";
                sql = "SELECT " + BioModelTable.table.id.getQualifiedColName() + "," + UserTable.table.userid.getUnqualifiedColName() + " FROM " + BioModelTable.table.getTableName() + "," + UserTable.table.getTableName() + " WHERE " + UserTable.table.id.getQualifiedColName() + " = " + BioModelTable.table.ownerRef.getQualifiedColName() + " AND " + BioModelTable.table.versionDate.getQualifiedColName() + BETWEEN_CONDITION + " UNION " + "SELECT " + MathModelTable.table.id.getQualifiedColName() + "," + UserTable.table.userid.getUnqualifiedColName() + " FROM " + MathModelTable.table.getTableName() + "," + UserTable.table.getTableName() + " WHERE " + UserTable.table.id.getQualifiedColName() + " = " + MathModelTable.table.ownerRef.getQualifiedColName() + " AND " + MathModelTable.table.versionDate.getQualifiedColName() + BETWEEN_CONDITION;
                stmt = con.createStatement();
                ResultSet rset = stmt.executeQuery(sql);
                TreeSet<String> uniqueUserIDTreeSet = new TreeSet<String>();
                Vector<KeyValue> keyValuesBetweenDatesV = new Vector<KeyValue>();
                while (rset.next()) {
                    uniqueUserIDTreeSet.add(rset.getString(UserTable.table.userid.getUnqualifiedColName()));
                    keyValuesBetweenDatesV.add(new KeyValue(rset.getBigDecimal(1)));
                }
                rset.close();
                stmt.close();
                return new LoadTestInfoOpResults(((LoadTestInfoOP) tsop).getBeginDate(), ((LoadTestInfoOP) tsop).getEndDate(), keyValuesBetweenDatesV.toArray(new KeyValue[0]), uniqueUserIDTreeSet.toArray(new String[0]));
            }
            // 
            // Get LoadTest Info
            // 
            // Get existing SoftwareVersion-Timestamp  count
            // 
            Vector<Integer> loadTestInfoCountV = new Vector<Integer>();
            stmt = con.createStatement();
            sql = "SELECT COUNT(*)," + LoadModelsStatTable.table.softwareVers.getUnqualifiedColName() + "," + LoadModelsStatTable.table.timeStamp.getUnqualifiedColName() + " FROM " + LoadModelsStatTable.table.getTableName() + " GROUP BY " + LoadModelsStatTable.table.softwareVers.getUnqualifiedColName() + "," + LoadModelsStatTable.table.timeStamp.getUnqualifiedColName();
            Vector<LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp> loadTestSoftwareVersionTimeStampsExistingV = new Vector<LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp>();
            ResultSet rset = stmt.executeQuery(sql);
            while (rset.next()) {
                String softwareVersion = TokenMangler.getSQLRestoredString(rset.getString(LoadModelsStatTable.table.softwareVers.getUnqualifiedColName()));
                String runTimeStamp = rset.getString(LoadModelsStatTable.table.timeStamp.getUnqualifiedColName());
                loadTestSoftwareVersionTimeStampsExistingV.add(new LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp(softwareVersion, runTimeStamp));
                loadTestInfoCountV.add(rset.getInt(1));
            }
            rset.close();
            stmt.close();
            // 
            // Get empty test info count (models that haven't been checked yet during a test run)
            // 
            stmt = con.createStatement();
            sql = "SELECT COUNT(*)," + LoadModelsStatTable.table.softwareVers.getUnqualifiedColName() + "," + LoadModelsStatTable.table.timeStamp.getUnqualifiedColName() + " FROM " + LoadModelsStatTable.table.getTableName() + " WHERE " + LoadModelsStatTable.table.resultFlag.getUnqualifiedColName() + " IS NULL" + " GROUP BY " + LoadModelsStatTable.table.softwareVers.getUnqualifiedColName() + "," + LoadModelsStatTable.table.timeStamp.getUnqualifiedColName();
            Vector<LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp> loadTestSoftwareVersionTimeStampsEmptyV = new Vector<LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp>();
            rset = stmt.executeQuery(sql);
            Integer[] loadTestInfoCountEmptyArr = new Integer[loadTestInfoCountV.size()];
            while (rset.next()) {
                String softwareVersion = TokenMangler.getSQLRestoredString(rset.getString(LoadModelsStatTable.table.softwareVers.getUnqualifiedColName()));
                String runTimeStamp = rset.getString(LoadModelsStatTable.table.timeStamp.getUnqualifiedColName());
                loadTestSoftwareVersionTimeStampsEmptyV.add(new LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp(softwareVersion, runTimeStamp));
                // match to existing array index so full and empty match
                for (int i = 0; i < loadTestSoftwareVersionTimeStampsExistingV.size(); i++) {
                    if (loadTestSoftwareVersionTimeStampsExistingV.elementAt(i).getSoftwareVersion().equals(softwareVersion) && loadTestSoftwareVersionTimeStampsExistingV.elementAt(i).getRunTimeStamp().equals(runTimeStamp)) {
                        loadTestInfoCountEmptyArr[i] = rset.getInt(1);
                    }
                }
            }
            rset.close();
            stmt.close();
            // 
            // Get total Math and Bio model count
            // 
            int totalBioMathModelCount = 0;
            stmt = con.createStatement();
            sql = "SELECT COUNT(*) FROM " + BioModelTable.table.getTableName() + " UNION " + "SELECT COUNT(*) FROM " + MathModelTable.table.getTableName();
            rset = stmt.executeQuery(sql);
            if (rset.next()) {
                totalBioMathModelCount = rset.getInt(1);
                if (rset.next()) {
                    totalBioMathModelCount += rset.getInt(1);
                } else {
                    totalBioMathModelCount = 0;
                }
            }
            if (totalBioMathModelCount == 0) {
                throw new DataAccessException("No results when querying bio and Mathmodel count");
            }
            rset.close();
            stmt.close();
            // 
            // Get slow Loads
            // 
            Object loadTestSlowHash = null;
            if (((LoadTestInfoOP) tsop).getSlowLoadThresholdMilliSec() != null) {
                Integer slowLoaderThreshold = ((LoadTestInfoOP) tsop).getSlowLoadThresholdMilliSec();
                loadTestSlowHash = getLoadTestDetails(con, slowLoaderThreshold, null);
            }
            // 
            // Get failed loads
            // 
            Object loadTestFailHash = getLoadTestDetails(con, null, null);
            // 
            // Get user specified query info.
            // 
            Object loadTestUserQueryHash = null;
            if (((LoadTestInfoOP) tsop).getUserQueryCondition() != null) {
                loadTestUserQueryHash = getLoadTestDetails(con, null, ((LoadTestInfoOP) tsop).getUserQueryCondition());
            }
            return new LoadTestInfoOpResults(loadTestInfoCountV.toArray(new Integer[0]), loadTestInfoCountEmptyArr, totalBioMathModelCount, loadTestSoftwareVersionTimeStampsExistingV.toArray(new LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp[0]), (Hashtable<LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp, Vector<LoadTestInfoOpResults.LoadTestFailDetails>>) loadTestFailHash, (Hashtable<LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp, Vector<LoadTestInfoOpResults.LoadTestSlowDetails>>) loadTestSlowHash, (Hashtable<LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp, Vector<LoadTestInfoOpResults.LoadTestDetails>>) loadTestUserQueryHash, ((LoadTestInfoOP) tsop).getSlowLoadThresholdMilliSec());
        }
        // 
        // TestSuite operations ---------------------------------------------------------------------------------------------------
        // 
        stmt = con.createStatement();
        if (tsop instanceof AddTestSuiteOP) {
            AddTestSuiteOP addts_tsop = (AddTestSuiteOP) tsop;
            String annotation = addts_tsop.getTestSuiteAnnotation();
            if (annotation != null) {
                if (annotation.length() == 0) {
                    annotation = null;
                } else {
                    annotation = TokenMangler.getSQLEscapedString(annotation);
                }
            }
            BigDecimal changedTSKey = keyFactory.getUniqueBigDecimal(con);
            final int NOT_LOCKED = 0;
            sql = "INSERT INTO " + TFTestSuiteTable.table.getTableName() + " VALUES(" + changedTSKey + ",'" + addts_tsop.getTestSuiteVersionID() + "'," + "'" + addts_tsop.getVCellBuildVersionID() + "'" + "," + "'" + addts_tsop.getNumericsBuildVersionID() + "'" + "," + "current_timestamp,current_timestamp," + (annotation == null ? "NULL" : "'" + annotation + "'") + "," + NOT_LOCKED + ")";
            stmt.executeUpdate(sql);
            if (addts_tsop.getAddTestCasesOPs() != null) {
                for (int i = 0; i < addts_tsop.getAddTestCasesOPs().length; i += 1) {
                    // Set new TSKey and do child OPs
                    AddTestCasesOP atcOP = addts_tsop.getAddTestCasesOPs()[i];
                    if (atcOP instanceof AddTestCasesOPMathModel) {
                        testSuiteOP(new AddTestCasesOPMathModel(changedTSKey, ((AddTestCasesOPMathModel) atcOP).getMathModelKey(), atcOP.getTestCaseType(), atcOP.getAnnotation(), ((AddTestCasesOPMathModel) atcOP).getAddTestCriteriaOPsMathModel()), con, user, keyFactory);
                    } else if (atcOP instanceof AddTestCasesOPBioModel) {
                        testSuiteOP(new AddTestCasesOPBioModel(changedTSKey, ((AddTestCasesOPBioModel) atcOP).getBioModelKey(), ((AddTestCasesOPBioModel) atcOP).getSimContextKey(), atcOP.getTestCaseType(), atcOP.getAnnotation(), ((AddTestCasesOPBioModel) atcOP).getAddTestCriteriaOPsBioModel()), con, user, keyFactory);
                    }
                }
            }
            changedTestSuiteKeys.add(changedTSKey);
        } else if (tsop instanceof AddTestCasesOPBioModel) {
            AddTestCasesOPBioModel addtc_tsop = (AddTestCasesOPBioModel) tsop;
            // 
            BigDecimal bmSimContextLinkRef = null;
            // Convert BioModelKey and SimContextKey to bmsimcontext key
            sql = "SELECT " + BioModelSimContextLinkTable.table.id.getQualifiedColName() + " FROM " + BioModelSimContextLinkTable.table.getTableName() + " WHERE " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "=" + addtc_tsop.getBioModelKey().toString() + " AND " + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + "=" + addtc_tsop.getSimContextKey().toString();
            ResultSet rset = stmt.executeQuery(sql);
            if (rset.next()) {
                bmSimContextLinkRef = rset.getBigDecimal(BioModelSimContextLinkTable.table.id.getUnqualifiedColName());
                if (rset.next()) {
                    throw new DataAccessException("Too many MathModelSimLink found for bmKey=" + addtc_tsop.getBioModelKey() + " simContextKey=" + addtc_tsop.getSimContextKey());
                }
            } else {
                throw new DataAccessException("No BioModelSimcontextLink found for bmKey=" + addtc_tsop.getBioModelKey() + " simContextKey=" + addtc_tsop.getSimContextKey());
            }
            rset.close();
            // 
            BigDecimal tcKey = keyFactory.getUniqueBigDecimal(con);
            String annotation = addtc_tsop.getAnnotation();
            if (annotation != null) {
                annotation = TokenMangler.getSQLEscapedString(annotation);
            }
            stmt.executeUpdate("INSERT INTO " + TFTestCaseTable.table.getTableName() + " VALUES(" + tcKey.toString() + "," + addtc_tsop.getTestSuiteKey().toString() + ",NULL," + "'" + addtc_tsop.getTestCaseType() + "'" + "," + "'" + annotation + "'" + "," + "current_timestamp" + "," + bmSimContextLinkRef.toString() + ")");
            if (addtc_tsop.getAddTestCriteriaOPsBioModel() != null) {
                for (int i = 0; i < addtc_tsop.getAddTestCriteriaOPsBioModel().length; i += 1) {
                    // Set new TSKey,TCaseKey and do child OPs
                    AddTestCriteriaOPBioModel atcritOP = addtc_tsop.getAddTestCriteriaOPsBioModel()[i];
                    testSuiteOP(new AddTestCriteriaOPBioModel(tcKey, atcritOP.getBioModelSimKey(), atcritOP.getRegressionBioModelKey(), atcritOP.getRegressionBioModelSimKey(), atcritOP.getMaxAbsoluteError(), atcritOP.getMaxRelativeError(), atcritOP.getAddTestResultsOP()), con, user, keyFactory);
                }
            }
            changedTestSuiteKeys.add(addtc_tsop.getTestSuiteKey());
        } else if (tsop instanceof AddTestCasesOPMathModel) {
            AddTestCasesOPMathModel addtc_tsop = (AddTestCasesOPMathModel) tsop;
            BigDecimal tcKey = keyFactory.getUniqueBigDecimal(con);
            KeyValue mmKey = addtc_tsop.getMathModelKey();
            String annotation = addtc_tsop.getAnnotation();
            if (annotation != null) {
                annotation = TokenMangler.getSQLEscapedString(annotation);
            }
            stmt.executeUpdate("INSERT INTO " + TFTestCaseTable.table.getTableName() + " VALUES(" + tcKey.toString() + "," + addtc_tsop.getTestSuiteKey().toString() + "," + mmKey.toString() + "," + "'" + addtc_tsop.getTestCaseType() + "'" + "," + "'" + annotation + "'" + "," + "current_timestamp" + ",NULL)");
            if (addtc_tsop.getAddTestCriteriaOPsMathModel() != null) {
                for (int i = 0; i < addtc_tsop.getAddTestCriteriaOPsMathModel().length; i += 1) {
                    // Set new TSKey,TCaseKey and do child OPs
                    AddTestCriteriaOPMathModel atcritOP = addtc_tsop.getAddTestCriteriaOPsMathModel()[i];
                    testSuiteOP(new AddTestCriteriaOPMathModel(tcKey, atcritOP.getMathModelSimKey(), atcritOP.getRegressionMathModelKey(), atcritOP.getRegressionMathModelSimKey(), atcritOP.getMaxAbsoluteError(), atcritOP.getMaxRelativeError(), atcritOP.getAddTestResultsOP()), con, user, keyFactory);
                }
            }
            changedTestSuiteKeys.add(addtc_tsop.getTestSuiteKey());
        } else if (tsop instanceof RemoveTestCasesOP) {
            RemoveTestCasesOP removetc_tsop = (RemoveTestCasesOP) tsop;
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < removetc_tsop.getTestCasesKeys().length; i += 1) {
                if (i != 0) {
                    sb.append(",");
                }
                sb.append(removetc_tsop.getTestCasesKeys()[i].toString());
            }
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + " IN (" + sb.toString() + ")" + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
            int numRowsUpdated = stmt.executeUpdate("DELETE FROM " + TFTestCaseTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getUnqualifiedColName() + " IN (" + sb.toString() + ")");
            if (numRowsUpdated != removetc_tsop.getTestCasesKeys().length) {
                throw new DataAccessException("Remove TestCase keys=" + sb.toString() + " from TSKey=" + removetc_tsop.getTestSuiteKey() + " removed row count=" + numRowsUpdated + " expected " + removetc_tsop.getTestCasesKeys().length);
            }
        } else if (tsop instanceof AddTestCriteriaOPMathModel) {
            AddTestCriteriaOPMathModel addtcrit_tsop = (AddTestCriteriaOPMathModel) tsop;
            BigDecimal tcritKey = keyFactory.getUniqueBigDecimal(con);
            BigDecimal tcKey = addtcrit_tsop.getTestCaseKey();
            KeyValue simKey = addtcrit_tsop.getMathModelSimKey();
            // Check that there is a single mathmodel associated with simkey and parentsimref is null
            sql = "SELECT " + MathModelSimulationLinkTable.table.id.getQualifiedColName() + " FROM " + MathModelSimulationLinkTable.table.getTableName() + "," + SimulationTable.table.getTableName() + " WHERE " + MathModelSimulationLinkTable.table.simRef.getQualifiedColName() + "=" + simKey.toString() + " AND " + MathModelSimulationLinkTable.table.simRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + " AND " + SimulationTable.table.getTableName() + "." + SimulationTable.versionParentSimRef_ColumnName + " IS NULL";
            ResultSet rset = stmt.executeQuery(sql);
            if (rset.next()) {
                if (rset.next()) {
                    throw new DataAccessException("Too many MathModelSimulationLink found for simKey=" + simKey);
                }
            } else {
                throw new DataAccessException("No MathModelSimulationLink found for simKey=" + simKey);
            }
            rset.close();
            // //
            // //Make sure TestCase type and regressionRef match
            // sql = "SELECT "+TFTestCaseTable.table.id.getQualifiedColName()+
            // " FROM "+TFTestCaseTable.table.getTableName()+
            // " WHERE "+
            // TFTestCaseTable.table.id.getQualifiedColName()+"="+tcKey.toString()+
            // " AND "+
            // TFTestCaseTable.table.tcSolutionType.getQualifiedColName()+
            // (regrSimKey != null?"=":"!=")+
            // "'"+cbit.vcell.numericstest.TestCaseNew.REGRESSION+"'";
            // rset = stmt.executeQuery(sql);
            // if(!rset.next()){
            // throw new DataAccessException("TestCase type not compatible with regressionSimKey");
            // }
            // rset.close();
            // 
            // 
            // Get simDataRef from simKey
            BigDecimal simDataRef = null;
            // sql =
            // "SELECT "+ResultSetMetaDataTable.table.id.getQualifiedColName()+
            // " FROM " +ResultSetMetaDataTable.table.getTableName()+
            // " WHERE "+
            // ResultSetMetaDataTable.table.simRef.getQualifiedColName()+"="+simKey.toString();
            // rset = stmt.executeQuery(sql);
            // if(rset.next()){
            // simDataRef = rset.getBigDecimal(MathModelSimulationLinkTable.table.id.getUnqualifiedColName());
            // if(rset.next()){
            // throw new DataAccessException("Too many ResultSetMetaData found for simKey="+simKey);
            // }
            // }
            // else{
            // throw new DataAccessException("No ResultSetMetaData found for simKey="+simKey);
            // }
            rset.close();
            // 
            // Insert TestCriteria
            sql = "INSERT INTO " + TFTestCriteriaTable.table.getTableName() + " VALUES(" + tcritKey.toString() + "," + tcKey.toString() + "," + simKey.toString() + "," + (simDataRef != null ? simDataRef.toString() : null) + "," + "NULL" + "," + (addtcrit_tsop.getMaxRelativeError() != null ? "TO_NUMBER('" + addtcrit_tsop.getMaxRelativeError().toString() + "')" : "null") + "," + (addtcrit_tsop.getMaxAbsoluteError() != null ? "TO_NUMBER('" + addtcrit_tsop.getMaxAbsoluteError().toString() + "')" : "null") + "," + "NULL,NULL," + "'" + TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT + "'" + ",null" + ")";
            stmt.executeUpdate(sql);
            if (addtcrit_tsop.getRegressionMathModelSimKey() != null) {
                testSuiteOP(new EditTestCriteriaOPMathModel(tcritKey, addtcrit_tsop.getRegressionMathModelKey(), addtcrit_tsop.getRegressionMathModelSimKey(), addtcrit_tsop.getMaxAbsoluteError(), addtcrit_tsop.getMaxRelativeError()), con, user, keyFactory);
            }
            if (addtcrit_tsop.getAddTestResultsOP() != null) {
                AddTestResultsOP atrOP = addtcrit_tsop.getAddTestResultsOP();
                // Set new TSKey,TCritKey and do child OPs
                testSuiteOP(new AddTestResultsOP(tcritKey, atrOP.getVariableComparisonSummaries()), con, user, keyFactory);
            }
            rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + tcritKey.toString() + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof AddTestCriteriaOPBioModel) {
            AddTestCriteriaOPBioModel addtcrit_tsop = (AddTestCriteriaOPBioModel) tsop;
            BigDecimal tcritKey = keyFactory.getUniqueBigDecimal(con);
            BigDecimal tcKey = addtcrit_tsop.getTestCaseKey();
            KeyValue simKey = addtcrit_tsop.getBioModelSimKey();
            // Check that there is a single biomodel associated with simkey and parentsimref is null
            sql = "SELECT " + BioModelSimulationLinkTable.table.id.getQualifiedColName() + " FROM " + BioModelSimulationLinkTable.table.getTableName() + "," + SimulationTable.table.getTableName() + " WHERE " + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + "=" + simKey.toString() + " AND " + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + " AND " + SimulationTable.table.getTableName() + "." + SimulationTable.versionParentSimRef_ColumnName + " IS NULL";
            ResultSet rset = stmt.executeQuery(sql);
            if (rset.next()) {
                if (rset.next()) {
                    throw new DataAccessException("Too many BioModelSimulationLink found for simKey=" + simKey);
                }
            } else {
                throw new DataAccessException("No BioModelSimulationLink found for simKey=" + simKey);
            }
            rset.close();
            // //
            // //Make sure TestCase type and regressionRef match
            // sql = "SELECT "+TFTestCaseTable.table.id.getQualifiedColName()+
            // " FROM "+TFTestCaseTable.table.getTableName()+
            // " WHERE "+
            // TFTestCaseTable.table.id.getQualifiedColName()+"="+tcKey.toString()+
            // " AND "+
            // TFTestCaseTable.table.tcSolutionType.getQualifiedColName()+
            // (regrSimKey != null?"=":"!=")+
            // "'"+cbit.vcell.numericstest.TestCaseNew.REGRESSION+"'";
            // rset = stmt.executeQuery(sql);
            // if(!rset.next()){
            // throw new DataAccessException("TestCase type not compatible with regressionSimKey");
            // }
            // rset.close();
            // 
            // 
            // Get simDataRef from simKey
            BigDecimal simDataRef = null;
            // sql =
            // "SELECT "+ResultSetMetaDataTable.table.id.getQualifiedColName()+
            // " FROM " +ResultSetMetaDataTable.table.getTableName()+
            // " WHERE "+
            // ResultSetMetaDataTable.table.simRef.getQualifiedColName()+"="+simKey.toString();
            // rset = stmt.executeQuery(sql);
            // if(rset.next()){
            // simDataRef = rset.getBigDecimal(BioModelSimulationLinkTable.table.id.getUnqualifiedColName());
            // if(rset.next()){
            // throw new DataAccessException("Too many ResultSetMetaData found for simKey="+simKey);
            // }
            // }
            // else{
            // throw new DataAccessException("No ResultSetMetaData found for simKey="+simKey);
            // }
            rset.close();
            // 
            // Insert TestCriteria
            sql = "INSERT INTO " + TFTestCriteriaTable.table.getTableName() + " VALUES(" + tcritKey.toString() + "," + tcKey.toString() + "," + simKey.toString() + "," + (simDataRef != null ? simDataRef.toString() : null) + "," + "null" + "," + (addtcrit_tsop.getMaxRelativeError() != null ? "TO_NUMBER('" + addtcrit_tsop.getMaxRelativeError().toString() + "')" : "null") + "," + (addtcrit_tsop.getMaxAbsoluteError() != null ? "TO_NUMBER('" + addtcrit_tsop.getMaxAbsoluteError().toString() + "')" : "null") + "," + "NULL,NULL," + "'" + TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT + "'" + ",null" + ")";
            stmt.executeUpdate(sql);
            if (addtcrit_tsop.getRegressionBioModelSimKey() != null) {
                testSuiteOP(new EditTestCriteriaOPBioModel(tcritKey, addtcrit_tsop.getRegressionBioModelKey(), addtcrit_tsop.getRegressionBioModelSimKey(), addtcrit_tsop.getMaxAbsoluteError(), addtcrit_tsop.getMaxRelativeError()), con, user, keyFactory);
            }
            if (addtcrit_tsop.getAddTestResultsOP() != null) {
                AddTestResultsOP atrOP = addtcrit_tsop.getAddTestResultsOP();
                // Set new TSKey,TCritKey and do child OPs
                testSuiteOP(new AddTestResultsOP(tcritKey, atrOP.getVariableComparisonSummaries()), con, user, keyFactory);
            }
            rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + tcritKey.toString() + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof RemoveTestCriteriaOP) {
            RemoveTestCriteriaOP removetcrit_tsop = (RemoveTestCriteriaOP) tsop;
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < removetcrit_tsop.getTestCriterias().length; i += 1) {
                if (i != 0) {
                    sb.append(",");
                }
                sb.append(removetcrit_tsop.getTestCriterias()[i].getTCritKey().toString());
            }
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + " IN (" + sb.toString() + ")" + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
            int numRowsUpdated = stmt.executeUpdate("DELETE FROM " + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCriteriaTable.table.id.getUnqualifiedColName() + " IN (" + sb.toString() + ")");
            if (numRowsUpdated != removetcrit_tsop.getTestCriterias().length) {
                throw new DataAccessException("Remove TestCriteria keys=" + sb.toString() + " removed row count=" + numRowsUpdated + " expected " + removetcrit_tsop.getTestCriterias().length);
            }
        } else if (tsop instanceof RemoveTestSuiteOP) {
            RemoveTestSuiteOP removets_tsop = (RemoveTestSuiteOP) tsop;
            int numRowsUpdated = stmt.executeUpdate("DELETE FROM " + TFTestSuiteTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getUnqualifiedColName() + "=" + removets_tsop.getTestSuiteKey().toString());
            if (numRowsUpdated != 1) {
                throw new DataAccessException("Remove SINGLE TestSuite - key=" + removets_tsop.getTestSuiteKey().toString() + " removed row count=" + numRowsUpdated);
            }
            changedTestSuiteKeys.add(removets_tsop.getTestSuiteKey());
        } else if (tsop instanceof AddTestResultsOP) {
            AddTestResultsOP addtr_tsop = (AddTestResultsOP) tsop;
            VariableComparisonSummary[] vcs = addtr_tsop.getVariableComparisonSummaries();
            if (vcs == null || vcs.length == 0) {
                throw new DataAccessException(RemoveTestCasesOP.class.getName() + " had no TestResults");
            }
            for (int i = 0; i < vcs.length; i += 1) {
                if (vcs[i] == null) {
                    throw new DataAccessException(RemoveTestCasesOP.class.getName() + " Array element was null");
                }
            }
            ResultSet rset = stmt.executeQuery("SELECT " + TFTestResultTable.table.id.getUnqualifiedColName() + " FROM " + TFTestResultTable.table.getTableName() + " WHERE " + TFTestResultTable.table.testCriteriaRef.getUnqualifiedColName() + "=" + addtr_tsop.getTestCriteriaKey().toString());
            if (rset.next()) {
                throw new DataAccessException("AddTestResultsOP Criteria key=" + addtr_tsop.getTestCriteriaKey() + " has results");
            }
            rset.close();
            for (int i = 0; i < vcs.length; i += 1) {
                sql = "INSERT INTO " + TFTestResultTable.table.getTableName() + " VALUES(" + "NEWSEQ.NEXTVAL" + "," + addtr_tsop.getTestCriteriaKey().toString() + "," + "'" + vcs[i].getName() + "'" + "," + "TO_NUMBER('" + vcs[i].getAbsoluteError() + "')" + "," + "TO_NUMBER('" + vcs[i].getRelativeError() + "')" + "," + "TO_NUMBER('" + vcs[i].getMaxRef() + "')" + "," + "TO_NUMBER('" + vcs[i].getMinRef() + "')" + "," + "TO_NUMBER('" + vcs[i].getMeanSqError() + "')" + "," + "TO_NUMBER('" + vcs[i].getTimeAbsoluteError() + "')" + "," + "TO_NUMBER('" + vcs[i].getIndexAbsoluteError() + "')" + "," + "TO_NUMBER('" + vcs[i].getTimeRelativeError() + "')" + "," + "TO_NUMBER('" + vcs[i].getIndexRelativeError() + "')" + ")";
                stmt.executeUpdate(sql);
            }
            rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + addtr_tsop.getTestCriteriaKey().toString() + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof RemoveTestResultsOP) {
            RemoveTestResultsOP removetr_tsop = (RemoveTestResultsOP) tsop;
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < removetr_tsop.getTestCriteriaKeys().length; i += 1) {
                if (i != 0) {
                    sb.append(",");
                }
                sb.append(removetr_tsop.getTestCriteriaKeys()[i].toString());
                stmt.executeUpdate("DELETE FROM " + TFTestResultTable.table.getTableName() + " WHERE " + TFTestResultTable.table.testCriteriaRef.getUnqualifiedColName() + "=" + removetr_tsop.getTestCriteriaKeys()[i].toString());
            }
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + " IN (" + sb.toString() + ")" + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof EditTestCriteriaOPReportStatus) {
            EditTestCriteriaOPReportStatus edittcrit_tsop = (EditTestCriteriaOPReportStatus) tsop;
            BigDecimal tcritKey = edittcrit_tsop.getTestCriteriaKey();
            if (tcritKey == null) {
                throw new DataAccessException(tsop.getClass().getName() + " had no TestCriteria keys");
            }
            String newRS = edittcrit_tsop.getNewReportStatus();
            if (newRS == null || (!newRS.equals(TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_FAILEDVARS) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_NODATA) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_NOREFREGR) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_PASSED) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_RPERROR) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_SIMFAILED) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_SIMRUNNING) && !newRS.equals(TestCriteriaNew.TCRIT_STATUS_SIMNOTRUNFAILDONE))) {
                throw new DataAccessException("Unsupported ReportStatus=" + edittcrit_tsop.getNewReportStatus());
            }
            String reportStatusMessage = edittcrit_tsop.getNewReportStatusMessage();
            if (reportStatusMessage != null) {
                reportStatusMessage = TokenMangler.getSQLEscapedString(reportStatusMessage);
                reportStatusMessage = reportStatusMessage.substring(0, Math.min(TFTestCriteriaTable.MAX_MESSAGE_SIZE, reportStatusMessage.length()));
            }
            stmt.executeUpdate("UPDATE " + TFTestCriteriaTable.table.getTableName() + " SET " + TFTestCriteriaTable.table.reportStatus.getQualifiedColName() + "=" + (newRS != null ? "'" + newRS + "'" : "null") + "," + TFTestCriteriaTable.table.reportMessage.getQualifiedColName() + "=" + (reportStatusMessage != null ? "'" + reportStatusMessage + "'" : "null") + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + tcritKey.toString());
            if (newRS.equals(TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT)) {
                testSuiteOP(new RemoveTestResultsOP(new BigDecimal[] { tcritKey }), con, user, keyFactory);
            }
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + " = " + tcritKey.toString() + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof EditTestCriteriaOPMathModel) {
            EditTestCriteriaOPMathModel edittcrit_tsop = (EditTestCriteriaOPMathModel) tsop;
            BigDecimal tcritKey = edittcrit_tsop.getTestCriteriaKey();
            if (tcritKey == null) {
                throw new DataAccessException(tsop.getClass().getName() + " had no TestCriteria keys");
            }
            if ((edittcrit_tsop.getMathModelRegressionRef() == null && edittcrit_tsop.getMathModelRegressionSimRef() != null) || (edittcrit_tsop.getMathModelRegressionRef() != null && edittcrit_tsop.getMathModelRegressionSimRef() == null)) {
                throw new DataAccessException(tsop.getClass().getName() + " MathRef and SimRef must both be null or both not null");
            }
            Double maxAbsError = edittcrit_tsop.getNewMaxAbsError();
            Double maxRelError = edittcrit_tsop.getNewMaxRelError();
            KeyValue regrSimRef = edittcrit_tsop.getMathModelRegressionSimRef();
            // Convert regrSimKey to regrMathModelSimLinkKey
            BigDecimal regrMathModelSimLink = null;
            if (regrSimRef != null) {
                sql = "SELECT " + MathModelSimulationLinkTable.table.id.getQualifiedColName() + " FROM " + MathModelSimulationLinkTable.table.getTableName() + " WHERE " + MathModelSimulationLinkTable.table.simRef.getQualifiedColName() + "=" + regrSimRef.toString();
                ResultSet rset = stmt.executeQuery(sql);
                if (rset.next()) {
                    regrMathModelSimLink = rset.getBigDecimal(MathModelSimulationLinkTable.table.id.getUnqualifiedColName());
                    if (rset.next()) {
                        throw new DataAccessException("Too many MathModelSimLink found for regrSimKey=" + regrSimRef);
                    }
                } else {
                    throw new DataAccessException("No MathModelSimLink found for regrSimKey=" + regrSimRef);
                }
                rset.close();
            }
            stmt.executeUpdate("UPDATE " + TFTestCriteriaTable.table.getTableName() + " SET " + TFTestCriteriaTable.table.maxAbsError.getQualifiedColName() + "=" + (maxAbsError != null ? "TO_NUMBER(" + maxAbsError.toString() + ")" : "null") + "," + TFTestCriteriaTable.table.maxRelError.getQualifiedColName() + "=" + (maxRelError != null ? "TO_NUMBER(" + maxRelError.toString() + ")" : "null") + "," + TFTestCriteriaTable.table.regressionMMSimRef.getQualifiedColName() + "=" + (regrMathModelSimLink != null ? regrMathModelSimLink.toString() : "null") + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + tcritKey.toString());
            testSuiteOP(new EditTestCriteriaOPReportStatus(tcritKey, TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT, null), con, user, keyFactory);
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + " = " + tcritKey.toString() + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof EditTestCriteriaOPBioModel) {
            EditTestCriteriaOPBioModel edittcrit_tsop = (EditTestCriteriaOPBioModel) tsop;
            BigDecimal tcritKey = edittcrit_tsop.getTestCriteriaKey();
            if (tcritKey == null) {
                throw new DataAccessException(tsop.getClass().getName() + " had no TestCriteria keys");
            }
            if ((edittcrit_tsop.getBioModelRegressionRef() == null && edittcrit_tsop.getBioModelRegressionSimRef() != null) || (edittcrit_tsop.getBioModelRegressionRef() != null && edittcrit_tsop.getBioModelRegressionSimRef() == null)) {
                throw new DataAccessException(tsop.getClass().getName() + " ApplicationRef and SimRef must both be null or both not null");
            }
            Double maxAbsError = edittcrit_tsop.getNewMaxAbsError();
            Double maxRelError = edittcrit_tsop.getNewMaxRelError();
            BigDecimal bmscAppKey = null;
            BigDecimal bmsltSimKey = null;
            final String BMSLT = "BMSLT";
            if (edittcrit_tsop.getBioModelRegressionSimRef() != null) {
                sql = "SELECT " + BioModelSimContextLinkTable.table.id.getQualifiedColName() + "," + BioModelSimulationLinkTable.table.id.getQualifiedColName() + " " + BMSLT + " FROM " + BioModelSimContextLinkTable.table.getTableName() + "," + SimContextTable.table.getTableName() + "," + SimulationTable.table.getTableName() + "," + BioModelSimulationLinkTable.table.getTableName() + " WHERE " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "=" + edittcrit_tsop.getBioModelRegressionRef() + " AND " + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + "=" + SimContextTable.table.id.getQualifiedColName() + " AND " + SimContextTable.table.mathRef.getQualifiedColName() + "=" + SimulationTable.table.mathRef.getQualifiedColName() + " AND " + SimulationTable.table.id.getQualifiedColName() + "=" + edittcrit_tsop.getBioModelRegressionSimRef().toString() + " AND " + BioModelSimulationLinkTable.table.bioModelRef.getQualifiedColName() + " = " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + " AND " + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + " = " + SimulationTable.table.id.getQualifiedColName();
                ResultSet rset = stmt.executeQuery(sql);
                if (rset.next()) {
                    bmscAppKey = rset.getBigDecimal(BioModelSimContextLinkTable.table.id.getUnqualifiedColName());
                    bmsltSimKey = rset.getBigDecimal(BMSLT);
                    if (rset.next()) {
                        throw new DataAccessException("Too many ResultSetMetaData found for simKey=" + edittcrit_tsop.getBioModelRegressionSimRef());
                    }
                }
                rset.close();
            }
            stmt.executeUpdate("UPDATE " + TFTestCriteriaTable.table.getTableName() + " SET " + TFTestCriteriaTable.table.maxAbsError.getQualifiedColName() + "=" + (maxAbsError != null ? "TO_NUMBER(" + maxAbsError.toString() + ")" : "null") + "," + TFTestCriteriaTable.table.maxRelError.getQualifiedColName() + "=" + (maxRelError != null ? "TO_NUMBER(" + maxRelError.toString() + ")" : "null") + "," + TFTestCriteriaTable.table.regressionBMAPPRef.getQualifiedColName() + "=" + (bmscAppKey != null ? bmscAppKey.toString() : "NULL") + "," + TFTestCriteriaTable.table.regressionBMSimRef.getQualifiedColName() + "=" + (bmsltSimKey != null ? bmsltSimKey.toString() : "NULL") + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + tcritKey.toString());
            testSuiteOP(new EditTestCriteriaOPReportStatus(tcritKey, TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT, null), con, user, keyFactory);
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + " = " + tcritKey.toString() + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof ChangeTestCriteriaErrorLimitOP) {
            ChangeTestCriteriaErrorLimitOP edittcrit_tsop = (ChangeTestCriteriaErrorLimitOP) tsop;
            BigDecimal[] tcritKeyArr = edittcrit_tsop.getTestCriteriaKeys();
            double[] maxAbsErrorArr = edittcrit_tsop.getAbsErrorLimits();
            double[] maxRelErrorArr = edittcrit_tsop.getRelErrorLimits();
            if (tcritKeyArr == null || (maxAbsErrorArr != null && maxAbsErrorArr.length != tcritKeyArr.length) || (maxAbsErrorArr != null && maxRelErrorArr.length != tcritKeyArr.length)) {
                throw new DataAccessException(tsop.getClass().getName() + " Improper arguments.");
            }
            StringBuffer tcritList = new StringBuffer();
            for (int i = 0; i < tcritKeyArr.length; i++) {
                if (i != 0) {
                    tcritList.append(",");
                }
                tcritList.append(tcritKeyArr[i]);
                stmt.executeUpdate("UPDATE " + TFTestCriteriaTable.table.getTableName() + " SET " + (maxAbsErrorArr != null ? TFTestCriteriaTable.table.maxAbsError.getQualifiedColName() + "=" + maxAbsErrorArr[i] : "") + (maxAbsErrorArr != null && maxRelErrorArr != null ? "," : "") + (maxRelErrorArr != null ? TFTestCriteriaTable.table.maxRelError.getQualifiedColName() + "=" + maxRelErrorArr[i] : "") + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + tcritKeyArr[i].toString());
                testSuiteOP(new EditTestCriteriaOPReportStatus(tcritKeyArr[i], TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT, null), con, user, keyFactory);
            }
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + " IN (" + tcritList.toString() + ")" + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
        } else if (tsop instanceof EditTestCasesOP) {
            EditTestCasesOP edittc_tsop = (EditTestCasesOP) tsop;
            BigDecimal[] tcaseKeys = edittc_tsop.getTestCasesKeys();
            String[] annots = edittc_tsop.getNewAnnotations();
            boolean[] newSteadyStates = edittc_tsop.getNewSteadyStates();
            if (tcaseKeys == null || tcaseKeys.length == 0) {
                throw new DataAccessException(tsop.getClass().getName() + " had no TestCase keys");
            }
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < tcaseKeys.length; i += 1) {
                if (i != 0) {
                    sb.append(",");
                }
                sb.append(tcaseKeys[i].toString());
                if (annots != null) {
                    String annotation = annots[i];
                    if (annotation != null) {
                        if (annotation.length() == 0) {
                            annotation = null;
                        } else {
                            annotation = TokenMangler.getSQLEscapedString(annotation);
                        }
                    }
                    stmt.executeUpdate("UPDATE " + TFTestCaseTable.table.getTableName() + " SET " + TFTestCaseTable.table.tcAnnotation.getQualifiedColName() + "=" + (annotation == null ? "NULL" : "'" + annotation + "'") + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + tcaseKeys[i].toString());
                }
                if (newSteadyStates != null) {
                    // Make sure the change is for EXACT type
                    ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestCriteriaTable.table.id.getQualifiedColName() + " FROM " + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + tcaseKeys[i].toString() + " AND " + "(" + TFTestCaseTable.table.tcSolutionType.getQualifiedColName() + "='" + TestCaseNew.EXACT + "'" + " OR " + TFTestCaseTable.table.tcSolutionType.getQualifiedColName() + "='" + TestCaseNew.EXACT_STEADY + "'" + ")" + " AND " + TFTestCriteriaTable.table.testCaseRef + "=" + TFTestCaseTable.table.id.getQualifiedColName());
                    // Get TestCriteria Keys for Test case
                    Vector<BigDecimal> tcritKeyV = new Vector<BigDecimal>();
                    while (rset.next()) {
                        tcritKeyV.add(rset.getBigDecimal(TFTestCriteriaTable.table.id.getUnqualifiedColName()));
                    }
                    if (tcritKeyV.size() == 0) {
                        throw new DataAccessException("Updating SteadyState on TestCase that is not EXACT is NOT allowed.");
                    }
                    rset.close();
                    // Change SteadyState type for TestCase
                    boolean newSteadyState = newSteadyStates[i];
                    stmt.executeUpdate("UPDATE " + TFTestCaseTable.table.getTableName() + " SET " + TFTestCaseTable.table.tcSolutionType.getQualifiedColName() + "=" + (newSteadyState ? "'" + TestCaseNew.EXACT_STEADY + "'" : "'" + TestCaseNew.EXACT + "'") + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + tcaseKeys[i].toString());
                    // Change Report status
                    for (int j = 0; j < tcritKeyV.size(); j++) {
                        EditTestCriteriaOPReportStatus etcors = new EditTestCriteriaOPReportStatus(tcritKeyV.elementAt(j), TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT, null);
                        testSuiteOP(etcors, con, user, keyFactory);
                    }
                }
            }
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + " WHERE " + TFTestCaseTable.table.id.getQualifiedColName() + " IN (" + sb.toString() + ")" + " AND " + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + "=" + TFTestSuiteTable.table.id.getQualifiedColName());
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof EditTestSuiteOP) {
            EditTestSuiteOP editts_tsop = (EditTestSuiteOP) tsop;
            BigDecimal[] tsKeys = editts_tsop.getTestSuiteKeys();
            String[] annots = editts_tsop.getNewAnnotations();
            if (tsKeys == null || tsKeys.length == 0) {
                throw new DataAccessException(tsop.getClass().getName() + " had no TestSuite keys");
            }
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < tsKeys.length; i += 1) {
                if (i != 0) {
                    sb.append(",");
                }
                sb.append(tsKeys[i].toString());
                if (editts_tsop.isLock() != null) {
                    stmt.executeUpdate("UPDATE " + TFTestSuiteTable.table.getTableName() + " SET " + TFTestSuiteTable.table.isLocked.getQualifiedColName() + "= 1" + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + tsKeys[i].toString());
                } else {
                    if (annots != null) {
                        String annotation = annots[i];
                        if (annotation != null) {
                            if (annotation.length() == 0) {
                                annotation = null;
                            } else {
                                annotation = TokenMangler.getSQLEscapedString(annotation);
                            }
                        }
                        stmt.executeUpdate("UPDATE " + TFTestSuiteTable.table.getTableName() + " SET " + TFTestSuiteTable.table.tsAnnotation.getQualifiedColName() + "=" + (annotation == null ? "NULL" : "'" + annotation + "'") + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + tsKeys[i].toString());
                    }
                }
            }
            ResultSet rset = stmt.executeQuery("SELECT DISTINCT " + TFTestSuiteTable.table.id.getQualifiedColName() + " FROM " + TFTestSuiteTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + " IN (" + sb.toString() + ")");
            while (rset.next()) {
                changedTestSuiteKeys.add(rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName()));
            }
            rset.close();
        } else if (tsop instanceof QueryTestCriteriaCrossRefOP) {
            QueryTestCriteriaCrossRefOP qtcritxr_tsop = (QueryTestCriteriaCrossRefOP) tsop;
            Vector<TestCriteriaCrossRefOPResults.CrossRefData> crossRefV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
            // 
            // BioModel query
            // 
            String TSID = "tsid";
            String TCID = "tcid";
            String TCRID = "tcrid";
            String BMNAME = "bmname";
            String SCNAME = "scname";
            String SIMNAME = "simname";
            String TSALT = "TSALT";
            String TCALT = "TCALT";
            String TCRALT = "TCRALT";
            String BSCALT = "BSCALT";
            String MMSIMALT = "MMSIMALT";
            String MODELID = "MODELID";
            String REFTSUITEKEY = "REFTSUITEKEY";
            String REFTCASEKEY = "REFTCASEKEY";
            String REFTCRITKEY = "REFTCRITKEY";
            // String TCRALT2 = "TCRALT2";
            // String SIM2 = "SIM2";
            sql = "SELECT DISTINCT " + TFTestSuiteTable.table.tsVersion.getQualifiedColName() + "," + TFTestSuiteTable.table.id.getQualifiedColName() + " " + TSID + "," + TFTestCaseTable.table.id.getQualifiedColName() + " " + TCID + "," + TFTestCriteriaTable.table.id.getQualifiedColName() + " " + TCRID + "," + BioModelTable.table.name.getQualifiedColName() + " " + BMNAME + "," + SimContextTable.table.name.getQualifiedColName() + " " + SCNAME + "," + SimulationTable.table.name.getQualifiedColName() + " " + SIMNAME + "," + TFTestCriteriaTable.table.maxAbsError.getQualifiedColName() + "," + TFTestCriteriaTable.table.maxRelError.getQualifiedColName() + "," + TFTestResultTable.table.varName.getQualifiedColName() + "," + TFTestResultTable.table.minRef.getQualifiedColName() + "," + TFTestResultTable.table.maxRef.getQualifiedColName() + "," + TFTestResultTable.table.absError.getQualifiedColName() + "," + TFTestResultTable.table.relError.getQualifiedColName() + "," + TFTestResultTable.table.meanSqrError.getQualifiedColName() + "," + TFTestResultTable.table.timeAbsError.getQualifiedColName() + "," + TFTestResultTable.table.indexAbsError.getQualifiedColName() + "," + TFTestResultTable.table.timeRelError.getQualifiedColName() + "," + TFTestResultTable.table.indexRelError.getQualifiedColName() + "," + TSALT + "." + TFTestSuiteTable.table.tsVersion.getUnqualifiedColName() + "," + BSCALT + "." + BioModelSimContextLinkTable.table.bioModelRef.getUnqualifiedColName() + "," + TFTestCaseTable.table.tcSolutionType.getQualifiedColName() + "," + BioModelTable.table.id.getQualifiedColName() + " " + MODELID + "," + TSALT + "." + TFTestSuiteTable.table.id.getUnqualifiedColName() + " " + REFTSUITEKEY + "," + TCALT + "." + TFTestCaseTable.table.id.getUnqualifiedColName() + " " + REFTCASEKEY + "," + "NULL " + // TCRALT2+"."+TFTestCriteriaTable.table.id.getUnqualifiedColName() +" "+REFTCRITKEY +
            REFTCRITKEY + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + "," + TFTestResultTable.table.getTableName() + "," + BioModelSimContextLinkTable.table.getTableName() + "," + BioModelTable.table.getTableName() + "," + SimContextTable.table.getTableName() + "," + SimulationTable.table.getTableName() + "," + BioModelSimulationLinkTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + " " + TSALT + "," + TFTestCaseTable.table.getTableName() + " " + TCALT + "," + TFTestCriteriaTable.table.getTableName() + " " + TCRALT + "," + BioModelSimContextLinkTable.table.getTableName() + " " + BSCALT + // ","+TFTestCriteriaTable.table.getTableName()+" "+TCRALT2+
            " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + "=" + TFTestCaseTable.table.id.getQualifiedColName() + " AND " + TFTestResultTable.table.testCriteriaRef.getQualifiedColName() + "(+)" + "=" + TFTestCriteriaTable.table.id.getQualifiedColName() + (qtcritxr_tsop.getVarName() != null ? " AND " + TFTestResultTable.table.varName.getQualifiedColName() + "(+)" + "=" + "'" + qtcritxr_tsop.getVarName() + "'" : "") + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + "=" + BioModelSimContextLinkTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "=" + BioModelTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + "=" + SimContextTable.table.id.getQualifiedColName() + " AND " + BioModelSimulationLinkTable.table.bioModelRef.getQualifiedColName() + "=" + BioModelTable.table.id.getQualifiedColName() + " AND " + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + " AND " + BioModelTable.table.versionBranchID.getQualifiedColName() + "=" + "(" + "SELECT DISTINCT " + BioModelTable.table.versionBranchID.getQualifiedColName() + " FROM " + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + "," + BioModelSimContextLinkTable.table.getTableName() + "," + BioModelTable.table.getTableName() + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + qtcritxr_tsop.getTestCriterium() + " AND " + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + "=" + TFTestCaseTable.table.id.getQualifiedColName() + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + "=" + BioModelSimContextLinkTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "=" + BioModelTable.table.id.getQualifiedColName() + ")" + " AND " + SimContextTable.table.name.getQualifiedColName() + "=" + "(" + "SELECT DISTINCT " + SimContextTable.table.name.getQualifiedColName() + " FROM " + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + "," + BioModelSimContextLinkTable.table.getTableName() + "," + SimContextTable.table.getTableName() + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + qtcritxr_tsop.getTestCriterium() + " AND " + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + "=" + TFTestCaseTable.table.id.getQualifiedColName() + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + "=" + BioModelSimContextLinkTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + "=" + SimContextTable.table.id.getQualifiedColName() + ")" + " AND " + SimulationTable.table.name.getQualifiedColName() + "=" + "(" + "SELECT DISTINCT " + SimulationTable.table.name.getQualifiedColName() + " FROM " + TFTestCriteriaTable.table.getTableName() + "," + SimulationTable.table.getTableName() + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + qtcritxr_tsop.getTestCriterium() + " AND " + TFTestCriteriaTable.table.simulationRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + ")" + // reference info
            " AND " + TSALT + "." + TFTestSuiteTable.table.id.getUnqualifiedColName() + "(+)" + "=" + TCALT + "." + TFTestCaseTable.table.testSuiteRef.getUnqualifiedColName() + " AND " + BSCALT + "." + BioModelSimContextLinkTable.table.id.getUnqualifiedColName() + "(+)" + "=" + TCRALT + "." + TFTestCriteriaTable.table.regressionBMAPPRef.getUnqualifiedColName() + " AND " + TCALT + "." + TFTestCaseTable.table.bmAppRef.getUnqualifiedColName() + "(+)" + "=" + TCRALT + "." + TFTestCriteriaTable.table.regressionBMAPPRef.getUnqualifiedColName() + " AND " + TCRALT + "." + TFTestCriteriaTable.table.id.getUnqualifiedColName() + "=" + TFTestCriteriaTable.table.id.getQualifiedColName() + // SIM2+"."+SimulationTable.table.name.getUnqualifiedColName()+"="+SimulationTable.table.name.getQualifiedColName()+
            " ORDER BY " + TSID;
            ResultSet rset = stmt.executeQuery(sql);
            while (rset.next()) {
                crossRefV.add(new TestCriteriaCrossRefOPResults.CrossRefData(rset, true));
            }
            rset.close();
            // 
            // MathModel query
            // 
            String MMNAME = "mmname";
            sql = "SELECT DISTINCT " + TFTestSuiteTable.table.tsVersion.getQualifiedColName() + "," + TFTestSuiteTable.table.id.getQualifiedColName() + " " + TSID + "," + TFTestCaseTable.table.id.getQualifiedColName() + " " + TCID + "," + TFTestCriteriaTable.table.id.getQualifiedColName() + " " + TCRID + "," + MathModelTable.table.name.getQualifiedColName() + " " + MMNAME + "," + SimulationTable.table.name.getQualifiedColName() + " " + SIMNAME + "," + TFTestCriteriaTable.table.maxAbsError.getQualifiedColName() + "," + TFTestCriteriaTable.table.maxRelError.getQualifiedColName() + "," + TFTestResultTable.table.varName.getQualifiedColName() + "," + TFTestResultTable.table.minRef.getQualifiedColName() + "," + TFTestResultTable.table.maxRef.getQualifiedColName() + "," + TFTestResultTable.table.absError.getQualifiedColName() + "," + TFTestResultTable.table.relError.getQualifiedColName() + "," + TFTestResultTable.table.meanSqrError.getQualifiedColName() + "," + TFTestResultTable.table.timeAbsError.getQualifiedColName() + "," + TFTestResultTable.table.indexAbsError.getQualifiedColName() + "," + TFTestResultTable.table.timeRelError.getQualifiedColName() + "," + TFTestResultTable.table.indexRelError.getQualifiedColName() + "," + TSALT + "." + TFTestSuiteTable.table.tsVersion.getUnqualifiedColName() + "," + MMSIMALT + "." + MathModelSimulationLinkTable.table.mathModelRef.getUnqualifiedColName() + "," + TFTestCaseTable.table.tcSolutionType.getQualifiedColName() + "," + MathModelTable.table.id.getQualifiedColName() + " " + MODELID + "," + TSALT + "." + TFTestSuiteTable.table.id.getUnqualifiedColName() + " " + REFTSUITEKEY + "," + TCALT + "." + TFTestCaseTable.table.id.getUnqualifiedColName() + " " + REFTCASEKEY + "," + "NULL " + // TCRALT2+"."+TFTestCriteriaTable.table.id.getUnqualifiedColName() +" "+REFTCRITKEY +
            REFTCRITKEY + " FROM " + TFTestSuiteTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + "," + TFTestResultTable.table.getTableName() + "," + MathModelTable.table.getTableName() + "," + SimulationTable.table.getTableName() + "," + MathModelSimulationLinkTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + " " + TSALT + "," + TFTestCaseTable.table.getTableName() + " " + TCALT + "," + TFTestCriteriaTable.table.getTableName() + " " + TCRALT + "," + MathModelSimulationLinkTable.table.getTableName() + " " + MMSIMALT + // ","+TFTestCriteriaTable.table.getTableName()+" "+TCRALT2+
            " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + "=" + TFTestCaseTable.table.id.getQualifiedColName() + " AND " + TFTestResultTable.table.testCriteriaRef.getQualifiedColName() + "(+)" + "=" + TFTestCriteriaTable.table.id.getQualifiedColName() + (qtcritxr_tsop.getVarName() != null ? " AND " + TFTestResultTable.table.varName.getQualifiedColName() + "(+)" + "=" + "'" + qtcritxr_tsop.getVarName() + "'" : "") + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + "=" + MathModelTable.table.id.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.simulationRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + " AND " + MathModelSimulationLinkTable.table.mathModelRef.getQualifiedColName() + "=" + MathModelTable.table.id.getQualifiedColName() + " AND " + MathModelSimulationLinkTable.table.simRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + " AND " + MathModelTable.table.versionBranchID.getQualifiedColName() + "=" + "(" + "SELECT DISTINCT " + MathModelTable.table.versionBranchID.getQualifiedColName() + " FROM " + TFTestCaseTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + "," + MathModelTable.table.getTableName() + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + qtcritxr_tsop.getTestCriterium() + " AND " + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + "=" + TFTestCaseTable.table.id.getQualifiedColName() + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + "=" + MathModelTable.table.id.getQualifiedColName() + ")" + " AND " + SimulationTable.table.name.getQualifiedColName() + "=" + "(" + "SELECT DISTINCT " + SimulationTable.table.name.getQualifiedColName() + " FROM " + TFTestCriteriaTable.table.getTableName() + "," + SimulationTable.table.getTableName() + " WHERE " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + qtcritxr_tsop.getTestCriterium() + " AND " + TFTestCriteriaTable.table.simulationRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + ")" + // reference info
            " AND " + TSALT + "." + TFTestSuiteTable.table.id.getUnqualifiedColName() + "(+)" + "=" + TCALT + "." + TFTestCaseTable.table.testSuiteRef.getUnqualifiedColName() + " AND " + TCALT + "." + TFTestCaseTable.table.mathModelRef.getUnqualifiedColName() + "(+)" + "=" + MMSIMALT + "." + MathModelSimulationLinkTable.table.mathModelRef.getUnqualifiedColName() + " AND " + TCRALT + "." + TFTestCriteriaTable.table.regressionMMSimRef.getUnqualifiedColName() + "=" + MMSIMALT + "." + MathModelSimulationLinkTable.table.id.getUnqualifiedColName() + "(+)" + " AND " + TCRALT + "." + TFTestCriteriaTable.table.id.getUnqualifiedColName() + "=" + TFTestCriteriaTable.table.id.getQualifiedColName() + // SIM2+"."+SimulationTable.table.name.getUnqualifiedColName()+"="+SimulationTable.table.name.getQualifiedColName()+
            " ORDER BY " + TSID;
            rset = stmt.executeQuery(sql);
            while (rset.next()) {
                crossRefV.add(new TestCriteriaCrossRefOPResults.CrossRefData(rset, false));
            }
            rset.close();
            return new TestCriteriaCrossRefOPResults(qtcritxr_tsop.getTestSuiteKey(), qtcritxr_tsop.getTestCriterium(), crossRefV);
        } else {
            throw new IllegalArgumentException("Unsupported OP+" + tsop);
        }
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
    Object[] changedTSKeys = changedTestSuiteKeys.toArray();
    for (int i = 0; i < changedTSKeys.length; i += 1) {
        System.out.println("TestSuite " + changedTSKeys[i].toString() + " changed");
    // testSuiteHash.remove(changedTSKeys[i]);
    }
    return new TestSuiteOPResults(null);
}
Also used : AddTestCriteriaOPBioModel(cbit.vcell.numericstest.AddTestCriteriaOPBioModel) AddTestCasesOPBioModel(cbit.vcell.numericstest.AddTestCasesOPBioModel) LoadTestInfoOpResults(cbit.vcell.numericstest.LoadTestInfoOpResults) LoadTestSoftwareVersionTimeStamp(cbit.vcell.numericstest.LoadTestInfoOpResults.LoadTestSoftwareVersionTimeStamp) AddTestResultsOP(cbit.vcell.numericstest.AddTestResultsOP) TreeSet(java.util.TreeSet) ResultSet(java.sql.ResultSet) TestSuiteOPResults(cbit.vcell.numericstest.TestSuiteOPResults) EditTestCriteriaOPBioModel(cbit.vcell.numericstest.EditTestCriteriaOPBioModel) VariableComparisonSummary(cbit.vcell.solver.test.VariableComparisonSummary) Vector(java.util.Vector) TestCriteriaCrossRefOPResults(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults) RemoveTestCasesOP(cbit.vcell.numericstest.RemoveTestCasesOP) AddTestCriteriaOPMathModel(cbit.vcell.numericstest.AddTestCriteriaOPMathModel) ModelGeometryOPResults(cbit.vcell.numericstest.ModelGeometryOPResults) RemoveTestSuiteOP(cbit.vcell.numericstest.RemoveTestSuiteOP) KeyValue(org.vcell.util.document.KeyValue) LoadTestInfoOP(cbit.vcell.numericstest.LoadTestInfoOP) AddTestCasesOP(cbit.vcell.numericstest.AddTestCasesOP) EditTestSuiteOP(cbit.vcell.numericstest.EditTestSuiteOP) RemoveTestResultsOP(cbit.vcell.numericstest.RemoveTestResultsOP) RemoveTestCriteriaOP(cbit.vcell.numericstest.RemoveTestCriteriaOP) EditTestCriteriaOPMathModel(cbit.vcell.numericstest.EditTestCriteriaOPMathModel) AddTestSuiteOP(cbit.vcell.numericstest.AddTestSuiteOP) AddTestCasesOPMathModel(cbit.vcell.numericstest.AddTestCasesOPMathModel) DataAccessException(org.vcell.util.DataAccessException) EditTestCriteriaOPReportStatus(cbit.vcell.numericstest.EditTestCriteriaOPReportStatus) ModelGeometryOP(cbit.vcell.numericstest.ModelGeometryOP) QueryTestCriteriaCrossRefOP(cbit.vcell.numericstest.QueryTestCriteriaCrossRefOP) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Hashtable(java.util.Hashtable) InsertHashtable(cbit.sql.InsertHashtable) BioModelInfo(org.vcell.util.document.BioModelInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) BigDecimal(java.math.BigDecimal) EditTestCasesOP(cbit.vcell.numericstest.EditTestCasesOP) ChangeTestCriteriaErrorLimitOP(cbit.vcell.numericstest.ChangeTestCriteriaErrorLimitOP) SimpleDateFormat(java.text.SimpleDateFormat)

Example 73 with BioModelInfo

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

the class DbDriver method testSuiteGet.

/**
 * Insert the method's description here.
 * Creation date: (10/16/2004 2:39:49 PM)
 * @return cbit.vcell.numericstest.TestSuiteInfoNew[]
 */
public static TestSuiteNew testSuiteGet(BigDecimal getThisTS, Connection con, User user, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
    if (!user.isTestAccount()) {
        throw new PermissionException("User=" + user.getName() + " not allowed TestSuiteInfo");
    }
    // if(testSuiteHash.containsKey(getThisTS)){
    // return (cbit.vcell.numericstest.TestSuiteNew)testSuiteHash.get(getThisTS);
    // }
    Hashtable simulationInfoH = new Hashtable();
    Hashtable mathModelInfoH = new Hashtable();
    Hashtable bioModelInfoH = new Hashtable();
    Statement stmt = null;
    ResultSet rset = null;
    String sql = null;
    Level origLogLevel = DatabasePolicySQL.lg.getLevel();
    try {
        DatabasePolicySQL.lg.setLevel(Level.WARN);
        // double begTime=System.currentTimeMillis();
        // int counter = 0;
        stmt = con.createStatement();
        // Get VariableComparisonSummaries
        Hashtable vcsH = new Hashtable();
        {
            sql = "SELECT " + TFTestResultTable.table.getTableName() + ".*" + " FROM " + TFTestResultTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + TFTestResultTable.table.testCriteriaRef.getQualifiedColName() + " ORDER BY UPPER(" + TFTestResultTable.table.varName.getQualifiedColName() + ")";
            rset = stmt.executeQuery(sql);
            while (rset.next()) {
                BigDecimal tcritRef = rset.getBigDecimal(TFTestResultTable.table.testCriteriaRef.getUnqualifiedColName());
                String varName = rset.getString(TFTestResultTable.table.varName.getUnqualifiedColName());
                double absError = rset.getDouble(TFTestResultTable.table.absError.getUnqualifiedColName());
                double relError = rset.getDouble(TFTestResultTable.table.relError.getUnqualifiedColName());
                double maxRef = rset.getDouble(TFTestResultTable.table.maxRef.getUnqualifiedColName());
                double minRef = rset.getDouble(TFTestResultTable.table.minRef.getUnqualifiedColName());
                double mse = rset.getDouble(TFTestResultTable.table.meanSqrError.getUnqualifiedColName());
                double timeAbsError = rset.getDouble(TFTestResultTable.table.timeAbsError.getUnqualifiedColName());
                int indexAbsError = rset.getInt(TFTestResultTable.table.indexAbsError.getUnqualifiedColName());
                double timeRelError = rset.getDouble(TFTestResultTable.table.timeRelError.getUnqualifiedColName());
                int indexRelError = rset.getInt(TFTestResultTable.table.indexRelError.getUnqualifiedColName());
                Vector v = (Vector) vcsH.get(tcritRef);
                if (v == null) {
                    v = new Vector();
                    vcsH.put(tcritRef, v);
                }
                v.add(new VariableComparisonSummary(varName, minRef, maxRef, absError, relError, mse, timeAbsError, indexAbsError, timeRelError, indexRelError));
            // counter+= 1;
            }
            // System.out.println("VCS count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
            rset.close();
        }
        // begTime=System.currentTimeMillis();
        // counter = 0;
        // Get TestCriteria for mathModel based TestCases
        Hashtable tcritH = new Hashtable();
        {
            sql = "SELECT " + TFTestCriteriaTable.table.getTableName() + ".*" + "," + MathModelSimulationLinkTable.table.getTableName() + ".*" + " FROM " + TFTestCriteriaTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + MathModelSimulationLinkTable.table.getTableName() + "," + SimulationTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + " IS NOT NULL " + " AND " + TFTestCriteriaTable.table.simulationRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.regressionMMSimRef.getQualifiedColName() + "=" + MathModelSimulationLinkTable.table.id.getQualifiedColName() + "(+)" + " ORDER BY UPPER(" + SimulationTable.table.name.getQualifiedColName() + ")";
            // System.out.println(sql);
            rset = stmt.executeQuery(sql);
            while (rset.next()) {
                BigDecimal tcritKey = rset.getBigDecimal(TFTestCriteriaTable.table.id.getUnqualifiedColName());
                BigDecimal tcaseRef = rset.getBigDecimal(TFTestCriteriaTable.table.testCaseRef.getUnqualifiedColName());
                BigDecimal simRef = rset.getBigDecimal(TFTestCriteriaTable.table.simulationRef.getUnqualifiedColName());
                BigDecimal simRegrRef = rset.getBigDecimal(MathModelSimulationLinkTable.table.simRef.getUnqualifiedColName());
                if (rset.wasNull()) {
                    simRegrRef = null;
                }
                BigDecimal mathRegrRef = rset.getBigDecimal(MathModelSimulationLinkTable.table.mathModelRef.getUnqualifiedColName());
                if (rset.wasNull()) {
                    mathRegrRef = null;
                }
                Double maxRelError = null;
                double dtemp = rset.getDouble(TFTestCriteriaTable.table.maxRelError.getUnqualifiedColName());
                if (rset.wasNull()) {
                    maxRelError = null;
                } else {
                    maxRelError = new Double(dtemp);
                }
                Double maxAbsError = null;
                dtemp = rset.getDouble(TFTestCriteriaTable.table.maxAbsError.getUnqualifiedColName());
                if (rset.wasNull()) {
                    maxAbsError = null;
                } else {
                    maxAbsError = new Double(dtemp);
                }
                String reportStatus = rset.getString(TFTestCriteriaTable.table.reportStatus.getUnqualifiedColName());
                if (rset.wasNull()) {
                    reportStatus = TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT;
                }
                String reportStatusMessage = rset.getString(TFTestCriteriaTable.table.reportMessage.getUnqualifiedColName());
                if (rset.wasNull()) {
                    reportStatusMessage = null;
                }
                if (reportStatusMessage != null && reportStatusMessage.length() > 0) {
                    reportStatusMessage = TokenMangler.getSQLRestoredString(reportStatusMessage);
                }
                Vector v = (Vector) tcritH.get(tcaseRef);
                if (v == null) {
                    v = new Vector();
                    tcritH.put(tcaseRef, v);
                }
                SimulationInfo simInfo = (SimulationInfo) simulationInfoH.get(simRef);
                if (simInfo == null) {
                    Vector<VersionInfo> simVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(simRef), false, dbSyntax);
                    if (simVector != null && simVector.size() > 0) {
                        simInfo = (SimulationInfo) simVector.firstElement();
                        simulationInfoH.put(simRef, simInfo);
                    }
                }
                SimulationInfo regrSimInfo = null;
                MathModelInfo regrMathModelInfo = null;
                if (simRegrRef != null) {
                    regrSimInfo = (SimulationInfo) simulationInfoH.get(simRegrRef);
                    if (regrSimInfo == null) {
                        Vector<VersionInfo> regSimVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(simRegrRef), false, dbSyntax);
                        if (regSimVector != null && regSimVector.size() > 0) {
                            regrSimInfo = (SimulationInfo) regSimVector.firstElement();
                            simulationInfoH.put(simRegrRef, regrSimInfo);
                        }
                    }
                    regrMathModelInfo = (MathModelInfo) mathModelInfoH.get(mathRegrRef);
                    if (regrMathModelInfo == null) {
                        Vector<VersionInfo> regMathVector = getVersionableInfos(con, user, VersionableType.MathModelMetaData, false, new KeyValue(mathRegrRef), false, dbSyntax);
                        if (regMathVector != null && regMathVector.size() > 0) {
                            regrMathModelInfo = (MathModelInfo) regMathVector.firstElement();
                            mathModelInfoH.put(mathRegrRef, regrMathModelInfo);
                        }
                    }
                }
                // 
                VariableComparisonSummary[] neededVCSArr = null;
                Vector vcsV = (Vector) vcsH.get(tcritKey);
                if (vcsV != null) {
                    neededVCSArr = new VariableComparisonSummary[vcsV.size()];
                    vcsV.copyInto(neededVCSArr);
                }
                // 
                TestCriteriaNew tcn = null;
                if (simInfo != null) {
                    tcn = new TestCriteriaNewMathModel(tcritKey, simInfo, regrMathModelInfo, regrSimInfo, maxRelError, maxAbsError, neededVCSArr, reportStatus, reportStatusMessage);
                    v.add(tcn);
                }
            // counter+= 1;
            }
            // System.out.println("TCrit count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
            rset.close();
        }
        // Get TestCriteria for bioModel based TestCases
        // Hashtable tcritH = new Hashtable();
        {
            final String REGRSIMREF = "REGRSIMREF";
            final String SCNAME = "SCNAME";
            sql = "SELECT " + TFTestCriteriaTable.table.getTableName() + ".*" + "," + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "," + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + " " + REGRSIMREF + "," + SimContextTable.table.name.getQualifiedColName() + " " + SCNAME + " FROM " + TFTestCriteriaTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + BioModelSimContextLinkTable.table.getTableName() + "," + SimContextTable.table.getTableName() + "," + BioModelSimulationLinkTable.table.getTableName() + // SimulationTable.table.getTableName()+
            " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + " IS NOT NULL " + " AND " + TFTestCriteriaTable.table.regressionBMAPPRef.getQualifiedColName() + "=" + BioModelSimContextLinkTable.table.id.getQualifiedColName() + "(+)" + " AND " + BioModelSimContextLinkTable.table.simContextRef + " = " + SimContextTable.table.id.getQualifiedColName() + "(+)" + // SimContextTable.table.mathRef.getQualifiedColName()+" = "+SimulationTable.table.mathRef.getQualifiedColName()+"(+)" +
            " AND " + TFTestCriteriaTable.table.regressionBMSimRef.getQualifiedColName() + " = " + BioModelSimulationLinkTable.table.id.getQualifiedColName() + "(+)";
            // System.out.println(sql);
            rset = stmt.executeQuery(sql);
            while (rset.next()) {
                BigDecimal tcritKey = rset.getBigDecimal(TFTestCriteriaTable.table.id.getUnqualifiedColName());
                BigDecimal tcaseRef = rset.getBigDecimal(TFTestCriteriaTable.table.testCaseRef.getUnqualifiedColName());
                BigDecimal tcSimRef = rset.getBigDecimal(TFTestCriteriaTable.table.simulationRef.getUnqualifiedColName());
                BigDecimal regrSimRef = rset.getBigDecimal(REGRSIMREF);
                // BigDecimal regrSimRef = rset.getBigDecimal(SimulationTable.table.id.getUnqualifiedColName());
                if (rset.wasNull()) {
                    regrSimRef = null;
                }
                BigDecimal regrBioModelRef = rset.getBigDecimal(BioModelSimContextLinkTable.table.bioModelRef.getUnqualifiedColName());
                if (rset.wasNull()) {
                    regrBioModelRef = null;
                }
                String regrSCName = rset.getString(SCNAME);
                if (rset.wasNull()) {
                    regrSCName = null;
                }
                Double maxRelError = null;
                double dtemp = rset.getDouble(TFTestCriteriaTable.table.maxRelError.getUnqualifiedColName());
                if (rset.wasNull()) {
                    maxRelError = null;
                } else {
                    maxRelError = new Double(dtemp);
                }
                Double maxAbsError = null;
                dtemp = rset.getDouble(TFTestCriteriaTable.table.maxAbsError.getUnqualifiedColName());
                if (rset.wasNull()) {
                    maxAbsError = null;
                } else {
                    maxAbsError = new Double(dtemp);
                }
                String reportStatus = rset.getString(TFTestCriteriaTable.table.reportStatus.getUnqualifiedColName());
                if (rset.wasNull()) {
                    reportStatus = TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT;
                }
                String reportStatusMessage = rset.getString(TFTestCriteriaTable.table.reportMessage.getUnqualifiedColName());
                if (rset.wasNull()) {
                    reportStatusMessage = null;
                }
                if (reportStatusMessage != null && reportStatusMessage.length() > 0) {
                    reportStatusMessage = TokenMangler.getSQLRestoredString(reportStatusMessage);
                }
                Vector v = (Vector) tcritH.get(tcaseRef);
                if (v == null) {
                    v = new Vector();
                    tcritH.put(tcaseRef, v);
                }
                SimulationInfo simInfo = (SimulationInfo) simulationInfoH.get(tcSimRef);
                if (simInfo == null) {
                    Vector<VersionInfo> simVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(tcSimRef), false, dbSyntax);
                    if (simVector != null && simVector.size() == 1) {
                        simInfo = (SimulationInfo) simVector.firstElement();
                        simulationInfoH.put(tcSimRef, simInfo);
                    } else {
                        throw new DataAccessException("Found more than 1 versionable for tcsimRef=" + tcSimRef);
                    }
                }
                SimulationInfo regrSimInfo = null;
                BioModelInfo regrBioModelInfo = null;
                if (regrSimRef != null) {
                    regrSimInfo = (SimulationInfo) simulationInfoH.get(regrSimRef);
                    if (regrSimInfo == null) {
                        Vector<VersionInfo> regSimVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(regrSimRef), false, dbSyntax);
                        if (regSimVector != null && regSimVector.size() == 1) {
                            regrSimInfo = (SimulationInfo) regSimVector.firstElement();
                            simulationInfoH.put(regrSimRef, regrSimInfo);
                        } else {
                            throw new DataAccessException("Found more than 1 versionable for simregRef=" + regrSimRef);
                        }
                    }
                    regrBioModelInfo = (BioModelInfo) mathModelInfoH.get(regrBioModelRef);
                    if (regrBioModelInfo == null) {
                        Vector<VersionInfo> regBioModelVector = getVersionableInfos(con, user, VersionableType.BioModelMetaData, false, new KeyValue(regrBioModelRef), false, dbSyntax);
                        if (regBioModelVector != null && regBioModelVector.size() == 1) {
                            regrBioModelInfo = (BioModelInfo) regBioModelVector.firstElement();
                            mathModelInfoH.put(regrBioModelRef, regrBioModelInfo);
                        } else {
                            throw new DataAccessException("Found more than 1 versionable for reegrbiomodelRef=" + regrBioModelRef);
                        }
                    }
                }
                // 
                VariableComparisonSummary[] neededVCSArr = null;
                Vector vcsV = (Vector) vcsH.get(tcritKey);
                if (vcsV != null) {
                    neededVCSArr = new VariableComparisonSummary[vcsV.size()];
                    vcsV.copyInto(neededVCSArr);
                }
                // 
                TestCriteriaNew tcn = null;
                if (simInfo != null) {
                    tcn = new TestCriteriaNewBioModel(tcritKey, simInfo, regrBioModelInfo, regrSCName, regrSimInfo, maxRelError, maxAbsError, neededVCSArr, reportStatus, reportStatusMessage);
                    v.add(tcn);
                }
            // counter+= 1;
            }
            // System.out.println("TCrit count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
            rset.close();
        }
        // Get TestCases
        Vector tcV = new Vector();
        // begTime=System.currentTimeMillis();
        // counter = 0;
        {
            // final String BMSCL = "bmscl";
            final String OBTCTYPECOLUMN = "OBTCTYPECOLUMN";
            final String OBNAMECOLUMN = "OBNAMECOLUMN";
            final String BMSCBMRNAME = "BMSCBMRNAME";
            final String BMSCSCRNAME = "BMSCSCRNAME";
            final String SCNAME = "SCNAME";
            final String SORTHELP1 = "SORTHELP1";
            final String SORTHELP2 = "SORTHELP2";
            sql = "SELECT " + "UPPER(" + MathModelTable.table.name.getQualifiedColName() + ") " + SORTHELP1 + "," + "TO_CHAR(NULL) " + SORTHELP2 + "," + TFTestCaseTable.table.getTableName() + ".*" + "," + "TO_NUMBER(NULL) " + BMSCBMRNAME + "," + "TO_NUMBER(NULL) " + BMSCSCRNAME + "," + "TO_CHAR(NULL) " + SCNAME + "," + "'MM' " + OBTCTYPECOLUMN + "," + MathModelTable.table.name.getQualifiedColName() + " " + OBNAMECOLUMN + " FROM " + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + MathModelTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + " IS NOT NULL" + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + " = " + MathModelTable.table.id.getQualifiedColName() + " UNION " + "SELECT " + "UPPER(" + BioModelTable.table.name.getQualifiedColName() + ") " + SORTHELP1 + ",UPPER(" + SimContextTable.table.name.getQualifiedColName() + ") " + SORTHELP2 + "," + TFTestCaseTable.table.getTableName() + ".*" + "," + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + " " + BMSCBMRNAME + "," + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + " " + BMSCSCRNAME + "," + SimContextTable.table.name.getQualifiedColName() + " " + SCNAME + "," + "'BM' " + OBTCTYPECOLUMN + "," + BioModelTable.table.name.getQualifiedColName() + " " + OBNAMECOLUMN + " FROM " + BioModelSimContextLinkTable.table.getTableName() + "," + SimContextTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + BioModelTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + " IS NOT NULL" + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + " = " + BioModelSimContextLinkTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + " = " + SimContextTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "=" + BioModelTable.table.id.getQualifiedColName() + // " ORDER BY 11,"+"UPPER(12)"+","+"UPPER(10)";
            " ORDER BY 13,1,2";
            rset = stmt.executeQuery(sql);
            while (rset.next()) {
                BigDecimal tcaseKey = rset.getBigDecimal(TFTestCaseTable.table.id.getUnqualifiedColName());
                BigDecimal mmRef = rset.getBigDecimal(TFTestCaseTable.table.mathModelRef.getUnqualifiedColName());
                if (rset.wasNull()) {
                    mmRef = null;
                }
                BigDecimal simContextRef = rset.getBigDecimal(BMSCSCRNAME);
                if (rset.wasNull()) {
                    simContextRef = null;
                }
                BigDecimal bioModelRef = rset.getBigDecimal(BMSCBMRNAME);
                if (rset.wasNull()) {
                    bioModelRef = null;
                }
                String simContextName = rset.getString(SCNAME);
                if (rset.wasNull()) {
                    simContextName = null;
                }
                String tcType = rset.getString(TFTestCaseTable.table.tcSolutionType.getUnqualifiedColName());
                String tcAnnot = rset.getString(TFTestCaseTable.table.tcAnnotation.getUnqualifiedColName());
                if (rset.wasNull()) {
                    tcAnnot = "";
                } else {
                    tcAnnot = TokenMangler.getSQLRestoredString(tcAnnot);
                }
                java.util.Date tcDate = VersionTable.getDate(rset, TFTestCaseTable.table.creationDate.getUnqualifiedColName());
                MathModelInfo mmInfo = null;
                BioModelInfo bmInfo = null;
                if (mmRef != null) {
                    mmInfo = (MathModelInfo) mathModelInfoH.get(mmRef);
                    if (mmInfo == null) {
                        Vector<VersionInfo> mathVector = getVersionableInfos(con, user, VersionableType.MathModelMetaData, false, new KeyValue(mmRef), false, dbSyntax);
                        if (mathVector != null && mathVector.size() > 0) {
                            mmInfo = (MathModelInfo) mathVector.firstElement();
                            mathModelInfoH.put(mmRef, mmInfo);
                        }
                    }
                } else if (bioModelRef != null) {
                    bmInfo = (BioModelInfo) bioModelInfoH.get(bioModelRef);
                    if (bmInfo == null) {
                        Vector<VersionInfo> bmAppVector = getVersionableInfos(con, user, VersionableType.BioModelMetaData, false, new KeyValue(bioModelRef), false, dbSyntax);
                        if (bmAppVector != null && bmAppVector.size() > 0) {
                            bmInfo = (BioModelInfo) bmAppVector.firstElement();
                            bioModelInfoH.put(bioModelRef, bmInfo);
                        }
                    }
                } else {
                    throw new RuntimeException("Test case in DB does not have MathmodelRef or BioModelAppRef");
                }
                TestCriteriaNew[] neededTcritArr = null;
                Vector needTcritV = (Vector) tcritH.get(tcaseKey);
                if (needTcritV != null) {
                    neededTcritArr = new TestCriteriaNew[needTcritV.size()];
                    needTcritV.copyInto(neededTcritArr);
                }
                TestCaseNew tcn = null;
                if (mmInfo != null) {
                    tcn = new TestCaseNewMathModel(tcaseKey, mmInfo, tcType, tcAnnot, neededTcritArr);
                    tcV.add(tcn);
                } else if (bmInfo != null) {
                    tcn = new TestCaseNewBioModel(tcaseKey, bmInfo, simContextName, new KeyValue(simContextRef), tcType, tcAnnot, neededTcritArr);
                    tcV.add(tcn);
                } else {
                // throw new RuntimeException("Expected testCase MathModelInfo or BioModelInfo to be not null");
                }
            // counter+= 1;
            }
            // System.out.println("TCase count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
            rset.close();
        }
        // Get TestSuite
        {
            TestCaseNew[] tcnArr = null;
            if (tcV.size() > 0) {
                tcnArr = new TestCaseNew[tcV.size()];
                tcV.copyInto(tcnArr);
            }
            sql = "SELECT " + TFTestSuiteTable.table.getTableName() + ".*" + " FROM " + TFTestSuiteTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " ORDER BY UPPER(" + TFTestSuiteTable.table.tsVersion.getQualifiedColName() + ")";
            rset = stmt.executeQuery(sql);
            BigDecimal tsKey = null;
            String tsVersion = null;
            String tsVCBuild = null;
            String tsNumericsBuild = null;
            java.util.Date tsDate = null;
            String tsAnnot = null;
            boolean islocked = true;
            if (rset.next()) {
                tsKey = rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName());
                tsVersion = rset.getString(TFTestSuiteTable.table.tsVersion.getUnqualifiedColName());
                tsVCBuild = rset.getString(TFTestSuiteTable.table.vcBuildVersion.getUnqualifiedColName());
                tsNumericsBuild = rset.getString(TFTestSuiteTable.table.vcNumericsVersion.getUnqualifiedColName());
                tsDate = VersionTable.getDate(rset, TFTestSuiteTable.table.creationDate.getUnqualifiedColName());
                tsAnnot = rset.getString(TFTestSuiteTable.table.tsAnnotation.getUnqualifiedColName());
                islocked = rset.getBoolean(TFTestSuiteTable.table.isLocked.getUnqualifiedColName());
            } else {
                throw new ObjectNotFoundException("TestSuite with key=" + getThisTS + " not found");
            }
            rset.close();
            TestSuiteInfoNew tsiNew = new TestSuiteInfoNew(tsKey, tsVersion, tsVCBuild, tsNumericsBuild, tsDate, tsAnnot, islocked);
            TestSuiteNew tsn = new TestSuiteNew(tsiNew, tcnArr);
            // testSuiteHash.put(tsKey,tsn);
            return tsn;
        }
    } catch (SQLException e) {
        lg.error("failed: (" + sql + "): " + e.getMessage(), e);
        throw e;
    } finally {
        DatabasePolicySQL.lg.setLevel(origLogLevel);
        if (stmt != null) {
            stmt.close();
        }
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) KeyValue(org.vcell.util.document.KeyValue) SQLException(java.sql.SQLException) TestCriteriaNewBioModel(cbit.vcell.numericstest.TestCriteriaNewBioModel) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) TestCriteriaNewMathModel(cbit.vcell.numericstest.TestCriteriaNewMathModel) ResultSet(java.sql.ResultSet) VariableComparisonSummary(cbit.vcell.solver.test.VariableComparisonSummary) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException) TestSuiteNew(cbit.vcell.numericstest.TestSuiteNew) Hashtable(java.util.Hashtable) InsertHashtable(cbit.sql.InsertHashtable) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) BioModelInfo(org.vcell.util.document.BioModelInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) TestCaseNew(cbit.vcell.numericstest.TestCaseNew) BigDecimal(java.math.BigDecimal) VersionInfo(org.vcell.util.document.VersionInfo) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) TestCriteriaNew(cbit.vcell.numericstest.TestCriteriaNew) Level(org.apache.log4j.Level) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel) TestSuiteInfoNew(cbit.vcell.numericstest.TestSuiteInfoNew) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 74 with BioModelInfo

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

the class DictionaryDbDriver method getDatabaseSpecies.

/**
 * Insert the method's description here.
 * Creation date: (2/15/2003 10:12:24 PM)
 * @return cbit.vcell.dictionary.DBSpecies[]
 * @param con java.sql.Connection
 * @param user cbit.vcell.server.User
 * @param bOnlyUser boolean
 */
public DBFormalSpecies[] getDatabaseSpecies(Connection con, User user, String likeString, boolean isBound, FormalSpeciesType speciesType, int restrictSearch, int rowLimit, boolean bOnlyUser) throws SQLException {
    if (speciesType != null && speciesType.equals(FormalSpeciesType.speciesMatchSearch)) {
        FormalSpeciesType.MatchSearchFormalSpeciesType matchSearchFormalSpeciesType = (FormalSpeciesType.MatchSearchFormalSpeciesType) speciesType;
        if (matchSearchFormalSpeciesType.getMatchCriterias() == null || matchSearchFormalSpeciesType.getMatchCriterias().length == 0) {
            return null;
        }
        ArrayList<VCDocumentInfo> matchedVCDocumentInfos = new ArrayList<VCDocumentInfo>();
        Statement stmt = null;
        // OR condition
        // String sql =
        // "SELECT UNIQUE "  +BioModelTable.table.id.getQualifiedColName() +
        // " FROM "  + BioModelTable.table.getTableName() + "," + SpeciesContextModelTable.table.getTableName() +
        // " WHERE " + BioModelTable.table.modelRef.getQualifiedColName() + " = "+ SpeciesContextModelTable.table.modelRef.getQualifiedColName() +
        // " AND (";
        // for (int i = 0; i < matchSearchFormalSpeciesType.getMatchCriterias().length; i++) {
        // sql+=
        // (i>0?" OR ":"") +
        // " LOWER("+SpeciesContextModelTable.table.name.getQualifiedColName()+") LIKE " + "'" + matchSearchFormalSpeciesType.getMatchCriterias()[i] + "'" + " ESCAPE '"+BeanUtils.SQL_ESCAPE_CHARACTER+"'";
        // }
        // sql+=")";
        // AND condition
        String sql = "";
        for (int i = 0; i < matchSearchFormalSpeciesType.getMatchCriterias().length; i++) {
            sql += (i > 0 ? " INTERSECT " : "") + "SELECT UNIQUE " + BioModelTable.table.id.getQualifiedColName() + " FROM " + BioModelTable.table.getTableName() + "," + SpeciesContextModelTable.table.getTableName() + " WHERE " + BioModelTable.table.modelRef.getQualifiedColName() + " = " + SpeciesContextModelTable.table.modelRef.getQualifiedColName() + " AND " + " LOWER(" + SpeciesContextModelTable.table.name.getQualifiedColName() + ") LIKE " + "'" + matchSearchFormalSpeciesType.getMatchCriterias()[i] + "'" + " ESCAPE '" + BeanUtils.SQL_ESCAPE_CHARACTER + "'";
        }
        try {
            stmt = con.createStatement();
            ResultSet rset = stmt.executeQuery(sql);
            while (rset.next()) {
                BigDecimal versionKey = rset.getBigDecimal(1);
                Version version = new Version(new KeyValue(versionKey), null, null, null, null, null, null, null, null);
                matchedVCDocumentInfos.add(new BioModelInfo(version, null, (BioModelChildSummary) null, null));
            }
        } finally {
            if (stmt != null) {
                stmt.close();
            }
        }
        if (matchedVCDocumentInfos.size() == 0) {
            return null;
        }
        return new DBFormalSpecies[] { new MatchedVCDocumentsFromSearch(matchedVCDocumentInfos) };
    }
    if (!speciesType.bValidProperties(restrictSearch)) {
        throw new IllegalArgumentException("Improper properties in restrictSearch");
    }
    if (bOnlyUser && isBound == false) {
        throw new IllegalArgumentException("user not null expects isBound = true");
    }
    if (!((rowLimit == -1) || (rowLimit > 0))) {
        throw new IllegalArgumentException("rowLimit must be -1(Unlimited) or greater than 0");
    }
    if ((((restrictSearch & FormalSpeciesType.COMPOUND_ID) != 0) && (restrictSearch != FormalSpeciesType.COMPOUND_ID)) || (((restrictSearch & FormalSpeciesType.ENZYME_ID) != 0) && (restrictSearch != FormalSpeciesType.ENZYME_ID)) || (((restrictSearch & FormalSpeciesType.PROTEIN_ID) != 0) && (restrictSearch != FormalSpeciesType.PROTEIN_ID))) {
        throw new RuntimeException("Incompatible search properties together");
    }
    likeString = likeString.toUpperCase();
    // Columns always needed
    String columns = (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.getTableName() + ".*" + "," + CompoundAliasTable.table.name.getQualifiedColName() + "," + CompoundAliasTable.table.preferred.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.getTableName() + ".*" + "," + EnzymeAliasTable.table.name.getQualifiedColName() + "," + EnzymeAliasTable.table.preferred.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.getTableName() + ".*" + "," + ProteinAliasTable.table.name.getQualifiedColName() + "," + ProteinAliasTable.table.preferred.getQualifiedColName() : "");
    // Columns if Bound (aliased because id in other tables)
    String dbSpeciesTable_id_alias = "dbspecies_id";
    if (isBound) {
        columns = columns + "," + DBSpeciesTable.table.id.getQualifiedColName() + " " + dbSpeciesTable_id_alias;
    }
    // Tables always needed
    String tables = (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.getTableName() + "," + CompoundAliasTable.table.getTableName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.getTableName() + "," + EnzymeAliasTable.table.getTableName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.getTableName() + "," + ProteinAliasTable.table.getTableName() : "");
    // Tables if Bound
    if (isBound) {
        tables = tables + "," + DBSpeciesTable.table.getTableName();
        if (bOnlyUser) {
            tables = tables + "," + SpeciesContextModelTable.table.getTableName() + "," + SpeciesTable.table.getTableName() + "," + ModelTable.table.getTableName();
        }
    }
    String condition = "";
    // Conditions always needed
    condition = condition + (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.id.getQualifiedColName() + "=" + CompoundAliasTable.table.compoundRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.id.getQualifiedColName() + "=" + EnzymeAliasTable.table.enzymeRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.id.getQualifiedColName() + "=" + ProteinAliasTable.table.proteinRef.getQualifiedColName() : "");
    java.util.Vector<String> likeConditions = new java.util.Vector<String>();
    if (speciesType.equals(FormalSpeciesType.compound)) {
        if ((restrictSearch & FormalSpeciesType.COMPOUND_ID) != 0) {
            likeConditions.add(" UPPER(" + CompoundTable.table.id.getQualifiedColName() + ") = " + likeString);
        }
        if ((restrictSearch & FormalSpeciesType.COMPOUND_ALIAS) != 0) {
            likeConditions.add(" UPPER(" + CompoundAliasTable.table.name.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.COMPOUND_KEGGID) != 0) {
            likeConditions.add(" UPPER(" + CompoundTable.table.keggID.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.COMPOUND_CASID) != 0) {
            likeConditions.add(" UPPER(" + CompoundTable.table.casID.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.COMPOUND_FORMULA) != 0) {
            likeConditions.add(" UPPER(" + CompoundTable.table.formula.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
    } else if (speciesType.equals(FormalSpeciesType.enzyme)) {
        if ((restrictSearch & FormalSpeciesType.ENZYME_ID) != 0) {
            likeConditions.add(" UPPER(" + EnzymeTable.table.id.getQualifiedColName() + ") = " + likeString);
        }
        if ((restrictSearch & FormalSpeciesType.ENZYME_ALIAS) != 0) {
            likeConditions.add(" UPPER(" + EnzymeAliasTable.table.name.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.ENZYME_SYSNAME) != 0) {
            likeConditions.add(" UPPER(" + EnzymeTable.table.sysname.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.ENZYME_ECNUMBER) != 0) {
            likeConditions.add(" UPPER(" + EnzymeTable.table.ecNumber.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        // if((restrictSearch & FormalSpeciesType.ENZYME_ECNUMBER) != 0){likeConditions.add(" UPPER("+EnzymeTable.table.ecNumber.getQualifiedColName() + ") LIKE " + "'EC "+likeString+"'");}
        if ((restrictSearch & FormalSpeciesType.ENZYME_REACTION) != 0) {
            likeConditions.add(" UPPER(" + EnzymeTable.table.reaction.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.ENZYME_CASID) != 0) {
            likeConditions.add(" UPPER(" + EnzymeTable.table.casID.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
    } else if (speciesType.equals(FormalSpeciesType.protein)) {
        if ((restrictSearch & FormalSpeciesType.PROTEIN_ID) != 0) {
            likeConditions.add(" UPPER(" + ProteinTable.table.id.getQualifiedColName() + ") = " + likeString);
        }
        if ((restrictSearch & FormalSpeciesType.PROTEIN_ALIAS) != 0) {
            likeConditions.add(" UPPER(" + ProteinAliasTable.table.name.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.PROTEIN_ACCESSION) != 0) {
            likeConditions.add(" UPPER(" + ProteinTable.table.accessionNumber.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.PROTEIN_SWISSPROTID) != 0) {
            likeConditions.add(" UPPER(" + ProteinTable.table.swissProtEntryName.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.PROTEIN_ORGANISM) != 0) {
            likeConditions.add(" UPPER(" + ProteinTable.table.organism.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.PROTEIN_KEYWORD) != 0) {
            likeConditions.add(" UPPER(" + ProteinTable.table.keywords.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
        if ((restrictSearch & FormalSpeciesType.PROTEIN_DESCR) != 0) {
            likeConditions.add(" UPPER(" + ProteinTable.table.description.getQualifiedColName() + ") LIKE " + "'" + likeString + "'" + " ESCAPE '/'");
        }
    } else {
        throw new RuntimeException(speciesType.getName() + " Unsupported");
    }
    if (likeConditions.size() > 0) {
        condition = condition + " AND ( ";
        for (int i = 0; i < likeConditions.size(); i += 1) {
            String newCondition = (String) likeConditions.get(i);
            if (i != 0) {
                condition = condition + " OR ";
            }
            condition = condition + newCondition;
        }
        condition = condition + ")";
    }
    if (isBound) {
        condition = condition + " AND " + (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.id.getQualifiedColName() + "=" + DBSpeciesTable.table.compoundRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.id.getQualifiedColName() + "=" + DBSpeciesTable.table.enzymeRef.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.id.getQualifiedColName() + "=" + DBSpeciesTable.table.proteinRef.getQualifiedColName() : "");
        if (bOnlyUser) {
            condition = condition + " AND " + SpeciesContextModelTable.table.speciesRef.getQualifiedColName() + " = " + SpeciesTable.table.id.getQualifiedColName() + " AND " + SpeciesTable.table.dbSpeciesRef.getQualifiedColName() + " = " + DBSpeciesTable.table.id.getQualifiedColName() + " AND " + SpeciesContextModelTable.table.modelRef.getQualifiedColName() + " = " + ModelTable.table.id.getQualifiedColName() + " AND " + ModelTable.table.ownerRef.getQualifiedColName() + " = " + user.getID();
        }
    }
    // ORDER BY 'id' must not be changed, used to collect multiple aliasnames into same info object
    String orderBy = (speciesType.equals(FormalSpeciesType.compound) ? CompoundTable.table.id.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.enzyme) ? EnzymeTable.table.id.getQualifiedColName() : "") + (speciesType.equals(FormalSpeciesType.protein) ? ProteinTable.table.id.getQualifiedColName() : "");
    String sql = "SELECT " + columns + " FROM " + tables + " WHERE " + condition + " ORDER BY " + orderBy;
    DBFormalSpecies[] databaseSpecies = null;
    Statement stmt = con.createStatement();
    if (rowLimit > 0) {
        stmt.setMaxRows(rowLimit);
    }
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (speciesType.equals(FormalSpeciesType.compound)) {
            databaseSpecies = CompoundTable.table.getCompounds(rset, isBound);
        } else if (speciesType.equals(FormalSpeciesType.enzyme)) {
            databaseSpecies = EnzymeTable.table.getEnzymes(rset, isBound);
        } else if (speciesType.equals(FormalSpeciesType.protein)) {
            databaseSpecies = ProteinTable.table.getProteins(rset, isBound);
        } else {
            throw new RuntimeException("FormalSpeciesType=" + speciesType.getName() + " Unsupported");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    // 
    return databaseSpecies;
}
Also used : BioModelChildSummary(org.vcell.util.document.BioModelChildSummary) KeyValue(org.vcell.util.document.KeyValue) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) BioModelInfo(org.vcell.util.document.BioModelInfo) FormalSpeciesType(cbit.vcell.model.FormalSpeciesType) BigDecimal(java.math.BigDecimal) MatchedVCDocumentsFromSearch(cbit.vcell.model.DBFormalSpecies.MatchedVCDocumentsFromSearch) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) Version(org.vcell.util.document.Version) ResultSet(java.sql.ResultSet) Vector(java.util.Vector)

Example 75 with BioModelInfo

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

the class VCComprehensiveStatistics method collectBioModelStats.

private void collectBioModelStats(long startDateInMs, long endDateInMs) throws DataAccessException {
    retrieveUsers();
    for (User user : userList) {
        if (!userConstraintList.contains(user.getName())) {
            continue;
        }
        if (!internalDeveloper.contains(user.getName())) {
            boolean bInternal = internalUsers.contains(user.getName());
            ModelStat modelStat = bioModelStats[bInternal ? 0 : 1];
            BioModelInfo[] bioModelInfos = dbServerImpl.getBioModelInfos(user, false);
            for (BioModelInfo bmi : bioModelInfos) {
                Date createDate = bmi.getVersion().getDate();
                long t = createDate.getTime();
                // }
                if (t < startDateInMs || t > endDateInMs) {
                    continue;
                }
                // modelStat.count_model ++;
                try {
                    BigString bioModelXML = dbServerImpl.getBioModelXML(user, bmi.getVersion().getVersionKey());
                    BioModel bioModel = (BioModel) waitForModel(bioModelXML, false);
                    if (bioModel == null) {
                        System.out.println("----------          Skipped BioModel " + bmi.getVersion() + "          ----------");
                        continue;
                    }
                    modelStat.count_model++;
                    for (SimulationContext simContext : bioModel.getSimulationContexts()) {
                        modelStat.count_geoDimApplications[simContext.getGeometry().getDimension()]++;
                        if (simContext.isStoch()) {
                            modelStat.count_app_stochastic++;
                        } else {
                            modelStat.count_app_deterministic++;
                        }
                    }
                    boolean bHasCompletedSim = false;
                    for (Simulation sim : bioModel.getSimulations()) {
                        SimulationStatusPersistent ss = dbServerImpl.getSimulationStatus(sim.getKey());
                        if (ss != null) {
                            for (int scan = 0; scan < sim.getScanCount(); scan++) {
                                SimulationJobStatusPersistent jobStatus = ss.getJobStatus(scan);
                                if (jobStatus != null) {
                                    if (jobStatus.getSchedulerStatus() == SchedulerStatus.COMPLETED) {
                                        bHasCompletedSim = true;
                                        long elapsed = jobStatus.getEndDate().getTime() - jobStatus.getStartDate().getTime();
                                        if (elapsed < 2 * MINUTE_IN_MS) {
                                            modelStat.runningTimeHistogram[0]++;
                                        } else if (elapsed < 5 * MINUTE_IN_MS) {
                                            modelStat.runningTimeHistogram[1]++;
                                        } else if (elapsed < 20 * MINUTE_IN_MS) {
                                            modelStat.runningTimeHistogram[2]++;
                                        } else if (elapsed < HOUR_IN_MS) {
                                            modelStat.runningTimeHistogram[3]++;
                                        } else if (elapsed < DAY_IN_MS) {
                                            modelStat.runningTimeHistogram[4]++;
                                        } else {
                                            modelStat.runningTimeHistogram[5]++;
                                        }
                                    }
                                    int dimension = sim.getMathDescription().getGeometry().getDimension();
                                    modelStat.count_geoDimSim[dimension]++;
                                    if (sim.getMathDescription().isNonSpatialStoch() || sim.getMathDescription().isSpatialStoch()) {
                                        modelStat.count_sim_stochastic++;
                                    } else {
                                        modelStat.count_sim_deterministic++;
                                    }
                                    if (dimension > 0) {
                                        if (sim.getSolverTaskDescription().getSolverDescription().isSemiImplicitPdeSolver()) {
                                            modelStat.count_semiSim++;
                                        } else {
                                            modelStat.count_fullySim++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (bHasCompletedSim) {
                        modelStat.count_model_simcomplete++;
                    }
                } catch (Exception e2) {
                    e2.printStackTrace(System.out);
                }
            }
        }
    }
    itemCount++;
    statOutputPW.println(itemCount + ". BioModel Statistics ");
    statOutputPW.println("====================================================");
    for (ModelStat modelStat : bioModelStats) {
        statOutputPW.println("\t" + modelStat.title);
        statOutputPW.println("========================================");
        statOutputPW.println("number of biomodels saved :\t" + modelStat.count_model);
        statOutputPW.println("number of biomodels that has at least 1 completed simulation :\t" + modelStat.count_model_simcomplete);
        statOutputPW.println();
        statOutputPW.println("Application statistics :");
        statOutputPW.println("number of application ODE :\t" + modelStat.count_geoDimApplications[0]);
        statOutputPW.println("number of application 1D :\t" + modelStat.count_geoDimApplications[1]);
        statOutputPW.println("number of application 2D :\t" + modelStat.count_geoDimApplications[2]);
        statOutputPW.println("number of application 3D :\t" + modelStat.count_geoDimApplications[3]);
        statOutputPW.println("number of application stochastic :\t" + modelStat.count_app_stochastic);
        statOutputPW.println("number of application deterministic :\t" + modelStat.count_app_deterministic);
        statOutputPW.println();
        statOutputPW.println("Simulation statistics (including all simulations (stopped, failed, completed) :");
        statOutputPW.println("number of run simulation ODE :\t" + modelStat.count_geoDimSim[0]);
        statOutputPW.println("number of run simulation 1D :\t" + modelStat.count_geoDimSim[1]);
        statOutputPW.println("number of run simulation 2D :\t" + modelStat.count_geoDimSim[2]);
        statOutputPW.println("number of run simulation 3D :\t" + modelStat.count_geoDimSim[3]);
        statOutputPW.println("number of run simulation Semi-Implicit :\t" + modelStat.count_semiSim);
        statOutputPW.println("number of run simulation Fully-Implicit :\t" + modelStat.count_fullySim);
        statOutputPW.println("number of run simulation stochastic :\t" + modelStat.count_sim_stochastic);
        statOutputPW.println("number of run simulation deterministic :\t" + modelStat.count_sim_deterministic);
        statOutputPW.println();
        statOutputPW.println("Running time histogram for completed simulations only:");
        statOutputPW.println("0 ~ 2min:\t" + modelStat.runningTimeHistogram[0]);
        statOutputPW.println("2 ~ 5min:\t" + modelStat.runningTimeHistogram[1]);
        statOutputPW.println("5 ~ 20min:\t" + modelStat.runningTimeHistogram[2]);
        statOutputPW.println("20min ~ 1hr:\t" + modelStat.runningTimeHistogram[3]);
        statOutputPW.println("1hr ~ 1day:\t" + modelStat.runningTimeHistogram[4]);
        statOutputPW.println(">1day:\t" + modelStat.runningTimeHistogram[5]);
        statOutputPW.println();
        statOutputPW.println();
        statOutputPW.flush();
    }
}
Also used : User(org.vcell.util.document.User) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent) BigString(org.vcell.util.BigString) Date(java.util.Date) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel)

Aggregations

BioModelInfo (org.vcell.util.document.BioModelInfo)79 DataAccessException (org.vcell.util.DataAccessException)38 MathModelInfo (org.vcell.util.document.MathModelInfo)37 BioModel (cbit.vcell.biomodel.BioModel)25 GeometryInfo (cbit.vcell.geometry.GeometryInfo)22 KeyValue (org.vcell.util.document.KeyValue)18 SimulationContext (cbit.vcell.mapping.SimulationContext)17 VCDocumentInfo (org.vcell.util.document.VCDocumentInfo)15 BigString (org.vcell.util.BigString)14 User (org.vcell.util.document.User)14 Vector (java.util.Vector)13 Simulation (cbit.vcell.solver.Simulation)12 XmlParseException (cbit.vcell.xml.XmlParseException)12 SQLException (java.sql.SQLException)12 XMLSource (cbit.vcell.xml.XMLSource)10 MathModel (cbit.vcell.mathmodel.MathModel)9 Hashtable (java.util.Hashtable)9 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)9 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)8 Geometry (cbit.vcell.geometry.Geometry)7