Search in sources :

Example 96 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class MathModelDbTreePanel method compareWithMenuItemEnable.

/**
 * Comment
 */
private void compareWithMenuItemEnable(VersionInfo vInfo) {
    boolean bPreviousEditionMenuItem = false;
    boolean bLatestEditionMenuItem = false;
    boolean bAnotherEditionMenuItem = false;
    if (vInfo != null) {
        MathModelInfo thisMathModelInfo = (MathModelInfo) vInfo;
        try {
            // 
            // Get the other versions of the Mathmodel
            // 
            MathModelInfo[] mathModelVersionsList = getMathModelVersionDates(thisMathModelInfo);
            if (mathModelVersionsList != null && mathModelVersionsList.length > 0) {
                bAnotherEditionMenuItem = true;
                // 
                // Obtaining the previous version of the current biomodel
                // 
                MathModelInfo previousMathModelInfo = mathModelVersionsList[0];
                boolean bPrevious = false;
                for (int i = 0; i < mathModelVersionsList.length; i++) {
                    if (mathModelVersionsList[i].getVersion().getDate().before(thisMathModelInfo.getVersion().getDate())) {
                        bPrevious = true;
                        previousMathModelInfo = mathModelVersionsList[i];
                    } else {
                        break;
                    }
                }
                if (previousMathModelInfo.equals(mathModelVersionsList[0]) && !bPrevious) {
                    bPreviousEditionMenuItem = false;
                } else {
                    bPreviousEditionMenuItem = true;
                }
                // 
                // Obtaining the latest version of the current mathmodel
                // 
                MathModelInfo latestMathModelInfo = mathModelVersionsList[mathModelVersionsList.length - 1];
                for (int i = 0; i < mathModelVersionsList.length; i++) {
                    if (mathModelVersionsList[i].getVersion().getDate().after(latestMathModelInfo.getVersion().getDate())) {
                        latestMathModelInfo = mathModelVersionsList[i];
                    }
                }
                if (thisMathModelInfo.getVersion().getDate().after(latestMathModelInfo.getVersion().getDate())) {
                    bLatestEditionMenuItem = false;
                } else {
                    bLatestEditionMenuItem = true;
                }
            }
        } catch (DataAccessException ex) {
            ex.printStackTrace();
        }
    }
    getJPreviousEditionMenuItem().setEnabled(bPreviousEditionMenuItem);
    getJLatestEditionMenuItem().setEnabled(bLatestEditionMenuItem);
    getJAnotherEditionMenuItem().setEnabled(bAnotherEditionMenuItem);
}
Also used : MathModelInfo(org.vcell.util.document.MathModelInfo) DataAccessException(org.vcell.util.DataAccessException)

Example 97 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class BioModelDbTreePanel method compareWithMenuItemEnable.

/**
 * Comment
 */
private void compareWithMenuItemEnable(VersionInfo vInfo) {
    boolean bPreviousEditionMenuItem = false;
    boolean bLatestEditionMenuItem = false;
    boolean bAnotherEditionMenuItem = false;
    BioModelInfo thisBioModelInfo = (BioModelInfo) vInfo;
    // 
    try {
        BioModelInfo[] bioModelVersionsList = getBioModelVersionDates(thisBioModelInfo);
        if (bioModelVersionsList != null && bioModelVersionsList.length > 0) {
            bAnotherEditionMenuItem = true;
            // 
            // Obtaining the previous version of the current biomodel.
            // 
            BioModelInfo previousBioModelInfo = bioModelVersionsList[0];
            boolean bPrevious = false;
            for (int i = 0; i < bioModelVersionsList.length; i++) {
                if (bioModelVersionsList[i].getVersion().getDate().before(thisBioModelInfo.getVersion().getDate())) {
                    bPrevious = true;
                    previousBioModelInfo = bioModelVersionsList[i];
                } else {
                    break;
                }
            }
            if (previousBioModelInfo.equals(bioModelVersionsList[0]) && !bPrevious) {
                bPreviousEditionMenuItem = false;
            } else {
                bPreviousEditionMenuItem = true;
            }
            // 
            // Obtaining the latest version of the current biomodel
            // 
            BioModelInfo latestBioModelInfo = bioModelVersionsList[bioModelVersionsList.length - 1];
            for (int i = 0; i < bioModelVersionsList.length; i++) {
                if (bioModelVersionsList[i].getVersion().getDate().after(latestBioModelInfo.getVersion().getDate())) {
                    latestBioModelInfo = bioModelVersionsList[i];
                }
            }
            if (thisBioModelInfo.getVersion().getDate().after(latestBioModelInfo.getVersion().getDate())) {
                bLatestEditionMenuItem = false;
            } else {
                bLatestEditionMenuItem = true;
            }
        }
    } catch (DataAccessException e) {
        e.printStackTrace();
    }
    getJPreviousEditionMenuItem().setEnabled(bPreviousEditionMenuItem);
    getLatestEditionMenuItem().setEnabled(bLatestEditionMenuItem);
    getAnotherEditionMenuItem().setEnabled(bAnotherEditionMenuItem);
}
Also used : BioModelInfo(org.vcell.util.document.BioModelInfo) DataAccessException(org.vcell.util.DataAccessException)

Example 98 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class LocaldbRegistrationService method getAdminDbServer.

private AdminDatabaseServer getAdminDbServer() throws DataAccessException {
    if (adminDbServer == null) {
        ConnectionFactory conFactory;
        try {
            conFactory = DatabaseService.getInstance().createConnectionFactory();
            KeyFactory keyFactory = conFactory.getKeyFactory();
            adminDbServer = new LocalAdminDbServer(conFactory, keyFactory);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException("failed to establish database connection for RegistrationService: " + e.getMessage(), e);
        } catch (DataAccessException e) {
            e.printStackTrace();
            throw e;
        }
    }
    return adminDbServer;
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) SQLException(java.sql.SQLException) LocalAdminDbServer(cbit.vcell.modeldb.LocalAdminDbServer) KeyFactory(org.vcell.db.KeyFactory) DataAccessException(org.vcell.util.DataAccessException)

Example 99 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class BatchTester method batchScanBioModels.

@SuppressWarnings("static-access")
public void batchScanBioModels(VCMultiBioVisitor databaseVisitor, String statusTable, int chunkSize) throws DataAccessException, XmlParseException, SQLException, IOException {
    PrintStream current = System.out;
    // System.setOut(new PrintStream(new NullStream()));
    try {
        String processHostId = ManagementFactory.getRuntimeMXBean().getName();
        String filename = processHostId + ".txt";
        FileOutputStream fos = new FileOutputStream(filename);
        System.setOut(new PrintStream(fos));
        OutputStreamWriter writer = new OutputStreamWriter(fos);
        // autoflush
        PrintWriter printWriter = new PrintWriter(writer, true);
        Connection conn = connFactory.getConnection(null);
        conn.setAutoCommit(true);
        printWriter.println("reserving slots");
        try (Statement statement = conn.createStatement()) {
            String query = "Update " + statusTable + " set scan_process = '" + processHostId + "', log_file = '" + filename + "' where scanned = 0 and scan_process is null and rownum <= " + chunkSize;
            int uCount = statement.executeUpdate(query);
            if (uCount > chunkSize) {
                throw new Error("logic / SQL bad");
            }
            if (uCount == 0) {
                printWriter.println("No models to scan, exiting");
                System.exit(100);
            }
        }
        printWriter.println("finding  ours");
        ArrayList<BioModelIdent> models = new ArrayList<BatchTester.BioModelIdent>();
        try (Statement statement = conn.createStatement()) {
            String query = "Select id, user_id, model_id from " + statusTable + " where scan_process ='" + processHostId + "' and scanned = 0";
            ResultSet rs = statement.executeQuery(query);
            while (rs.next()) {
                BioModelIdent mi = new BioModelIdent(rs);
                models.add(mi);
                printWriter.println("claiming " + mi.statusId);
            }
        }
        try {
            // start visiting models and writing log
            printWriter.println("Start scanning bio-models......");
            printWriter.println("\n");
            PreparedStatement ps = conn.prepareStatement("Update " + statusTable + " set scanned = 1, good = ? , exception_type = ?, exception = ?, scan_process = null where id = ?");
            for (BioModelIdent modelIdent : models) {
                ScanStatus scanStatus = ScanStatus.PASS;
                String exceptionMessage = null;
                String exceptionClass = null;
                try {
                    User user = new User("", convert(modelIdent.userId));
                    KeyValue modelKey = convert(modelIdent.modelId);
                    BigString bioModelXML = null;
                    // seconds
                    long dbSleepTime = 10;
                    while (bioModelXML == null) {
                        try {
                            bioModelXML = dbServerImpl.getBioModelXML(user, modelKey);
                        } catch (DataAccessException dae) {
                            Throwable cause = dae.getCause();
                            if (cause.getClass().getSimpleName().equals("UniversalConnectionPoolException")) {
                                printWriter.println("No db connection for  " + modelIdent.statusId + ", sleeping " + dbSleepTime + " seconds");
                                Thread.currentThread().sleep(dbSleepTime * 1000);
                                // wait a little longer next time
                                dbSleepTime *= 1.5;
                            } else {
                                // other exception, just rethrow
                                throw dae;
                            }
                        }
                    }
                    BioModel storedModel = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
                    if (databaseVisitor.filterBioModel(storedModel)) {
                        storedModel.refreshDependencies();
                        boolean goodModel = verifyMathDescriptionsUnchanged(storedModel, printWriter);
                        if (goodModel) {
                            printWriter.println("Model for " + modelIdent.statusId + " good");
                            databaseVisitor.setBioModel(storedModel, printWriter);
                            for (BioModel bioModel : databaseVisitor) {
                                SimulationContext[] simContexts = bioModel.getSimulationContexts();
                                for (SimulationContext sc : simContexts) {
                                    // try {
                                    // long start = System.currentTimeMillis();
                                    sc.createNewMathMapping().getMathDescription();
                                // long end = System.currentTimeMillis();
                                // printWriter.println("mapping took " + (end - start)/1000.0 + " sec ");
                                /*
									} catch (Exception e) {
										//printWriter.println("\t " + bioModel.getName() + " :: " + sc.getName() + " ----> math regeneration failed.s");
										// e.printStackTrace();
									}
											 */
                                }
                            }
                        } else {
                            throw new MathRegenFail();
                        }
                    } else {
                        scanStatus = ScanStatus.FILTERED;
                    }
                } catch (Exception e) {
                    lg.error(e.getMessage(), e);
                    scanStatus = ScanStatus.FAIL;
                    exceptionClass = e.getClass().getName();
                    exceptionMessage = e.getMessage();
                    printWriter.println("failed " + modelIdent.statusId);
                    e.printStackTrace(printWriter);
                }
                ps.setInt(1, scanStatus.code);
                ps.setString(2, exceptionClass);
                ps.setString(3, exceptionMessage);
                ps.setLong(4, modelIdent.statusId);
                boolean estat = ps.execute();
                if (estat) {
                    throw new Error("logic");
                }
                int uc = ps.getUpdateCount();
                if (uc != 1) {
                    throw new Error("logic / sql ");
                }
            }
        } catch (Exception e) {
            e.printStackTrace(printWriter);
        }
        printWriter.close();
    } finally {
        System.setOut(current);
    }
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) ResultSet(java.sql.ResultSet) DataAccessException(org.vcell.util.DataAccessException) PrintWriter(java.io.PrintWriter) PrintStream(java.io.PrintStream) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SimulationContext(cbit.vcell.mapping.SimulationContext) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) FileOutputStream(java.io.FileOutputStream) BioModel(cbit.vcell.biomodel.BioModel) OutputStreamWriter(java.io.OutputStreamWriter) XMLSource(cbit.vcell.xml.XMLSource)

Example 100 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class BatchTester method batchScanMathModels.

@SuppressWarnings("static-access")
public void batchScanMathModels(BadMathVisitor databaseVisitor, String statusTable, int chunkSize) throws DataAccessException, XmlParseException, SQLException, IOException {
    PrintStream current = System.out;
    // System.setOut(new PrintStream(new NullStream()));
    try {
        String processHostId = ManagementFactory.getRuntimeMXBean().getName();
        String filename = processHostId + ".txt";
        FileOutputStream fos = new FileOutputStream(filename);
        System.setOut(new PrintStream(fos));
        OutputStreamWriter writer = new OutputStreamWriter(fos);
        // autoflush
        PrintWriter printWriter = new PrintWriter(writer, true);
        Connection conn = connFactory.getConnection(null);
        conn.setAutoCommit(true);
        printWriter.println("reserving slots");
        try (Statement statement = conn.createStatement()) {
            String query = "Update " + statusTable + " set scan_process = '" + processHostId + "', log_file = '" + filename + "' where scanned = 0 and scan_process is null and rownum <= " + chunkSize;
            int uCount = statement.executeUpdate(query);
            if (uCount > chunkSize) {
                throw new Error("logic / SQL bad");
            }
            if (uCount == 0) {
                printWriter.println("No models to scan, exiting");
                System.exit(100);
            }
        }
        printWriter.println("finding  ours");
        ArrayList<MathModelIdent> models = new ArrayList<BatchTester.MathModelIdent>();
        try (Statement statement = conn.createStatement()) {
            String query = "Select model_id from " + statusTable + " where scan_process ='" + processHostId + "' and scanned = 0";
            ResultSet rs = statement.executeQuery(query);
            while (rs.next()) {
                MathModelIdent mmi = new MathModelIdent(rs);
                models.add(mmi);
                printWriter.println("claiming " + mmi.id);
            }
        }
        try {
            // start visiting models and writing log
            printWriter.println("Start scanning math-models......");
            printWriter.println("\n");
            PreparedStatement ps = conn.prepareStatement("Update " + statusTable + " set scanned = 1, good = ? , exception_type = ?, exception = ?, scan_process = null where model_id = ?");
            for (MathModelIdent modelIdent : models) {
                ScanStatus scanStatus = ScanStatus.PASS;
                String exceptionMessage = null;
                String exceptionClass = null;
                try {
                    KeyValue modelKey = convert(modelIdent.id);
                    BigString mathModelXML = null;
                    // seconds
                    long dbSleepTime = 10;
                    while (mathModelXML == null) {
                        try {
                            mathModelXML = dbServerImpl.getMathModelXML(BatchTester.ADMINISTRATOR, modelKey);
                        } catch (DataAccessException dae) {
                            Throwable cause = dae.getCause();
                            if (cause.getClass().getSimpleName().equals("UniversalConnectionPoolException")) {
                                printWriter.println("No db connection for  " + modelIdent.id + ", sleeping " + dbSleepTime + " seconds");
                                Thread.currentThread().sleep(dbSleepTime * 1000);
                                // wait a little longer next time
                                dbSleepTime *= 1.5;
                            } else {
                                // other exception, just rethrow
                                throw dae;
                            }
                        }
                    }
                    MathModel storedModel = cbit.vcell.xml.XmlHelper.XMLToMathModel(new XMLSource(mathModelXML.toString()));
                    databaseVisitor.visitMathModel(storedModel, System.out);
                } catch (Exception e) {
                    lg.error(e.getMessage(), e);
                    scanStatus = ScanStatus.FAIL;
                    exceptionClass = e.getClass().getName();
                    exceptionMessage = e.getMessage();
                    printWriter.println("failed " + modelIdent.id);
                    e.printStackTrace(printWriter);
                }
                ps.setInt(1, scanStatus.code);
                ps.setString(2, exceptionClass);
                ps.setString(3, exceptionMessage);
                ps.setLong(4, modelIdent.id);
                boolean estat = ps.execute();
                if (estat) {
                    throw new Error("logic");
                }
                int uc = ps.getUpdateCount();
                if (uc != 1) {
                    throw new Error("logic / sql ");
                }
                printWriter.println("model " + modelIdent.id + " " + scanStatus);
            }
            printWriter.close();
        } finally {
            System.setOut(current);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) KeyValue(org.vcell.util.document.KeyValue) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) ResultSet(java.sql.ResultSet) DataAccessException(org.vcell.util.DataAccessException) PrintWriter(java.io.PrintWriter) PrintStream(java.io.PrintStream) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) XMLSource(cbit.vcell.xml.XMLSource)

Aggregations

DataAccessException (org.vcell.util.DataAccessException)345 KeyValue (org.vcell.util.document.KeyValue)82 XmlParseException (cbit.vcell.xml.XmlParseException)80 ExpressionException (cbit.vcell.parser.ExpressionException)78 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)71 SQLException (java.sql.SQLException)67 IOException (java.io.IOException)60 MathException (cbit.vcell.math.MathException)59 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)46 BigString (org.vcell.util.BigString)45 User (org.vcell.util.document.User)42 FileNotFoundException (java.io.FileNotFoundException)38 ResultSet (java.sql.ResultSet)38 PropertyVetoException (java.beans.PropertyVetoException)37 File (java.io.File)34 PermissionException (org.vcell.util.PermissionException)34 Statement (java.sql.Statement)33 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)32 BioModelInfo (org.vcell.util.document.BioModelInfo)29 Vector (java.util.Vector)26