String transformedQuery = JDBCUtil.transformQueryForMultipleInParameters(query, ":resourceIds", resourceIdSubArray.length); ps = conn.prepareStatement(transformedQuery); JDBCUtil.bindNTimes(ps, resourceIdSubArray, 1); ps.execute(); ps.close(); log.warn("Could not insert cached current availabilities for newly imported Resources: " + e); } finally { JDBCUtil.safeClose(ps); JDBCUtil.safeClose(conn);
public ResourceAvailability getLatestAvailability(int resourceId) { Query query = entityManager.createNamedQuery(ResourceAvailability.QUERY_FIND_BY_RESOURCE_ID); query.setParameter("resourceId", resourceId); try { ResourceAvailability result = (ResourceAvailability) query.getSingleResult(); return result; } catch (NoResultException nre) { return null; } catch (RuntimeException re) { Throwable cause = re.getCause(); if (cause instanceof SQLException) { log.error("Failed to get latest avail for Resource [" + resourceId + "]: " + JDBCUtil.convertSQLExceptionToString((SQLException) cause)); } throw re; } }
st.execute("SET synchronous_commit = off"); } finally { JDBCUtil.safeClose(st); String keyNextvalSql = JDBCUtil.getNextValSql(conn, "RHQ_calltime_data_key"); insertKeySql = String.format(CALLTIME_KEY_INSERT_STATEMENT, keyNextvalSql); } else if (dbType instanceof SQLServerDatabaseType) { log.error("Failed to persist call-time data keys", t); } finally { JDBCUtil.safeClose(conn, ps, null);
String transformedQuery = JDBCUtil.transformQueryForMultipleInParameters(queryString, "@@DEFINITION_IDS@@", measurementDefinitionIds.length); defUpdateStmt = conn.prepareStatement(transformedQuery); defUpdateStmt.setLong(i++, collectionInterval); JDBCUtil.bindNTimes(defUpdateStmt, measurementDefinitionIds, i); defUpdateStmt.executeUpdate(); transformedQuery = JDBCUtil.transformQueryForMultipleInParameters(queryString, "@@DEFINITION_IDS@@", measurementDefinitionIds.length); schedUpdateStmt = conn.prepareStatement(transformedQuery); schedUpdateStmt.setLong(i++, collectionInterval); JDBCUtil.bindNTimes(schedUpdateStmt, measurementDefinitionIds, i++); schedUpdateStmt.executeUpdate(); String s = JDBCUtil.convertSQLExceptionToString((SQLException) e); errorMessage += ": " + s; throw new MeasurementException("Error updating measurement definitions: " + e); } finally { JDBCUtil.safeClose(defUpdateStmt); JDBCUtil.safeClose(schedUpdateStmt); JDBCUtil.safeClose(conn);
/** * Populate the passed query with bindCount number of placeholders '?'. The method will not put necessary parenteses * around the placeholders. * * @param query the original query including text to replace * @param replaceable the part of the original query that should be replaced by '?'s. * @param bindCount how many placeholders '?' should be generated * * @return The modified query */ public static String transformQueryForMultipleInParameters(String query, String replaceable, int bindCount) { String replacement = generateInBinds(bindCount); return query.replace(replaceable, replacement); }
st.execute("SET synchronous_commit = off"); } finally { JDBCUtil.safeClose(st); String valueNextvalSql = JDBCUtil.getNextValSql(conn, "RHQ_calltime_data_value"); insertValueSql = String.format(CALLTIME_VALUE_INSERT_STATEMENT, valueNextvalSql); } else if (dbType instanceof SQLServerDatabaseType) { log.error("Failed to persist call-time data values", t); } finally { JDBCUtil.safeClose(conn, ps, null);
.transformQueryForMultipleInParameters(ResourceGroup.QUERY_NATIVE_ADD_RESOURCES_TO_GROUP_EXPLICIT, "@@RESOURCE_IDS@@", resourceIdsToAdd.length); insertExplicitStatement = conn.prepareStatement(insertExplicitQueryString); insertExplicitStatement.setInt(1, groupId); JDBCUtil.bindNTimes(insertExplicitStatement, resourceIdsToAdd, 2); insertExplicitStatement.executeUpdate(); } catch (SQLException sqle) { + sqle.getMessage()); } finally { JDBCUtil.safeClose(insertExplicitStatement); JDBCUtil.safeClose(conn);
String nextvalSql = JDBCUtil.getNextValSql(conn, EventSource.TABLE_NAME); statementSql = String.format(EVENT_SOURCE_INSERT_STMT, nextvalSql); } else if (dbType instanceof SQLServerDatabaseType) { JDBCUtil.safeClose(ps); String nextvalSql = JDBCUtil.getNextValSql(conn, Event.TABLE_NAME); statementSql = String.format(EVENT_INSERT_STMT, nextvalSql); } else if (dbType instanceof SQLServerDatabaseType) { JDBCUtil.safeClose(ps); JDBCUtil.safeClose(conn);
/** * @param connection a connection to the DB (won't be closed by this method) * @param version the version to set for all servers * @throws SQLException */ public int setVersionForAllServers(Connection connection, String version) throws SQLException { PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement("UPDATE RHQ_SERVER SET VERSION = ?"); preparedStatement.setString(1, version); return preparedStatement.executeUpdate(); } finally { JDBCUtil.safeClose(null, preparedStatement, null); } } }
insertQueryString = JDBCUtil.transformQueryForMultipleInParameters(insertQueryString, "@@RESOURCES@@", batchIds.length); insertStatement = conn.prepareStatement(insertQueryString); JDBCUtil.bindNTimes(insertStatement, batchIds, 1); JDBCUtil.safeClose(conn, insertStatement, null);
/** * @param connection a connection to the DB (won't be closed by this method) * @param version the version to set for all nodes * @throws SQLException */ public int setVersionForAllNodes(Connection connection, String version) throws SQLException { PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement("UPDATE RHQ_STORAGE_NODE SET VERSION = ?"); preparedStatement.setString(1, version); return preparedStatement.executeUpdate(); } finally { JDBCUtil.safeClose(null, preparedStatement, null); } } }
String insertImplicitQueryString = JDBCUtil.transformQueryForMultipleInParameters( ResourceGroup.QUERY_NATIVE_ADD_RESOURCES_TO_GROUP_IMPLICIT, "@@RESOURCE_IDS@@", resourceIdsToAdd.length); insertImplicitStatement = conn.prepareStatement(insertImplicitQueryString); insertImplicitStatement.setInt(1, groupId); JDBCUtil.bindNTimes(insertImplicitStatement, resourceIdsToAdd, 2); insertImplicitStatement.executeUpdate(); + sqle.getMessage()); } finally { JDBCUtil.safeClose(insertExplicitStatement); JDBCUtil.safeClose(insertImplicitStatement); JDBCUtil.safeClose(conn);
@PostConstruct public void init() { Connection conn = null; try { conn = rhqDs.getConnection(); databaseType = DatabaseTypeFactory.getDatabaseType(conn); } catch (Exception e) { throw new RuntimeException(e); } finally { JDBCUtil.safeClose(conn); } }
String deleteImplicitQueryString = JDBCUtil.transformQueryForMultipleInParameters( ResourceGroup.QUERY_NATIVE_REMOVE_RESOURCES_FROM_GROUP_IMPLICIT, "@@RESOURCE_IDS@@", resourceIds.length); deleteImplicitStatement = conn.prepareStatement(deleteImplicitQueryString); deleteImplicitStatement.setInt(1, groupId); JDBCUtil.bindNTimes(deleteImplicitStatement, resourceIdsArray, 2); deleteImplicitStatement.executeUpdate(); .transformQueryForMultipleInParameters(ResourceGroup.QUERY_NATIVE_REMOVE_RESOURCES_FROM_GROUP_EXPLICIT, "@@RESOURCE_IDS@@", resourceIds.length); deleteExplicitStatement = conn.prepareStatement(deleteExplicitQueryString); deleteExplicitStatement.setInt(1, groupId); JDBCUtil.bindNTimes(deleteExplicitStatement, resourceIdsArray, 2); deleteExplicitStatement.executeUpdate(); } catch (SQLException sqle) { + sqle.getMessage()); } finally { JDBCUtil.safeClose(deleteExplicitStatement); JDBCUtil.safeClose(deleteImplicitStatement); JDBCUtil.safeClose(conn);
/** * @param connection a connection to the DB (won't be closed by this method) * @param version the version to set for server with the specified <code>name</code> * @param name server name * @throws java.sql.SQLException */ public int setVersionForServerWithName(Connection connection, String version, String name) throws SQLException { PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement("UPDATE RHQ_SERVER SET VERSION = ? WHERE NAME = ?"); preparedStatement.setString(1, version); preparedStatement.setString(2, name); return preparedStatement.executeUpdate(); } finally { JDBCUtil.safeClose(null, preparedStatement, null); } }
resultsQueryString = JDBCUtil.transformQueryForMultipleInParameters(resultsQueryString, "@@RESOURCES@@", batchIds.length); resultsStatement = conn.prepareStatement(resultsQueryString); JDBCUtil.bindNTimes(resultsStatement, batchIds, 1); JDBCUtil.safeClose(conn, resultsStatement, null);
/** * @param connection a connection to the DB (won't be closed by this method) * @param version the version to set for node with the specified <code>address</code> * @param address storage node address * @throws SQLException */ public int setVersionForNodeWithAddress(Connection connection, String version, String address) throws SQLException { PreparedStatement preparedStatement = null; try { preparedStatement = connection .prepareStatement("UPDATE RHQ_STORAGE_NODE SET VERSION = ? WHERE ADDRESS = ?"); preparedStatement.setString(1, version); preparedStatement.setString(2, address); return preparedStatement.executeUpdate(); } finally { JDBCUtil.safeClose(null, preparedStatement, null); } }
String insertImplicitQueryString = JDBCUtil.transformQueryForMultipleInParameters( ResourceGroup.QUERY_NATIVE_ADD_RESOURCES_TO_GROUP_IMPLICIT, "@@RESOURCE_IDS@@", resourceIdsToAdd.size()); insertImplicitStatement = conn.prepareStatement(insertImplicitQueryString); insertImplicitStatement.setInt(1, implicitRecursiveGroupId); JDBCUtil.bindNTimes(insertImplicitStatement, ArrayUtils.unwrapCollection(resourceIdsToAdd), 2); insertImplicitStatement.executeUpdate(); + "] to necessary implicit groups", e); } finally { JDBCUtil.safeClose(insertImplicitStatement); JDBCUtil.safeClose(conn);