Search in sources :

Example 6 with ElementCollection

use of javax.persistence.ElementCollection in project cloudstack by apache.

the class SqlGenerator method findEcAttributes.

protected void findEcAttributes() {
    for (Attribute attr : _attributes) {
        if (attr.field == null) {
            continue;
        }
        ElementCollection ec = attr.field.getAnnotation(ElementCollection.class);
        if (ec != null) {
            Attribute idAttr = _ids.get(attr.table).get(0);
            assert supportsElementCollection(attr.field) : "Doesn't support ElementCollection for " + attr.field.getName();
            attr.attache = new EcInfo(attr, idAttr);
            _ecAttrs.add(attr);
        }
    }
}
Also used : ElementCollection(javax.persistence.ElementCollection)

Example 7 with ElementCollection

use of javax.persistence.ElementCollection in project cosmic by MissionCriticalCloud.

the class SqlGenerator method findEcAttributes.

protected void findEcAttributes() {
    for (final Attribute attr : _attributes) {
        if (attr.field == null) {
            continue;
        }
        final ElementCollection ec = attr.field.getAnnotation(ElementCollection.class);
        if (ec != null) {
            final Attribute idAttr = _ids.get(attr.table).get(0);
            assert supportsElementCollection(attr.field) : "Doesn't support ElementCollection for " + attr.field.getName();
            attr.attache = new EcInfo(attr, idAttr);
            _ecAttrs.add(attr);
        }
    }
}
Also used : ElementCollection(javax.persistence.ElementCollection)

Example 8 with ElementCollection

use of javax.persistence.ElementCollection in project cosmic by MissionCriticalCloud.

the class SqlGenerator method supportsElementCollection.

protected boolean supportsElementCollection(final Field field) {
    final ElementCollection otm = field.getAnnotation(ElementCollection.class);
    if (otm.fetch() == FetchType.LAZY) {
        assert (false) : "Doesn't support laz fetch: " + field.getName();
        return false;
    }
    final CollectionTable ct = field.getAnnotation(CollectionTable.class);
    if (ct == null) {
        assert (false) : "No collection table sepcified for " + field.getName();
        return false;
    }
    return true;
}
Also used : CollectionTable(javax.persistence.CollectionTable) ElementCollection(javax.persistence.ElementCollection)

Example 9 with ElementCollection

use of javax.persistence.ElementCollection in project cosmic by MissionCriticalCloud.

the class Attribute method setupColumnInfo.

protected void setupColumnInfo(final Class<?> clazz, final AttributeOverride[] overrides, final String tableName, final boolean isEmbedded, final boolean isId) {
    flags = Flag.Selectable.setTrue(flags);
    final GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
    if (gv != null) {
        if (gv.strategy() == GenerationType.IDENTITY) {
            flags = Flag.DbGenerated.setTrue(flags);
        } else if (gv.strategy() == GenerationType.SEQUENCE) {
            assert (false) : "Sequence generation not supported.";
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.SequenceGV.setTrue(flags);
        } else if (gv.strategy() == GenerationType.TABLE) {
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.TableGV.setTrue(flags);
        } else if (gv.strategy() == GenerationType.AUTO) {
            flags = Flag.DaoGenerated.setTrue(flags);
            flags = Flag.Insertable.setTrue(flags);
            flags = Flag.AutoGV.setTrue(flags);
        }
    }
    if (isEmbedded) {
        flags = Flag.Embedded.setTrue(flags);
    }
    if (isId) {
        flags = Flag.Id.setTrue(flags);
    } else {
        final Id id = field.getAnnotation(Id.class);
        if (id != null) {
            flags = Flag.Id.setTrue(flags);
        }
    }
    column = field.getAnnotation(Column.class);
    if (gv == null) {
        if (column == null || (column.insertable() && column.table().length() == 0)) {
            flags = Flag.Insertable.setTrue(flags);
        }
        if (column == null || (column.updatable() && column.table().length() == 0)) {
            flags = Flag.Updatable.setTrue(flags);
        }
        if (column == null || column.nullable()) {
            flags = Flag.Nullable.setTrue(flags);
        }
        final Encrypt encrypt = field.getAnnotation(Encrypt.class);
        if (encrypt != null && encrypt.encrypt()) {
            flags = Flag.Encrypted.setTrue(flags);
        }
    }
    final ElementCollection ec = field.getAnnotation(ElementCollection.class);
    if (ec != null) {
        flags = Flag.Insertable.setFalse(flags);
        flags = Flag.Selectable.setFalse(flags);
    }
    final Temporal temporal = field.getAnnotation(Temporal.class);
    if (temporal != null) {
        if (temporal.value() == TemporalType.DATE) {
            flags = Flag.Date.setTrue(flags);
        } else if (temporal.value() == TemporalType.TIME) {
            flags = Flag.Time.setTrue(flags);
        } else if (temporal.value() == TemporalType.TIMESTAMP) {
            flags = Flag.TimeStamp.setTrue(flags);
        }
    }
    if (column != null && column.table().length() > 0) {
        table = column.table();
    }
    columnName = DbUtil.getColumnName(field, overrides);
}
Also used : GeneratedValue(javax.persistence.GeneratedValue) Temporal(javax.persistence.Temporal) Column(javax.persistence.Column) Id(javax.persistence.Id) ElementCollection(javax.persistence.ElementCollection)

Example 10 with ElementCollection

use of javax.persistence.ElementCollection in project hibernate-orm by hibernate.

the class Ejb3XmlElementCollectionTest method testNoChildren.

@Test
public void testNoChildren() throws Exception {
    reader = getReader(Entity2.class, "field1", "element-collection.orm1.xml");
    assertAnnotationPresent(ElementCollection.class);
    assertAnnotationNotPresent(OrderBy.class);
    assertAnnotationNotPresent(OrderColumn.class);
    assertAnnotationNotPresent(MapKey.class);
    assertAnnotationNotPresent(MapKeyClass.class);
    assertAnnotationNotPresent(MapKeyTemporal.class);
    assertAnnotationNotPresent(MapKeyEnumerated.class);
    assertAnnotationNotPresent(MapKeyColumn.class);
    assertAnnotationNotPresent(MapKeyJoinColumns.class);
    assertAnnotationNotPresent(MapKeyJoinColumn.class);
    assertAnnotationNotPresent(Column.class);
    assertAnnotationNotPresent(Temporal.class);
    assertAnnotationNotPresent(Enumerated.class);
    assertAnnotationNotPresent(Lob.class);
    assertAnnotationNotPresent(AttributeOverride.class);
    assertAnnotationNotPresent(AttributeOverrides.class);
    assertAnnotationNotPresent(AssociationOverride.class);
    assertAnnotationNotPresent(AssociationOverrides.class);
    assertAnnotationNotPresent(CollectionTable.class);
    assertAnnotationNotPresent(Access.class);
    ElementCollection relAnno = reader.getAnnotation(ElementCollection.class);
    assertEquals(FetchType.LAZY, relAnno.fetch());
    assertEquals(void.class, relAnno.targetClass());
}
Also used : ElementCollection(javax.persistence.ElementCollection) Test(org.junit.Test)

Aggregations

ElementCollection (javax.persistence.ElementCollection)13 Column (javax.persistence.Column)4 Id (javax.persistence.Id)4 CollectionTable (javax.persistence.CollectionTable)3 GeneratedValue (javax.persistence.GeneratedValue)3 Temporal (javax.persistence.Temporal)3 ManyToMany (javax.persistence.ManyToMany)2 OneToMany (javax.persistence.OneToMany)2 HashMap (java.util.HashMap)1 Basic (javax.persistence.Basic)1 DiscriminatorColumn (javax.persistence.DiscriminatorColumn)1 EmbeddedId (javax.persistence.EmbeddedId)1 FetchType (javax.persistence.FetchType)1 JoinColumn (javax.persistence.JoinColumn)1 JoinColumns (javax.persistence.JoinColumns)1 JoinTable (javax.persistence.JoinTable)1 ManyToOne (javax.persistence.ManyToOne)1 MapKeyColumn (javax.persistence.MapKeyColumn)1 MapKeyJoinColumn (javax.persistence.MapKeyJoinColumn)1 MapKeyJoinColumns (javax.persistence.MapKeyJoinColumns)1