Examples of ForeignKeyConstraint


Examples of net.sf.hajdbc.ForeignKeyConstraint

  @Override
  public void getCreateForeignKeyConstraintSQL() throws SQLException
  {
    QualifiedName table = mock(QualifiedName.class);
    QualifiedName foreignTable = mock(QualifiedName.class);
    ForeignKeyConstraint constraint = mock(ForeignKeyConstraint.class);
   
    when(table.getDDLName()).thenReturn("table");
    when(foreignTable.getDDLName()).thenReturn("foreign_table");
    when(constraint.getName()).thenReturn("name");
    when(constraint.getTable()).thenReturn(table);
    when(constraint.getColumnList()).thenReturn(Arrays.asList("column1", "column2"));
    when(constraint.getForeignTable()).thenReturn(foreignTable);
    when(constraint.getForeignColumnList()).thenReturn(Arrays.asList("foreign_column1", "foreign_column2"));
    when(constraint.getDeferrability()).thenReturn(DatabaseMetaData.importedKeyInitiallyDeferred);
    when(constraint.getDeleteRule()).thenReturn(DatabaseMetaData.importedKeyCascade);
    when(constraint.getUpdateRule()).thenReturn(DatabaseMetaData.importedKeyRestrict);
   
    String result = this.dialect.getCreateForeignKeyConstraintSQL(constraint);
   
    assertEquals("ALTER TABLE table ADD CONSTRAINT name FOREIGN KEY (column1, column2) REFERENCES foreign_table (foreign_column1, foreign_column2) ON DELETE CASCADE", result);
  }
View Full Code Here

Examples of net.sourceforge.squirrel_sql.plugins.mssql.sql.constraint.ForeignKeyConstraint

        {
          /* NOTE: there are two rows.
           * NOTE: MssqlConstraint holds the columns in the table participating in the key.
           * NOTE: ForeignKeyConstraint holds the columns in the referenced table IN THE SAME ORDER.
           */
          ForeignKeyConstraint fk = new ForeignKeyConstraint();

          fk.setConstraintName(constraintName);

          String foreignColumns[] = constraintKeys.split(", ");
          for (int i = 0; i < foreignColumns.length; i++)
            fk.addConstraintColumn(foreignColumns[i]);

          rs.next();

          constraintKeys = rs.getString(7);
          // constraintKeys looks like this --> `REFERENCES pubs.dbo.foo (fooid, quuxid)'
          constraintKeys = constraintKeys.substring(11); // chop off "REFERENCES "
          String[] tableAndColumns = constraintKeys.split(" ", 2);
          // now tableAndColumns[0] contains the table name and tableAndColumns[1] contains
          // the bracketed list of columns.
          fk.setReferencedTable(tableAndColumns[0]);
          String primaryColumns[] =
            tableAndColumns[1].substring(1, tableAndColumns[1].length() - 2).split(",");
          for (int i = 0; i < primaryColumns.length; i++)
            fk.addPrimaryColumn(primaryColumns[i]);

          constraints.addConstraint(fk);
        }
        else if (constraintType.startsWith("PRIMARY KEY"))
        {
View Full Code Here

Examples of net.sourceforge.squirrel_sql.plugins.mssql.sql.constraint.ForeignKeyConstraint

      }

      List<ForeignKeyConstraint> fks = constraints.getForeignKeyConstraints();
      for (int i = 0; i < fks.size(); i++)
      {
        ForeignKeyConstraint fk = fks.get(i);
        buf.append("\tFOREIGN KEY\n\t(\n\t\t");
        Object[] foreignColumns = fk.getConstraintColumns();
        for (int j = 0; j < foreignColumns.length; j++)
        {
          buf.append("[");
          buf.append((String) foreignColumns[j]);
          buf.append("]");
          if (j < foreignColumns.length - 1) buf.append(", ");
        }
        buf.append("\n\t) REFERENCES [");
        buf.append(fk.getReferencedTable());
        buf.append("] (\n\t\t");
        Object[] primaryColumns = fk.getPrimaryColumns();
        for (int j = 0; j < primaryColumns.length; j++)
        {
          buf.append("[");
          buf.append((String) primaryColumns[j]);
          buf.append("]");
View Full Code Here

Examples of net.sourceforge.squirrel_sql.plugins.mssql.sql.constraint.ForeignKeyConstraint

      assertEquals(1, list.size());
    }

    @Test
    public final void testGetForeignKeyConstraints() {
      ForeignKeyConstraint constraint = new ForeignKeyConstraint();
      constraintsUnderTest.addConstraint(constraint);
      List<ForeignKeyConstraint> list = constraintsUnderTest.getForeignKeyConstraints();
      assertEquals(1, list.size());
    }
View Full Code Here

Examples of org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint

  @Override
  public String getAddForeignKeyStatement(String tableName, String constraintName,
                                          List<String> keyColumns,
                                          String referenceTableName,
                                          List<String> referenceColumns) {
    ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint();
    foreignKeyConstraint.setName(constraintName);
    foreignKeyConstraint.setTargetTable(referenceTableName);
    foreignKeyConstraint.setSourceFields(keyColumns);
    foreignKeyConstraint.setTargetFields(referenceColumns);

    TableDefinition tableDefinition = new TableDefinition();
    tableDefinition.setName(tableName);

    Writer writer = new StringWriter();
View Full Code Here

Examples of org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint

  @Override
  public String getDropConstraintStatement(String tableName, String constraintName) {
    Writer writer = new StringWriter();

    ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint();
    foreignKeyConstraint.setName(constraintName);
    foreignKeyConstraint.setTargetTable(tableName);

    TableDefinition tableDefinition = new TableDefinition();
    tableDefinition.setName(tableName);
    tableDefinition.buildConstraintDeletionWriter(
        createStubAbstractSessionFromPlatform(databasePlatform),
View Full Code Here

Examples of org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint

  @Override
  public String getAddForeignKeyStatement(String tableName, String constraintName,
                                          List<String> keyColumns,
                                          String referenceTableName,
                                          List<String> referenceColumns) {
    ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint();
    foreignKeyConstraint.setName(constraintName);
    foreignKeyConstraint.setTargetTable(referenceTableName);
    foreignKeyConstraint.setSourceFields(keyColumns);
    foreignKeyConstraint.setTargetFields(referenceColumns);

    TableDefinition tableDefinition = new TableDefinition();
    tableDefinition.setName(tableName);

    Writer writer = new StringWriter();
View Full Code Here

Examples of org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint

  @Override
  public String getDropConstraintStatement(String tableName, String constraintName) {
    Writer writer = new StringWriter();

    ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint();
    foreignKeyConstraint.setName(constraintName);
    foreignKeyConstraint.setTargetTable(tableName);

    TableDefinition tableDefinition = new TableDefinition();
    tableDefinition.setName(tableName);
    tableDefinition.buildConstraintDeletionWriter(
        createStubAbstractSessionFromPlatform(databasePlatform),
View Full Code Here

Examples of org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint

  @Override
  public String getAddForeignKeyStatement(String tableName, String constraintName,
                                          List<String> keyColumns,
                                          String referenceTableName,
                                          List<String> referenceColumns) {
    ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint();
    foreignKeyConstraint.setName(constraintName);
    foreignKeyConstraint.setTargetTable(referenceTableName);
    foreignKeyConstraint.setSourceFields(keyColumns);
    foreignKeyConstraint.setTargetFields(referenceColumns);

    TableDefinition tableDefinition = new TableDefinition();
    tableDefinition.setName(tableName);

    Writer writer = new StringWriter();
View Full Code Here

Examples of org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint

  @Override
  public String getDropConstraintStatement(String tableName, String constraintName) {
    Writer writer = new StringWriter();

    ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint();
    foreignKeyConstraint.setName(constraintName);
    foreignKeyConstraint.setTargetTable(tableName);

    TableDefinition tableDefinition = new TableDefinition();
    tableDefinition.setName(tableName);
    tableDefinition.buildConstraintDeletionWriter(
        createStubAbstractSessionFromPlatform(databasePlatform),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.