Package org.apache.ws.jaxme.sqls

Examples of org.apache.ws.jaxme.sqls.Table


  }

  /** <p>Test for composed primary keys.</p>
   */
  public void testComposedPrimaryKey() {
    Table table = getComposedKeyTable();

    SelectStatement statement = table.getSelectStatement();
    statement.getWhere().addColumnSetQuery(table.getPrimaryKey(), statement.getTableReference());
    SQLGenerator generator = sqlFactory.newSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(statement);
    assertEquals("SELECT MyIndex, MyName, MyDate, VerNum FROM MySchema.MyTable WHERE (MyIndex=? AND VerNum=?)", s);
  }
View Full Code Here


  /** <p>Test for index names.</p>
   */
  public void testIndexNames() {
    SQLGenerator gen = sqlFactory.newSQLGenerator();
    Table table = getBasicTable();
    for (int i = 0;  i < 10;  i++) {
      Index index = table.newIndex();
      index.addColumn("MyName");
      String s = (String) gen.getCreate(index).iterator().next();
      assertEquals("CREATE INDEX MyTable_I" + i + " ON MySchema.MyTable (MyName)", s);
    }

View Full Code Here

  /** <p>Test for subselects.</p>
   */
  public void testSubSelect() {
    SQLGenerator gen = sqlFactory.newSQLGenerator();
    Table table = getComposedKeyTable();

    Table otherTable = table.getSchema().newTable("OtherTable");
    Column otherIndex = otherTable.newColumn("MyIndex", Column.Type.INTEGER);
    otherTable.newPrimaryKey().addColumn(otherIndex);
    ForeignKey foreignKey = otherTable.newForeignKey(table);
    SelectStatement selectStatement = sqlFactory.newSelectStatement();
    selectStatement.setTable(otherTable);
    DeleteStatement deleteStatement = sqlFactory.newDeleteStatement();
    deleteStatement.setTable(table);
    List columns = new ArrayList();
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
      Column column = (Column) iter.next();
      Column refColumn = otherTable.newColumn("Ref" + column.getName(), column.getType());
      foreignKey.addColumnLink(refColumn, column);
      if (column.isPrimaryKeyPart()) {
        selectStatement.addResultColumn(selectStatement.getTableReference().newColumnReference(refColumn));
        columns.add(deleteStatement.getTableReference().newColumnReference(column));
      }
View Full Code Here

    String got = gen.getQuery(deleteStatement);
    assertEquals(expect, got);
  }

  public void testVirtualColumn() {
    Table table = getBasicTable();
    SelectStatement selectStatement = table.getSelectStatement();
    VirtualColumn col = new VirtualColumn("virtCol", Column.Type.VARCHAR);
    selectStatement.addResultColumn(col);
    col.setValue("null");
    SQLGenerator gen = sqlFactory.newSQLGenerator();
    String query = gen.getQuery(selectStatement);
View Full Code Here

  public Collection getCreate(Schema pSchema, boolean pAll) {
    if (!pAll) { return getCreate(pSchema); }
    List result = new ArrayList();
    result.addAll(getCreate(pSchema));
    for (Iterator iter = pSchema.getTables();  iter.hasNext()) {
      Table table = (Table) iter.next();
      result.addAll(getCreate(table, true));
    }
    return result;
  }
View Full Code Here

    for (Iterator iter = pSchema.getTables();  iter.hasNext()) {
      tables.add(iter.next());
    }
    Collections.reverse(tables);
    for (Iterator iter = tables.iterator();  iter.hasNext()) {
      Table table = (Table) iter.next();
      result.addAll(getDrop(table, true));
    }
    result.addAll(getDrop(pSchema));
    return result;
  }
View Full Code Here

      Integer maxLength = getSQLFactory().getMaxTableNameLength();
      if (maxLength != null  &&  pName.getName().length() > maxLength.intValue()) {
         throw new IllegalArgumentException("The length of the table name " + pName +
                                             " exceeds the maximum length of " + maxLength);
      }
      Table table = getTable(pName);
      if (table != null) {
         throw new IllegalStateException("A table named " + table.getName() +
                                          " already exists in the schema " + getName());
      }
      table = ((SQLFactoryImpl) getSQLFactory()).newTableImpl(this, pName);
      tables.add(table);
      return table;
View Full Code Here

  public Table getTable(Table.Name pName) {
      if (pName == null) {
         throw new NullPointerException("A table name must not be null.");
      }
      for (Iterator iter = getTables();  iter.hasNext()) {
         Table table = (Table) iter.next();
         if (getSQLFactory().isTableNameCaseSensitive()) {
            if (pName.getName().equalsIgnoreCase(table.getName().getName())) {
               return table;
            }
         } else {
            if (pName.equals(table.getName())) {
               return table;
            }
         }
      }
      return null;
View Full Code Here

  public boolean equals(Object o) {
    if (o == null  ||  !(o instanceof Column)) {
      return false;
    }
    Column other = (Column) o;
    Table table = getTable();
    if (table == null) {
      if (other.getTable() != null) {
        return false;
      }
    } else {
      if (!table.equals(other.getTable())) {
        return false;
      }
    }
    return getName().equals(other.getName());
  }
View Full Code Here

      versionGenerator.setGeneratingLogging(isGeneratingLogging());
      boolean isFirstTable = true;

      for (Iterator iter = myTables.iterator();  iter.hasNext()) {
        String tableName = (String) iter.next();
        Table table = sch.getTable(tableName);
        if (table == null) {
          throw new IllegalArgumentException("Invalid table name: " + tableName);
        }

        VersionGenerator.ColumnUpdater columnUpdater;
        if (isFirstTable) {
          Column column = null;
          int columnNum = -1;
          int i = 0;
          for (Iterator colIter = table.getColumns();  colIter.hasNext();  i++) {
            Column colIterColumn = (Column) colIter.next();
            if (colIterColumn.getName().equals(columnName)) {
              column = colIterColumn;
              columnNum = i;
              break;
            }
          }
          if (column == null) {
            throw new IllegalArgumentException("No column " + columnName +
                                               " found in table " + table.getQName());
          }
          isFirstTable = false;
          columnUpdater = new VerNumIncrementer(columnNum);
        } else {
          List pkColumns = new ArrayList();
          Index primaryKey = table.getPrimaryKey();
          if (primaryKey != null) {
            for (Iterator pkIter = primaryKey.getColumns();  pkIter.hasNext()) {
              Column pkColumn = (Column) pkIter.next();
              int columnNum = -1;
              int i = 0;
              for (Iterator colIter = table.getColumns();  colIter.hasNext();  i++) {
                Column colIterColumn = (Column) colIter.next();
                if (colIterColumn.getName().equals(pkColumn.getName())) {
                  columnNum = i;
                  break;
                }
              }
              if (columnNum == -1) {
                throw new IllegalStateException("Primary key column " + pkColumn.getQName() +
                                                " not found in table " + table.getQName());
              }
              pkColumns.add(new Integer(columnNum));
            }
          }
          if (pkColumns.size() == 0) {
            throw new IllegalArgumentException("The table " + table.getQName() +
                                               " doesn't have a primary key.");
          }
          columnUpdater = new IdIncrementer(pkColumns);
        }
        versionGenerator.addTable(table, columnUpdater);
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.sqls.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.