Search in sources :

Example 6 with SecondaryTable

use of javax.persistence.SecondaryTable in project CloudStack-archive by CloudStack-extras.

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) {
        addPrimaryKeyJoinColumns(innerJoin, tableName, st.name(), st.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)

Example 7 with SecondaryTable

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

the class DbUtil method getSecondaryTables.

public static final SecondaryTable[] getSecondaryTables(AnnotatedElement clazz) {
    SecondaryTable[] sts = null;
    SecondaryTable stAnnotation = clazz.getAnnotation(SecondaryTable.class);
    if (stAnnotation == null) {
        SecondaryTables stsAnnotation = clazz.getAnnotation(SecondaryTables.class);
        sts = stsAnnotation != null ? stsAnnotation.value() : new SecondaryTable[0];
    } else {
        sts = new SecondaryTable[] { stAnnotation };
    }
    return sts;
}
Also used : SecondaryTables(javax.persistence.SecondaryTables) SecondaryTable(javax.persistence.SecondaryTable)

Example 8 with SecondaryTable

use of javax.persistence.SecondaryTable 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

SecondaryTable (javax.persistence.SecondaryTable)8 SecondaryTables (javax.persistence.SecondaryTables)5 ArrayList (java.util.ArrayList)3 Entity (javax.persistence.Entity)3 PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)3 JoinTable (javax.persistence.JoinTable)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 AssociationOverrides (javax.persistence.AssociationOverrides)1 AttributeOverrides (javax.persistence.AttributeOverrides)1 DiscriminatorColumn (javax.persistence.DiscriminatorColumn)1 ExcludeDefaultListeners (javax.persistence.ExcludeDefaultListeners)1 ExcludeSuperclassListeners (javax.persistence.ExcludeSuperclassListeners)1 IdClass (javax.persistence.IdClass)1 Inheritance (javax.persistence.Inheritance)1 MappedSuperclass (javax.persistence.MappedSuperclass)1 NamedNativeQueries (javax.persistence.NamedNativeQueries)1 NamedQueries (javax.persistence.NamedQueries)1 PrimaryKeyJoinColumns (javax.persistence.PrimaryKeyJoinColumns)1 SequenceGenerator (javax.persistence.SequenceGenerator)1 SqlResultSetMappings (javax.persistence.SqlResultSetMappings)1