Search in sources :

Example 16 with PrimaryKeyJoinColumn

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

the class DbUtil method getPrimaryKeyJoinColumns.

public static PrimaryKeyJoinColumn[] getPrimaryKeyJoinColumns(Class<?> clazz) {
    PrimaryKeyJoinColumn pkjc = clazz.getAnnotation(PrimaryKeyJoinColumn.class);
    if (pkjc != null) {
        return new PrimaryKeyJoinColumn[] { pkjc };
    }
    PrimaryKeyJoinColumns pkjcs = clazz.getAnnotation(PrimaryKeyJoinColumns.class);
    if (pkjcs != null) {
        return pkjcs.value();
    }
    return null;
}
Also used : PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns)

Example 17 with PrimaryKeyJoinColumn

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

the class SqlGenerator method buildJoins.

protected static void buildJoins(StringBuilder innerJoin, Class<?> clazz) {
    String tableName = DbUtil.getTableName(clazz);
    SecondaryTable[] sts = DbUtil.getSecondaryTables(clazz);
    ArrayList<String> secondaryTables = new ArrayList<String>();
    for (SecondaryTable st : sts) {
        JoinType jt = clazz.getAnnotation(JoinType.class);
        String join = null;
        if (jt != null) {
            join = jt.type();
        }
        addPrimaryKeyJoinColumns(innerJoin, tableName, st.name(), join, st.pkJoinColumns());
        secondaryTables.add(st.name());
    }
    Class<?> parent = clazz.getSuperclass();
    if (parent.getAnnotation(Entity.class) != null) {
        String table = DbUtil.getTableName(parent);
        PrimaryKeyJoinColumn[] pkjcs = DbUtil.getPrimaryKeyJoinColumns(clazz);
        assert (pkjcs != null) : "No Join columns specified for the super class";
        addPrimaryKeyJoinColumns(innerJoin, tableName, table, null, pkjcs);
    }
}
Also used : Entity(javax.persistence.Entity) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) ArrayList(java.util.ArrayList) SecondaryTable(javax.persistence.SecondaryTable)

Aggregations

PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)17 PrimaryKeyJoinColumns (javax.persistence.PrimaryKeyJoinColumns)8 ArrayList (java.util.ArrayList)4 Entity (javax.persistence.Entity)4 DiscriminatorColumn (javax.persistence.DiscriminatorColumn)3 SecondaryTable (javax.persistence.SecondaryTable)3 Test (org.junit.Test)3 Date (java.util.Date)2 JoinColumn (javax.persistence.JoinColumn)2 JoinTable (javax.persistence.JoinTable)2 MappedSuperclass (javax.persistence.MappedSuperclass)2 Table (javax.persistence.Table)2 UniqueConstraint (javax.persistence.UniqueConstraint)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 AssociationOverrides (javax.persistence.AssociationOverrides)1 AttributeOverrides (javax.persistence.AttributeOverrides)1