コード例 #1
0
  public void connect(String fileName, String tableName) throws DAOException {

    try {
      c = ConnectionHelper.getConnection(fileName);
      Statement s = c.createStatement();

      s.execute(
          "CREATE TABLE IF NOT EXISTS "
              + tableName
              + " ("
              + "   id INTEGER, "
              + "   numProcessed INTEGER, "
              + "   totalToProcess INTEGER, "
              + "   startUp INTEGER, "
              + "   runTime INTEGER, "
              + "   shutDown INTEGER "
              + ")");

      s.execute("DELETE FROM " + tableName);

    } catch (SQLException e) {
      e.printStackTrace();
      throw new DAOException(e);
    }
  }
コード例 #2
0
ファイル: SchemaExport.java プロジェクト: nladd/dayTrader
  private void execute(
      boolean script, boolean export, Writer fileOutput, Statement statement, final String sql)
      throws IOException, SQLException {
    final SqlExceptionHelper sqlExceptionHelper = new SqlExceptionHelper();

    String formatted = formatter.format(sql);
    if (delimiter != null) formatted += delimiter;
    if (script) System.out.println(formatted);
    LOG.debug(formatted);
    if (outputFile != null) {
      fileOutput.write(formatted + "\n");
    }
    if (export) {

      statement.executeUpdate(sql);
      try {
        SQLWarning warnings = statement.getWarnings();
        if (warnings != null) {
          sqlExceptionHelper.logAndClearWarnings(connectionHelper.getConnection());
        }
      } catch (SQLException sqle) {
        LOG.unableToLogSqlWarnings(sqle);
      }
    }
  }
コード例 #3
0
  public DatabaseExporter(ConnectionHelper connectionHelper, SqlExceptionHelper sqlExceptionHelper)
      throws SQLException {
    this.connectionHelper = connectionHelper;
    this.sqlExceptionHelper = sqlExceptionHelper;

    connectionHelper.prepare(false); // CUSTOM: changed auto-commit flag to false
    connection = connectionHelper.getConnection();
    statement = connection.createStatement();
  }
コード例 #4
0
  /**
   * return the first connection available that refers to this table by moving up to the last
   * Package instance that hold this table and finding the connection linked to it
   *
   * @param metadataTable
   * @return
   */
  public static Connection getFirstConnection(MetadataTable metadataTable) {
    assert metadataTable != null;
    Connection connection = null;
    Namespace namespace = metadataTable.getNamespace();
    // for the file connection
    if (namespace != null && namespace instanceof RecordFile) {
      return ConnectionHelper.getConnection((RecordFile) namespace);
    }

    // for the mdm connection
    if (namespace != null && namespace instanceof TdXmlSchema) {
      return ConnectionHelper.getConnection((Package) namespace);
    }

    if (namespace != null) {
      Package thePackage = SwitchHelpers.PACKAGE_SWITCH.doSwitch(namespace);
      if (thePackage != null) {
        connection = getFirstPackageConnection(thePackage);
      }
    } // else class is not linked to any package
    return connection;
  }
コード例 #5
0
ファイル: InventoryReader.java プロジェクト: rbutti/jsr-352
  public InventoryRecord readItem() throws Exception {

    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet rs = null;

    try {
      connection = ConnectionHelper.getConnection(dataSource);

      statement = connection.prepareStatement(ConnectionHelper.SELECT_INVENTORY);
      statement.setInt(1, 1);
      rs = statement.executeQuery();

      int quantity = -1;
      while (rs.next()) {
        quantity = rs.getInt("quantity");
      }

      // If we run out of items we are done so stop processing orders
      if (quantity < 1) {
        return null;
      }

      // decrement the quantity and update the table

      InventoryRecord ir = new InventoryRecord(1, --quantity);
      decrementInventory(connection, ir);

      readerIndex++;
      this.inventoryCheckpoint.setInventoryCount(readerIndex);

      return new InventoryRecord(1, 1); // Every order only orders 1 item
    } catch (SQLException e) {
      throw e;
    } finally {
      ConnectionHelper.cleanupConnection(connection, rs, statement);
    }
  }