List of usage examples for java.sql ResultSet CONCUR_READ_ONLY
int CONCUR_READ_ONLY
To view the source code for java.sql ResultSet CONCUR_READ_ONLY.
Click Source Link
ResultSet
object that may NOT be updated. From source file:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from ww w . j a v a2s . c o m*/ public Document getDocument(final String user, final String password, final String db, final String table, final String name, final boolean allowEmpty, final Map<String, String[]> defaultFieldValues) throws BackendException { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = this.connectToDB(user, password, db); PostgresDocument doc = this.createEmptyDocument(conn, table, name, db); String nameField = this.getNameField(conn, table, db); st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String queryString = String.format("select * from \"%s\".\"%s\" where \"%s\"='%s'", this.getSchemaName(table, db), this.getPlainTableName(table), nameField, name); this.logString(queryString, user); rs = st.executeQuery(queryString); if (this.getNumRows(rs) == 0) { if (allowEmpty) { if (defaultFieldValues != null) { for (String key : defaultFieldValues.keySet()) { Field field = doc.getAllFields().get(key); if (field != null) { if (field.getType() == FieldType.string || field.getType() == FieldType.text) { field.setValue(defaultFieldValues.get(key)[0]); } else if (field.getType() == FieldType.date) { try { field.setValue(new SimpleDateFormat("y-M-d") .parse(defaultFieldValues.get(key)[0])); } catch (ParseException e) { throw new BackendException(e); } } else if (field.getType() == FieldType.dec) { field.setValue(Integer.valueOf(defaultFieldValues.get(key)[0])); } else if (field.getType() == FieldType.num) { field.setValue(Double.valueOf(defaultFieldValues.get(key)[0])); } } } } return doc; } else { throw new DocumentNotFoundException(String.format("Document '%s' not found in table '%s.%s'.", name, this.getSchemaName(table, db), this.getPlainTableName(table))); } } rs.next(); ResultSetMetaData md = rs.getMetaData(); for (int i = 1; i <= md.getColumnCount(); i++) { Field field = doc.getAllFields().get(md.getColumnName(i)); if (field.getType() == FieldType.string || field.getType() == FieldType.text) { field.setValue(rs.getString(i)); } else if (field.getType() == FieldType.date) { field.setValue(rs.getDate(i)); } else if (field.getType() == FieldType.dec) { field.setValue(rs.getInt(i)); } else if (field.getType() == FieldType.num) { field.setValue(rs.getDouble(i)); } } return doc; } catch (SQLException e) { throw new BackendException(e); } catch (ClassNotFoundException e) { throw new BackendException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(st); DbUtils.closeQuietly(conn); } }
From source file:com.streamsets.pipeline.stage.origin.jdbc.JdbcSource.java
@Override public String produce(String lastSourceOffset, int maxBatchSize, BatchMaker batchMaker) throws StageException { int batchSize = Math.min(this.commonSourceConfigBean.maxBatchSize, maxBatchSize); String nextSourceOffset = lastSourceOffset == null ? initialOffset : lastSourceOffset; long now = System.currentTimeMillis(); long delay = Math.max(0, (lastQueryCompletedTime + queryIntervalMillis) - now); if (delay > 0) { // Sleep in one second increments so we don't tie up the app. LOG.debug("{}ms remaining until next fetch.", delay); ThreadUtil.sleep(Math.min(delay, 1000)); } else {/* ww w .ja v a 2s . com*/ Statement statement = null; Hasher hasher = HF.newHasher(); try { if (null == resultSet || resultSet.isClosed()) { // The result set got closed outside of us, so we also clean up the connection (if any) closeQuietly(connection); connection = dataSource.getConnection(); if (!txnColumnName.isEmpty()) { // CDC requires scrollable cursors. statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); } else { statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } int fetchSize = batchSize; // MySQL does not support cursors or fetch size except 0 and "streaming" (1 at a time). if (hikariConfigBean.getConnectionString().toLowerCase().contains("mysql")) { // Enable MySQL streaming mode. fetchSize = Integer.MIN_VALUE; } LOG.debug("Using query fetch size: {}", fetchSize); statement.setFetchSize(fetchSize); if (getContext().isPreview()) { statement.setMaxRows(batchSize); } preparedQuery = prepareQuery(query, lastSourceOffset); LOG.trace("Executing query: " + preparedQuery); hashedQuery = hasher.putString(preparedQuery, Charsets.UTF_8).hash().toString(); LOG.debug("Executing query: " + hashedQuery); resultSet = statement.executeQuery(preparedQuery); queryRowCount = 0; numQueryErrors = 0; firstQueryException = null; } // Read Data and track last offset int rowCount = 0; String lastTransactionId = ""; boolean haveNext = true; while (continueReading(rowCount, batchSize) && (haveNext = resultSet.next())) { final Record record = processRow(resultSet, rowCount); if (null != record) { if (!txnColumnName.isEmpty()) { String newTransactionId = resultSet.getString(txnColumnName); if (lastTransactionId.isEmpty()) { lastTransactionId = newTransactionId; batchMaker.addRecord(record); } else if (lastTransactionId.equals(newTransactionId)) { batchMaker.addRecord(record); } else { // The Transaction ID Column Name config should not be used with MySQL as it // does not provide a change log table and the JDBC driver may not support scrollable cursors. resultSet.relative(-1); break; // Complete this batch without including the new record. } } else { batchMaker.addRecord(record); } } // Get the offset column value for this record if (isIncrementalMode) { nextSourceOffset = resultSet.getString(offsetColumn); } else { nextSourceOffset = initialOffset; } ++rowCount; ++queryRowCount; ++noMoreDataRecordCount; shouldFire = true; } LOG.debug("Processed rows: " + rowCount); if (!haveNext || rowCount == 0) { // We didn't have any data left in the cursor. Close everything // We may not have the statement here if we're not producing the // same batch as when we got it, so get it from the result set // Get it before we close the result set, just to be safe! statement = resultSet.getStatement(); closeQuietly(resultSet); closeQuietly(statement); closeQuietly(connection); lastQueryCompletedTime = System.currentTimeMillis(); LOG.debug("Query completed at: {}", lastQueryCompletedTime); QUERY_SUCCESS.create(getContext()).with(QUERY, preparedQuery) .with(TIMESTAMP, lastQueryCompletedTime).with(ROW_COUNT, queryRowCount) .with(SOURCE_OFFSET, nextSourceOffset).createAndSend(); // In case of non-incremental mode, we need to generate no-more-data event as soon as we hit end of the // result set. Incremental mode will try to run the query again and generate the event if and only if // the next query results in zero rows. if (!isIncrementalMode) { generateNoMoreDataEvent(); } } /* * We want to generate no-more data event on next batch if: * 1) We run a query in this batch and returned empty. * 2) We consumed at least some data since last time (to not generate the event all the time) */ if (isIncrementalMode && rowCount == 0 && !haveNext && shouldFire && !firstTime) { generateNoMoreDataEvent(); shouldFire = false; } firstTime = false; } catch (SQLException e) { if (++numQueryErrors == 1) { firstQueryException = e; } String formattedError = jdbcUtil.formatSqlException(e); LOG.error(formattedError, e); if (resultSet != null) { try { statement = resultSet.getStatement(); } catch (SQLException e1) { LOG.debug("Error while getting statement from result set: {}", e1.toString(), e1); } closeQuietly(resultSet); closeQuietly(statement); } closeQuietly(connection); lastQueryCompletedTime = System.currentTimeMillis(); QUERY_FAILURE.create(getContext()).with(QUERY, preparedQuery) .with(TIMESTAMP, lastQueryCompletedTime).with(ERROR, formattedError) .with(ROW_COUNT, queryRowCount).with(SOURCE_OFFSET, nextSourceOffset).createAndSend(); LOG.debug("Query '{}' failed at: {}; {} errors so far", preparedQuery, lastQueryCompletedTime, numQueryErrors); if (numQueryErrors > commonSourceConfigBean.numSQLErrorRetries) { throw new StageException(JdbcErrors.JDBC_77, e.getClass().getSimpleName(), preparedQuery, numQueryErrors, jdbcUtil.formatSqlException(firstQueryException)); } // else allow nextSourceOffset to be returned, to retry } } return nextSourceOffset; }
From source file:com.google.enterprise.connector.salesforce.storetype.DBStore.java
public void setDocList(String checkpoint, String str_store_entry) { DatabaseMetaData dbm = null;/* w ww .j av a2 s . c o m*/ Connection connection = null; logger.log(Level.FINEST, "Setting doclist " + checkpoint); logger.log(Level.FINEST, "Setting store_entry " + str_store_entry); try { connection = ds.getConnection(); connection.setAutoCommit(true); dbm = connection.getMetaData(); //logger.log(Level.FINE,"Base64 ENCODING..."); String encode_entry = new String( org.apache.commons.codec.binary.Base64.encodeBase64(str_store_entry.getBytes())); str_store_entry = encode_entry; //logger.log(Level.FINE,"Setting store_entry ENCODED " + str_store_entry); if (dbm.getDatabaseProductName().equals("MySQL")) { //get the most recent row Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); String update_stmt = "select crawl_set from " + this.instance_table + " where crawl_set=(select max(crawl_set) from " + this.instance_table + ")"; logger.log(Level.FINE, "Getting lastentryp in db: " + update_stmt); ResultSet rs = statement.executeQuery(update_stmt); boolean ret_rows = rs.first(); String last_entry_in_db = null; while (ret_rows) { BigDecimal crawl_set = rs.getBigDecimal("crawl_set"); last_entry_in_db = crawl_set.toPlainString(); ret_rows = rs.next(); } logger.log(Level.FINER, "Last_Entry_in_Database " + last_entry_in_db); if (last_entry_in_db != null) { if (last_entry_in_db.startsWith(checkpoint)) { //increment if in the same set BigDecimal bd = new BigDecimal(last_entry_in_db); bd = bd.add(new BigDecimal(".00001")); logger.log(Level.INFO, "Adding to DBStore. Index Value: " + bd.toPlainString()); update_stmt = "insert into " + this.instance_table + " (crawl_set,crawl_data) values (?,COMPRESS(?))"; PreparedStatement ps = connection.prepareStatement(update_stmt); ps.setString(1, bd.toPlainString()); ps.setString(2, str_store_entry); ps.executeUpdate(); ps.close(); } else { //otherwise add the the 0th row for this set logger.log(Level.INFO, "Adding to DBStore. Index Value: " + checkpoint + ".00000"); update_stmt = "insert into " + this.instance_table + " (crawl_set,crawl_data) values (?,COMPRESS(?))"; PreparedStatement ps = connection.prepareStatement(update_stmt); ps.setString(1, checkpoint + ".00000"); ps.setString(2, str_store_entry); ps.executeUpdate(); ps.close(); } } else { logger.log(Level.INFO, "Adding to DBStore. Index Value: " + checkpoint + ".00000"); update_stmt = "insert into " + this.instance_table + " (crawl_set,crawl_data) values (?,COMPRESS(?))"; PreparedStatement ps = connection.prepareStatement(update_stmt); ps.setString(1, checkpoint + ".00000"); ps.setString(2, str_store_entry); ps.executeUpdate(); ps.close(); } rs.close(); statement.close(); connection.close(); } } catch (Exception ex) { logger.log(Level.SEVERE, "Exception initializing context Datasource " + ex); return; } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AttachmentTagTable.java
public void deleteAttachmentTag(MSSBamAuthorization Authorization, MSSBamAttachmentTagBuff Buff) { final String S_ProcName = "deleteAttachmentTag"; try {/*w w w. j a va2 s .c o m*/ Connection cnx = schema.getCnx(); long AttachmentId = Buff.getRequiredAttachmentId(); long TagId = Buff.getRequiredTagId(); String TagValue = Buff.getRequiredTagValue(); int Revision = Buff.getRequiredRevision(); MSSBamAttachmentTagBuff readBuff = readBuffByIdIdx(Authorization, AttachmentId, TagId); int oldRevision = readBuff.getRequiredRevision(); if (oldRevision != Revision) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName, Buff); } String sql = "DELETE FROM mssbam110.ctcattch_tag " + "WHERE " + "AttachmentId = " + Long.toString(AttachmentId) + " " + "AND " + "TagId = " + Long.toString(TagId) + " " + "AND " + "Revision = " + Integer.toString(Revision); ; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); int rowsAffected = stmt.executeUpdate(sql); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by delete, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ChainTable.java
public MSSBamChainBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "readBuffByTenantIdx"; try {/*from www .java2s . com*/ Connection cnx = schema.getCnx(); String sql = S_sqlSelectChainBuff + "WHERE " + "anyo.TenantId = " + Long.toString(TenantId) + " " + "ORDER BY " + "anyo.Id ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamChainBuff> buffList = new ArrayList<MSSBamChainBuff>(); while (resultSet.next()) { MSSBamChainBuff buff = unpackChainResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamChainBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:BQJDBC.QueryResultTest.QueryResultTest.java
@Test public void QueryResultTest12() { int limitNum = 40000; final String sql = "SELECT weight_pounds FROM publicdata:samples.natality LIMIT " + limitNum; this.logger.info("Test number: 12"); this.logger.info("Running query:" + sql); java.sql.ResultSet Result = null; try {/*w ww .j a v a2 s . co m*/ Statement stm = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stm.setFetchSize(1000); Result = stm.executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(Result); try {/* int j = 0; for (int i = 0; i < limitNum-1; i++) { if(i%1000 == 0) { logger.debug("fetched 1k for the " + ++j + ". time"); } Assert.assertTrue(Result.next()); }*/ Result.absolute(limitNum); Assert.assertTrue(true); } catch (SQLException e) { e.printStackTrace(); Assert.fail(); } }
From source file:com.netspective.axiom.sql.StoredProcedure.java
/** * Executes the stored procedure without any statistical logging * * @param cc Connection context * @param overrideIndexes parameter indexes to override * @param overrideValues parameter override values */// ww w .ja va2s . co m protected QueryResultSet executeAndIgnoreStatistics(ConnectionContext cc, int[] overrideIndexes, Object[] overrideValues, boolean scrollable) throws NamingException, SQLException { if (log.isTraceEnabled()) trace(cc, overrideIndexes, overrideValues); Connection conn = null; CallableStatement stmt = null; boolean closeConnection = true; try { getMetaData(cc); conn = cc.getConnection(); String sql = StringUtils.strip(getSqlText(cc)); if (scrollable) stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); else stmt = conn.prepareCall(sql); if (parameters != null) { parameters.apply(cc, stmt, overrideIndexes, overrideValues); stmt.execute(); parameters.extract(cc, stmt); StoredProcedureParameter rsParameter = parameters.getResultSetParameter(); if (rsParameter != null) { closeConnection = false; return (QueryResultSet) rsParameter.getExtractedValue(cc.getDatabaseValueContext()); } else return null; } else { stmt.execute(); return null; } } catch (SQLException e) { log.error(createExceptionMessage(cc, overrideIndexes, overrideValues), e); throw e; } }
From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurveAnalysis.java
public void evaluate() throws SQLException { kernelRegression = new TreeMap<VariableAttributes, KernelRegressionItem>(); for (VariableAttributes v : variables) { KernelRegressionItem kItem = new KernelRegressionItem(v, kernelFunction, bandwidth, uniformDistributionApproximation); kernelRegression.put(v, kItem);// w ww . j av a 2 s.c o m } ResultSet rs = null; Statement stmt = null; try { //connect to db Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); for (VariableAttributes v : variables) { select.addColumn(sqlTable, v.getName().nameForDatabase()); } select.addColumn(sqlTable, regressorVariable.getName().nameForDatabase()); if (hasGroupVariable) select.addColumn(sqlTable, groupByVariable.getName().nameForDatabase()); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); KernelRegressionItem kernelRegressionItem; Object itemResponse; Double score; Object tempGroup; String group; while (rs.next()) { //increment kernel regression objects //omit examinees with missing data score = rs.getDouble(regressorVariable.getName().nameForDatabase()); if (!rs.wasNull()) { for (VariableAttributes v : kernelRegression.keySet()) { kernelRegressionItem = kernelRegression.get(v); itemResponse = rs.getObject(v.getName().nameForDatabase()); if (itemResponse != null) kernelRegressionItem.increment(score, itemResponse); } } updateProgress(); } } catch (SQLException ex) { throw ex; } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); } this.firePropertyChange("progress-ind-on", null, null); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BlobDefTable.java
public MSSBamBlobDefBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "readAllDerived"; MSSBamBlobDefBuff[] buffArray;//from w w w.j a v a 2 s. c o m if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } String classCode; ArrayList<String> classCodeList = new ArrayList<String>(); try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBlobDefDistinctClassCode; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); while (resultSet.next()) { classCode = resultSet.getString(1); classCodeList.add(classCode); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } ArrayList<MSSBamBlobDefBuff> resultList = new ArrayList<MSSBamBlobDefBuff>(); for (int classCodeIdx = 0; classCodeIdx < classCodeList.size(); classCodeIdx++) { MSSBamBlobDefBuff[] subList; classCode = classCodeList.get(classCodeIdx); if (classCode.equals("BLB")) { subList = readAllBuff(Authorization); } else if (classCode.equals("TBLB")) { subList = schema.getTableTableBlob().readAllBuff(Authorization); } else if (classCode.equals("SBLB")) { subList = schema.getTableSchemaBlob().readAllBuff(Authorization); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } for (int idxSubList = 0; idxSubList < subList.length; idxSubList++) { resultList.add(subList[idxSubList]); } } buffArray = resultList.toArray(new MSSBamBlobDefBuff[0]); return (buffArray); }
From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java
/** * @param databaseNameSource//w w w. j a v a2s . c o m * @param databaseNameDest * @throws Exception */ public void verifyDB(final String databaseNameSource, final String databaseNameDest) throws Exception { String path = UIRegistry.getUserHomeDir() + File.separator + "verify"; convLogger.initialize(path, databaseNameDest); String title = "From " + databaseNameSource + " to " + databaseNameDest; System.out.println("************************************************************"); System.out.println(title); System.out.println("************************************************************"); HibernateUtil.shutdown(); Properties initPrefs = BuildSampleDatabase.getInitializePrefs(databaseNameDest); String driverNameSource = ""; String databaseHostSource = ""; DatabaseDriverInfo driverInfoSource = null; String driverNameDest = ""; String databaseHostDest = ""; DatabaseDriverInfo driverInfoDest = null; log.debug("Running an non-custom MySQL convert, using old default login creds"); driverNameSource = initPrefs.getProperty("initializer.driver", "MySQL"); databaseHostSource = initPrefs.getProperty("initializer.host", "localhost"); driverNameDest = initPrefs.getProperty("initializer.driver", "MySQL"); databaseHostDest = initPrefs.getProperty("initializer.host", "localhost"); log.debug("Custom Convert Source Properties ----------------------"); log.debug("databaseNameSource: " + databaseNameSource); log.debug("driverNameSource: " + driverNameSource); log.debug("databaseHostSource: " + databaseHostSource); log.debug("Custom Convert Destination Properties ----------------------"); log.debug("databaseNameDest: " + databaseNameDest); log.debug("driverNameDest: " + driverNameDest); log.debug("databaseHostDest: " + databaseHostDest); driverInfoSource = DatabaseDriverInfo.getDriver(driverNameSource); driverInfoDest = DatabaseDriverInfo.getDriver(driverNameDest); if (driverInfoSource == null) { throw new RuntimeException( "Couldn't find Source DB driver by name [" + driverInfoSource + "] in driver list."); } if (driverInfoDest == null) { throw new RuntimeException( "Couldn't find Destination driver by name [" + driverInfoDest + "] in driver list."); } if (driverNameDest.equals("MySQL")) BasicSQLUtils.myDestinationServerType = BasicSQLUtils.SERVERTYPE.MySQL; else if (driverNameDest.equals("SQLServer")) BasicSQLUtils.myDestinationServerType = BasicSQLUtils.SERVERTYPE.MS_SQLServer; if (driverNameSource.equals("MySQL")) BasicSQLUtils.mySourceServerType = BasicSQLUtils.SERVERTYPE.MySQL; else if (driverNameSource.equals("SQLServer")) BasicSQLUtils.mySourceServerType = BasicSQLUtils.SERVERTYPE.MS_SQLServer; else { log.error("Error setting ServerType for destination database for conversion. Could affect the" + " way that SQL string are generated and executed on differetn DB egnines"); } String destConnectionString = driverInfoDest.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, databaseHostDest, "", itUsrPwd.first, itUsrPwd.second, driverNameDest); log.debug("attempting login to destination: " + destConnectionString); // This will log us in and return true/false // This will connect without specifying a DB, which allows us to create the DB if (!UIHelper.tryLogin(driverInfoDest.getDriverClassName(), driverInfoDest.getDialectClassName(), databaseNameDest, destConnectionString, itUsrPwd.first, itUsrPwd.second)) { log.error("Failed connection string: " + driverInfoSource.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, databaseHostDest, databaseNameDest, itUsrPwd.first, itUsrPwd.second, driverNameDest)); throw new RuntimeException( "Couldn't login into [" + databaseNameDest + "] " + DBConnection.getInstance().getErrorMsg()); } convLogger.setIndexTitle(databaseNameDest + " Verify " + (new SimpleDateFormat("yyy-MM-dd hh:mm:ss")).format(Calendar.getInstance().getTime())); //MEG WHY IS THIS COMMENTED OUT??? //DataBuilder.setSession(HibernateUtil.getNewSession()); log.debug("DESTINATION driver class: " + driverInfoDest.getDriverClassName()); log.debug("DESTINATION dialect class: " + driverInfoDest.getDialectClassName()); log.debug("DESTINATION Connection String: " + driverInfoDest.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, databaseHostDest, databaseNameDest, itUsrPwd.first, itUsrPwd.second, driverNameDest)); // This will log us in and return true/false if (!UIHelper.tryLogin(driverInfoDest.getDriverClassName(), driverInfoDest.getDialectClassName(), databaseNameDest, driverInfoDest.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, databaseHostDest, databaseNameDest, itUsrPwd.first, itUsrPwd.second, driverNameDest), itUsrPwd.first, itUsrPwd.second)) { throw new RuntimeException( "Couldn't login into [" + databaseNameDest + "] " + DBConnection.getInstance().getErrorMsg()); } String srcConStr = driverInfoSource.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, databaseHostSource, databaseNameSource, itUsrPwd.first, itUsrPwd.second, driverNameSource); DBConnection oldDB = DBConnection.createInstance(driverInfoSource.getDriverClassName(), null, databaseNameSource, srcConStr, itUsrPwd.first, itUsrPwd.second); oldDBConn = oldDB.getConnection(); if (oldDBConn == null) { throw new RuntimeException(oldDB.getErrorMsg()); } newDBConn = DBConnection.getInstance().createConnection(); newDBStmt = newDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); oldDBStmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); long startTime = System.currentTimeMillis(); String[] tableNames = { "CollectingEvent", "CollectingEvent", "Locality", "Locality" }; for (int i = 0; i < tableNames.length; i += 2) { verifyTableCounts(tableNames[i].toLowerCase(), tableNames[i + 1].toLowerCase()); } progressFrame = new ProgressFrame("Checking Catalog Objects...."); progressFrame.adjustProgressFrame(); String cntSQL = compareTo6DBs ? "SELECT COUNT(*) FROM collectionobject" : "SELECT COUNT(*) FROM collectionobjectcatalog WHERE CollectionObjectTypeID > 8 && CollectionObjectTypeID < 20"; Integer numColObjs = BasicSQLUtils.getCount(oldDBConn, cntSQL); progressFrame.setProcess(0, numColObjs); //progressFrame.setDesc("Checking Catalog Objects...."); progressFrame.setOverall(0, numColObjs * 4); progressFrame.setOverall(0); progressFrame.setDesc(""); UIHelper.centerAndShow(progressFrame); SwingUtilities.invokeLater(new Runnable() { public void run() { UIHelper.centerAndShow(progressFrame); } }); HashMap<Integer, TableWriter> tblWriterHash = new HashMap<Integer, TableWriter>(); for (int i = 1; i < labels.length - 1; i++) { tblWriter = convLogger.getWriter(labels[i] + ".html", labels[i]); //printVerifyHeader(labels[i]); tblWriter.startTable(); tblWriter.logHdr("ID", "Desc"); tblWriterHash.put(codes[i], tblWriter); System.out.println(codes[i] + " - " + labels[i]); } boolean nullCEOk = false; File ceFile = new File(databaseNameDest + ".ce_all"); if (ceFile.exists()) { nullCEOk = true; //ceFile.delete(); } nullCEOk = true; // For Debug coOptions = DO_CO_ALL; //if (coOptions > NO_OPTIONS) { int i = 0; Statement stmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String sql = compareTo6DBs ? "SELECT CatalogNumber FROM collectionobject ORDER BY CatalogNumber ASC" : "SELECT CatalogNumber FROM collectionobjectcatalog WHERE CollectionObjectTypeID > 8 && CollectionObjectTypeID < 20 AND SubNumber >= 0 ORDER BY CatalogNumber ASC"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int oldCatNum = rs.getInt(1); String newCatNum = convertCatNum(oldCatNum); //if (oldCatNum < 1643) continue; if (isCOOn(DO_CO_DETERMINER)) { tblWriter = tblWriterHash.get(DO_CO_DETERMINER); if (!verifyDeterminer(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_DETERMINER]++; } } if (isCOOn(DO_CO_CATLOGER)) { tblWriter = tblWriterHash.get(DO_CO_CATLOGER); if (!verifyCataloger(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_CATLOGER]++; } } if (isCOOn(DO_CO_COLLECTORS)) { tblWriter = tblWriterHash.get(DO_CO_COLLECTORS); if (!verifyCollector(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_COLLECTORS]++; } } if (isCOOn(DO_CO_GEO)) { tblWriter = tblWriterHash.get(DO_CO_GEO); if (!verifyGeography(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_GEO]++; } } if (isCOOn(DO_CO_CE)) { tblWriter = tblWriterHash.get(DO_CO_CE); if (!verifyCollectingEvent(oldCatNum, newCatNum, nullCEOk)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_CE]++; } } if (isCOOn(DO_CO_TAXON)) { tblWriter = tblWriterHash.get(DO_CO_TAXON); if (!verifyTaxon(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_TAXON]++; } } if (isCOOn(DO_CO_LOCALITY)) { tblWriter = tblWriterHash.get(DO_CO_LOCALITY); if (!verifyCOToLocality(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_LOCALITY]++; } } if (isCOOn(DO_CO_PREPARATION)) { tblWriter = tblWriterHash.get(DO_CO_PREPARATION); if (!verifyPreparation(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_PREPARATION]++; } } if (isCOOn(DO_CO_PREPARER)) { tblWriter = tblWriterHash.get(DO_CO_PREPARER); if (!verifyPreparer(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_CO_PREPARER]++; } } if (isCOOn(DO_TAXON_CIT)) { tblWriter = tblWriterHash.get(DO_TAXON_CIT); if (!verifyTaxonCitations(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_TAXON_CIT]++; } } if (isCOOn(DO_OTHER_IDENT)) { tblWriter = tblWriterHash.get(DO_OTHER_IDENT); if (!verifyOtherIdentifier(oldCatNum, newCatNum)) { catNumsInErrHash.put(newCatNum, oldCatNum); errorCnts[DO_OTHER_IDENT]++; } } if ((i % 100) == 0) { System.out.println(i + " " + oldCatNum); progressFrame.setProcess(i); progressFrame.setOverall(i); } if ((i % 1000) == 0) { for (TableWriter tw : tblWriterHash.values()) { tw.flush(); } } i++; } rs.close(); stmt.close(); } for (int i = 0; i < errorCnts.length; i++) { if (errorCnts[i] > 0) { System.out.println(i + " -> " + errorCnts[i]); } } progressFrame.setProcess(numColObjs); if (isCOOn(DO_COLLECTORS)) { tblWriter = tblWriterHash.get(DO_COLLECTORS); //verifyCollectors(); } if (isCOOn(DO_AGENTS)) { tblWriter = tblWriterHash.get(DO_AGENTS); verifyAgents(); } progressFrame.setOverall(numColObjs * 2); if (isCOOn(DO_COLLEVENTS)) { tblWriter = tblWriterHash.get(DO_COLLEVENTS); verifyCEs(); } //progressFrame.setOverall(numColObjs*2); if (isCOOn(DO_COLLEVENTS)) { tblWriter = tblWriterHash.get(DO_COLLEVENTS); verifyShipments(); } if (isCOOn(DO_LOANS)) { tblWriter = tblWriterHash.get(DO_LOANS); verifyLoans(); verifyGifts(); verifyLoanRetPreps(); } for (TableWriter tw : tblWriterHash.values()) { tw.endTable(); } progressFrame.setOverall(numColObjs * 3); tblWriter = convLogger.getWriter("CatalogNumberSummary.html", "Catalog Nummber Summary"); tblWriter.startTable(); tblWriter.logHdr("Number", "Description"); tblWriter.logErrors(Integer.toString(numErrors), "All Errors"); tblWriter.logErrors(Integer.toString(catNumsInErrHash.size()), "Catalog Number with Errors"); tblWriter.endTable(); tblWriter.println("<BR>"); tblWriter.println("Catalog Summary:<BR>"); Vector<String> catNumList = new Vector<String>(catNumsInErrHash.keySet()); Collections.sort(catNumList); for (String catNum : catNumList) { tblWriter.println(catNum + "<BR>"); } tblWriter.println("<BR>"); numErrors = 0; //----------------------------------------------------------------------------------------------------------- // Accessions //----------------------------------------------------------------------------------------------------------- // For Debug acOptions = DO_AC_ALL; HashMap<Long, TableWriter> accTblWriterHash = new HashMap<Long, TableWriter>(); for (int i = 1; i < accLabels.length; i++) { long id = (long) Math.pow(2, i - 1); id = Math.max(id, 1); tblWriter = convLogger.getWriter("accession_" + accLabels[i] + ".html", "Accession " + accLabels[i]); tblWriter.startTable(); tblWriter.logHdr("ID", "Desc"); accTblWriterHash.put(id, tblWriter); } if (acOptions > NO_OPTIONS) { int i = 0; Statement stmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("SELECT Number FROM accession ORDER BY Number ASC"); while (rs.next()) { String oldAccNum = rs.getString(1); String newAccNum = oldAccNum; if (isACOn(DO_ACCESSIONS)) { tblWriter = accTblWriterHash.get(DO_ACCESSIONS); if (!verifyAccessions(oldAccNum, newAccNum)) { log.error("Accession Num: " + oldAccNum); accNumsInErrHash.put(newAccNum, oldAccNum); } //log.error("New SQL: "+newSQL); //log.error("Old SQL: "+oldSQL); //break; } if (isACOn(DO_AC_AGENTS)) { tblWriter = accTblWriterHash.get(DO_AC_AGENTS); if (!verifyAccessionAgents(oldAccNum, newAccNum)) { log.error("Accession Num: " + oldAccNum); accNumsInErrHash.put(newAccNum, oldAccNum); } //log.error("New SQL: "+newSQL); //log.error("Old SQL: "+oldSQL); //break; } if ((i % 100) == 0) { System.out.println(i + " " + oldAccNum); } i++; } rs.close(); stmt.close(); } progressFrame.setOverall(numColObjs * 4); newDBConn.close(); oldDBConn.close(); for (TableWriter tw : accTblWriterHash.values()) { tw.endTable(); } printAccessionTotal("Accession"); File indexFile = convLogger.closeAll(); long endTime = System.currentTimeMillis(); int convertTimeInSeconds = (int) ((endTime - startTime) / 1000.0); //ConvertStatSender sender = new ConvertStatSender("verify.php"); //sender.senConvertInfo(databaseNameDest, numColObjs, convertTimeInSeconds); log.info("Done."); progressFrame.setVisible(false); AttachmentUtils.openURI(indexFile.toURI()); System.exit(0); }