@Test
 @Resources(annotatedClasses = TestEntity6.class)
 public void testElementCollectionWithJoinColumn() {
   EntityBinding entityBinding = getEntityBinding(TestEntity6.class);
   BagBinding bagBinding = (BagBinding) entityBinding.locateAttributeBinding("strings");
   TableSpecification tableSpec = bagBinding.getPluralAttributeKeyBinding().getCollectionTable();
   Column column = tableSpec.locateColumn("FOO");
   assertNotNull("The join column should be named FOO", column);
 }
 @Test
 @Resources(annotatedClasses = TestEntity4.class)
 public void testExplicitJoinTableName() {
   EntityBinding entityBinding = getEntityBinding(TestEntity4.class);
   BagBinding bagBinding = (BagBinding) entityBinding.locateAttributeBinding("strings");
   TableSpecification tableSpec = bagBinding.getPluralAttributeKeyBinding().getCollectionTable();
   assertEquals(
       "Wrong default collection table name",
       "STRING_COLLECTION",
       tableSpec.getLogicalName().getText());
 }
 @Test
 public void testAbstractTableExistence() {
   for (Schema schema : getMetadata().getDatabase().getSchemas()) {
     for (TableSpecification table : schema.getTables()) {
       if ("AbstractEntity_AUD".equals(table.getLogicalName().getText())) {
         Assert.assertFalse(Table.class.isInstance(table));
         return;
       }
     }
   }
   Assert.fail();
 }
示例#4
0
  @Test
  public void testTableGeneratorIndex() {
    TableSpecification table = SchemaUtil.getTable("ID_GEN", metadata());

    Iterator<org.hibernate.metamodel.spi.relational.Index> indexes = table.getIndexes().iterator();
    assertTrue(indexes.hasNext());
    org.hibernate.metamodel.spi.relational.Index index = indexes.next();
    assertFalse(indexes.hasNext());
    assertTrue("index name is not generated", StringHelper.isNotEmpty(index.getName()));
    assertEquals(1, index.getColumnSpan());
    org.hibernate.metamodel.spi.relational.Column column = index.getColumns().get(0);
    assertEquals("GEN_VALUE", column.getColumnName().getText());
    assertSame(table, index.getTable());
  }
  private SingularAttributeBinding locateAttributeBindingFromIdentifier(
      TableSpecification table, List<? extends Value> values) {
    if (!primaryTable.equals(table)) {
      return null;
    }

    final EntityIdentifier idInfo = hierarchyDetails.getEntityIdentifier();
    final SingularAttributeBinding idAttributeBinding =
        idInfo.getEntityIdentifierBinding().getAttributeBinding();
    final List<? extends Value> idAttributeValues = idAttributeBinding.getValues();
    // order-insensitive check (column order handled later)
    if (idAttributeValues.size() == values.size() && idAttributeValues.containsAll(values)) {
      return idAttributeBinding;
    }
    //		if ( idAttributeValues.equals( values ) ) {
    //			return idAttributeBinding;
    //		}

    return null;
  }
 private void testTableUniqueConstraints(
     TableSpecification table, String ukName, int ukNumColumns) {
   Iterable<UniqueKey> uniqueKeyIterable = table.getUniqueKeys();
   assertNotNull(uniqueKeyIterable);
   int i = 0;
   for (UniqueKey key : uniqueKeyIterable) {
     i++;
     assertEquals(ukName, key.getName());
     assertTrue(table == key.getTable());
     assertNotNull(key.getColumns());
     assertEquals(
         "There should be " + ukNumColumns + " columns in the unique constraint",
         ukNumColumns,
         key.getColumns().size());
     assertEquals(
         "There should be " + ukNumColumns + " columns in the unique constraint",
         ukNumColumns,
         key.getColumnSpan());
   }
   assertEquals("There should only be one unique constraint", 1, i);
 }