congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
JDBCUtil
Code IndexAdd Tabnine to your IDE (free)

How to use
JDBCUtil
in
org.rhq.core.util.jdbc

Best Java code snippets using org.rhq.core.util.jdbc.JDBCUtil (Showing top 20 results out of 315)

origin: rhq-project/rhq

public static void safeClose(Connection conn, Statement stm, ResultSet rs) {
  safeClose(rs);
  safeClose(stm);
  safeClose(conn);
}
origin: org.rhq/rhq-enterprise-server

    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);
origin: org.rhq/rhq-enterprise-server

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;
  }
}
origin: org.rhq/rhq-enterprise-server

      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);
origin: org.rhq/rhq-enterprise-server

  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);
origin: rhq-project/rhq

/**
 * 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);
}
origin: org.rhq/rhq-enterprise-server

      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);
origin: rhq-project/rhq

public static void safeClose(Statement stm, ResultSet rs) {
  safeClose(rs);
  safeClose(stm);
}
origin: org.rhq/rhq-enterprise-server

    .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);
origin: org.rhq/rhq-enterprise-server

  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);
origin: org.rhq/rhq-core-dbutils

  /**
   * @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);
    }
  }
}
origin: org.rhq/rhq-enterprise-server

insertQueryString = JDBCUtil.transformQueryForMultipleInParameters(insertQueryString, "@@RESOURCES@@",
  batchIds.length);
insertStatement = conn.prepareStatement(insertQueryString);
JDBCUtil.bindNTimes(insertStatement, batchIds, 1);
JDBCUtil.safeClose(conn, insertStatement, null);
origin: org.rhq/rhq-core-dbutils

  /**
   * @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);
    }
  }
}
origin: org.rhq/rhq-enterprise-server

    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);
origin: org.rhq/rhq-enterprise-server

@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);
  }
}
origin: org.rhq/rhq-enterprise-server

    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);
origin: org.rhq/rhq-core-dbutils

/**
 * @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);
  }
}
origin: org.rhq/rhq-enterprise-server

resultsQueryString = JDBCUtil.transformQueryForMultipleInParameters(resultsQueryString, "@@RESOURCES@@",
  batchIds.length);
resultsStatement = conn.prepareStatement(resultsQueryString);
JDBCUtil.bindNTimes(resultsStatement, batchIds, 1);
JDBCUtil.safeClose(conn, resultsStatement, null);
origin: org.rhq/rhq-core-dbutils

/**
 * @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);
  }
}
origin: org.rhq/rhq-enterprise-server

    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);
org.rhq.core.util.jdbcJDBCUtil

Javadoc

Take care of some JDBC related stuff. Mostly closing resources

Most used methods

  • safeClose
  • bindNTimes
  • convertSQLExceptionToString
  • generateInBinds
    Generate count '? separated by comma
  • getNextValSql
  • transformQueryForMultipleInParameters

Popular in Java

  • Reading from database using SQL prepared statement
  • runOnUiThread (Activity)
  • getApplicationContext (Context)
  • setContentView (Activity)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Top 12 Jupyter Notebook Extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now