コード例 #1
0
  /**
   * Ok, this is cheating, but heck is easy and fast.
   *
   * @param entityId
   * @param currencyId
   * @return
   * @throws SQLException
   * @throws NamingException
   */
  private static boolean entityHasCurrency(Integer entityId, Integer currencyId)
      throws SQLException, NamingException {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet result = null;
    try {
      JNDILookup jndi = JNDILookup.getFactory();
      conn = jndi.lookUpDataSource().getConnection();
      stmt =
          conn.prepareStatement(
              "select 1 "
                  + "  from currency_entity_map "
                  + " where currency_id = ? "
                  + "   and entity_id = ?");

      stmt.setInt(1, currencyId);
      stmt.setInt(2, entityId);
      result = stmt.executeQuery();
      return result.next();
    } finally {
      Util.closeQuietly(result);
      Util.closeQuietly(stmt);
      Util.closeQuietly(conn);
    }
  }
コード例 #2
0
  /*
   * The name of the file has to start with '/'.
   * Example: "/jbilling.properties"
   * Otherwise it won't find it in the classpath
   */
  public RefreshBettyTable(String propertiesFile)
      throws FileNotFoundException, IOException, ClassNotFoundException, SQLException,
          NamingException {
    if (propertiesFile != null) {
      Properties globalProperties = new Properties();
      globalProperties.load(RefreshBettyTable.class.getResourceAsStream(propertiesFile));

      Class.forName(globalProperties.getProperty("driver_class"));
      this.conn =
          DriverManager.getConnection(
              globalProperties.getProperty("connection_url"),
              globalProperties.getProperty("connection_username"),
              globalProperties.getProperty("connection_password"));
    } else {
      JNDILookup jndi = JNDILookup.getFactory();
      // the connection will be closed by the RowSet as soon as it
      // finished executing the command
      this.conn = jndi.lookUpDataSource().getConnection();
    }

    Logger.getLogger(this.toString()).debug("Refreshing tables with " + "connection = " + conn);
  }