HHH-7484 Separating the org.hibernate.metamodel.spi.source implementations from the model build in org.hibernate.metamodel.internal.source.annotations.entity and org.hibernate.metamodel.internal.source.annotations.attribute
This commit is contained in:
parent
ddaf155423
commit
eb7608cd1b
|
@ -21,7 +21,12 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
|
@ -21,9 +21,10 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import org.hibernate.TruthValue;
|
import org.hibernate.TruthValue;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.spi.relational.JdbcDataType;
|
import org.hibernate.metamodel.spi.relational.JdbcDataType;
|
||||||
import org.hibernate.metamodel.spi.relational.Size;
|
import org.hibernate.metamodel.spi.relational.Size;
|
||||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
import org.hibernate.metamodel.spi.source.ColumnSource;
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -32,13 +32,12 @@ import java.util.Map;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.internal.util.ValueHolder;
|
import org.hibernate.internal.util.ValueHolder;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableClass;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.SingularAttributeSourceImpl;
|
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.ToOneAttributeSourceImpl;
|
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSource;
|
import org.hibernate.metamodel.spi.source.AttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.ComponentAttributeSource;
|
import org.hibernate.metamodel.spi.source.ComponentAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
|
@ -21,8 +21,9 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.FormulaValue;
|
||||||
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
||||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
|
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
|
||||||
import org.hibernate.metamodel.spi.source.DiscriminatorSource;
|
import org.hibernate.metamodel.spi.source.DiscriminatorSource;
|
|
@ -42,8 +42,6 @@ import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
|
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntitySourceImpl;
|
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.SubclassEntitySourceImpl;
|
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
|
|
|
@ -21,14 +21,18 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
import org.jboss.jandex.AnnotationValue;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
import org.hibernate.cfg.NotYetImplementedException;
|
||||||
|
@ -37,9 +41,11 @@ import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAttributeSourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.SingularAttributeSourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.ToOneAttributeSourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.source.AttributeSource;
|
import org.hibernate.metamodel.spi.source.AttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.ConstraintSource;
|
import org.hibernate.metamodel.spi.source.ConstraintSource;
|
||||||
|
@ -48,6 +54,7 @@ import org.hibernate.metamodel.spi.source.JpaCallbackSource;
|
||||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
||||||
|
import org.hibernate.metamodel.spi.source.PrimaryKeyJoinColumnSource;
|
||||||
import org.hibernate.metamodel.spi.source.SecondaryTableSource;
|
import org.hibernate.metamodel.spi.source.SecondaryTableSource;
|
||||||
import org.hibernate.metamodel.spi.source.SubclassEntitySource;
|
import org.hibernate.metamodel.spi.source.SubclassEntitySource;
|
||||||
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
|
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
|
||||||
|
@ -105,7 +112,20 @@ public class EntitySourceImpl implements EntitySource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableSpecificationSource getPrimaryTable() {
|
public TableSpecificationSource getPrimaryTable() {
|
||||||
return entityClass.getPrimaryTableSource();
|
if ( !entityClass.definesItsOwnTable() ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( entityClass.hostsAnnotation( HibernateDotNames.SUB_SELECT ) ) {
|
||||||
|
return new InLineViewSourceImpl( entityClass );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AnnotationInstance tableAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
|
entityClass.getClassInfo(),
|
||||||
|
JPADotNames.TABLE
|
||||||
|
);
|
||||||
|
return new TableSourceImpl( tableAnnotation );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -243,7 +263,46 @@ public class EntitySourceImpl implements EntitySource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<ConstraintSource> getConstraints() {
|
public Iterable<ConstraintSource> getConstraints() {
|
||||||
return entityClass.getConstraintSources();
|
Set<ConstraintSource> constraintSources = new HashSet<ConstraintSource>();
|
||||||
|
|
||||||
|
// primary table
|
||||||
|
if ( entityClass.hostsAnnotation( JPADotNames.TABLE ) ) {
|
||||||
|
AnnotationInstance table = JandexHelper.getSingleAnnotation(
|
||||||
|
entityClass.getClassInfo(),
|
||||||
|
JPADotNames.TABLE
|
||||||
|
);
|
||||||
|
addUniqueConstraints( constraintSources, table, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
// secondary table(s)
|
||||||
|
if ( entityClass.hostsAnnotation( JPADotNames.SECONDARY_TABLE ) ) {
|
||||||
|
AnnotationInstance secondaryTable = JandexHelper.getSingleAnnotation(
|
||||||
|
entityClass.getClassInfo(),
|
||||||
|
JPADotNames.SECONDARY_TABLE
|
||||||
|
);
|
||||||
|
String tableName = JandexHelper.getValue( secondaryTable, "name", String.class );
|
||||||
|
addUniqueConstraints( constraintSources, secondaryTable, tableName );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( entityClass.hostsAnnotation( JPADotNames.SECONDARY_TABLES ) ) {
|
||||||
|
AnnotationInstance secondaryTables = JandexHelper.getSingleAnnotation(
|
||||||
|
entityClass.getClassInfo(),
|
||||||
|
JPADotNames.SECONDARY_TABLES
|
||||||
|
);
|
||||||
|
if ( secondaryTables != null ) {
|
||||||
|
for ( AnnotationInstance secondaryTable : JandexHelper.getValue(
|
||||||
|
secondaryTables,
|
||||||
|
"value",
|
||||||
|
AnnotationInstance[].class
|
||||||
|
) ) {
|
||||||
|
String tableName = JandexHelper.getValue( secondaryTable, "name", String.class );
|
||||||
|
addUniqueConstraints( constraintSources, secondaryTable, tableName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return constraintSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -253,7 +312,38 @@ public class EntitySourceImpl implements EntitySource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<SecondaryTableSource> getSecondaryTables() {
|
public Set<SecondaryTableSource> getSecondaryTables() {
|
||||||
return entityClass.getSecondaryTableSources();
|
Set<SecondaryTableSource> secondaryTableSources = new HashSet<SecondaryTableSource>();
|
||||||
|
|
||||||
|
// process a singular @SecondaryTable annotation
|
||||||
|
if ( entityClass.hostsAnnotation( JPADotNames.SECONDARY_TABLE ) ) {
|
||||||
|
AnnotationInstance secondaryTable = JandexHelper.getSingleAnnotation(
|
||||||
|
entityClass.getClassInfo(),
|
||||||
|
JPADotNames.SECONDARY_TABLE
|
||||||
|
);
|
||||||
|
if ( secondaryTable != null ) {
|
||||||
|
secondaryTableSources.add( createSecondaryTableSource( secondaryTable ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// process any @SecondaryTables grouping
|
||||||
|
if ( entityClass.hostsAnnotation( JPADotNames.SECONDARY_TABLES ) ) {
|
||||||
|
AnnotationInstance secondaryTables = JandexHelper.getSingleAnnotation(
|
||||||
|
entityClass.getClassInfo(),
|
||||||
|
JPADotNames.SECONDARY_TABLES
|
||||||
|
);
|
||||||
|
if ( secondaryTables != null ) {
|
||||||
|
AnnotationInstance[] tableAnnotations = JandexHelper.getValue(
|
||||||
|
secondaryTables,
|
||||||
|
"value",
|
||||||
|
AnnotationInstance[].class
|
||||||
|
);
|
||||||
|
for ( AnnotationInstance secondaryTable : tableAnnotations ) {
|
||||||
|
secondaryTableSources.add( createSecondaryTableSource( secondaryTable ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return secondaryTableSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -283,6 +373,46 @@ public class EntitySourceImpl implements EntitySource {
|
||||||
throw new AnnotationException( "Use of the same entity name twice: " + getJpaEntityName(), e );
|
throw new AnnotationException( "Use of the same entity name twice: " + getJpaEntityName(), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addUniqueConstraints(Set<ConstraintSource> constraintSources, AnnotationInstance tableAnnotation, String tableName) {
|
||||||
|
final AnnotationValue value = tableAnnotation.value( "uniqueConstraints" );
|
||||||
|
if ( value == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final AnnotationInstance[] uniqueConstraints = value.asNestedArray();
|
||||||
|
for ( final AnnotationInstance unique : uniqueConstraints ) {
|
||||||
|
final String name = unique.value( "name" ) == null ? null : unique.value( "name" ).asString();
|
||||||
|
final String[] columnNames = unique.value( "columnNames" ).asStringArray();
|
||||||
|
final UniqueConstraintSourceImpl uniqueConstraintSource =
|
||||||
|
new UniqueConstraintSourceImpl(
|
||||||
|
name, tableName, Arrays.asList( columnNames )
|
||||||
|
);
|
||||||
|
constraintSources.add( uniqueConstraintSource );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SecondaryTableSource createSecondaryTableSource(AnnotationInstance tableAnnotation) {
|
||||||
|
final List<PrimaryKeyJoinColumnSource> keys = collectionSecondaryTableKeys( tableAnnotation );
|
||||||
|
return new SecondaryTableSourceImpl( new TableSourceImpl( tableAnnotation ), keys );
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PrimaryKeyJoinColumnSource> collectionSecondaryTableKeys(final AnnotationInstance tableAnnotation) {
|
||||||
|
final AnnotationInstance[] joinColumnAnnotations = JandexHelper.getValue(
|
||||||
|
tableAnnotation,
|
||||||
|
"pkJoinColumns",
|
||||||
|
AnnotationInstance[].class
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( joinColumnAnnotations == null ) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
final List<PrimaryKeyJoinColumnSource> keys = new ArrayList<PrimaryKeyJoinColumnSource>();
|
||||||
|
for ( final AnnotationInstance joinColumnAnnotation : joinColumnAnnotations ) {
|
||||||
|
keys.add( new PrimaryKeyJoinColumnSourceImpl( joinColumnAnnotation ) );
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
|
import org.hibernate.metamodel.spi.source.InLineViewSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class InLineViewSourceImpl implements InLineViewSource {
|
||||||
|
private final InlineViewInfo inlineViewInfo;
|
||||||
|
|
||||||
|
public InLineViewSourceImpl(EntityClass entityClass) {
|
||||||
|
this.inlineViewInfo = createInlineViewInfo( entityClass );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSelectStatement() {
|
||||||
|
return inlineViewInfo.getSelectStatement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExplicitSchemaName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExplicitCatalogName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLogicalName() {
|
||||||
|
return inlineViewInfo.getLogicalName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private InlineViewInfo createInlineViewInfo(EntityClass entityClass) {
|
||||||
|
AnnotationInstance subselectAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
|
entityClass.getClassInfo(),
|
||||||
|
HibernateDotNames.SUB_SELECT
|
||||||
|
);
|
||||||
|
|
||||||
|
return new InlineViewInfo(
|
||||||
|
JandexHelper.getValue( subselectAnnotation, "value", String.class ),
|
||||||
|
entityClass.getEntityName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class InlineViewInfo {
|
||||||
|
private final String selectStatement;
|
||||||
|
private final String logicalName;
|
||||||
|
|
||||||
|
private InlineViewInfo(String selectStatement, String logicalName) {
|
||||||
|
this.selectStatement = selectStatement;
|
||||||
|
this.logicalName = logicalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectStatement() {
|
||||||
|
return selectStatement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogicalName() {
|
||||||
|
return logicalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if ( this == o ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( o == null || getClass() != o.getClass() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
InlineViewInfo that = ( InlineViewInfo ) o;
|
||||||
|
|
||||||
|
if ( logicalName != null ? !logicalName.equals( that.logicalName ) : that.logicalName != null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( selectStatement != null ? !selectStatement.equals( that.selectStatement ) : that.selectStatement != null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = selectStatement != null ? selectStatement.hashCode() : 0;
|
||||||
|
result = 31 * result + ( logicalName != null ? logicalName.hashCode() : 0 );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class JpaCallbackSourceImpl implements JpaCallbackSource {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final boolean isListener;
|
private final boolean isListener;
|
||||||
|
|
||||||
JpaCallbackSourceImpl(String name,
|
public JpaCallbackSourceImpl(String name,
|
||||||
Map<Class<?>, String> callbacksByType,
|
Map<Class<?>, String> callbacksByType,
|
||||||
boolean isListener) {
|
boolean isListener) {
|
||||||
this.name = name;
|
this.name = name;
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -29,6 +29,8 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
||||||
import org.hibernate.metamodel.spi.binding.CascadeType;
|
import org.hibernate.metamodel.spi.binding.CascadeType;
|
||||||
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
|
import org.hibernate.metamodel.spi.source.ManyToManyPluralAttributeElementSource;
|
||||||
import org.hibernate.metamodel.spi.source.PluralAttributeElementNature;
|
import org.hibernate.metamodel.spi.source.PluralAttributeElementNature;
|
|
@ -21,10 +21,12 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.FormulaValue;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,6 +32,7 @@ import org.hibernate.FetchMode;
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
|
import org.hibernate.metamodel.spi.source.PrimaryKeyJoinColumnSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class PrimaryKeyJoinColumnSourceImpl implements PrimaryKeyJoinColumnSource {
|
||||||
|
private final String columnName;
|
||||||
|
private final String referencedColumnName;
|
||||||
|
private final String columnDefinition;
|
||||||
|
|
||||||
|
PrimaryKeyJoinColumnSourceImpl(AnnotationInstance joinColumnAnnotation) {
|
||||||
|
this(
|
||||||
|
JandexHelper.getValue( joinColumnAnnotation, "name", String.class ),
|
||||||
|
JandexHelper.getValue( joinColumnAnnotation, "referencedColumnName", String.class ),
|
||||||
|
JandexHelper.getValue( joinColumnAnnotation, "columnDefinition", String.class )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrimaryKeyJoinColumnSourceImpl(
|
||||||
|
String columnName,
|
||||||
|
String referencedColumnName,
|
||||||
|
String columnDefinition) {
|
||||||
|
this.columnName = columnName;
|
||||||
|
this.referencedColumnName = referencedColumnName;
|
||||||
|
this.columnDefinition = columnDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName() {
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getReferencedColumnName() {
|
||||||
|
return referencedColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnDefinition() {
|
||||||
|
return columnDefinition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -37,11 +37,10 @@ import org.hibernate.engine.OptimisticLockStyle;
|
||||||
import org.hibernate.id.EntityIdentifierNature;
|
import org.hibernate.id.EntityIdentifierNature;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.DiscriminatorSourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.MutliTenancySourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.SimpleIdentifierSourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.entity.IdType;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.SingularAttributeSourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.VersionAttributeSourceImpl;
|
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -21,12 +21,14 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.id.EntityIdentifierNature;
|
import org.hibernate.id.EntityIdentifierNature;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
|
||||||
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
||||||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
|
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
|
|
@ -21,13 +21,16 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.attribute.type.ExplicitHibernateTypeSourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.attribute.type.ExplicitHibernateTypeSourceImpl;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
|
@ -21,8 +21,9 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||||
import org.hibernate.metamodel.spi.source.EntitySource;
|
import org.hibernate.metamodel.spi.source.EntitySource;
|
||||||
import org.hibernate.metamodel.spi.source.SubclassEntitySource;
|
import org.hibernate.metamodel.spi.source.SubclassEntitySource;
|
||||||
|
|
|
@ -0,0 +1,180 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
|
import org.hibernate.metamodel.spi.source.TableSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
class TableSourceImpl implements TableSource {
|
||||||
|
private final TableInfo tableInfo;
|
||||||
|
|
||||||
|
TableSourceImpl(AnnotationInstance tableAnnotation) {
|
||||||
|
this.tableInfo = createTableInfo( tableAnnotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExplicitSchemaName() {
|
||||||
|
return tableInfo.getSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExplicitCatalogName() {
|
||||||
|
return tableInfo.getCatalog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExplicitTableName() {
|
||||||
|
return tableInfo.getTableName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if ( this == o ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( o == null || getClass() != o.getClass() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TableSourceImpl that = ( TableSourceImpl ) o;
|
||||||
|
|
||||||
|
if ( tableInfo != null ? !tableInfo.equals( that.tableInfo ) : that.tableInfo != null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return tableInfo != null ? tableInfo.hashCode() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TableInfo createTableInfo(AnnotationInstance tableAnnotation) {
|
||||||
|
if ( tableAnnotation != null ) {
|
||||||
|
return createPrimaryTableInfo( tableAnnotation );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new TableInfo( null, null, null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TableInfo createPrimaryTableInfo(AnnotationInstance tableAnnotation) {
|
||||||
|
final String schemaName = determineSchemaName( tableAnnotation );
|
||||||
|
final String catalogName = determineCatalogName( tableAnnotation );
|
||||||
|
|
||||||
|
final String explicitTableName = tableAnnotation == null
|
||||||
|
? null
|
||||||
|
: JandexHelper.getValue( tableAnnotation, "name", String.class );
|
||||||
|
|
||||||
|
return new TableInfo( schemaName, catalogName, explicitTableName );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String determineSchemaName(AnnotationInstance tableAnnotation) {
|
||||||
|
return tableAnnotation == null
|
||||||
|
? null
|
||||||
|
: JandexHelper.getValue( tableAnnotation, "schema", String.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String determineCatalogName(AnnotationInstance tableAnnotation) {
|
||||||
|
return tableAnnotation == null
|
||||||
|
? null
|
||||||
|
: JandexHelper.getValue( tableAnnotation, "catalog", String.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TableInfo {
|
||||||
|
private final String schema;
|
||||||
|
private final String catalog;
|
||||||
|
private final String tableName;
|
||||||
|
|
||||||
|
private TableInfo(String schema, String catalog, String tableName) {
|
||||||
|
this.schema = schema;
|
||||||
|
this.catalog = catalog;
|
||||||
|
this.tableName = tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSchema() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCatalog() {
|
||||||
|
return catalog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTableName() {
|
||||||
|
return tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if ( this == o ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( o == null || getClass() != o.getClass() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TableInfo tableInfo = ( TableInfo ) o;
|
||||||
|
|
||||||
|
if ( catalog != null ? !catalog.equals( tableInfo.catalog ) : tableInfo.catalog != null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( schema != null ? !schema.equals( tableInfo.schema ) : tableInfo.schema != null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( tableName != null ? !tableName.equals( tableInfo.tableName ) : tableInfo.tableName != null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = schema != null ? schema.hashCode() : 0;
|
||||||
|
result = 31 * result + ( catalog != null ? catalog.hashCode() : 0 );
|
||||||
|
result = 31 * result + ( tableName != null ? tableName.hashCode() : 0 );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append( "TableInfo" );
|
||||||
|
sb.append( "{schema='" ).append( schema ).append( '\'' );
|
||||||
|
sb.append( ", catalog='" ).append( catalog ).append( '\'' );
|
||||||
|
sb.append( ", tableName='" ).append( tableName ).append( '\'' );
|
||||||
|
sb.append( '}' );
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -33,10 +33,11 @@ import org.hibernate.FetchMode;
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.engine.spi.CascadeStyle;
|
import org.hibernate.engine.spi.CascadeStyle;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
|
||||||
import org.hibernate.metamodel.spi.relational.Value;
|
import org.hibernate.metamodel.spi.relational.Value;
|
||||||
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
|
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
|
||||||
import org.hibernate.metamodel.spi.source.SingularAttributeNature;
|
import org.hibernate.metamodel.spi.source.SingularAttributeNature;
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -21,8 +21,10 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
package org.hibernate.metamodel.internal.source.annotations;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute;
|
||||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.source.VersionAttributeSource;
|
import org.hibernate.metamodel.spi.source.VersionAttributeSource;
|
||||||
|
|
|
@ -178,6 +178,16 @@ public class ConfiguredClass {
|
||||||
return localBindingContext;
|
return localBindingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hostsAnnotation(DotName annotationName) {
|
||||||
|
List<AnnotationInstance> annotationList = classInfo.annotations().get( annotationName );
|
||||||
|
if ( annotationList == null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return annotationList.size() > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<BasicAttribute> getSimpleAttributes() {
|
public Collection<BasicAttribute> getSimpleAttributes() {
|
||||||
return simpleAttributeMap.values();
|
return simpleAttributeMap.values();
|
||||||
}
|
}
|
||||||
|
@ -328,12 +338,12 @@ public class ConfiguredClass {
|
||||||
if ( annotationTarget instanceof MethodInfo ) {
|
if ( annotationTarget instanceof MethodInfo ) {
|
||||||
Method m;
|
Method m;
|
||||||
try {
|
try {
|
||||||
m = clazz.getMethod( ( (MethodInfo) annotationTarget ).name() );
|
m = clazz.getMethod( ( ( MethodInfo ) annotationTarget ).name() );
|
||||||
}
|
}
|
||||||
catch ( NoSuchMethodException e ) {
|
catch ( NoSuchMethodException e ) {
|
||||||
throw new HibernateException(
|
throw new HibernateException(
|
||||||
"Unable to load method "
|
"Unable to load method "
|
||||||
+ ( (MethodInfo) annotationTarget ).name()
|
+ ( ( MethodInfo ) annotationTarget ).name()
|
||||||
+ " of class " + clazz.getName()
|
+ " of class " + clazz.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -343,12 +353,12 @@ public class ConfiguredClass {
|
||||||
else {
|
else {
|
||||||
Field f;
|
Field f;
|
||||||
try {
|
try {
|
||||||
f = clazz.getField( ( (FieldInfo) annotationTarget ).name() );
|
f = clazz.getField( ( ( FieldInfo ) annotationTarget ).name() );
|
||||||
}
|
}
|
||||||
catch ( NoSuchFieldException e ) {
|
catch ( NoSuchFieldException e ) {
|
||||||
throw new HibernateException(
|
throw new HibernateException(
|
||||||
"Unable to load field "
|
"Unable to load field "
|
||||||
+ ( (FieldInfo) annotationTarget ).name()
|
+ ( ( FieldInfo ) annotationTarget ).name()
|
||||||
+ " of class " + clazz.getName()
|
+ " of class " + clazz.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -412,8 +422,9 @@ public class ConfiguredClass {
|
||||||
|
|
||||||
private void createMappedAttribute(Member member, ResolvedTypeWithMembers resolvedType, AccessType accessType) {
|
private void createMappedAttribute(Member member, ResolvedTypeWithMembers resolvedType, AccessType accessType) {
|
||||||
final String attributeName = ReflectionHelper.getPropertyName( member );
|
final String attributeName = ReflectionHelper.getPropertyName( member );
|
||||||
final ResolvedMember[] resolvedMembers = Field.class.isInstance( member ) ? resolvedType.getMemberFields() : resolvedType.getMemberMethods();
|
final ResolvedMember[] resolvedMembers = Field.class.isInstance( member ) ? resolvedType.getMemberFields() : resolvedType
|
||||||
Class<?> attributeType = (Class<?>) findResolvedType( member.getName(), resolvedMembers );
|
.getMemberMethods();
|
||||||
|
Class<?> attributeType = ( Class<?> ) findResolvedType( member.getName(), resolvedMembers );
|
||||||
final Map<DotName, List<AnnotationInstance>> annotations = JandexHelper.getMemberAnnotations(
|
final Map<DotName, List<AnnotationInstance>> annotations = JandexHelper.getMemberAnnotations(
|
||||||
classInfo, member.getName()
|
classInfo, member.getName()
|
||||||
);
|
);
|
||||||
|
@ -423,7 +434,12 @@ public class ConfiguredClass {
|
||||||
switch ( attributeNature ) {
|
switch ( attributeNature ) {
|
||||||
case BASIC: {
|
case BASIC: {
|
||||||
BasicAttribute attribute = BasicAttribute.createSimpleAttribute(
|
BasicAttribute attribute = BasicAttribute.createSimpleAttribute(
|
||||||
attributeName, attributeType, attributeNature, annotations, accessTypeString, getLocalBindingContext()
|
attributeName,
|
||||||
|
attributeType,
|
||||||
|
attributeNature,
|
||||||
|
annotations,
|
||||||
|
accessTypeString,
|
||||||
|
getLocalBindingContext()
|
||||||
);
|
);
|
||||||
if ( attribute.isId() ) {
|
if ( attribute.isId() ) {
|
||||||
idAttributeMap.put( attributeName, attribute );
|
idAttributeMap.put( attributeName, attribute );
|
||||||
|
@ -446,7 +462,12 @@ public class ConfiguredClass {
|
||||||
}
|
}
|
||||||
case EMBEDDED_ID: {
|
case EMBEDDED_ID: {
|
||||||
final BasicAttribute attribute = BasicAttribute.createSimpleAttribute(
|
final BasicAttribute attribute = BasicAttribute.createSimpleAttribute(
|
||||||
attributeName, attributeType, attributeNature, annotations, accessTypeString, getLocalBindingContext()
|
attributeName,
|
||||||
|
attributeType,
|
||||||
|
attributeNature,
|
||||||
|
annotations,
|
||||||
|
accessTypeString,
|
||||||
|
getLocalBindingContext()
|
||||||
);
|
);
|
||||||
idAttributeMap.put( attributeName, attribute );
|
idAttributeMap.put( attributeName, attribute );
|
||||||
}
|
}
|
||||||
|
@ -584,7 +605,7 @@ public class ConfiguredClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = discoveredAttributeTypes.size();
|
int size = discoveredAttributeTypes.size();
|
||||||
switch ( size ){
|
switch ( size ) {
|
||||||
case 0:
|
case 0:
|
||||||
return AttributeNature.BASIC;
|
return AttributeNature.BASIC;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -621,10 +642,10 @@ public class ConfiguredClass {
|
||||||
for ( AnnotationInstance transientMember : transientMembers ) {
|
for ( AnnotationInstance transientMember : transientMembers ) {
|
||||||
AnnotationTarget target = transientMember.target();
|
AnnotationTarget target = transientMember.target();
|
||||||
if ( target instanceof FieldInfo ) {
|
if ( target instanceof FieldInfo ) {
|
||||||
transientFieldNames.add( ( (FieldInfo) target ).name() );
|
transientFieldNames.add( ( ( FieldInfo ) target ).name() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
transientMethodNames.add( ( (MethodInfo) target ).name() );
|
transientMethodNames.add( ( ( MethodInfo ) target ).name() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import javax.persistence.PostLoad;
|
import javax.persistence.PostLoad;
|
||||||
|
@ -56,6 +54,7 @@ import org.hibernate.annotations.PolymorphismType;
|
||||||
import org.hibernate.engine.OptimisticLockStyle;
|
import org.hibernate.engine.OptimisticLockStyle;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
|
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.JpaCallbackSourceImpl;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.AnnotationParserHelper;
|
import org.hibernate.metamodel.internal.source.annotations.util.AnnotationParserHelper;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
|
import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||||
|
@ -64,11 +63,7 @@ import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
import org.hibernate.metamodel.spi.source.ConstraintSource;
|
|
||||||
import org.hibernate.metamodel.spi.source.JpaCallbackSource;
|
import org.hibernate.metamodel.spi.source.JpaCallbackSource;
|
||||||
import org.hibernate.metamodel.spi.source.PrimaryKeyJoinColumnSource;
|
|
||||||
import org.hibernate.metamodel.spi.source.SecondaryTableSource;
|
|
||||||
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an entity or mapped superclass configured via annotations/orm-xml.
|
* Represents an entity or mapped superclass configured via annotations/orm-xml.
|
||||||
|
@ -85,10 +80,6 @@ public class EntityClass extends ConfiguredClass {
|
||||||
private final List<String> synchronizedTableNames;
|
private final List<String> synchronizedTableNames;
|
||||||
private final int batchSize;
|
private final int batchSize;
|
||||||
|
|
||||||
private final TableSpecificationSource primaryTableSource;
|
|
||||||
private final Set<SecondaryTableSource> secondaryTableSources;
|
|
||||||
private final Set<ConstraintSource> constraintSources;
|
|
||||||
|
|
||||||
private boolean isMutable;
|
private boolean isMutable;
|
||||||
private boolean isExplicitPolymorphism;
|
private boolean isExplicitPolymorphism;
|
||||||
private OptimisticLockStyle optimisticLockStyle;
|
private OptimisticLockStyle optimisticLockStyle;
|
||||||
|
@ -130,14 +121,7 @@ public class EntityClass extends ConfiguredClass {
|
||||||
super( classInfo, hierarchyAccessType, parent, context );
|
super( classInfo, hierarchyAccessType, parent, context );
|
||||||
this.inheritanceType = inheritanceType;
|
this.inheritanceType = inheritanceType;
|
||||||
|
|
||||||
final boolean hasOwnTable = definesItsOwnTable();
|
|
||||||
|
|
||||||
this.explicitEntityName = determineExplicitEntityName();
|
this.explicitEntityName = determineExplicitEntityName();
|
||||||
|
|
||||||
this.constraintSources = new HashSet<ConstraintSource>();
|
|
||||||
this.primaryTableSource = hasOwnTable ? createPrimaryTableSource() : null;
|
|
||||||
this.secondaryTableSources = createSecondaryTableSources();
|
|
||||||
|
|
||||||
this.customLoaderQueryName = determineCustomLoader();
|
this.customLoaderQueryName = determineCustomLoader();
|
||||||
this.synchronizedTableNames = determineSynchronizedTableNames();
|
this.synchronizedTableNames = determineSynchronizedTableNames();
|
||||||
this.batchSize = determineBatchSize();
|
this.batchSize = determineBatchSize();
|
||||||
|
@ -189,19 +173,6 @@ public class EntityClass extends ConfiguredClass {
|
||||||
return naturalIdCaching;
|
return naturalIdCaching;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableSpecificationSource getPrimaryTableSource() {
|
|
||||||
// todo : this is different from hbm which returns null if "!definesItsOwnTable()"
|
|
||||||
return definesItsOwnTable() ? primaryTableSource : ( ( EntityClass ) getParent() ).getPrimaryTableSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<SecondaryTableSource> getSecondaryTableSources() {
|
|
||||||
return secondaryTableSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<ConstraintSource> getConstraintSources() {
|
|
||||||
return constraintSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExplicitEntityName() {
|
public String getExplicitEntityName() {
|
||||||
return explicitEntityName;
|
return explicitEntityName;
|
||||||
}
|
}
|
||||||
|
@ -270,6 +241,10 @@ public class EntityClass extends ConfiguredClass {
|
||||||
return jpaCallbacks;
|
return jpaCallbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean definesItsOwnTable() {
|
||||||
|
return !InheritanceType.SINGLE_TABLE.equals( inheritanceType ) || isEntityRoot();
|
||||||
|
}
|
||||||
|
|
||||||
private String determineExplicitEntityName() {
|
private String determineExplicitEntityName() {
|
||||||
final AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation(
|
final AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
getClassInfo(), JPADotNames.ENTITY
|
getClassInfo(), JPADotNames.ENTITY
|
||||||
|
@ -278,10 +253,6 @@ public class EntityClass extends ConfiguredClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean definesItsOwnTable() {
|
|
||||||
return !InheritanceType.SINGLE_TABLE.equals( inheritanceType ) || isEntityRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processDiscriminatorValue() {
|
private void processDiscriminatorValue() {
|
||||||
final AnnotationInstance discriminatorValueAnnotation = JandexHelper.getSingleAnnotation(
|
final AnnotationInstance discriminatorValueAnnotation = JandexHelper.getSingleAnnotation(
|
||||||
getClassInfo(), JPADotNames.DISCRIMINATOR_VALUE
|
getClassInfo(), JPADotNames.DISCRIMINATOR_VALUE
|
||||||
|
@ -458,185 +429,12 @@ public class EntityClass extends ConfiguredClass {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TableSpecificationSource createPrimaryTableSource() {
|
|
||||||
AnnotationInstance tableAnnotation = JandexHelper.getSingleAnnotation(
|
|
||||||
getClassInfo(),
|
|
||||||
JPADotNames.TABLE
|
|
||||||
);
|
|
||||||
AnnotationInstance subselectAnnotation = JandexHelper.getSingleAnnotation(
|
|
||||||
getClassInfo(),
|
|
||||||
JPADotNames.SUBSELECT
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( tableAnnotation != null ) {
|
|
||||||
return createPrimaryTableSourceAsTable( tableAnnotation );
|
|
||||||
}
|
|
||||||
else if ( subselectAnnotation != null ) {
|
|
||||||
return createPrimaryTableSourceAsInLineView( subselectAnnotation );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return new TableSourceImpl( null, null, null );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableSpecificationSource createPrimaryTableSourceAsTable(AnnotationInstance tableAnnotation) {
|
|
||||||
final String schemaName = determineSchemaName( tableAnnotation );
|
|
||||||
final String catalogName = determineCatalogName( tableAnnotation );
|
|
||||||
|
|
||||||
final String explicitTableName = tableAnnotation == null
|
|
||||||
? null
|
|
||||||
: JandexHelper.getValue( tableAnnotation, "name", String.class );
|
|
||||||
|
|
||||||
if ( tableAnnotation != null ) {
|
|
||||||
createUniqueConstraints( tableAnnotation, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TableSourceImpl( schemaName, catalogName, explicitTableName );
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableSpecificationSource createPrimaryTableSourceAsInLineView(AnnotationInstance subselectAnnotation) {
|
|
||||||
return new InLineViewSourceImpl(
|
|
||||||
JandexHelper.getValue( subselectAnnotation, "value", String.class ),
|
|
||||||
getEntityName()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String determineSchemaName(AnnotationInstance tableAnnotation) {
|
|
||||||
return tableAnnotation == null
|
|
||||||
? null
|
|
||||||
: JandexHelper.getValue( tableAnnotation, "schema", String.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
private String determineCatalogName(AnnotationInstance tableAnnotation) {
|
|
||||||
return tableAnnotation == null
|
|
||||||
? null
|
|
||||||
: JandexHelper.getValue( tableAnnotation, "catalog", String.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createUniqueConstraints(AnnotationInstance tableAnnotation, String tableName) {
|
|
||||||
final AnnotationValue value = tableAnnotation.value( "uniqueConstraints" );
|
|
||||||
if ( value == null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final AnnotationInstance[] uniqueConstraints = value.asNestedArray();
|
|
||||||
for ( final AnnotationInstance unique : uniqueConstraints ) {
|
|
||||||
final String name = unique.value( "name" ) == null ? null : unique.value( "name" ).asString();
|
|
||||||
final String[] columnNames = unique.value( "columnNames" ).asStringArray();
|
|
||||||
final UniqueConstraintSourceImpl uniqueConstraintSource =
|
|
||||||
new UniqueConstraintSourceImpl(
|
|
||||||
name, tableName, Arrays.asList( columnNames )
|
|
||||||
);
|
|
||||||
constraintSources.add( uniqueConstraintSource );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<SecondaryTableSource> createSecondaryTableSources() {
|
|
||||||
final Set<SecondaryTableSource> secondaryTableSources = new HashSet<SecondaryTableSource>();
|
|
||||||
|
|
||||||
// process a singular @SecondaryTable annotation
|
|
||||||
{
|
|
||||||
AnnotationInstance secondaryTable = JandexHelper.getSingleAnnotation(
|
|
||||||
getClassInfo(),
|
|
||||||
JPADotNames.SECONDARY_TABLE
|
|
||||||
);
|
|
||||||
if ( secondaryTable != null ) {
|
|
||||||
secondaryTableSources.add( createSecondaryTableSource( secondaryTable ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// process any @SecondaryTables grouping
|
|
||||||
{
|
|
||||||
AnnotationInstance secondaryTables = JandexHelper.getSingleAnnotation(
|
|
||||||
getClassInfo(),
|
|
||||||
JPADotNames.SECONDARY_TABLES
|
|
||||||
);
|
|
||||||
if ( secondaryTables != null ) {
|
|
||||||
for ( AnnotationInstance secondaryTable : JandexHelper.getValue(
|
|
||||||
secondaryTables,
|
|
||||||
"value",
|
|
||||||
AnnotationInstance[].class
|
|
||||||
) ) {
|
|
||||||
secondaryTableSources.add( createSecondaryTableSource( secondaryTable ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return secondaryTableSources;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SecondaryTableSource createSecondaryTableSource(AnnotationInstance tableAnnotation) {
|
|
||||||
final String schemaName = determineSchemaName( tableAnnotation );
|
|
||||||
final String catalogName = determineCatalogName( tableAnnotation );
|
|
||||||
final String tableName = JandexHelper.getValue( tableAnnotation, "name", String.class );
|
|
||||||
|
|
||||||
createUniqueConstraints( tableAnnotation, tableName );
|
|
||||||
|
|
||||||
final List<PrimaryKeyJoinColumnSource> keys = collectionSecondaryTableKeys( tableAnnotation );
|
|
||||||
return new SecondaryTableSourceImpl( new TableSourceImpl( schemaName, catalogName, tableName ), keys );
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<PrimaryKeyJoinColumnSource> collectionSecondaryTableKeys(final AnnotationInstance tableAnnotation) {
|
|
||||||
final AnnotationInstance[] joinColumnAnnotations = JandexHelper.getValue(
|
|
||||||
tableAnnotation,
|
|
||||||
"pkJoinColumns",
|
|
||||||
AnnotationInstance[].class
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( joinColumnAnnotations == null ) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
final List<PrimaryKeyJoinColumnSource> keys = new ArrayList<PrimaryKeyJoinColumnSource>();
|
|
||||||
for ( final AnnotationInstance joinColumnAnnotation : joinColumnAnnotations ) {
|
|
||||||
keys.add( new PrimaryKeyJoinColumnSourceImpl( joinColumnAnnotation ) );
|
|
||||||
}
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasMultiTenancySourceInformation() {
|
public boolean hasMultiTenancySourceInformation() {
|
||||||
return JandexHelper.getSingleAnnotation( getClassInfo(), HibernateDotNames.MULTI_TENANT ) != null
|
return JandexHelper.getSingleAnnotation( getClassInfo(), HibernateDotNames.MULTI_TENANT ) != null
|
||||||
|| JandexHelper.getSingleAnnotation( getClassInfo(), HibernateDotNames.TENANT_COLUMN ) != null
|
|| JandexHelper.getSingleAnnotation( getClassInfo(), HibernateDotNames.TENANT_COLUMN ) != null
|
||||||
|| JandexHelper.getSingleAnnotation( getClassInfo(), HibernateDotNames.TENANT_FORMULA ) != null;
|
|| JandexHelper.getSingleAnnotation( getClassInfo(), HibernateDotNames.TENANT_FORMULA ) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class PrimaryKeyJoinColumnSourceImpl implements PrimaryKeyJoinColumnSource {
|
|
||||||
private final String columnName;
|
|
||||||
private final String referencedColumnName;
|
|
||||||
private final String columnDefinition;
|
|
||||||
|
|
||||||
private PrimaryKeyJoinColumnSourceImpl(AnnotationInstance joinColumnAnnotation) {
|
|
||||||
this(
|
|
||||||
JandexHelper.getValue( joinColumnAnnotation, "name", String.class ),
|
|
||||||
JandexHelper.getValue( joinColumnAnnotation, "referencedColumnName", String.class ),
|
|
||||||
JandexHelper.getValue( joinColumnAnnotation, "columnDefinition", String.class )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PrimaryKeyJoinColumnSourceImpl(
|
|
||||||
String columnName,
|
|
||||||
String referencedColumnName,
|
|
||||||
String columnDefinition) {
|
|
||||||
this.columnName = columnName;
|
|
||||||
this.referencedColumnName = referencedColumnName;
|
|
||||||
this.columnDefinition = columnDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getColumnName() {
|
|
||||||
return columnName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getReferencedColumnName() {
|
|
||||||
return referencedColumnName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getColumnDefinition() {
|
|
||||||
return columnDefinition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String determineCustomLoader() {
|
private String determineCustomLoader() {
|
||||||
String customLoader = null;
|
String customLoader = null;
|
||||||
// Custom sql loader
|
// Custom sql loader
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.spi.source.InLineViewSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class InLineViewSourceImpl implements InLineViewSource {
|
|
||||||
private final String selectStatement;
|
|
||||||
private final String logicalName;
|
|
||||||
|
|
||||||
public InLineViewSourceImpl(String selectStatement, String logicalName) {
|
|
||||||
this.selectStatement = selectStatement;
|
|
||||||
this.logicalName = logicalName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSelectStatement() {
|
|
||||||
return selectStatement;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitSchemaName() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitCatalogName() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLogicalName() {
|
|
||||||
return logicalName;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.metamodel.internal.source.annotations.entity;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.spi.source.TableSource;
|
|
||||||
|
|
||||||
class TableSourceImpl implements TableSource {
|
|
||||||
private final String schema;
|
|
||||||
private final String catalog;
|
|
||||||
private final String tableName;
|
|
||||||
|
|
||||||
TableSourceImpl(String schema, String catalog, String tableName) {
|
|
||||||
this.schema = schema;
|
|
||||||
this.catalog = catalog;
|
|
||||||
this.tableName = tableName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitSchemaName() {
|
|
||||||
return schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitCatalogName() {
|
|
||||||
return catalog;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExplicitTableName() {
|
|
||||||
return tableName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if ( this == o ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if ( o == null || getClass() != o.getClass() ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TableSourceImpl that = (TableSourceImpl) o;
|
|
||||||
|
|
||||||
if ( catalog != null ? !catalog.equals( that.catalog ) : that.catalog != null ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ( schema != null ? !schema.equals( that.schema ) : that.schema != null ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ( tableName != null ? !tableName.equals( that.tableName ) : that.tableName != null ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = schema != null ? schema.hashCode() : 0;
|
|
||||||
result = 31 * result + ( catalog != null ? catalog.hashCode() : 0 );
|
|
||||||
result = 31 * result + ( tableName != null ? tableName.hashCode() : 0 );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append( "TableSourceImpl" );
|
|
||||||
sb.append( "{schema='" ).append( schema ).append( '\'' );
|
|
||||||
sb.append( ", catalog='" ).append( catalog ).append( '\'' );
|
|
||||||
sb.append( ", tableName='" ).append( tableName ).append( '\'' );
|
|
||||||
sb.append( '}' );
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
<!--
|
||||||
|
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
~
|
||||||
|
~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
~ indicated by the @author tags or express copyright attribution
|
||||||
|
~ statements applied by the authors. All third-party contributions are
|
||||||
|
~ distributed under license by Red Hat Middleware LLC.
|
||||||
|
~
|
||||||
|
~ This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
~ copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
~ Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
~
|
||||||
|
~ This program is distributed in the hope that it will be useful,
|
||||||
|
~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
~ for more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU Lesser General Public License
|
||||||
|
~ along with this distribution; if not, write to:
|
||||||
|
~ Free Software Foundation, Inc.
|
||||||
|
~ 51 Franklin Street, Fifth Floor
|
||||||
|
~ Boston, MA 02110-1301 USA
|
||||||
|
~
|
||||||
|
-->
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head></head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
This package contains the implementations of the source interfaces defined in
|
||||||
|
<i>org.hibernate.metamodel.spi.source</i>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -113,8 +113,6 @@ import javax.persistence.Version;
|
||||||
|
|
||||||
import org.jboss.jandex.DotName;
|
import org.jboss.jandex.DotName;
|
||||||
|
|
||||||
import org.hibernate.annotations.Subselect;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the dot names for the JPA annotations
|
* Defines the dot names for the JPA annotations
|
||||||
*
|
*
|
||||||
|
@ -201,7 +199,6 @@ public interface JPADotNames {
|
||||||
DotName SEQUENCE_GENERATOR = DotName.createSimple( SequenceGenerator.class.getName() );
|
DotName SEQUENCE_GENERATOR = DotName.createSimple( SequenceGenerator.class.getName() );
|
||||||
DotName SQL_RESULT_SET_MAPPING = DotName.createSimple( SqlResultSetMapping.class.getName() );
|
DotName SQL_RESULT_SET_MAPPING = DotName.createSimple( SqlResultSetMapping.class.getName() );
|
||||||
DotName SQL_RESULT_SET_MAPPINGS = DotName.createSimple( SqlResultSetMappings.class.getName() );
|
DotName SQL_RESULT_SET_MAPPINGS = DotName.createSimple( SqlResultSetMappings.class.getName() );
|
||||||
DotName SUBSELECT = DotName.createSimple( Subselect.class.getName() );
|
|
||||||
DotName TABLE = DotName.createSimple( Table.class.getName() );
|
DotName TABLE = DotName.createSimple( Table.class.getName() );
|
||||||
DotName TABLE_GENERATOR = DotName.createSimple( TableGenerator.class.getName() );
|
DotName TABLE_GENERATOR = DotName.createSimple( TableGenerator.class.getName() );
|
||||||
DotName TEMPORAL = DotName.createSimple( Temporal.class.getName() );
|
DotName TEMPORAL = DotName.createSimple( Temporal.class.getName() );
|
||||||
|
|
Loading…
Reference in New Issue