public int getSubEntityBindingClosureSpan() {
   int n = subEntityBindings.size();
   for (final EntityBinding seb : subEntityBindings) {
     n += seb.getSubEntityBindingClosureSpan();
   }
   return n;
 }
 public DynamicMapInstantiator(EntityBinding mappingInfo) {
   this.entityName = mappingInfo.getEntity().getName();
   isInstanceEntityNames.add(entityName);
   for (EntityBinding subEntityBinding : mappingInfo.getPostOrderSubEntityBindingClosure()) {
     isInstanceEntityNames.add(subEntityBinding.getEntity().getName());
   }
 }
 @Test
 @Resources(annotatedClasses = VersionBindingTests.Item2.class)
 public void testVersionUnsavedValue() {
   EntityBinding binding = getEntityBinding(Item2.class);
   assertTrue(binding.isVersioned());
   assertEquals("undefined", binding.getHierarchyDetails().getEntityVersion().getUnsavedValue());
 }
Esempio n. 4
0
 @Test
 @Resources(annotatedClasses = {User.class, Address.class})
 public void testEmbeddable() {
   EntityBinding binding = getEntityBinding(User.class);
   EntityIdentifier identifier = binding.getHierarchyDetails().getEntityIdentifier();
   assertTrue(!identifier.isNonAggregatedComposite());
   assertEquals(identifier.getNature(), EntityIdentifierNature.AGGREGATED_COMPOSITE);
 }
 @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);
 }
  /**
   * Used to instantiate the EntityBinding for an entity that is a subclass (sub-entity) in an
   * inheritance hierarchy
   *
   * @param superEntityBinding The entity binding of this binding's super
   */
  public EntityBinding(EntityBinding superEntityBinding) {
    this.superEntityBinding = superEntityBinding;
    this.hierarchyDetails = superEntityBinding.getHierarchyDetails();
    this.subEntityBindingId = superEntityBinding.nextSubEntityBindingId();

    // TODO: the ID attribute binding needs to be recreated for this EntityBinding
    // otherwise, this !=
    // hierarchyDetails.getEntityIdentifier().getAttributeBinding().getContainer()
  }
 private EntityBinding[] getPreOrderSubEntityBindingClosure(
     boolean includeThis, EntityBinding[] results) {
   if (includeThis) {
     results = ArrayHelper.join(results, this);
   }
   for (EntityBinding subEntityBinding : subEntityBindings) {
     results = subEntityBinding.getPreOrderSubEntityBindingClosure(true, results);
   }
   return results;
 }
 @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());
 }
  public AttributeBinding[] getNonIdEntitiesAttributeBindingClosure() {
    AttributeBinding[] results = getNonIdAttributeBindingClosure();

    for (EntityBinding subEntityBinding : getPreOrderSubEntityBindingClosure()) {
      // only add attribute bindings declared for the subEntityBinding

      results = ArrayHelper.join(results, subEntityBinding.internalGetNonIdAttributeBindings());
      // TODO: if EntityBinding.attributeBindings() excludes joined attributes, then they need to be
      // added here
    }
    return results;
  }
 public SecondaryTable[] getSubEntitySecondaryTables() {
   SecondaryTable[] results = new SecondaryTable[0];
   for (EntityBinding eb : getPreOrderSubEntityBindingClosure()) {
     Collection<SecondaryTable> sts = eb.getSecondaryTables().values();
     int size = sts.size();
     if (size == 0) {
       continue;
     }
     results = ArrayHelper.join(results, sts.toArray(new SecondaryTable[size]));
   }
   return results;
 }
  private SessionFactory buildSessionFactory() {
    // Extra options located in src/test/resources/hibernate.properties
    Properties envProps = Environment.getProperties();
    envProps.setProperty(Environment.DIALECT, "HSQL");
    envProps.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
    envProps.setProperty(
        Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName());
    envProps.setProperty(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory");
    envProps.setProperty(Environment.TRANSACTION_STRATEGY, "jta");
    envProps.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta");
    envProps.setProperty(Environment.RELEASE_CONNECTIONS, "auto");
    envProps.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
    envProps.setProperty(Environment.USE_QUERY_CACHE, "true");
    envProps.put(AvailableSettings.JTA_PLATFORM, new JBossStandAloneJtaPlatform());
    envProps.setProperty(
        Environment.CACHE_REGION_FACTORY,
        "org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase$TestInfinispanRegionFactory");
    serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(envProps);

    MetadataSources sources = new MetadataSources(serviceRegistry);

    String[] mappings =
        new String[] {"org/hibernate/test/cache/infinispan/functional/Item.hbm.xml"};
    for (String mapping : mappings) {
      sources.addResource(mapping);
    }
    Metadata metadata = sources.buildMetadata();
    Iterator<EntityBinding> entityIter = metadata.getEntityBindings().iterator();
    while (entityIter.hasNext()) {
      EntityBinding binding = entityIter.next();
      binding.getHierarchyDetails().getCaching().setAccessType(AccessType.TRANSACTIONAL);
      binding.getHierarchyDetails().getCaching().setRequested(TruthValue.TRUE);
      binding.getHierarchyDetails().getCaching().setRegion(binding.getEntityName());
      binding.getHierarchyDetails().getCaching().setCacheLazyProperties(true);
    }
    Iterator<PluralAttributeBinding> collectionIter = metadata.getCollectionBindings().iterator();
    while (collectionIter.hasNext()) {
      PluralAttributeBinding binding = collectionIter.next();
      binding.getCaching().setAccessType(AccessType.TRANSACTIONAL);
      binding.getCaching().setRequested(TruthValue.TRUE);
      binding
          .getCaching()
          .setRegion(
              StringHelper.qualify(
                  binding.getContainer().seekEntityBinding().getEntityName(),
                  binding.getAttribute().getName()));
      binding.getCaching().setCacheLazyProperties(true);
    }
    return metadata.buildSessionFactory();
  }
 /**
  * Returns sub-EntityBinding objects in a special 'order', most derived subclasses first.
  * Specifically, the sub-entity bindings follow a depth-first, post-order traversal
  *
  * <p>Note that the returned value excludes this entity binding.
  *
  * @return sub-entity bindings ordered by those entity bindings that are most derived.
  */
 public EntityBinding[] getPostOrderSubEntityBindingClosure() {
   EntityBinding[] results = new EntityBinding[0];
   if (subEntityBindings.isEmpty()) {
     return results;
   }
   for (EntityBinding subEntityBinding : subEntityBindings) {
     EntityBinding[] subSubEntityBindings = subEntityBinding.getPostOrderSubEntityBindingClosure();
     results = ArrayHelper.join(results, subSubEntityBindings);
   }
   if (!subEntityBindings.isEmpty()) {
     results =
         ArrayHelper.join(
             results, subEntityBindings.toArray(new EntityBinding[subEntityBindings.size()]));
   }
   return results;
 }
 public String[] getSynchronizedTableNameClosure() {
   if (isRoot()) {
     return getSynchronizedTableNames();
   }
   return ArrayHelper.join(
       superEntityBinding.getSynchronizedTableNameClosure(), getSynchronizedTableNames());
 }
 public Class<? extends EntityPersister> getCustomEntityPersisterClass() {
   if (customEntityPersisterClass != null) {
     return customEntityPersisterClass;
   } else if (superEntityBinding != null) {
     return superEntityBinding.getCustomEntityPersisterClass();
   }
   return null;
 }
 public SecondaryTable[] getSecondaryTableClosure() {
   if (isRoot()) {
     return secondaryTables.values().toArray(new SecondaryTable[secondaryTables.size()]);
   } else {
     return ArrayHelper.join(
         superEntityBinding.getSecondaryTableClosure(),
         secondaryTables.values().toArray(new SecondaryTable[secondaryTables.size()]));
   }
 }
 @Override
 public Class<? extends EntityTuplizer> getCustomTuplizerClass() {
   if (customEntityTuplizerClass != null) {
     return customEntityTuplizerClass;
   } else if (superEntityBinding != null) {
     return superEntityBinding.getCustomTuplizerClass();
   }
   return null;
 }
 @Override
 public List<FilterConfiguration> getFilterConfigurations() {
   if (superEntityBinding != null) {
     List<FilterConfiguration> results = new ArrayList<FilterConfiguration>(filterConfigurations);
     results.addAll(superEntityBinding.getFilterConfigurations());
     return results;
   }
   return filterConfigurations;
 }
 public AttributeBinding[] getNonIdAttributeBindingClosure() {
   // TODO: update size to account for joins
   if (isRoot()) {
     return internalGetNonIdAttributeBindings();
   } else {
     return ArrayHelper.join(
         superEntityBinding.getNonIdAttributeBindingClosure(),
         internalGetNonIdAttributeBindings());
   }
 }
 @Test
 @Resources(annotatedClasses = VersionBindingTests.Item2.class)
 public void testVersionTypeAttribute() {
   EntityBinding binding = getEntityBinding(Item2.class);
   assertTrue(binding.isVersioned());
   HibernateTypeDescriptor descriptor =
       binding
           .getHierarchyDetails()
           .getEntityVersion()
           .getVersioningAttributeBinding()
           .getHibernateTypeDescriptor();
   //		assertEquals( "Long", descriptor.getExplicitTypeName() );
   assertEquals(Long.class.getName(), descriptor.getClassReference().getName());
   assertEquals(Long.class, descriptor.getClassReference().getResolvedClass());
   assertNotNull(descriptor.getResolvedTypeMapping());
   assertEquals(LongType.class, descriptor.getResolvedTypeMapping().getClass());
   assertNotNull(descriptor.getTypeParameters());
   assertTrue(descriptor.getTypeParameters().isEmpty());
 }
  /**
   * @return the attribute bindings for this EntityBinding and all of its sub-EntityBinding,
   *     starting from the root of the hierarchy; includes the identifier and attribute bindings
   *     defined as part of a join.
   */
  public AttributeBinding[] getEntitiesAttributeBindingClosure() {
    AttributeBinding[] results = getAttributeBindingClosure();

    for (EntityBinding subEntityBinding : getPreOrderSubEntityBindingClosure()) {
      // only add attribute bindings declared for the subEntityBinding

      results =
          ArrayHelper.join(
              results,
              subEntityBinding
                  .attributeBindingMapInternal()
                  .values()
                  .toArray(
                      new AttributeBinding[subEntityBinding.attributeBindingMapInternal().size()]));
      // TODO: if EntityBinding.attributeBindings() excludes joined attributes, then they need to be
      // added here
    }
    return results;
  }
 /**
  * Gets the attribute bindings defined on this class, including the identifier attribute binding
  * and attribute bindings defined as part of a join.
  *
  * @return The attribute bindings.
  */
 public AttributeBinding[] getAttributeBindingClosure() {
   // TODO: update size to account for joins
   if (isRoot()) {
     return attributeBindingMapInternal()
         .values()
         .toArray(new AttributeBinding[attributeBindingMapInternal().size()]);
   } else {
     return ArrayHelper.join(
         superEntityBinding.getAttributeBindingClosure(),
         attributeBindingMapInternal()
             .values()
             .toArray(new AttributeBinding[attributeBindingMapInternal().size()]));
   }
 }
 @Test
 @Resources(annotatedClasses = {TableWithUniqueConstraint.class, SecondTable.class})
 public void testTableUniqueConstraints() {
   EntityBinding binding = getEntityBinding(TableWithUniqueConstraint.class);
   testTableUniqueConstraints(binding.getPrimaryTable(), "u1", 2);
   testTableUniqueConstraints(
       ((MultipleHiLoPerTableGenerator)
               binding.getHierarchyDetails().getEntityIdentifier().getIdentifierGenerator())
           .getTable(),
       "u2",
       1);
   testTableUniqueConstraints(
       SchemaUtil.getCollection(TableWithUniqueConstraint.class, "secondTables", meta)
           .getPluralAttributeKeyBinding()
           .getCollectionTable(),
       "u3",
       2);
   testTableUniqueConstraints(
       SchemaUtil.getCollection(TableWithUniqueConstraint.class, "elements", meta)
           .getPluralAttributeKeyBinding()
           .getCollectionTable(),
       "u4",
       1);
 }
 public TableSpecification[] getTableClosure() {
   if (isRoot()) {
     return new TableSpecification[] {getPrimaryTable()};
   }
   return ArrayHelper.join(superEntityBinding.getTableClosure(), getPrimaryTable());
 }
 public EntityBinding[] getEntityBindingClosure() {
   if (isRoot()) {
     return new EntityBinding[] {this};
   }
   return ArrayHelper.join(superEntityBinding.getEntityBindingClosure(), this);
 }
 public int getSecondaryTableClosureSpan() {
   return isRoot()
       ? secondaryTables.size()
       : superEntityBinding.getSecondaryTableClosureSpan() + secondaryTables.size();
 }
 public boolean isClassOrSuperclassSecondaryTable(SecondaryTable secondaryTable) {
   return secondaryTables.containsKey(secondaryTable.getSecondaryTableReference().getLogicalName())
       || (superEntityBinding != null
           && superEntityBinding.isClassOrSuperclassSecondaryTable(secondaryTable));
 }
 private int nextSubEntityBindingId() {
   return isRoot() ? ++nextSubEntityBindingId : superEntityBinding.nextSubEntityBindingId();
 }