コード例 #1
0
ファイル: RezeptDao.java プロジェクト: BackupTheBerlios/das
  public static void saveZutaten(Rezept r, Connection con) throws SQLException {
    Set set = r.zutaten.keySet();
    Iterator iter = set.iterator();

    PreparedStatement stmt = null;

    try {
      String sql = "delete from zut2rez where rez_id = ?";
      stmt = con.prepareStatement(sql);
      stmt.setLong(1, r.getId());
      stmt.execute();
      stmt.close();

      sql = "insert into zut2rez(zut_id, rez_id, menge) values(?,?,?)";
      stmt = con.prepareStatement(sql);

      while (iter.hasNext()) {
        Long id = (Long) iter.next();
        Long wert = r.zutaten.get(id);
        stmt.setLong(1, id);
        stmt.setLong(2, r.getId());
        stmt.setLong(3, wert);
        stmt.execute();
        stmt.clearParameters();
      }
    } finally {
      DbUtil.close(stmt);
    }
  }
コード例 #2
0
 /**
  * Adds a LOINCCode to an office visit.
  *
  * @param LOINCCode A string of the code being added.
  * @param visitID The ID of the office visit the code is being added to.
  * @param pid The patient's MID associated with this transaction.
  * @return The unique ID of the code that was added.
  * @throws DBException
  */
 public long addLabProcedureToOfficeVisit(String LOINCCode, long visitID, long pid)
     throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps =
         conn.prepareStatement(
             "INSERT INTO LabProcedure (LaboratoryProcedureCode,OfficeVisitID,"
                 + "Commentary, Results, PatientMID, Status, Rights) VALUES (?,?,?,?,?,?,?)");
     ps.setString(1, LOINCCode);
     ps.setLong(2, visitID);
     ps.setString(3, "");
     ps.setString(4, "");
     ps.setLong(5, pid);
     ps.setString(6, LabProcedureBean.Not_Received);
     ps.setString(7, "ALLOWED");
     ps.executeUpdate();
     return DBUtil.getLastInsert(conn);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
コード例 #3
0
  public static void Update(Unlocked p) throws ResponseException {
    PreparedStatement statement = null;
    String query =
        "Update unlocked SET fk_profile_id=?,bonus_info=?,content_info=? where fk_profile_id=?;";
    Connection connect = null;
    IConnection c = MiscUtil.getIConnection();

    try {
      connect = c.init();
      statement = connect.prepareStatement(query);
      statement.setLong(1, p.getProfileId());
      statement.setString(2, p.getBonusInfo());
      statement.setString(3, p.getContentInfo());
      statement.setLong(4, p.getProfileId());
      statement.executeUpdate();
    } catch (SQLException e) {
      logger.error("SQL Error", e);
      throw new ResponseException("SQL Error", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (ResponseException e) {
      throw e;
    } finally {
      try {
        if (statement != null) statement.close();
        if (connect != null) connect.close();
      } catch (SQLException e) {
        logger.error("SQL Error", e);
      }
    }
  }
コード例 #4
0
ファイル: ShopConnector.java プロジェクト: TryFailRepeat/ds
  /**
   * Cancels an order. Note that cancel requests for orders will be rejected if they are older than
   * one hour, or don't target the given customer.
   *
   * @param alias the customer alias
   * @param passwordHash the customer password-hash
   * @param orderIdentity the order identity
   * @throws IllegalStateException if the login data is invalid, if the order is too old, or if it
   *     is not targeting the given customer
   * @throws SQLException if there is a problem with the underlying JDBC connection
   */
  public void deleteOrder(final String alias, final byte[] passwordHash, final long orderIdentity)
      throws SQLException {
    final Customer customer = this.queryCustomer(alias, passwordHash);
    final Order order = this.queryOrder(alias, passwordHash, orderIdentity);
    if (order.getCustomerIdentity() != customer.getIdentity())
      throw new IllegalStateException("purchase not created by given customer.");
    if (System.currentTimeMillis() > order.getCreationTimestamp() + TimeUnit.HOURS.toMillis(1))
      throw new IllegalStateException("purchase too old.");

    synchronized (this.connection) {
      try (PreparedStatement statement = this.connection.prepareStatement(SQL_DELETE_PURCHASE)) {
        statement.setLong(1, orderIdentity);
        statement.executeUpdate();
      }
    }

    for (final OrderItem item : order.getItems()) {
      synchronized (this.connection) {
        try (PreparedStatement statement =
            this.connection.prepareStatement(SQL_RELEASE_ARTICLE_UNITS)) {
          statement.setLong(1, item.getCount());
          statement.setLong(2, item.getArticleIdentity());
          statement.executeUpdate();
        }
      }
    }
  }
コード例 #5
0
ファイル: TaskDAO.java プロジェクト: wangdabin/BDP-agent
 /**
  * 更新任务
  *
  * @param task
  * @throws SQLException
  */
 public long update(Task task) throws SQLException {
   // ID,NAME,STATUS,CTIME,FTIME,MESSAGE
   String upSql =
       "update " + TABLE_NAME + " set NAME=?,STATUS=?,CTIME=?,FTIME=?,MESSAGE=? where ID=?";
   Connection conn = null;
   PreparedStatement upStmt = null;
   try {
     conn = DBUtil.getConnection();
     conn.setAutoCommit(false);
     upStmt = conn.prepareStatement(upSql);
     upStmt.setString(1, task.getName());
     upStmt.setInt(2, task.getStatus());
     upStmt.setLong(3, task.getcTime());
     upStmt.setLong(4, task.getfTime());
     upStmt.setString(5, task.getMessage());
     upStmt.setLong(6, task.getId());
     upStmt.execute();
     this.orderDAO.update(conn, task.getOrders());
     conn.commit();
     return task.getId();
   } catch (Exception e) {
     LOG.error("Will rollback");
     conn.rollback();
     LOG.error(e.getMessage(), e);
     throw new RuntimeException(e);
   } finally {
     if (upStmt != null) {
       upStmt.close();
     }
     if (conn != null) {
       conn.close();
     }
   }
 }
  public void deleteISOTimezone(
      CFSecurityAuthorization Authorization, CFSecurityISOTimezoneBuff Buff) {
    final String S_ProcName = "deleteISOTimezone";
    ResultSet resultSet = null;
    try {
      Connection cnx = schema.getCnx();
      short ISOTimezoneId = Buff.getRequiredISOTimezoneId();

      String sql =
          "SELECT "
              + schema.getLowerDbSchemaName()
              + ".sp_delete_isotz( ?, ?, ?, ?, ?"
              + ", "
              + "?"
              + ", "
              + "?"
              + " ) as DeletedFlag";
      if (stmtDeleteByPKey == null) {
        stmtDeleteByPKey = cnx.prepareStatement(sql);
      }
      int argIdx = 1;
      stmtDeleteByPKey.setLong(
          argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
      stmtDeleteByPKey.setString(
          argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
      stmtDeleteByPKey.setString(
          argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
      stmtDeleteByPKey.setLong(
          argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
      stmtDeleteByPKey.setLong(
          argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
      stmtDeleteByPKey.setShort(argIdx++, ISOTimezoneId);
      stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision());
      ;
      resultSet = stmtDeleteByPKey.executeQuery();
      if (resultSet.next()) {
        boolean deleteFlag = resultSet.getBoolean(1);
        if (resultSet.next()) {
          throw CFLib.getDefaultExceptionFactory()
              .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
        }
      } else {
        throw CFLib.getDefaultExceptionFactory()
            .newRuntimeException(
                getClass(),
                S_ProcName,
                "Expected 1 record result set to be returned by delete, not 0 rows");
      }
    } catch (SQLException e) {
      throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
      if (resultSet != null) {
        try {
          resultSet.close();
        } catch (SQLException e) {
        }
        resultSet = null;
      }
    }
  }
コード例 #7
0
 private void writeRouteStops(TransportRoute r, List<TransportStop> stops, boolean direction)
     throws SQLException {
   int i = 0;
   for (TransportStop s : stops) {
     if (!visitedStops.contains(s.getId())) {
       transStopsStat.setLong(1, s.getId());
       transStopsStat.setDouble(2, s.getLocation().getLatitude());
       transStopsStat.setDouble(3, s.getLocation().getLongitude());
       transStopsStat.setString(4, s.getName());
       transStopsStat.setString(5, s.getEnName());
       int x = (int) MapUtils.getTileNumberX(24, s.getLocation().getLongitude());
       int y = (int) MapUtils.getTileNumberY(24, s.getLocation().getLatitude());
       addBatch(transStopsStat);
       try {
         transportStopsTree.insert(new LeafElement(new Rect(x, y, x, y), s.getId()));
       } catch (RTreeInsertException e) {
         throw new IllegalArgumentException(e);
       } catch (IllegalValueException e) {
         throw new IllegalArgumentException(e);
       }
       visitedStops.add(s.getId());
     }
     transRouteStopsStat.setLong(1, r.getId());
     transRouteStopsStat.setLong(2, s.getId());
     transRouteStopsStat.setInt(3, direction ? 1 : 0);
     transRouteStopsStat.setInt(4, i++);
     addBatch(transRouteStopsStat);
   }
 }
コード例 #8
0
ファイル: H2LogStore.java プロジェクト: tonyw/jraft
  @Override
  public byte[] packLog(long index, int itemsToPack) {
    if (index < this.startIndex.get() || index >= this.nextIndex.get()) {
      throw new IllegalArgumentException("index out of range");
    }

    try {
      ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
      GZIPOutputStream gzipStream = new GZIPOutputStream(memoryStream);
      PreparedStatement ps = this.connection.prepareStatement(SELECT_RANGE_SQL);
      ps.setLong(1, index);
      ps.setLong(2, index + itemsToPack);
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        byte[] value = rs.getBytes(4);
        int size = value.length + Long.BYTES + 1 + Integer.BYTES;
        ByteBuffer buffer = ByteBuffer.allocate(size);
        buffer.putInt(size);
        buffer.putLong(rs.getLong(2));
        buffer.put(rs.getByte(3));
        buffer.put(value);
        gzipStream.write(buffer.array());
      }

      rs.close();
      gzipStream.flush();
      memoryStream.flush();
      gzipStream.close();
      return memoryStream.toByteArray();
    } catch (Throwable error) {
      this.logger.error("failed to pack log entries", error);
      throw new RuntimeException("log store error", error);
    }
  }
コード例 #9
0
  protected void updateFileEntryTitle(long fileEntryId, String title, String version)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps = con.prepareStatement("update DLFileEntry set title = ? where fileEntryId = ?");

      ps.setString(1, title);
      ps.setLong(2, fileEntryId);

      ps.executeUpdate();

      ps =
          con.prepareStatement(
              "update DLFileVersion set title = ? where fileEntryId = " + "? and version = ?");

      ps.setString(1, title);
      ps.setLong(2, fileEntryId);
      ps.setString(3, version);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }
コード例 #10
0
  /**
   * Marks as deleted the entry with the given id
   *
   * @param id the entry id
   * @throws DataAccessException if an error occurs
   * @return the number of updated entries
   */
  public int markAsDeleted(long id) throws DataAccessException {

    Connection con = null;
    PreparedStatement ps = null;
    int rowsUpdated = 0;

    try {

      con = getConnection();

      ps = con.prepareStatement(queryDesc.getUpdateStatusQuery());

      ps.setLong(1, System.currentTimeMillis());
      ps.setString(2, RegistryEntryStatus.DELETED);
      ps.setLong(3, id);

      rowsUpdated = ps.executeUpdate();

    } catch (Exception ex) {

      throw new DataAccessException("Error marking entry with id '" + id + "' as deleted", ex);

    } finally {
      DBTools.close(con, ps, null);
    }
    return rowsUpdated;
  }
コード例 #11
0
ファイル: H2LogStore.java プロジェクト: tonyw/jraft
  @Override
  public void writeAt(long index, LogEntry logEntry) {
    if (index >= this.nextIndex.get() || index < this.startIndex.get()) {
      throw new IllegalArgumentException("index out of range");
    }

    try {
      PreparedStatement ps = this.connection.prepareStatement(UPDATE_ENTRY_SQL);
      ps.setLong(1, logEntry.getTerm());
      ps.setByte(2, logEntry.getValueType().toByte());
      ps.setBytes(3, logEntry.getValue());
      ps.setLong(4, index);
      ps.execute();
      ps = this.connection.prepareStatement(TRIM_TABLE_SQL);
      ps.setLong(1, index);
      ps.execute();
      ps = this.connection.prepareStatement(UPDATE_SEQUENCE_SQL);
      ps.setLong(1, index + 1);
      ps.execute();
      this.connection.commit();
      this.nextIndex.set(index + 1);
      this.lastEntry = logEntry;
    } catch (Throwable error) {
      this.logger.error("failed to write an entry at a specific index", error);
      throw new RuntimeException("log store error", error);
    }
  }
コード例 #12
0
  protected void addResourcePermission(
      long resourcePermissionId,
      long companyId,
      String name,
      int scope,
      String primKey,
      long roleId,
      long actionIds)
      throws Exception {

    PreparedStatement ps = null;

    try {
      ps =
          connection.prepareStatement(
              "insert into ResourcePermission (resourcePermissionId, "
                  + "companyId, name, scope, primKey, roleId, actionIds) "
                  + "values (?, ?, ?, ?, ?, ?, ?)");

      ps.setLong(1, resourcePermissionId);
      ps.setLong(2, companyId);
      ps.setString(3, name);
      ps.setInt(4, scope);
      ps.setString(5, primKey);
      ps.setLong(6, roleId);
      ps.setLong(7, actionIds);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(ps);
    }
  }
コード例 #13
0
  private void saveCategoryEmployee(long masterId, PayrollCategory[] categories) throws Exception {

    String sql =
        "INSERT INTO "
            + IDBConstants.TABLE_PAYROLL_CATEGORY_EMPLOYEE_HISTORY
            + "("
            + IDBConstants.ATTR_HISTORY_MASTER
            + ","
            + IDBConstants.ATTR_CATEGORY
            + ","
            + IDBConstants.ATTR_EMPLOYEE
            + ")"
            + " values (?, ?, ?)";

    for (int i = 0; i < categories.length; i++) {
      PayrollCategory payrollCategory = categories[i];

      IHRMSQL iSql = new HRMSQLSAP();
      Employee[] employees =
          iSql.getPayrollCategoryEmployee(payrollCategory.getIndex(), connection);

      for (int j = 0; j < employees.length; j++) {
        Employee emp = employees[j];

        PreparedStatement stm = connection.prepareStatement(sql);

        stm.setLong(1, masterId);
        stm.setLong(2, payrollCategory.getNewIndex());
        stm.setLong(3, emp.getIndex());

        stm.executeUpdate();
      }
    }
  }
コード例 #14
0
  protected long getCompanyGroupId(long companyId) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps =
          con.prepareStatement(
              "select groupId from Group_ where classNameId = ? and " + "classPK = ?");

      ps.setLong(1, PortalUtil.getClassNameId(Company.class.getName()));
      ps.setLong(2, companyId);

      rs = ps.executeQuery();

      if (rs.next()) {
        return rs.getLong("groupId");
      }

      return 0;
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
コード例 #15
0
  protected void addPortletPreferences(
      long ownerId, int ownerType, long plid, String portletId, String preferences)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "insert into PortletPreferences (portletPreferencesId, "
                  + "ownerId, ownerType, plid, portletId, preferences) "
                  + "values (?, ?, ?, ?, ?, ?)");

      ps.setLong(1, increment());
      ps.setLong(2, ownerId);
      ps.setInt(3, ownerType);
      ps.setLong(4, plid);
      ps.setString(5, portletId);
      ps.setString(6, preferences);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }
コード例 #16
0
  protected boolean hasFileEntry(long groupId, long folderId, String fileName) throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps =
          con.prepareStatement(
              "select count(*) from DLFileEntry where groupId = ? and "
                  + "folderId = ? and fileName = ?");

      ps.setLong(1, groupId);
      ps.setLong(2, folderId);
      ps.setString(3, fileName);

      rs = ps.executeQuery();

      while (rs.next()) {
        int count = rs.getInt(1);

        if (count > 0) {
          return true;
        }
      }

      return false;
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
コード例 #17
0
  protected long getPortletPreferencesId(long ownerId, int ownerType, long plid, String portletId)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "select portletPreferencesId from PortletPreferences where "
                  + "ownerId = ? and ownerType = ? and plid = ? and "
                  + "portletId = ?");

      ps.setLong(1, ownerId);
      ps.setInt(2, ownerType);
      ps.setLong(3, plid);
      ps.setString(4, portletId);

      rs = ps.executeQuery();

      if (rs.next()) {
        return rs.getLong("portletPreferencesId");
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    return 0;
  }
コード例 #18
0
  public void updateOrderTable(InventoryModel invProd, String PaymentType, long SmartCalCardNo)
      throws SQLException {
    PreparedStatement statement = null;
    String query;
    Connection connection = databaseFactory.getConnection();
    try {

      query =
          "insert into orderdetails(SmartCalCardNumber,PaymentType,SKU,LineItemPrice,LineItemQuantity,TotalAmount,OrderStatus,ProductId,VendingMachineId) values(?,?,?,?,?,?,?,?,?)";
      statement = connection.prepareStatement(query);
      statement.setLong(1, SmartCalCardNo);
      statement.setString(2, PaymentType);
      statement.setLong(3, invProd.getskuId());
      statement.setDouble(4, invProd.getProductPrice());
      statement.setInt(5, 1);
      statement.setDouble(6, invProd.getProductPrice());
      statement.setString(7, "Paid");
      statement.setLong(8, invProd.getProductId());
      statement.setLong(9, invProd.getVendingMachineId());
      statement.executeUpdate();
    } catch (SQLException e) {
      e.printStackTrace();
      throw e;
    } finally {
      DBUtils.closeStatement(statement);
      databaseFactory.closeConnection();
    }
  }
コード例 #19
0
ファイル: DBAccess.java プロジェクト: utoxin/TimTheWordWarBot
  void update_war(int db_id, long duration, long remaining, long time_to_start, int current_chain) {
    Connection con = null;
    try {
      con = pool.getConnection(timeout);

      PreparedStatement s =
          con.prepareStatement(
              "UPDATE `wars` SET `duration` = ? ,`remaining` = ?, `time_to_start` = ?, `current_chain` = ? WHERE id = ?");
      s.setLong(1, duration);
      s.setLong(2, remaining);
      s.setLong(3, time_to_start);
      s.setInt(4, current_chain);
      s.setInt(5, db_id);
      s.executeUpdate();
      s.close();
    } catch (SQLException ex) {
      Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      try {
        if (con != null) {
          con.close();
        }
      } catch (SQLException ex) {
        Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
コード例 #20
0
ファイル: SqliteDirTreeDb.java プロジェクト: n-i-e/dirtreedb
  @Override
  public void update(DbPathEntry oldentry, PathEntry newentry)
      throws SQLException, InterruptedException {
    assert (oldentry.getPath().equals(newentry.getPath()));

    PreparedStatement ps;
    if (newentry.isCsumNull()) {
      ps =
          conn.prepareStatement(
              "UPDATE directory SET datelastmodified=?, size=?, compressedsize=?, status=?, csum=NULL WHERE pathid=?");
      ps.setLong(5, oldentry.getPathId());
    } else {
      ps =
          conn.prepareStatement(
              "UPDATE directory SET datelastmodified=?, size=?, compressedsize=?, status=?, csum=? WHERE pathid=?");
      ps.setLong(5, newentry.getCsum());
      ps.setLong(6, oldentry.getPathId());
    }
    Date d = new Date(newentry.getDateLastModified());
    ps.setString(1, sdf.format(d));
    ps.setLong(2, newentry.getSize());
    ps.setLong(3, newentry.getCompressedSize());
    ps.setInt(4, newentry.getStatus());
    ps.executeUpdate();
    ps.close();
  }
コード例 #21
0
  @Override
  @SuppressWarnings("ValueOfIncrementOrDecrementUsed")
  protected void fill(final PreparedStatement pstm, final Pou item, final boolean update)
      throws SQLException {
    final PreparedStatementEx pstmEx = new PreparedStatementEx(pstm);
    int index = 1;
    pstm.setString(index++, item.getNazev());
    pstmEx.setBoolean(index++, item.getNespravny());
    pstm.setInt(index++, item.getOrpKod());
    pstm.setInt(index++, item.getSpravniObecKod());
    pstm.setLong(index++, item.getIdTransRuian());
    pstmEx.setDate(index++, item.getPlatiOd());
    pstm.setLong(index++, item.getNzIdGlobalni());
    pstmEx.setBoolean(index++, item.getZmenaGrafiky());

    if (!Config.isNoGis()) {
      pstm.setString(index++, item.getDefinicniBod());
      pstm.setString(index++, item.getHranice());
    }

    pstm.setInt(index++, item.getKod());

    if (update) {
      pstmEx.setLong(index++, item.getIdTransRuian());
    }
  }
コード例 #22
0
ファイル: SqliteDirTreeDb.java プロジェクト: n-i-e/dirtreedb
 @Override
 public void insertEquality(long pathid1, long pathid2, long size, int csum)
     throws SQLException, InterruptedException {
   PreparedStatement ps =
       prepareStatement(
           "INSERT INTO equality (pathid1, pathid2, size, csum, datelasttested) VALUES (?, ?, ?, ?, ?)");
   try {
     if (pathid1 > pathid2) {
       ps.setLong(1, pathid1);
       ps.setLong(2, pathid2);
     } else {
       ps.setLong(1, pathid2);
       ps.setLong(2, pathid1);
     }
     ps.setLong(3, size);
     ps.setInt(4, csum);
     Date d = new Date();
     ps.setString(5, sdf.format(d));
     ps.executeUpdate();
   } catch (SQLException e) {
     Debug.writelog("SQLException at addEquality: pathid1=" + pathid1 + ", pathid2=" + pathid2);
     throw e;
   } finally {
     ps.close();
   }
 }
コード例 #23
0
 @Override
 protected void map(Project project, PreparedStatement stmt) throws SQLException {
   // id
   stmt.setInt(1, seq.get(Sequence.PROJECT, project.id));
   // ref_id
   stmt.setString(2, project.id);
   // name
   stmt.setString(3, project.name);
   // description
   stmt.setString(4, project.description);
   // f_category
   if (Category.isNull(project.categoryid)) stmt.setNull(5, java.sql.Types.INTEGER);
   else stmt.setInt(5, seq.get(Sequence.CATEGORY, project.categoryid));
   // creation_date
   stmt.setDate(6, project.creationdate);
   // functional_unit
   stmt.setString(7, project.functionalunit);
   // last_modification_date
   stmt.setDate(8, project.lastmodificationdate);
   // goal
   stmt.setString(9, project.goal);
   // f_author
   if (project.f_author == null) stmt.setNull(10, java.sql.Types.INTEGER);
   else stmt.setInt(10, seq.get(Sequence.ACTOR, project.f_author));
   // f_impact_method
   stmt.setNull(11, java.sql.Types.INTEGER);
   // f_nwset
   stmt.setNull(12, java.sql.Types.INTEGER);
   stmt.setLong(13, System.currentTimeMillis());
   stmt.setLong(14, 4294967296L);
 }
コード例 #24
0
ファイル: Product.java プロジェクト: impos89/trunk
 private void save() {
   try (Connection con = DatabaseFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement(
               "INSERT INTO `buylists`(`buylist_id`, `item_id`, `count`, `next_restock_time`) VALUES(?, ?, ?, ?) ON DUPLICATE KEY UPDATE `count` = ?, `next_restock_time` = ?")) {
     ps.setInt(1, getBuyListId());
     ps.setInt(2, getItemId());
     ps.setLong(3, getCount());
     ps.setLong(5, getCount());
     if ((_restockTask != null) && (_restockTask.getDelay(TimeUnit.MILLISECONDS) > 0)) {
       final long nextRestockTime =
           System.currentTimeMillis() + _restockTask.getDelay(TimeUnit.MILLISECONDS);
       ps.setLong(4, nextRestockTime);
       ps.setLong(6, nextRestockTime);
     } else {
       ps.setLong(4, 0);
       ps.setLong(6, 0);
     }
     ps.executeUpdate();
   } catch (Exception e) {
     _log.log(
         Level.WARNING,
         "Failed to save Product buylist_id:" + getBuyListId() + " item_id:" + getItemId(),
         e);
   }
 }
 public CFSecurityTSecGroupBuff lockBuff(
     CFSecurityAuthorization Authorization, CFSecurityTSecGroupPKey PKey) {
   final String S_ProcName = "lockBuff";
   if (!schema.isTransactionOpen()) {
     throw CFLib.getDefaultExceptionFactory()
         .newUsageException(getClass(), S_ProcName, "Transaction not open");
   }
   ResultSet resultSet = null;
   try {
     Connection cnx = schema.getCnx();
     long TenantId = PKey.getRequiredTenantId();
     int TSecGroupId = PKey.getRequiredTSecGroupId();
     String sql =
         "SELECT * FROM "
             + schema.getLowerDbSchemaName()
             + ".sp_lock_tsecgrp( ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + ", "
             + "?"
             + " )";
     if (stmtLockBuffByPKey == null) {
       stmtLockBuffByPKey = cnx.prepareStatement(sql);
     }
     int argIdx = 1;
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtLockBuffByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
     stmtLockBuffByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
     stmtLockBuffByPKey.setLong(argIdx++, TenantId);
     stmtLockBuffByPKey.setInt(argIdx++, TSecGroupId);
     resultSet = stmtLockBuffByPKey.executeQuery();
     if (resultSet.next()) {
       CFSecurityTSecGroupBuff buff = unpackTSecGroupResultSetToBuff(resultSet);
       if (resultSet.next()) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
       }
       return (buff);
     } else {
       return (null);
     }
   } catch (SQLException e) {
     throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
   } finally {
     if (resultSet != null) {
       try {
         resultSet.close();
       } catch (SQLException e) {
       }
       resultSet = null;
     }
   }
 }
コード例 #26
0
ファイル: IndexWriter.java プロジェクト: rytina/cdo-light
  public void addCommitInfo(CDOBranchPoint branchPoint, long pointer) {
    if (TRACER.isEnabled()) {
      TRACER.format("addCommitInfo: {0}, {1}", branchPoint, pointer); // $NON-NLS-1$
    }

    try {
      if (addCommitInfoStatement == null) {
        String sql = index.commitInfos.sqlAddCommitInfo();
        addCommitInfoStatement = connection.prepareStatement(sql);
      }

      int column = 0;

      long timeStamp = branchPoint.getTimeStamp();
      addCommitInfoStatement.setLong(++column, timeStamp);

      if (supportingBranches) {
        CDOBranch branch = branchPoint.getBranch();
        int branchID = branch.getID();
        addCommitInfoStatement.setInt(++column, branchID);
      }

      addCommitInfoStatement.setLong(++column, pointer);
      execute(addCommitInfoStatement);
    } catch (SQLException ex) {
      throw new DBException(ex);
    }
  }
コード例 #27
0
 private void setValues(PreparedStatement ps, OfficeVisitBean ov) throws SQLException {
   ps.setDate(1, new java.sql.Date(ov.getVisitDate().getTime()));
   ps.setString(2, ov.getNotes());
   ps.setLong(3, ov.getHcpID());
   ps.setLong(4, ov.getPatientID());
   ps.setString(5, ov.getHospitalID());
 }
コード例 #28
0
 /* (non-Javadoc)
  * @see model.dao.IDataModel#insert()
  */
 @Override
 public Long insert() throws SQLException {
   try {
     Class.forName(Settings.DATABASE_JDBC_CLASSNAME);
   } catch (ClassNotFoundException e) {
     System.err.println("ClassNotFoundException: " + e.getMessage());
     e.printStackTrace();
   }
   Connection conn;
   PreparedStatement statement;
   try {
     conn = SQLiteManager.getInstance().getConnection();
     String sql =
         "INSERT INTO account_entries (account_id, booked_document_id, text, amount, created_time)"
             + " VALUES (?,          ?,                  ?,    ?,      ?)";
     statement = conn.prepareStatement(sql);
     statement.setLong(1, getAccount().getId());
     statement.setLong(2, bookedDocument.getId());
     statement.setString(3, text);
     statement.setDouble(4, amount);
     statement.setString(5, util.Date.toSqlTimeString(Calendar.getInstance().getTime()));
     statement.execute();
     sql = "SELECT last_insert_rowid()";
     ResultSet resultSet = conn.createStatement().executeQuery(sql);
     if (resultSet.next()) id = resultSet.getLong(1);
     else throw new SQLException("unable to fetch insert-id");
     resultSet.close();
   } catch (SQLException e) {
     System.err.println("SQLException: " + e.getMessage());
     e.printStackTrace();
   }
   return id;
 }
コード例 #29
0
 public void ejbStore() {
   if (!isModified()) {
     return;
   }
   BMPConnection bmp = getConnection();
   try {
     PreparedStatement ps =
         bmp.prepareStatement(
             "UPDATE "
                 + "ANA_RUO_SIC_TAB "
                 + "SET "
                 + "COD_RUO_SIC=?, "
                 + "NOM_RUO_SIC=?, "
                 + "DES_RUO_SIC=? "
                 + "WHERE "
                 + "COD_RUO_SIC=?");
     ps.setLong(1, COD_RUO_SIC);
     ps.setString(2, NOM_RUO_SIC);
     ps.setString(3, DES_RUO_SIC);
     ps.setLong(4, COD_RUO_SIC);
     if (ps.executeUpdate() == 0) {
       throw new NoSuchEntityException("Ruolo per la sicurezza con ID= non trovato");
     }
   } catch (Exception ex) {
     throw new EJBException(ex);
   } finally {
     bmp.close();
   }
 }
コード例 #30
0
  private long insertRegion(Region region) {

    final String INSERT_SQL =
        "insert into cd_region (record_key, region_type_rid, name, name_common, code_alpha, parent_region_rid, active_flag) values (?, ?, ?, ?, ?, ?, ?)";

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(
        connection -> {
          PreparedStatement ps =
              connection.prepareStatement(INSERT_SQL, new String[] {"record_id"});
          ps.setString(1, UUID.randomUUID().toString());
          ps.setLong(2, typeHashMap.get(region.categoryName).identity);
          ps.setString(3, region.name);
          ps.setString(4, getCommonName(region.code, region.getShortName()));
          ps.setString(5, region.code);
          if (region.parentCode == null || region.parentCode.isEmpty()) {
            // No parent == region directly under country.
            try {
              ps.setLong(6, countryHashMap.get(region.countryCode).identity);
            } catch (Exception e) {
              e.printStackTrace();
            }
          } else {
            // Subregion
            ps.setLong(6, regionHashMap.get(region.parentCode).identity);
          }
          ps.setBoolean(7, getActiveFlag(region.code));
          return ps;
        },
        keyHolder);

    return keyHolder.getKey().longValue();
  }