use of javax.persistence.PrimaryKeyJoinColumn in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getPrimaryKeyJoinColumns.
/**
* @param mergeWithAnnotations Whether to use Java annotations for this
* element, if present and not disabled by the XMLContext defaults.
* In some contexts (such as an association mapping) merging with
* annotations is never allowed.
*/
private PrimaryKeyJoinColumns getPrimaryKeyJoinColumns(Element element, XMLContext.Default defaults, boolean mergeWithAnnotations) {
PrimaryKeyJoinColumn[] columns = buildPrimaryKeyJoinColumns(element);
if (mergeWithAnnotations) {
if (columns.length == 0 && defaults.canUseJavaAnnotations()) {
PrimaryKeyJoinColumn annotation = getPhysicalAnnotation(PrimaryKeyJoinColumn.class);
if (annotation != null) {
columns = new PrimaryKeyJoinColumn[] { annotation };
} else {
PrimaryKeyJoinColumns annotations = getPhysicalAnnotation(PrimaryKeyJoinColumns.class);
columns = annotations != null ? annotations.value() : columns;
}
}
}
if (columns.length > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(PrimaryKeyJoinColumns.class);
ad.setValue("value", columns);
return AnnotationFactory.create(ad);
} else {
return null;
}
}
use of javax.persistence.PrimaryKeyJoinColumn in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildPrimaryKeyJoinColumns.
private PrimaryKeyJoinColumn[] buildPrimaryKeyJoinColumns(Element element) {
if (element == null) {
return new PrimaryKeyJoinColumn[] {};
}
List pkJoinColumnElementList = element.elements("primary-key-join-column");
PrimaryKeyJoinColumn[] pkJoinColumns = new PrimaryKeyJoinColumn[pkJoinColumnElementList.size()];
int index = 0;
Iterator pkIt = pkJoinColumnElementList.listIterator();
while (pkIt.hasNext()) {
Element subelement = (Element) pkIt.next();
AnnotationDescriptor pkAnn = new AnnotationDescriptor(PrimaryKeyJoinColumn.class);
copyStringAttribute(pkAnn, subelement, "name", false);
copyStringAttribute(pkAnn, subelement, "referenced-column-name", false);
copyStringAttribute(pkAnn, subelement, "column-definition", false);
pkJoinColumns[index++] = AnnotationFactory.create(pkAnn);
}
return pkJoinColumns;
}
use of javax.persistence.PrimaryKeyJoinColumn in project CloudStack-archive by CloudStack-extras.
the class SqlGenerator method handleDaoAttributes.
protected void handleDaoAttributes(Class<?> clazz) {
Attribute attr;
Class<?> current = clazz;
while (current != null && current.getAnnotation(Entity.class) != null) {
DiscriminatorColumn column = current.getAnnotation(DiscriminatorColumn.class);
if (column != null) {
String columnName = column.name();
attr = findAttribute(columnName);
if (attr != null) {
attr.setTrue(Attribute.Flag.DaoGenerated);
attr.setTrue(Attribute.Flag.Insertable);
attr.setTrue(Attribute.Flag.Updatable);
attr.setFalse(Attribute.Flag.Nullable);
attr.setTrue(Attribute.Flag.DC);
} else {
attr = new Attribute(DbUtil.getTableName(current), column.name());
attr.setFalse(Flag.Selectable);
attr.setTrue(Flag.Insertable);
attr.setTrue(Flag.DaoGenerated);
attr.setTrue(Flag.DC);
_attributes.add(attr);
}
if (column.discriminatorType() == DiscriminatorType.CHAR) {
attr.setTrue(Attribute.Flag.CharDT);
} else if (column.discriminatorType() == DiscriminatorType.STRING) {
attr.setTrue(Attribute.Flag.StringDT);
} else if (column.discriminatorType() == DiscriminatorType.INTEGER) {
attr.setTrue(Attribute.Flag.IntegerDT);
}
}
PrimaryKeyJoinColumn[] pkjcs = DbUtil.getPrimaryKeyJoinColumns(current);
if (pkjcs != null) {
for (PrimaryKeyJoinColumn pkjc : pkjcs) {
String tableName = DbUtil.getTableName(current);
attr = findAttribute(pkjc.name());
if (attr == null || !tableName.equals(attr.table)) {
Attribute id = new Attribute(DbUtil.getTableName(current), pkjc.name());
if (pkjc.referencedColumnName().length() > 0) {
attr = findAttribute(pkjc.referencedColumnName());
assert (attr != null) : "Couldn't find referenced column name " + pkjc.referencedColumnName();
}
id.field = attr.field;
id.setTrue(Flag.Id);
id.setTrue(Flag.Insertable);
id.setFalse(Flag.Updatable);
id.setFalse(Flag.Nullable);
id.setFalse(Flag.Selectable);
_attributes.add(id);
List<Attribute> attrs = _ids.get(id.table);
attrs.add(id);
}
}
}
current = current.getSuperclass();
}
attr = findAttribute(GenericDao.CREATED_COLUMN);
if (attr != null && attr.field.getType() == Date.class) {
attr.setTrue(Attribute.Flag.DaoGenerated);
attr.setTrue(Attribute.Flag.Insertable);
attr.setFalse(Attribute.Flag.Updatable);
attr.setFalse(Attribute.Flag.Date);
attr.setFalse(Attribute.Flag.Time);
attr.setTrue(Attribute.Flag.TimeStamp);
attr.setFalse(Attribute.Flag.Nullable);
attr.setTrue(Attribute.Flag.Created);
}
attr = findAttribute(GenericDao.XID_COLUMN);
if (attr != null && attr.field.getType() == String.class) {
attr.setTrue(Attribute.Flag.DaoGenerated);
attr.setTrue(Attribute.Flag.Insertable);
attr.setFalse(Attribute.Flag.Updatable);
attr.setFalse(Attribute.Flag.TimeStamp);
attr.setFalse(Attribute.Flag.Time);
attr.setFalse(Attribute.Flag.Date);
attr.setFalse(Attribute.Flag.Nullable);
attr.setFalse(Attribute.Flag.Removed);
}
}
use of javax.persistence.PrimaryKeyJoinColumn in project CloudStack-archive by CloudStack-extras.
the class SqlGenerator method addPrimaryKeyJoinColumns.
protected static void addPrimaryKeyJoinColumns(StringBuilder sql, String fromTable, String toTable, String joinType, PrimaryKeyJoinColumn[] pkjcs) {
if ("right".equalsIgnoreCase(joinType)) {
sql.append(" RIGHT JOIN ").append(toTable).append(" ON ");
} else if ("left".equalsIgnoreCase(joinType)) {
sql.append(" LEFT JOIN ").append(toTable).append(" ON ");
} else {
sql.append(" INNER JOIN ").append(toTable).append(" ON ");
}
for (PrimaryKeyJoinColumn pkjc : pkjcs) {
sql.append(fromTable).append(".").append(pkjc.name());
String refColumn = DbUtil.getReferenceColumn(pkjc);
sql.append("=").append(toTable).append(".").append(refColumn).append(" ");
}
}
use of javax.persistence.PrimaryKeyJoinColumn 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);
}
}
Aggregations