示例#1
0
  public Collection batchSave(Connection conn, Collection coll) throws DBLevelException {
    if (coll == null) return null;

    PreparedStatement pstmt = null;
    try {
      pstmt = conn.prepareStatement(insertSql);
      Column[] columns = table.getColumns();

      CollectionPageBatch cpb = new CollectionPageBatch();
      cpb.setPageSize(DBPower.getMaxBatchSize());
      cpb.setColumns(columns);
      cpb.setPreparedStatement(pstmt);
      cpb.doBatch(coll);

      return cpb.getResult();
    } catch (SQLException e) {
      logger.error("", e);
      throw new DBLevelException(e);
    } catch (Exception e) {
      logger.error("", e);
      throw new RalasafeException(e);
    } finally {
      DBUtil.close(pstmt);
    }
  }
 public Collection getAllNonRolePrivilegesFromDb() {
   FieldWhereElement emt = new FieldWhereElement();
   emt.setColumn(table.getColumns()[8]);
   emt.setCompartor(SingleValueComparator.EQUAL);
   emt.setValue(new Integer(Privilege.NON_ROLE_PRIVILEGE));
   SelectCondition cdtn = new SelectCondition();
   cdtn.setWhereElement(emt);
   return selector.select(cdtn, null);
 }
示例#3
0
  public void save(Connection conn, Object o) throws EntityExistException, DBLevelException {
    PreparedStatement pstmt = null;
    try {
      pstmt = conn.prepareStatement(insertSql);
      Column[] columns = table.getColumns();
      for (int i = 0; i < columns.length; i++) {
        Column column = columns[i];
        ColumnAdapter columnAdapter = column.getAdapter();
        columnAdapter.setPreparedStatement(pstmt, i + 1, o);
      }

      pstmt.executeUpdate();
    } catch (SQLException e) {
      logger.error("", e);

      if (conn != null) {
        // violate pk or unique constraints?
        if (!Util.isEmpty(table.getIdColumns())) {
          boolean isExist = selector.isExistByIdColumns(conn, o);
          if (isExist) {
            throw new EntityExistException(o);
          }
        }

        if (!Util.isEmpty(table.getUniqueColumns())) {
          boolean isExist = selector.isExistByUniqueColumns(conn, o);
          if (isExist) {
            throw new EntityExistException(o);
          }
        }

        throw new DBLevelException(e);
      } else {
        throw new DBLevelException(e);
      }
    } finally {
      DBUtil.close(pstmt);
    }
  }