List of usage examples for java.sql ResultSet TYPE_SCROLL_SENSITIVE
int TYPE_SCROLL_SENSITIVE
To view the source code for java.sql ResultSet TYPE_SCROLL_SENSITIVE.
Click Source Link
ResultSet
object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet
. From source file:org.opennms.provisiond.utils.CsvRequisitionParser.java
private static void migrateDbNodes() throws SQLException, UnknownHostException, ClassNotFoundException { String distinctNodesQueryStr = " " + "SELECT nodeId AS \"nodeid\"," + " nodeLabel AS \"nodelabel\"," + " foreignSource AS \"foreignsource\"," + " foreignId AS \"foreignid\" " + " FROM node " + " WHERE nodeid in (" + " SELECT " + "DISTINCT nodeid " + " FROM ipinterface " + " WHERE iplike(ipaddr, '" + m_iplikeQuery + "')) " + "ORDER BY nodeid"; if (m_addOnly) { distinctNodesQueryStr = " " + "SELECT nodeId AS \"nodeid\"," + " nodeLabel AS \"nodelabel\"," + " foreignSource AS \"foreignsource\"," + " foreignId AS \"foreignid\" " + " FROM node " + " WHERE nodeid in (" + " SELECT " + "DISTINCT nodeid " + " FROM ipinterface " + " WHERE iplike(ipaddr, '" + m_iplikeQuery + "')) " + " AND foreignsource is NULL " + "ORDER BY nodeid"; }/*from w ww .jav a2 s .co m*/ Connection connection = null; Statement distinctNodesStatement = null; PoolingConnection pool = null; connection = createConnection(); connection.setAutoCommit(false); pool = new PoolingConnection(connection); distinctNodesStatement = pool.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet distinctNodesResultSet = null; int rowsFound = 0; distinctNodesResultSet = distinctNodesStatement.executeQuery(distinctNodesQueryStr); distinctNodesResultSet.last(); rowsFound = distinctNodesResultSet.getRow(); distinctNodesResultSet.beforeFirst(); System.out.println(rowsFound + " nodes found."); int nodesMigrated = 0; while (distinctNodesResultSet.next()) { System.out.println("Processing row: " + distinctNodesResultSet.getRow() + "..."); int nodeId = distinctNodesResultSet.getInt("nodeid"); String queryStr = "" + " SELECT ipaddr " + " FROM ipinterface " + " WHERE nodeid = " + nodeId + " " + " AND issnmpprimary = 'P' " + "ORDER BY inet(ipaddr)" + " LIMIT 1"; Statement findPrimaryStatement = pool.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); System.out.println("Querying DB for SNMP Primary interface for node: " + nodeId + "..."); ResultSet findPrimaryResultSet = findPrimaryStatement.executeQuery(queryStr); String primaryIp = null; if (findPrimaryResultSet.next()) { primaryIp = findPrimaryResultSet.getString("ipaddr"); System.out.println("SNMP Primary found: " + primaryIp); } findPrimaryResultSet.close(); findPrimaryStatement.close(); if (primaryIp == null) { System.out.println("SNMP Primary not found. Determining lowest numbered IP to set as Primary..."); queryStr = "" + " SELECT ipaddr " + " FROM ipinterface " + " WHERE nodeid = " + nodeId + " " + "ORDER BY inet(ipaddr)" + " LIMIT 1"; findPrimaryStatement = pool.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); findPrimaryResultSet = findPrimaryStatement.executeQuery(queryStr); } if (primaryIp == null && findPrimaryResultSet.next()) { primaryIp = findPrimaryResultSet.getString("ipaddr"); System.out.println("SNMP Primary found: " + primaryIp); } findPrimaryResultSet.close(); findPrimaryStatement.close(); if (primaryIp == null) { System.out.println( "SNMP Primary not found. Skipping node. (This should never happen since it is the iplike query that finds the distinct nodes :( )"); continue; } String foreignId = null; if (m_useNodeId) { foreignId = String.valueOf(nodeId); } else { foreignId = String.valueOf(System.currentTimeMillis()); } String label = distinctNodesResultSet.getString("nodelabel"); distinctNodesResultSet.updateString("foreignsource", m_foreignSource); distinctNodesResultSet.updateString("foreignId", foreignId); System.out.println("Updating node (" + nodeId + ":" + label + ") with foreignsource:" + m_foreignSource + " and foreignId:" + foreignId); distinctNodesResultSet.updateRow(); System.out.println("Node updated."); RequisitionData rd = new RequisitionData(label, primaryIp, m_foreignSource, foreignId); if (m_categoryAddExisting) { String categoriesQueryString = "" + "SELECT c.categoryname as \"categoryname\" " + " FROM categories c " + " JOIN category_node cn " + " ON cn.categoryid = c.categoryid " + " JOIN node n on n.nodeid = cn.nodeid " + " WHERE n.nodeid = " + nodeId; Statement categoriesStatement = pool.createStatement(); ResultSet crs = categoriesStatement.executeQuery(categoriesQueryString); Set<String> categories = new LinkedHashSet<String>(); while (crs.next()) { categories.add(crs.getString("categoryname")); } crs.close(); categoriesStatement.close(); rd.setCategories(categories); } System.out.println("Updating requistion..."); createOrUpdateRequistion(rd); System.out.println("Requistion updated! Next...\n"); nodesMigrated++; } try { connection.commit(); } catch (SQLException e) { e.printStackTrace(); connection.rollback(); } distinctNodesResultSet.close(); distinctNodesStatement.close(); pool.close(); connection.close(); System.out.println(nodesMigrated + " Nodes migrated to foreign source " + m_foreignSource); }
From source file:org.jtotus.database.LocalJDBC.java
public double[] fetchPeriod(String tableName, DateTime startDate, DateTime endDate, String type) { BigDecimal retValue = null;/*w ww.j a v a 2 s . c o m*/ PreparedStatement pstm = null; java.sql.Date retDate = null; ResultSet results = null; ArrayList<Double> closingPrices = new ArrayList<Double>(600); Connection connection = null; try { String query = "SELECT " + type + ", DATE FROM " + this.normTableName(tableName) + " WHERE DATE>=? AND DATE<=? ORDER BY DATE ASC"; // this.createTable(connection, this.normTableName(tableName)); connection = this.getConnection(); pstm = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); java.sql.Date startSqlDate = new java.sql.Date(startDate.getMillis()); pstm.setDate(1, startSqlDate); java.sql.Date endSqlDate = new java.sql.Date(endDate.getMillis()); pstm.setDate(2, endSqlDate); DateIterator dateIter = new DateIterator(startDate, endDate); results = pstm.executeQuery(); DateTime dateCheck; if (debug) { System.out.printf("start data %s end date: %s\n", startSqlDate.toString(), endSqlDate.toString()); } while (dateIter.hasNext()) { dateCheck = dateIter.nextInCalendar(); if (results.next()) { retValue = results.getBigDecimal(1); retDate = results.getDate(2); DateTime compCal = new DateTime(retDate.getTime()); if (compCal.getDayOfMonth() == dateCheck.getDayOfMonth() && compCal.getMonthOfYear() == dateCheck.getMonthOfYear() && compCal.getYear() == dateCheck.getYear()) { closingPrices.add(retValue.doubleValue()); continue; } else { results.previous(); } } BigDecimal failOverValue = getFetcher().fetchData(tableName, dateCheck, type); if (failOverValue != null) { closingPrices.add(failOverValue.doubleValue()); } } } catch (SQLException ex) { System.err.printf("LocalJDBC Unable to find date for:'%s' from'%s' Time" + startDate.toDate() + "\n", "Cosing Price", tableName); ex.printStackTrace(); SQLException xp = null; while ((xp = ex.getNextException()) != null) { xp.printStackTrace(); } } finally { try { if (results != null) results.close(); if (pstm != null) pstm.close(); if (connection != null) connection.close(); // System.out.printf("Max connect:%d in use:%d\n",mainPool.getMaxConnections(), mainPool.getActiveConnections()); // mainPool.dispose(); } catch (SQLException ex) { Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex); } } return ArrayUtils.toPrimitive(closingPrices.toArray(new Double[0])); }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
@Override public Vector<String> getTableNames() { Vector<String> tablesNames = new Vector<String>(); Connection dbConnection = null; Statement dbStatement = null; try {/*from w w w . j av a2 s . c om*/ dbConnection = DBConnection.getInstance().createConnection(); if (dbConnection != null) { dbStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = dbStatement.executeQuery("show tables"); ResultSetMetaData metaData = resultSet.getMetaData(); while (resultSet.next()) { for (int i = 0; i < metaData.getColumnCount(); i++) { String name = resultSet.getString(i + 1); tablesNames.add(name); } } resultSet.close(); return tablesNames; } } catch (SQLException ex) { ex.printStackTrace(); } finally { try { if (dbStatement != null) { dbStatement.close(); } if (dbConnection != null) { dbConnection.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } return null; }
From source file:org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.java
/** * Constructor./* w ww . j a va 2s . c om*/ * * @param derivations whether to apply product derivations * @param loadGlobals whether to attempt to load the global properties */ public JDBCConfigurationImpl(boolean derivations, boolean loadGlobals) { super(false, false); String[] aliases; schema = addString("jdbc.Schema"); schemas = addStringList("jdbc.Schemas"); transactionIsolation = addInt("jdbc.TransactionIsolation"); aliases = new String[] { "default", String.valueOf(-1), "none", String.valueOf(Connection.TRANSACTION_NONE), "read-committed", String.valueOf(Connection.TRANSACTION_READ_COMMITTED), "read-uncommitted", String.valueOf(Connection.TRANSACTION_READ_UNCOMMITTED), "repeatable-read", String.valueOf(Connection.TRANSACTION_REPEATABLE_READ), "serializable", String.valueOf(Connection.TRANSACTION_SERIALIZABLE) }; transactionIsolation.setAliases(aliases); transactionIsolation.setDefault(aliases[0]); transactionIsolation.set(-1); transactionIsolation.setAliasListComprehensive(true); resultSetType = addInt("jdbc.ResultSetType"); aliases = new String[] { "forward-only", String.valueOf(ResultSet.TYPE_FORWARD_ONLY), "scroll-sensitive", String.valueOf(ResultSet.TYPE_SCROLL_SENSITIVE), "scroll-insensitive", String.valueOf(ResultSet.TYPE_SCROLL_INSENSITIVE), }; resultSetType.setAliases(aliases); resultSetType.setDefault(aliases[0]); resultSetType.set(ResultSet.TYPE_FORWARD_ONLY); resultSetType.setAliasListComprehensive(true); fetchDirection = addInt("jdbc.FetchDirection"); aliases = new String[] { "forward", String.valueOf(ResultSet.FETCH_FORWARD), "reverse", String.valueOf(ResultSet.FETCH_REVERSE), "unknown", String.valueOf(ResultSet.FETCH_UNKNOWN), }; fetchDirection.setAliases(aliases); fetchDirection.setDefault(aliases[0]); fetchDirection.set(ResultSet.FETCH_FORWARD); fetchDirection.setAliasListComprehensive(true); eagerFetchMode = new FetchModeValue("jdbc.EagerFetchMode"); eagerFetchMode.setDefault(FetchModeValue.EAGER_PARALLEL); eagerFetchMode.set(EagerFetchModes.EAGER_PARALLEL); addValue(eagerFetchMode); subclassFetchMode = new FetchModeValue("jdbc.SubclassFetchMode"); subclassFetchMode.setDefault(FetchModeValue.EAGER_JOIN); subclassFetchMode.set(EagerFetchModes.EAGER_JOIN); addValue(subclassFetchMode); lrsSize = addInt("jdbc.LRSSize"); aliases = new String[] { "query", String.valueOf(LRSSizes.SIZE_QUERY), "unknown", String.valueOf(LRSSizes.SIZE_UNKNOWN), "last", String.valueOf(LRSSizes.SIZE_LAST), }; lrsSize.setAliases(aliases); lrsSize.setDefault(aliases[0]); lrsSize.set(LRSSizes.SIZE_QUERY); lrsSize.setAliasListComprehensive(true); synchronizeMappings = addString("jdbc.SynchronizeMappings"); aliases = new String[] { "false", null }; synchronizeMappings.setAliases(aliases); synchronizeMappings.setDefault(aliases[0]); jdbcListenerPlugins = addPluginList("jdbc.JDBCListeners"); jdbcListenerPlugins.setInstantiatingGetter("getJDBCListenerInstances"); connectionDecoratorPlugins = addPluginList("jdbc.ConnectionDecorators"); connectionDecoratorPlugins.setInstantiatingGetter("getConnectionDecoratorInstances"); dbdictionaryPlugin = addPlugin("jdbc.DBDictionary", true); aliases = new String[] { "access", "org.apache.openjpa.jdbc.sql.AccessDictionary", "db2", "org.apache.openjpa.jdbc.sql.DB2Dictionary", "derby", "org.apache.openjpa.jdbc.sql.DerbyDictionary", "empress", "org.apache.openjpa.jdbc.sql.EmpressDictionary", "foxpro", "org.apache.openjpa.jdbc.sql.FoxProDictionary", "h2", "org.apache.openjpa.jdbc.sql.H2Dictionary", "hsql", "org.apache.openjpa.jdbc.sql.HSQLDictionary", "informix", "org.apache.openjpa.jdbc.sql.InformixDictionary", "ingres", "org.apache.openjpa.jdbc.sql.IngresDictionary", "jdatastore", "org.apache.openjpa.jdbc.sql.JDataStoreDictionary", "mysql", "org.apache.openjpa.jdbc.sql.MySQLDictionary", "oracle", "org.apache.openjpa.jdbc.sql.OracleDictionary", "pointbase", "org.apache.openjpa.jdbc.sql.PointbaseDictionary", "postgres", "org.apache.openjpa.jdbc.sql.PostgresDictionary", "soliddb", "org.apache.openjpa.jdbc.sql.SolidDBDictionary", "sqlserver", "org.apache.openjpa.jdbc.sql.SQLServerDictionary", "sybase", "org.apache.openjpa.jdbc.sql.SybaseDictionary", "maxdb", MaxDBDictionary.class.getCanonicalName(), }; dbdictionaryPlugin.setAliases(aliases); dbdictionaryPlugin.setInstantiatingGetter("getDBDictionaryInstance"); updateManagerPlugin = addPlugin("jdbc.UpdateManager", true); aliases = new String[] { "default", BatchingConstraintUpdateManager.class.getName(), "operation-order", "org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager", "constraint", "org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager", "batching-constraint", BatchingConstraintUpdateManager.class.getName(), "batching-operation-order", BatchingOperationOrderUpdateManager.class.getName(), }; updateManagerPlugin.setAliases(aliases); updateManagerPlugin.setDefault(aliases[0]); updateManagerPlugin.setString(aliases[0]); updateManagerPlugin.setInstantiatingGetter("getUpdateManagerInstance"); driverDataSourcePlugin = addPlugin("jdbc.DriverDataSource", false); aliases = new String[] { "auto", "org.apache.openjpa.jdbc.schema.AutoDriverDataSource", "simple", "org.apache.openjpa.jdbc.schema.SimpleDriverDataSource", "dbcp", "org.apache.openjpa.jdbc.schema.DBCPDriverDataSource", }; driverDataSourcePlugin.setAliases(aliases); driverDataSourcePlugin.setDefault(aliases[0]); driverDataSourcePlugin.setString(aliases[0]); schemaFactoryPlugin = addPlugin("jdbc.SchemaFactory", true); aliases = new String[] { "dynamic", "org.apache.openjpa.jdbc.schema.DynamicSchemaFactory", "native", "org.apache.openjpa.jdbc.schema.LazySchemaFactory", "file", "org.apache.openjpa.jdbc.schema.FileSchemaFactory", "table", "org.apache.openjpa.jdbc.schema.TableSchemaFactory", // deprecated alias "db", "org.apache.openjpa.jdbc.schema.TableSchemaFactory", }; schemaFactoryPlugin.setAliases(aliases); schemaFactoryPlugin.setDefault(aliases[0]); schemaFactoryPlugin.setString(aliases[0]); schemaFactoryPlugin.setInstantiatingGetter("getSchemaFactoryInstance"); sqlFactoryPlugin = addPlugin("jdbc.SQLFactory", true); aliases = new String[] { "default", "org.apache.openjpa.jdbc.sql.SQLFactoryImpl", }; sqlFactoryPlugin.setAliases(aliases); sqlFactoryPlugin.setDefault(aliases[0]); sqlFactoryPlugin.setString(aliases[0]); sqlFactoryPlugin.setInstantiatingGetter("getSQLFactoryInstance"); mappingFactoryPlugin = new MappingFactoryValue("jdbc.MappingFactory"); addValue(mappingFactoryPlugin); mappingDefaultsPlugin = addPlugin("jdbc.MappingDefaults", true); aliases = new String[] { "default", "org.apache.openjpa.jdbc.meta.MappingDefaultsImpl", }; mappingDefaultsPlugin.setAliases(aliases); mappingDefaultsPlugin.setDefault(aliases[0]); mappingDefaultsPlugin.setString(aliases[0]); mappingDefaultsPlugin.setInstantiatingGetter("getMappingDefaultsInstance"); // set up broker factory defaults brokerFactoryPlugin.setAlias("jdbc", JDBCBrokerFactory.class.getName()); brokerFactoryPlugin.setDefault("jdbc"); brokerFactoryPlugin.setString("jdbc"); // set new default for mapping repos metaRepositoryPlugin.setAlias("default", "org.apache.openjpa.jdbc.meta.MappingRepository"); metaRepositoryPlugin.setDefault("default"); metaRepositoryPlugin.setString("default"); // set new default for lock manager lockManagerPlugin.setAlias("pessimistic", PessimisticLockManager.class.getName()); lockManagerPlugin.setDefault("pessimistic"); lockManagerPlugin.setString("pessimistic"); // native savepoint manager options savepointManagerPlugin.setAlias("jdbc", "org.apache.openjpa.jdbc.kernel.JDBC3SavepointManager"); // set new aliases and defaults for sequence seqPlugin.setAliases(JDBCSeqValue.ALIASES); seqPlugin.setDefault(JDBCSeqValue.ALIASES[0]); seqPlugin.setString(JDBCSeqValue.ALIASES[0]); // This plug-in is declared in superclass but defined here // because PreparedQueryCache is currently available for JDBC // backend only preparedQueryCachePlugin = addPlugin("jdbc.QuerySQLCache", true); aliases = new String[] { "true", "org.apache.openjpa.jdbc.kernel.PreparedQueryCacheImpl", "false", null }; preparedQueryCachePlugin.setAliases(aliases); preparedQueryCachePlugin.setAliasListComprehensive(true); preparedQueryCachePlugin.setDefault(aliases[0]); preparedQueryCachePlugin.setClassName(aliases[1]); preparedQueryCachePlugin.setDynamic(true); preparedQueryCachePlugin.setInstantiatingGetter("getQuerySQLCacheInstance"); finderCachePlugin = addPlugin("jdbc.FinderCache", true); aliases = new String[] { "true", "org.apache.openjpa.jdbc.kernel.FinderCacheImpl", "false", null }; finderCachePlugin.setAliases(aliases); finderCachePlugin.setAliasListComprehensive(true); finderCachePlugin.setDefault(aliases[0]); finderCachePlugin.setClassName(aliases[1]); finderCachePlugin.setDynamic(true); finderCachePlugin.setInstantiatingGetter("getFinderCacheInstance"); identifierUtilPlugin = addPlugin("jdbc.IdentifierUtil", true); aliases = new String[] { "default", "org.apache.openjpa.jdbc.identifier.DBIdentifierUtilImpl" }; identifierUtilPlugin.setAliases(aliases); identifierUtilPlugin.setDefault(aliases[0]); identifierUtilPlugin.setString(aliases[0]); identifierUtilPlugin.setInstantiatingGetter("getIdentifierUtilInstance"); // this static initializer is to get past a weird // ClassCircularityError that happens only under IBM's // JDK 1.3.1 on Linux from within the JRun ClassLoader; // while exact causes are unknown, it is almost certainly // a bug in JRun, and we can get around it by forcing // Instruction.class to be loaded and initialized // before TypedInstruction.class try { serp.bytecode.lowlevel.Entry.class.getName(); } catch (Throwable t) { } try { serp.bytecode.Instruction.class.getName(); } catch (Throwable t) { } supportedOptions().add(OPTION_QUERY_SQL); supportedOptions().add(OPTION_JDBC_CONNECTION); supportedOptions().remove(OPTION_VALUE_INCREMENT); supportedOptions().remove(OPTION_NULL_CONTAINER); if (derivations) ProductDerivations.beforeConfigurationLoad(this); if (loadGlobals) loadGlobals(); }
From source file:org.apache.ambari.server.checks.CheckDatabaseHelper.java
protected void checkForConfigsSelectedMoreThanOnce() { String GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY = "select c.cluster_name, ccm.type_name from clusterconfigmapping ccm " + "join clusters c on ccm.cluster_id=c.cluster_id " + "group by c.cluster_name, ccm.type_name " + "having sum(selected) > 1"; Multimap<String, String> clusterConfigTypeMap = HashMultimap.create(); ResultSet rs = null;//from w ww . ja v a 2 s. co m try { Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); rs = statement.executeQuery(GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY); if (rs != null) { while (rs.next()) { clusterConfigTypeMap.put(rs.getString("cluster_name"), rs.getString("type_name")); } for (String clusterName : clusterConfigTypeMap.keySet()) { LOG.error( "You have config(s), in cluster {}, that is(are) selected more than once in clusterconfigmapping table: {}", clusterName, StringUtils.join(clusterConfigTypeMap.get(clusterName), ",")); errorAvailable = true; } } } catch (SQLException e) { LOG.error("Exception occurred during check for config selected more than ones procedure: ", e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { LOG.error("Exception occurred during result set closing procedure: ", e); } } } }
From source file:org.apache.tajo.jdbc.JdbcConnection.java
@Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) { throw new SQLException("TYPE_SCROLL_SENSITIVE is not supported"); }//from ww w . j a v a 2s . c o m if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) { throw new SQLException("CONCUR_READ_ONLY mode is not supported."); } return new TajoStatement(this, tajoClient); }
From source file:gov.nih.nci.migration.MigrationDriver.java
private void setAESEncryption() throws EncryptionException, SQLException { Connection connection = getConnection(); Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet resultSet = stmt.executeQuery("SELECT * FROM CSM_CONFIGURATION_PROPS"); String aesEncryptionKey = null; String md5HashKey = null;/*from w w w . j a va 2 s . c om*/ while (resultSet.next()) { String propertyKey = resultSet.getString("PROPERTY_KEY"); if ("AES_ENCRYPTION_KEY".equals(propertyKey)) aesEncryptionKey = resultSet.getString("PROPERTY_VALUE"); if ("MD5_HASH_KEY".equals(propertyKey)) md5HashKey = resultSet.getString("PROPERTY_VALUE"); if ("PASSWORD_EXPIRY_DAYS".equals(propertyKey)) expiryDays = resultSet.getString("PROPERTY_VALUE"); } setExpiryDays(expiryDays); aesEncryption = new AESEncryption(aesEncryptionKey, Boolean.parseBoolean(md5HashKey)); }
From source file:net.solarnetwork.node.dao.jdbc.JdbcSettingDao.java
private void storeSettingInternal(final String key, final String ttype, final String value, final int flags) { final String type = (ttype == null ? "" : ttype); final Timestamp now = new Timestamp(System.currentTimeMillis()); // to avoid bumping modified date column when values haven't changed, we are careful here // to compare before actually updating getJdbcTemplate().query(new PreparedStatementCreator() { @Override//from w w w . ja v a2 s. c om public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement queryStmt = con.prepareStatement(sqlGet, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT); queryStmt.setString(1, key); queryStmt.setString(2, type); return queryStmt; } }, new ResultSetExtractor<Object>() { @Override public Object extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { String oldValue = rs.getString(1); if (!value.equals(oldValue)) { rs.updateString(1, value); rs.updateTimestamp(2, now); rs.updateRow(); } } else { rs.moveToInsertRow(); rs.updateString(1, value); rs.updateTimestamp(2, now); rs.updateString(3, key); rs.updateString(4, type); rs.updateInt(5, flags); rs.insertRow(); } return null; } }); }
From source file:net.firejack.platform.core.config.upgrader.SchemaUpgrader.java
/** * This method update database package version and increase version number * * @param packageLookup - Openflame Package lookup * @param version - database version * @return version//from www .j a v a2 s .c o m */ private Version updateDatabaseVersion(String packageLookup, Version version) { try { Connection connection = dataSource.getConnection(); try { connection.setAutoCommit(true); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); statement.addBatch("UPDATE opf_registry_node SET database_version = " + version.getToVersion() + " " + "WHERE lookup = '" + packageLookup + "';"); try { statement.executeBatch(); return new Version(version.getToVersion()); } finally { JdbcUtils.closeStatement(statement); } } finally { connection.setAutoCommit(false); JdbcUtils.closeConnection(connection); } } catch (SQLException e) { throw new RuntimeException(e); } }
From source file:org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection.java
@Override protected JenaStatement createStatementInternal(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed"); if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) throw new SQLFeatureNotSupportedException( "Remote endpoint backed connection do not support scroll sensitive result sets"); if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) throw new SQLFeatureNotSupportedException( "Remote endpoint backed connections only support read-only result sets"); return new RemoteEndpointStatement(this, this.client, resultSetType, ResultSet.FETCH_FORWARD, 0, resultSetHoldability);// w w w . ja va 2s . co m }