Package org.apache.ws.jaxme.sqls

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


    }
    return result;
  }

  public DeleteStatement getDeleteStatement() {
    DeleteStatement result = getSchema().getSQLFactory().newDeleteStatement();
    result.setTable(this);
    ColumnSet primaryKey = getPrimaryKey();
    if (primaryKey == null) {
      throw new IllegalStateException("Cannot create a default delete statement without a primary key.");
    }
    result.getWhere().addColumnSetQuery(primaryKey, result.getTableReference());
    return result;
  }
View Full Code Here


  /** <p>Basic test for creating an <code>DELETE</code> statement.</p>
   */
  public void testBasicDelete() {
    Table table = getPrimaryKeyTable();
    DeleteStatement deleteStatement = table.getDeleteStatement();
    SQLGenerator generator = sqlFactory.newSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(deleteStatement);
    assertEquals("DELETE FROM MySchema.MyTable WHERE MyIndex=?", s);
  }
View Full Code Here

    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));
      }
    }
    BooleanConstraint eq = selectStatement.getWhere().createEQ();
    eq.addPart(selectStatement.getTableReference().newColumnReference("RefMyName"));
    eq.addPlaceholder();

    BooleanConstraint bc = deleteStatement.getWhere().createIN();
    bc.addPart((ColumnReference[]) columns.toArray(new ColumnReference[columns.size()]));
    bc.addPart(selectStatement);
    String expect = "DELETE FROM MySchema.MyTable WHERE (MyIndex, VerNum) IN (SELECT RefMyIndex, RefVerNum FROM MySchema.OtherTable WHERE RefMyName=?)";
    String got = gen.getQuery(deleteStatement);
    assertEquals(expect, got);
View Full Code Here

   
    /** <p>Basic test for creating an <code>DELETE</code> statement.</p>
     */
    public void testBasicDelete() {
        Table table = getPrimaryKeyTable();
        DeleteStatement deleteStatement = table.getDeleteStatement();
        SQLGenerator generator = getSQLGenerator();
        generator.setLineTerminator("\n");
        String s = generator.getQuery(deleteStatement);
        assertEquals("DELETE FROM MySchema.MyTable WHERE MyIndex=?", s);
    }
View Full Code Here

        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));
            }
        }
        BooleanConstraint eq = selectStatement.getWhere().createEQ();
        eq.addPart(selectStatement.getTableReference().newColumnReference("RefMyName"));
        eq.addPlaceholder();
       
        BooleanConstraint bc = deleteStatement.getWhere().createIN();
        bc.addPart((ColumnReference[]) columns.toArray(new ColumnReference[columns.size()]));
        bc.addPart(selectStatement);
        String expect = "DELETE FROM MySchema.MyTable WHERE (MyIndex, VerNum) IN ((SELECT RefMyIndex, RefVerNum FROM MySchema.OtherTable WHERE RefMyName=?))";
        String got = gen.getQuery(deleteStatement);
        assertEquals(expect, got);
View Full Code Here

    }
    return result;
  }

  public DeleteStatement getDeleteStatement() {
    DeleteStatement result = getSchema().getSQLFactory().newDeleteStatement();
    result.setTable(this);
    ColumnSet primaryKey = getPrimaryKey();
    if (primaryKey == null) {
      throw new IllegalStateException("Cannot create a default delete statement without a primary key.");
    }
    result.getWhere().addColumnSetQuery(primaryKey, result.getTableReference());
    return result;
  }
View Full Code Here

   
    /** <p>Basic test for creating an <code>DELETE</code> statement.</p>
     */
    public void testBasicDelete() {
        Table table = getPrimaryKeyTable();
        DeleteStatement deleteStatement = table.getDeleteStatement();
        SQLGenerator generator = getSQLGenerator();
        generator.setLineTerminator("\n");
        String s = generator.getQuery(deleteStatement);
        assertEquals("DELETE FROM MySchema.MyTable WHERE MyIndex=?", s);
    }
View Full Code Here

        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));
            }
        }
        BooleanConstraint eq = selectStatement.getWhere().createEQ();
        eq.addPart(selectStatement.getTableReference().newColumnReference("RefMyName"));
        eq.addPlaceholder();
       
        BooleanConstraint bc = deleteStatement.getWhere().createIN();
        bc.addPart((ColumnReference[]) columns.toArray(new ColumnReference[columns.size()]));
        bc.addPart(selectStatement);
        String expect = "DELETE FROM MySchema.MyTable WHERE (MyTable.MyIndex, VerNum) IN ((SELECT RefMyIndex, RefVerNum FROM MySchema.OtherTable WHERE RefMyName=?))";
        String got = gen.getQuery(deleteStatement);
        assertEquals(expect, got);
View Full Code Here

     *     CONNECT BY PRIOR KE.AID=KE.AVERTRETERID
     *   )
     * </pre></p>
     */
    private DeleteStatement getDeleteAllChildsByOrganisationsId() {
        DeleteStatement dstmt = sqlFactory.newDeleteStatement();
        dstmt.setTable(kettenElement);
        TableReference tRef  = dstmt.getTableReference();
        CombinedConstraint whereClause = dstmt.getWhere();
        BooleanConstraint bc = whereClause.createIN();
        bc.addPart(tRef.newColumnReference(kettenElement.getColumn("aId")));
        bc.addPart(getSelectAllChildsByOrganisationsId());
        return dstmt;
    }
View Full Code Here

     * <pre>
     * </pre>
     * and verifies the generator results.</p>
     */
    public void testDelete1() {
      DeleteStatement ds = getDeleteAllChildsByOrganisationsId();
        String expect = "DELETE FROM KettenElement WHERE KettenElement.aId IN" +
                        " ((SELECT * FROM KettenElement KettenElement0 START WITH KettenElement0.aId IN ((SELECT KettenElement1.aId FROM KettenElement KettenElement1, VertreterKette WHERE KettenElement1.aId=wurzelElement AND KettenElement1.organisationsId=?)) CONNECT BY PRIOR KettenElement0.aId=KettenElement0.aVertreterId))";
        String got = sqlGenerator.getQuery(ds);
        assertEquals(expect, got);
    }
View Full Code Here

TOP

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

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.