Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 @Override
 public Row get() {
   Row row = new Row(result.currentRow(), 0);
   row.setKey(row.getValue(0).getLong());
   return row;
 }