Beispiel #1
0
  public void setTable(Table table) {
    this.table = table;
    insertSql = DBUtil.insertSql(table.getName(), table.getColumnNames());

    selector = new TableSelectorImpl();
    selector.setTable(table);
  }
  public void setTable(Table table) {
    this.table = table;

    if (!Util.isEmpty(table.getIdColumns())) {
      deleteSql = DBUtil.deleteSql(table.getName(), table.getIdColumnNames());
    }
  }
Beispiel #3
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 void delete(Connection conn, WhereElement emt, Object o) {
    String sql = WhereElementUtil.toSql(emt);
    List byColumns = new LinkedList();
    List hints = new LinkedList();
    WhereElementUtil.extractColumns(emt, byColumns, o, hints);

    PreparedStatement pstmt = null;
    try {
      pstmt = conn.prepareStatement("DELETE FROM " + table.getName() + " " + sql);

      if (byColumns.size() > 0) {
        int i = 1;
        Iterator hintIter = hints.iterator();
        for (Iterator columnIter = byColumns.iterator(); columnIter.hasNext(); ) {
          Column column = (Column) columnIter.next();
          ColumnAdapter adapter = column.getAdapter();
          adapter.setPreparedStatement(pstmt, i, hintIter.next());
          i++;
        }
      }

      pstmt.executeUpdate();
    } catch (SQLException e) {
      logger.error("", e);
      throw new DBLevelException(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);
 }
Beispiel #6
0
 public Collection batchSave(Collection coll) throws DBLevelException {
   Connection conn = null;
   try {
     conn = DBPower.getConnection(table.getId());
     return batchSave(conn, coll);
   } finally {
     DBUtil.close(conn);
   }
 }
Beispiel #7
0
 public int[] batchSave(Object[] os) throws DBLevelException {
   Connection conn = null;
   try {
     conn = DBPower.getConnection(table.getId());
     return batchSave(conn, os);
   } finally {
     DBUtil.close(conn);
   }
 }
Beispiel #8
0
 public void save(Object o) throws EntityExistException, DBLevelException {
   Connection conn = null;
   try {
     conn = DBPower.getConnection(table.getId());
     save(conn, o);
   } finally {
     DBUtil.close(conn);
   }
 }
 public void delete(WhereElement emt, Object o) {
   Connection conn = null;
   try {
     conn = DBPower.getConnection(table.getId());
     delete(conn, emt, o);
   } finally {
     DBUtil.close(conn);
   }
 }
 public void deleteByIdColumns(Object o) {
   Connection conn = null;
   try {
     conn = DBPower.getConnection(table.getId());
     deleteByIdColumns(conn, o);
   } finally {
     DBUtil.close(conn);
   }
 }
Beispiel #11
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);
    }
  }
  /**
   * @param idColumns
   * @param multiValueTables
   * @return
   */
  private TableDeletorImpl[] getMultiValueTableDeletors(Table[] tables, ComplexTable complexTable) {
    TableDeletorImpl[] impls = null;
    if (tables != null) {
      impls = new TableDeletorImpl[tables.length];
      for (int i = 0; i < tables.length; i++) {
        TableDeletorImpl impl = new TableDeletorImpl();
        Table multiValueTable = tables[i];
        Table newTable = new Table();
        newTable.setId(multiValueTable.getId());
        newTable.setName(multiValueTable.getName());
        newTable.setIdColumnNames(complexTable.getMainTable().getIdColumnNames());
        newTable.setIdColumns(complexTable.getMainTable().getIdColumns());

        impl.setTable(newTable);
        impls[i] = impl;
      }
    }

    return impls;
  }
  public void deleteByIdColumns(Connection conn, Object o) {
    PreparedStatement pstmt = null;
    try {
      pstmt = conn.prepareStatement(deleteSql);
      // set DELETE WHERE PART VALUES
      Column[] idColumns = table.getIdColumns();
      for (int i = 0; i < idColumns.length; i++) {
        Column column = idColumns[i];
        ColumnAdapter columnAdapter = column.getAdapter();
        columnAdapter.setPreparedStatement(pstmt, i + 1, o);
      }

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

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