HHH-6092 : Merge with master
This commit is contained in:
parent
412fa9406f
commit
653bbfa46d
|
@ -34,11 +34,9 @@ import org.dom4j.Element;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.HibernateLogger;
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.mapping.MetaAttribute;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.metamodel.relational.Table;
|
import org.hibernate.metamodel.relational.Table;
|
||||||
import org.hibernate.metamodel.relational.Value;
|
|
||||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||||
import org.hibernate.metamodel.source.util.DomHelper;
|
import org.hibernate.metamodel.source.util.DomHelper;
|
||||||
|
|
||||||
|
@ -79,8 +77,8 @@ public abstract class PluralAttributeBinding extends AbstractAttributeBinding {
|
||||||
String getLoaderName();
|
String getLoaderName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HibernateLogger LOG = Logger.getMessageLogger(
|
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||||
HibernateLogger.class, PluralAttributeBinding.class.getName()
|
CoreMessageLogger.class, PluralAttributeBinding.class.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private Table collectionTable;
|
private Table collectionTable;
|
||||||
|
|
|
@ -1,199 +0,0 @@
|
||||||
package org.hibernate.metamodel.source.annotations;
|
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
|
||||||
import org.jboss.jandex.ClassInfo;
|
|
||||||
import org.jboss.jandex.DotName;
|
|
||||||
import org.jboss.jandex.Index;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Composite annotation index. Represents an annotation index for xml generated annotations and class level
|
|
||||||
* defined annotations.
|
|
||||||
*
|
|
||||||
* @author John Bailey
|
|
||||||
*/
|
|
||||||
// TODO Use the composite index to abstract between xml and class source of annotations
|
|
||||||
public class AnnotationIndex {
|
|
||||||
final Collection<Index> indexes;
|
|
||||||
|
|
||||||
public AnnotationIndex(final Collection<Index> indexes) {
|
|
||||||
this.indexes = indexes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotationIndex(final AnnotationIndex... indexes) {
|
|
||||||
this.indexes = new ArrayList<Index>();
|
|
||||||
for ( AnnotationIndex index : indexes ) {
|
|
||||||
this.indexes.addAll( index.indexes );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see {@link Index#getAnnotations(org.jboss.jandex.DotName)}
|
|
||||||
*/
|
|
||||||
public List<AnnotationInstance> getAnnotations(final DotName annotationName) {
|
|
||||||
final List<AnnotationInstance> allInstances = new ArrayList<AnnotationInstance>();
|
|
||||||
for ( Index index : indexes ) {
|
|
||||||
final List<AnnotationInstance> list = index.getAnnotations( annotationName );
|
|
||||||
if ( list != null ) {
|
|
||||||
allInstances.addAll( list );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableList( allInstances );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see {@link Index#getKnownDirectSubclasses(org.jboss.jandex.DotName)}
|
|
||||||
*/
|
|
||||||
public Set<ClassInfo> getKnownDirectSubclasses(final DotName className) {
|
|
||||||
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
|
|
||||||
for ( Index index : indexes ) {
|
|
||||||
final List<ClassInfo> list = index.getKnownDirectSubclasses( className );
|
|
||||||
if ( list != null ) {
|
|
||||||
allKnown.addAll( list );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableSet( allKnown );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all known subclasses of the given class, even non-direct sub classes. (i.e. it returns all known classes that are
|
|
||||||
* assignable to the given class);
|
|
||||||
*
|
|
||||||
* @param className The class
|
|
||||||
*
|
|
||||||
* @return All known subclasses
|
|
||||||
*/
|
|
||||||
public Set<ClassInfo> getAllKnownSubclasses(final DotName className) {
|
|
||||||
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
|
|
||||||
final Set<DotName> processedClasses = new HashSet<DotName>();
|
|
||||||
getAllKnownSubClasses( className, allKnown, processedClasses );
|
|
||||||
return allKnown;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getAllKnownSubClasses(DotName className, Set<ClassInfo> allKnown, Set<DotName> processedClasses) {
|
|
||||||
final Set<DotName> subClassesToProcess = new HashSet<DotName>();
|
|
||||||
subClassesToProcess.add( className );
|
|
||||||
while ( !subClassesToProcess.isEmpty() ) {
|
|
||||||
final Iterator<DotName> toProcess = subClassesToProcess.iterator();
|
|
||||||
DotName name = toProcess.next();
|
|
||||||
toProcess.remove();
|
|
||||||
processedClasses.add( name );
|
|
||||||
getAllKnownSubClasses( name, allKnown, subClassesToProcess, processedClasses );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getAllKnownSubClasses(DotName name, Set<ClassInfo> allKnown, Set<DotName> subClassesToProcess,
|
|
||||||
Set<DotName> processedClasses) {
|
|
||||||
for ( Index index : indexes ) {
|
|
||||||
final List<ClassInfo> list = index.getKnownDirectSubclasses( name );
|
|
||||||
if ( list != null ) {
|
|
||||||
for ( final ClassInfo clazz : allKnown ) {
|
|
||||||
final DotName className = clazz.name();
|
|
||||||
if ( !processedClasses.contains( className ) ) {
|
|
||||||
allKnown.add( clazz );
|
|
||||||
subClassesToProcess.add( className );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see {@link Index#getKnownDirectImplementors(DotName)}
|
|
||||||
*/
|
|
||||||
public Set<ClassInfo> getKnownDirectImplementors(final DotName className) {
|
|
||||||
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
|
|
||||||
for ( Index index : indexes ) {
|
|
||||||
final List<ClassInfo> list = index.getKnownDirectImplementors( className );
|
|
||||||
if ( list != null ) {
|
|
||||||
allKnown.addAll( list );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableSet( allKnown );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all known classes that implement the given interface, directly and indirectly. This will all return classes that
|
|
||||||
* implement sub interfaces of the interface, and sub classes of classes that implement the interface. (In short, it will
|
|
||||||
* return every class that is assignable to the interface that is found in the index)
|
|
||||||
* <p/>
|
|
||||||
* This will only return classes, not interfaces.
|
|
||||||
*
|
|
||||||
* @param interfaceName The interface
|
|
||||||
*
|
|
||||||
* @return All known implementors of the interface
|
|
||||||
*/
|
|
||||||
public Set<ClassInfo> getAllKnownImplementors(final DotName interfaceName) {
|
|
||||||
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
|
|
||||||
final Set<DotName> subInterfacesToProcess = new HashSet<DotName>();
|
|
||||||
final Set<DotName> processedClasses = new HashSet<DotName>();
|
|
||||||
subInterfacesToProcess.add( interfaceName );
|
|
||||||
while ( !subInterfacesToProcess.isEmpty() ) {
|
|
||||||
final Iterator<DotName> toProcess = subInterfacesToProcess.iterator();
|
|
||||||
DotName name = toProcess.next();
|
|
||||||
toProcess.remove();
|
|
||||||
processedClasses.add( name );
|
|
||||||
getKnownImplementors( name, allKnown, subInterfacesToProcess, processedClasses );
|
|
||||||
}
|
|
||||||
return allKnown;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getKnownImplementors(DotName name, Set<ClassInfo> allKnown, Set<DotName> subInterfacesToProcess,
|
|
||||||
Set<DotName> processedClasses) {
|
|
||||||
for ( Index index : indexes ) {
|
|
||||||
final List<ClassInfo> list = index.getKnownDirectImplementors( name );
|
|
||||||
if ( list != null ) {
|
|
||||||
for ( final ClassInfo clazz : allKnown ) {
|
|
||||||
final DotName className = clazz.name();
|
|
||||||
if ( !processedClasses.contains( className ) ) {
|
|
||||||
if ( Modifier.isInterface( clazz.flags() ) ) {
|
|
||||||
subInterfacesToProcess.add( className );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ( !allKnown.contains( clazz ) ) {
|
|
||||||
allKnown.add( clazz );
|
|
||||||
processedClasses.add( className );
|
|
||||||
getAllKnownSubClasses( className, allKnown, processedClasses );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see {@link Index#getClassByName(org.jboss.jandex.DotName)}
|
|
||||||
*/
|
|
||||||
public ClassInfo getClassByName(final DotName className) {
|
|
||||||
for ( Index index : indexes ) {
|
|
||||||
final ClassInfo info = index.getClassByName( className );
|
|
||||||
if ( info != null ) {
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see {@link org.jboss.jandex.Index#getKnownClasses()}
|
|
||||||
*/
|
|
||||||
public Collection<ClassInfo> getKnownClasses() {
|
|
||||||
final List<ClassInfo> allKnown = new ArrayList<ClassInfo>();
|
|
||||||
for ( Index index : indexes ) {
|
|
||||||
final Collection<ClassInfo> list = index.getKnownClasses();
|
|
||||||
if ( list != null ) {
|
|
||||||
allKnown.addAll( list );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableCollection( allKnown );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,9 +27,7 @@ import java.util.Iterator;
|
||||||
|
|
||||||
import org.dom4j.Attribute;
|
import org.dom4j.Attribute;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.HibernateLogger;
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.engine.Versioning;
|
import org.hibernate.engine.Versioning;
|
||||||
|
@ -57,10 +55,6 @@ import org.hibernate.metamodel.source.hbm.state.relational.HbmSimpleValueRelatio
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
abstract class AbstractEntityBinder {
|
abstract class AbstractEntityBinder {
|
||||||
private static final HibernateLogger LOG = Logger.getMessageLogger(
|
|
||||||
HibernateLogger.class, AbstractEntityBinder.class.getName()
|
|
||||||
);
|
|
||||||
|
|
||||||
private final HibernateMappingBinder hibernateMappingBinder;
|
private final HibernateMappingBinder hibernateMappingBinder;
|
||||||
private final Schema.Name schemaName;
|
private final Schema.Name schemaName;
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
||||||
assertNotNull( nameBinding.getValue() );
|
assertNotNull( nameBinding.getValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Test
|
@Test
|
||||||
public void testEntityWithElementCollection() {
|
public void testEntityWithElementCollection() {
|
||||||
EntityBinding entityBinding = buildEntityWithElementCollectionBinding();
|
EntityBinding entityBinding = buildEntityWithElementCollectionBinding();
|
||||||
|
@ -104,10 +105,11 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
||||||
assertNotNull( nameBinding.getAttribute() );
|
assertNotNull( nameBinding.getAttribute() );
|
||||||
assertNotNull( nameBinding.getValue() );
|
assertNotNull( nameBinding.getValue() );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public abstract EntityBinding buildSimpleVersionedEntityBinding();
|
public abstract EntityBinding buildSimpleVersionedEntityBinding();
|
||||||
|
|
||||||
public abstract EntityBinding buildSimpleEntityBinding();
|
public abstract EntityBinding buildSimpleEntityBinding();
|
||||||
|
|
||||||
public abstract EntityBinding buildEntityWithElementCollectionBinding();
|
//public abstract EntityBinding buildEntityWithElementCollectionBinding();
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,9 +83,6 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
|
||||||
fail( "Unable to index" );
|
fail( "Unable to index" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return indexer.complete();
|
||||||
List<Index> indexList = new ArrayList<Index>();
|
|
||||||
indexList.add( indexer.complete() );
|
|
||||||
return new AnnotationIndex( indexList );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.binding;
|
package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.internal.util.ConfigHelper;
|
import org.hibernate.internal.util.ConfigHelper;
|
||||||
import org.hibernate.internal.util.xml.MappingReader;
|
import org.hibernate.internal.util.xml.MappingReader;
|
||||||
import org.hibernate.internal.util.xml.Origin;
|
import org.hibernate.internal.util.xml.Origin;
|
||||||
|
@ -42,7 +46,7 @@ import static org.junit.Assert.fail;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class BasicHbmBindingTests extends AbstractBasicBindingTests {
|
public class BasicHbmBindingTests extends AbstractBasicBindingTests {
|
||||||
private static final Logger log = LoggerFactory.getLogger( BasicHbmBindingTests.class );
|
private static final Logger log = Logger.getLogger( BasicHbmBindingTests.class.getName() );
|
||||||
|
|
||||||
public EntityBinding buildSimpleEntityBinding() {
|
public EntityBinding buildSimpleEntityBinding() {
|
||||||
Metadata metadata = new Metadata();
|
Metadata metadata = new Metadata();
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic binding "smopke" tests
|
* Basic binding "smoke" tests
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -48,6 +48,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase {
|
||||||
public static final Datatype VARCHAR = new Datatype( Types.VARCHAR, "VARCHAR", String.class );
|
public static final Datatype VARCHAR = new Datatype( Types.VARCHAR, "VARCHAR", String.class );
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBasicMiddleOutBuilding() {
|
public void testBasicMiddleOutBuilding() {
|
||||||
Table table = new Table( new Schema( null, null ), "the_table" );
|
Table table = new Table( new Schema( null, null ), "the_table" );
|
||||||
Entity entity = new Entity( "TheEntity", null );
|
Entity entity = new Entity( "TheEntity", null );
|
||||||
|
|
Loading…
Reference in New Issue