METAGEN-25 Ensure that the default package name gets used in all cases where class names can be specified
This commit is contained in:
parent
9fb1f05259
commit
787359a073
|
@ -29,12 +29,12 @@ public class StringUtil {
|
||||||
private StringUtil() {
|
private StringUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String determineFullyQualifiedClassName(String packageName, String name) {
|
public static String determineFullyQualifiedClassName(String defaultPackage, String name) {
|
||||||
if ( isFullyQualified( name ) ) {
|
if ( isFullyQualified( name ) ) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return packageName + NAME_SEPARATOR + name;
|
return defaultPackage + NAME_SEPARATOR + name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ public class XmlMetaEntity implements MetaEntity {
|
||||||
|
|
||||||
protected final String clazzName;
|
protected final String clazzName;
|
||||||
protected final String packageName;
|
protected final String packageName;
|
||||||
|
protected final String defaultPackageName;
|
||||||
protected final ImportContext importContext;
|
protected final ImportContext importContext;
|
||||||
protected final List<MetaAttribute> members = new ArrayList<MetaAttribute>();
|
protected final List<MetaAttribute> members = new ArrayList<MetaAttribute>();
|
||||||
protected final TypeElement element;
|
protected final TypeElement element;
|
||||||
|
@ -79,37 +80,42 @@ public class XmlMetaEntity implements MetaEntity {
|
||||||
private EmbeddableAttributes embeddableAttributes;
|
private EmbeddableAttributes embeddableAttributes;
|
||||||
protected AccessTypeInformation accessTypeInfo;
|
protected AccessTypeInformation accessTypeInfo;
|
||||||
|
|
||||||
public XmlMetaEntity(Entity ormEntity, String packageName, TypeElement element, Context context) {
|
public XmlMetaEntity(Entity ormEntity, String defaultPackageName, TypeElement element, Context context) {
|
||||||
this( ormEntity.getClazz(), packageName, element, context, ormEntity.isMetadataComplete() );
|
this( ormEntity.getClazz(), defaultPackageName, element, context, ormEntity.isMetadataComplete() );
|
||||||
this.attributes = ormEntity.getAttributes();
|
this.attributes = ormEntity.getAttributes();
|
||||||
this.embeddableAttributes = null;
|
this.embeddableAttributes = null;
|
||||||
// entities can be directly initialised
|
// entities can be directly initialised
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected XmlMetaEntity(MappedSuperclass mappedSuperclass, String packageName, TypeElement element, Context context) {
|
protected XmlMetaEntity(MappedSuperclass mappedSuperclass, String defaultPackageName, TypeElement element, Context context) {
|
||||||
this( mappedSuperclass.getClazz(), packageName, element, context, mappedSuperclass.isMetadataComplete() );
|
this(
|
||||||
|
mappedSuperclass.getClazz(), defaultPackageName, element, context, mappedSuperclass.isMetadataComplete()
|
||||||
|
);
|
||||||
this.attributes = mappedSuperclass.getAttributes();
|
this.attributes = mappedSuperclass.getAttributes();
|
||||||
this.embeddableAttributes = null;
|
this.embeddableAttributes = null;
|
||||||
// entities can be directly initialised
|
// entities can be directly initialised
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected XmlMetaEntity(Embeddable embeddable, String packageName, TypeElement element, Context context) {
|
protected XmlMetaEntity(Embeddable embeddable, String defaultPackageName, TypeElement element, Context context) {
|
||||||
this( embeddable.getClazz(), packageName, element, context, embeddable.isMetadataComplete() );
|
this( embeddable.getClazz(), defaultPackageName, element, context, embeddable.isMetadataComplete() );
|
||||||
this.attributes = null;
|
this.attributes = null;
|
||||||
this.embeddableAttributes = embeddable.getAttributes();
|
this.embeddableAttributes = embeddable.getAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private XmlMetaEntity(String clazz, String packageName, TypeElement element, Context context, Boolean metaComplete) {
|
private XmlMetaEntity(String clazz, String defaultPackageName, TypeElement element, Context context, Boolean metaComplete) {
|
||||||
|
this.defaultPackageName = defaultPackageName;
|
||||||
String className = clazz;
|
String className = clazz;
|
||||||
|
String pkg = defaultPackageName;
|
||||||
if ( StringUtil.isFullyQualified( className ) ) {
|
if ( StringUtil.isFullyQualified( className ) ) {
|
||||||
// we have to extract the package name from the fqcn. default package name gets ignored
|
// if the class name is fully qualified we have to extract the package name from the fqcn.
|
||||||
packageName = StringUtil.packageNameFromFqcn( className );
|
// default package name gets ignored
|
||||||
|
pkg = StringUtil.packageNameFromFqcn( className );
|
||||||
className = StringUtil.classNameFromFqcn( clazz );
|
className = StringUtil.classNameFromFqcn( clazz );
|
||||||
}
|
}
|
||||||
this.clazzName = className;
|
this.clazzName = className;
|
||||||
this.packageName = packageName;
|
this.packageName = pkg;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.importContext = new ImportContextImpl( getPackageName() );
|
this.importContext = new ImportContextImpl( getPackageName() );
|
||||||
this.element = element;
|
this.element = element;
|
||||||
|
@ -389,14 +395,11 @@ public class XmlMetaEntity implements MetaEntity {
|
||||||
String[] types;
|
String[] types;
|
||||||
XmlMetaCollection metaCollection;
|
XmlMetaCollection metaCollection;
|
||||||
ElementKind elementKind = getElementKind( collection.getAccess() );
|
ElementKind elementKind = getElementKind( collection.getAccess() );
|
||||||
MapKeyClass mapKeyClass = collection.getMapKeyClass();
|
String explicitTargetClass = determineExplicitTargetEntity( collection.getTargetClass() );
|
||||||
String explicitMapKey = null;
|
String explicitMapKey = determineExplicitMapKeyClass( collection.getMapKeyClass() );
|
||||||
if ( mapKeyClass != null ) {
|
|
||||||
explicitMapKey = mapKeyClass.getClazz();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
types = getCollectionTypes(
|
types = getCollectionTypes(
|
||||||
collection.getName(), collection.getTargetClass(), explicitMapKey, elementKind
|
collection.getName(), explicitTargetClass, explicitMapKey, elementKind
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch ( MetaModelGenerationException e ) {
|
catch ( MetaModelGenerationException e ) {
|
||||||
|
@ -415,17 +418,32 @@ public class XmlMetaEntity implements MetaEntity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String determineExplicitTargetEntity(String targetClass) {
|
||||||
|
String explicitTargetClass = targetClass;
|
||||||
|
if ( explicitTargetClass != null ) {
|
||||||
|
explicitTargetClass = StringUtil.determineFullyQualifiedClassName(
|
||||||
|
defaultPackageName, targetClass
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return explicitTargetClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String determineExplicitMapKeyClass(MapKeyClass mapKeyClass) {
|
||||||
|
String explicitMapKey = null;
|
||||||
|
if ( mapKeyClass != null ) {
|
||||||
|
explicitMapKey = StringUtil.determineFullyQualifiedClassName( defaultPackageName, mapKeyClass.getClazz() );
|
||||||
|
}
|
||||||
|
return explicitMapKey;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean parseOneToMany(OneToMany oneToMany) {
|
private boolean parseOneToMany(OneToMany oneToMany) {
|
||||||
String[] types;
|
String[] types;
|
||||||
XmlMetaCollection metaCollection;
|
XmlMetaCollection metaCollection;
|
||||||
ElementKind elementKind = getElementKind( oneToMany.getAccess() );
|
ElementKind elementKind = getElementKind( oneToMany.getAccess() );
|
||||||
MapKeyClass mapKeyClass = oneToMany.getMapKeyClass();
|
String explicitTargetClass = determineExplicitTargetEntity( oneToMany.getTargetEntity() );
|
||||||
String explicitMapKey = null;
|
String explicitMapKey = determineExplicitMapKeyClass( oneToMany.getMapKeyClass() );
|
||||||
if ( mapKeyClass != null ) {
|
|
||||||
explicitMapKey = mapKeyClass.getClazz();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
types = getCollectionTypes( oneToMany.getName(), oneToMany.getTargetEntity(), explicitMapKey, elementKind );
|
types = getCollectionTypes( oneToMany.getName(), explicitTargetClass, explicitMapKey, elementKind );
|
||||||
}
|
}
|
||||||
catch ( MetaModelGenerationException e ) {
|
catch ( MetaModelGenerationException e ) {
|
||||||
logMetaModelException( oneToMany.getName(), e );
|
logMetaModelException( oneToMany.getName(), e );
|
||||||
|
@ -447,14 +465,11 @@ public class XmlMetaEntity implements MetaEntity {
|
||||||
String[] types;
|
String[] types;
|
||||||
XmlMetaCollection metaCollection;
|
XmlMetaCollection metaCollection;
|
||||||
ElementKind elementKind = getElementKind( manyToMany.getAccess() );
|
ElementKind elementKind = getElementKind( manyToMany.getAccess() );
|
||||||
MapKeyClass mapKeyClass = manyToMany.getMapKeyClass();
|
String explicitTargetClass = determineExplicitTargetEntity( manyToMany.getTargetEntity() );
|
||||||
String explicitMapKey = null;
|
String explicitMapKey = determineExplicitMapKeyClass( manyToMany.getMapKeyClass() );
|
||||||
if ( mapKeyClass != null ) {
|
|
||||||
explicitMapKey = mapKeyClass.getClazz();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
types = getCollectionTypes(
|
types = getCollectionTypes(
|
||||||
manyToMany.getName(), manyToMany.getTargetEntity(), explicitMapKey, elementKind
|
manyToMany.getName(), explicitTargetClass, explicitMapKey, elementKind
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch ( MetaModelGenerationException e ) {
|
catch ( MetaModelGenerationException e ) {
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
|
<package>org.hibernate.jpamodelgen.test.elementcollection</package>
|
||||||
<entity class="org.hibernate.jpamodelgen.test.elementcollection.Hostel">
|
<entity class="org.hibernate.jpamodelgen.test.elementcollection.Hostel">
|
||||||
<attributes>
|
<attributes>
|
||||||
<one-to-many name="cleaners" target-entity="org.hibernate.jpamodelgen.test.elementcollection.Cleaner">
|
<one-to-many name="cleaners" target-entity="Cleaner">
|
||||||
<map-key-class class="org.hibernate.jpamodelgen.test.elementcollection.Room"/>
|
<map-key-class class="org.hibernate.jpamodelgen.test.elementcollection.Room"/>
|
||||||
</one-to-many>
|
</one-to-many>
|
||||||
<element-collection name="roomsByName"
|
<element-collection name="roomsByName"
|
||||||
|
|
Loading…
Reference in New Issue