Package net.sourceforge.squirrel_sql.plugins.mssql.sql.constraint

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


      }

      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

      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

TOP

Related Classes of net.sourceforge.squirrel_sql.plugins.mssql.sql.constraint.ForeignKeyConstraint

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.