Search in sources :

Example 1 with List

use of org.hibernate.mapping.List in project hibernate-orm by hibernate.

the class ListBinder method bindIndex.

private void bindIndex(final MetadataBuildingContext buildingContext) {
    if (!indexColumn.isImplicit()) {
        PropertyHolder valueHolder = PropertyHolderBuilder.buildPropertyHolder(this.collection, StringHelper.qualify(this.collection.getRole(), "key"), null, null, propertyHolder, getBuildingContext());
        List list = (List) this.collection;
        if (!list.isOneToMany())
            indexColumn.forceNotNull();
        indexColumn.setPropertyHolder(valueHolder);
        SimpleValueBinder value = new SimpleValueBinder();
        value.setColumns(new Ejb3Column[] { indexColumn });
        value.setExplicitType("integer");
        value.setBuildingContext(getBuildingContext());
        SimpleValue indexValue = value.make();
        indexColumn.linkWithValue(indexValue);
        list.setIndex(indexValue);
        list.setBaseIndex(indexColumn.getBase());
        if (list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse()) {
            String entityName = ((OneToMany) list.getElement()).getReferencedEntityName();
            PersistentClass referenced = buildingContext.getMetadataCollector().getEntityBinding(entityName);
            IndexBackref ib = new IndexBackref();
            ib.setName('_' + propertyName + "IndexBackref");
            ib.setUpdateable(false);
            ib.setSelectable(false);
            ib.setCollectionRole(list.getRole());
            ib.setEntityName(list.getOwner().getEntityName());
            ib.setValue(list.getIndex());
            referenced.addProperty(ib);
        }
    } else {
        Collection coll = this.collection;
        throw new AnnotationException("List/array has to be annotated with an @OrderColumn (or @IndexColumn): " + coll.getRole());
    }
}
Also used : PropertyHolder(org.hibernate.cfg.PropertyHolder) Collection(org.hibernate.mapping.Collection) AnnotationException(org.hibernate.AnnotationException) List(org.hibernate.mapping.List) IndexBackref(org.hibernate.mapping.IndexBackref) OneToMany(org.hibernate.mapping.OneToMany) SimpleValue(org.hibernate.mapping.SimpleValue) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 2 with List

use of org.hibernate.mapping.List in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testSetIndex.

@Test
public void testSetIndex() {
    List valueTarget = new List(null, null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertNull(valueTarget.getIndex());
    SimpleValue indexTarget = new SimpleValue(null);
    IValue indexFacade = FACADE_FACTORY.createValue(indexTarget);
    valueFacade.setIndex(indexFacade);
    Assert.assertSame(indexTarget, valueTarget.getIndex());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) List(org.hibernate.mapping.List) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 3 with List

use of org.hibernate.mapping.List in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testIsList.

@Test
public void testIsList() {
    valueTarget = new SimpleValue(null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertFalse(valueFacade.isList());
    valueTarget = new List(null, null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertTrue(valueFacade.isList());
}
Also used : List(org.hibernate.mapping.List) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 4 with List

use of org.hibernate.mapping.List in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testSetIndex.

@Test
public void testSetIndex() {
    List valueTarget = new List(null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertNull(valueTarget.getIndex());
    SimpleValue indexTarget = new SimpleValue();
    IValue indexFacade = FACADE_FACTORY.createValue(indexTarget);
    valueFacade.setIndex(indexFacade);
    Assert.assertSame(indexTarget, valueTarget.getIndex());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) List(org.hibernate.mapping.List) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 5 with List

use of org.hibernate.mapping.List in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testIsList.

@Test
public void testIsList() {
    valueTarget = new SimpleValue(null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertFalse(valueFacade.isList());
    valueTarget = new List(null, null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertTrue(valueFacade.isList());
}
Also used : List(org.hibernate.mapping.List) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

List (org.hibernate.mapping.List)27 SimpleValue (org.hibernate.mapping.SimpleValue)26 Test (org.junit.Test)25 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)8 Component (org.hibernate.mapping.Component)2 OneToMany (org.hibernate.mapping.OneToMany)2 AnnotationException (org.hibernate.AnnotationException)1 MetadataSources (org.hibernate.boot.MetadataSources)1 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)1 PropertyHolder (org.hibernate.cfg.PropertyHolder)1 ClassAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData)1 ComponentAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData)1 PropertyAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData)1 Any (org.hibernate.mapping.Any)1 Array (org.hibernate.mapping.Array)1 Bag (org.hibernate.mapping.Bag)1 Collection (org.hibernate.mapping.Collection)1 DependantValue (org.hibernate.mapping.DependantValue)1 IdentifierBag (org.hibernate.mapping.IdentifierBag)1 IndexBackref (org.hibernate.mapping.IndexBackref)1