Exemplo n.º 1
0
  @Override
  public void add(Session session, Row row) {
    StatementBuilder sql = new StatementBuilder("insert into ");
    sql.append(getName()).append("(_gui_row_id_");

    for (Column c : getColumns()) {
      sql.append(",");
      sql.append(c.getName());
    }

    sql.append(") values (");
    sql.append(row.getKey());

    for (Column c : getColumns()) {
      sql.append(",");
      Value v = row.getValue(c.getColumnId());
      if (v == null) {
        sql.append("DEFAULT");
      } else {
        sql.append(v.getSQL());
      }
    }
    sql.append(")");

    Prepared prepared = session.prepare(sql.toString(), true);
    prepared.setLocal(false);
    prepared.update();
  }
Exemplo n.º 2
0
  public GlobalUniqueIndex(
      Session session,
      MVTable table,
      int id,
      String indexName,
      IndexColumn[] columns,
      IndexType indexType) {
    initIndexBase(table, id, indexName, columns, indexType);
    if (!database.isStarting()) {
      checkIndexColumnTypes(columns);
    }

    StatementBuilder sql = new StatementBuilder("create ");
    if (table.isGlobalTemporary()) sql.append("global temporary ");
    else if (table.isTemporary()) sql.append("local temporary ");
    sql.append("table if not exists ").append(getName()).append("(_gui_row_id_ long,");

    for (Column c : getColumns()) {
      sql.append(c.getCreateSQL()).append(",");
    }

    sql.append("primary key(");
    for (Column c : getColumns()) {
      sql.appendExceptFirst(",");
      sql.append(c.getName());
    }
    sql.append("))");

    Prepared prepared = session.prepare(sql.toString(), true);
    prepared.setLocal(true);
    prepared.update();
  }
Exemplo n.º 3
0
  @Override
  public void rename(String newName) {
    StatementBuilder sql = new StatementBuilder("alter table ");
    sql.append(getName()).append(" rename to").append(newName);

    Prepared prepared = getDatabase().getSystemSession().prepare(sql.toString(), true);
    prepared.setLocal(true);
    prepared.update();
  }
Exemplo n.º 4
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();
  }
Exemplo n.º 5
0
  @Override
  public void remove(Session session, Row row) {
    StatementBuilder sql = new StatementBuilder("delete from ");
    sql.append(getName());
    if (row != null) {
      sql.append(" where ");

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

    Prepared prepared = session.prepare(sql.toString(), true);
    prepared.setLocal(false);
    prepared.update();
  }
Exemplo n.º 6
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);
  }
Exemplo n.º 7
0
 @Override
 public void truncate(Session session) {
   Prepared prepared = session.prepare("truncate table " + getName(), true);
   prepared.setLocal(true);
   prepared.update();
 }
Exemplo n.º 8
0
 @Override
 public void remove(Session session) {
   Prepared prepared = session.prepare("drop table if exists " + getName(), true);
   prepared.setLocal(true);
   prepared.update();
 }