Пример #1
0
  @Override
  public long getRowCount(Session session) {
    StatementBuilder sql = new StatementBuilder("select count(*) from ");
    sql.append(getName());

    if (session == null) session = getDatabase().getSystemSession();
    Prepared prepared = session.prepare(sql.toString(), true);
    prepared.setLocal(false);
    ResultInterface result = prepared.query(0);
    return result.getRowCount();
  }
Пример #2
0
 public int update() {
   int count;
   session.getUser().checkRight(table, Right.INSERT);
   session.getUser().checkRight(table, Right.UPDATE);
   setCurrentRowNumber(0);
   if (list.size() > 0) {
     count = 0;
     for (int x = 0, size = list.size(); x < size; x++) {
       Expression[] expr = list.get(x);
       Row newRow;
       try {
         newRow = createRow(expr, x);
         if (newRow == null) {
           continue;
         }
       } catch (DbException ex) {
         throw setRow(ex, count + 1, getSQL(expr));
       }
       setCurrentRowNumber(++count);
       merge(newRow);
     }
   } else {
     ResultInterface rows = query.query(0);
     count = 0;
     table.fire(session, Trigger.UPDATE | Trigger.INSERT, true);
     table.lock(session, true, false);
     while (rows.next()) {
       Value[] values = rows.currentRow();
       Row newRow;
       try {
         newRow = createRow(values);
         if (newRow == null) {
           continue;
         }
       } catch (DbException ex) {
         throw setRow(ex, count + 1, getSQL(values));
       }
       setCurrentRowNumber(++count);
       merge(newRow);
     }
     rows.close();
     table.fire(session, Trigger.UPDATE | Trigger.INSERT, false);
   }
   return count;
 }
Пример #3
0
  private Cursor find(Session session, SearchRow first, boolean bigger, SearchRow last) {
    StatementBuilder sql = new StatementBuilder("select _gui_row_id_");
    for (Column c : getColumns()) {
      sql.append(",");
      sql.append(c.getName());
    }
    sql.append(" from ").append(getName());

    if (first != null || last != null) {
      sql.append(" where ");

      for (Column c : getColumns()) {
        sql.appendExceptFirst(" and ");
        if (first != null) {
          sql.append(c.getName()).append(">=");
          Value v = first.getValue(c.getColumnId());
          if (v != null) {
            sql.append(v.getSQL());
          }
        }
        if (last != null) {
          sql.append(c.getName()).append("<=");
          Value v = last.getValue(c.getColumnId());
          if (v != null) {
            sql.append(v.getSQL());
          }
        }
      }
    }

    Prepared prepared = session.prepare(sql.toString(), true);
    prepared.setLocal(false);
    ResultInterface result = prepared.query(0);
    if (bigger) result.next();
    return new GlobalUniqueIndexTableCursor(result);
  }
Пример #4
0
 private static SimpleResultSet getSimpleResultSet(ResultInterface rs, int maxrows) {
   int columnCount = rs.getVisibleColumnCount();
   SimpleResultSet simple = new SimpleResultSet();
   for (int i = 0; i < columnCount; i++) {
     String name = rs.getColumnName(i);
     int sqlType = DataType.convertTypeToSQLType(rs.getColumnType(i));
     int precision = MathUtils.convertLongToInt(rs.getColumnPrecision(i));
     int scale = rs.getColumnScale(i);
     simple.addColumn(name, sqlType, precision, scale);
   }
   rs.reset();
   for (int i = 0; i < maxrows && rs.next(); i++) {
     Object[] list = new Object[columnCount];
     for (int j = 0; j < columnCount; j++) {
       list[j] = rs.currentRow()[j].getObject();
     }
     simple.addRow(list);
   }
   return simple;
 }
Пример #5
0
 @Override
 public boolean next() {
   return result.next();
 }
Пример #6
0
 @Override
 public Row get() {
   Row row = new Row(result.currentRow(), 0);
   row.setKey(row.getValue(0).getLong());
   return row;
 }