METAGEN-86 Checking now each mapping file for xml-mapping-metadata-complete. Technically this is not 100% correct since we don't differentiate between persistence units.
This commit is contained in:
parent
8ace40f351
commit
d49407b23d
|
@ -60,7 +60,11 @@ public final class Context {
|
||||||
private final String persistenceXmlLocation;
|
private final String persistenceXmlLocation;
|
||||||
private final List<String> ormXmlFiles;
|
private final List<String> ormXmlFiles;
|
||||||
|
|
||||||
private boolean isPersistenceUnitCompletelyXmlConfigured;
|
/**
|
||||||
|
* Keeping track which (if any) of the mapping files is xml-mapping-metadata-complete. If all are metadata complete
|
||||||
|
* no annotation processing will take place.
|
||||||
|
*/
|
||||||
|
private List<Boolean> fullyXmlConfigured;
|
||||||
private boolean addGeneratedAnnotation = true;
|
private boolean addGeneratedAnnotation = true;
|
||||||
private boolean addGenerationDate;
|
private boolean addGenerationDate;
|
||||||
private boolean addSuppressWarningsAnnotation;
|
private boolean addSuppressWarningsAnnotation;
|
||||||
|
@ -68,6 +72,7 @@ public final class Context {
|
||||||
|
|
||||||
public Context(ProcessingEnvironment pe) {
|
public Context(ProcessingEnvironment pe) {
|
||||||
this.pe = pe;
|
this.pe = pe;
|
||||||
|
this.fullyXmlConfigured = new ArrayList<Boolean>();
|
||||||
|
|
||||||
if ( pe.getOptions().get( JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION ) != null ) {
|
if ( pe.getOptions().get( JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION ) != null ) {
|
||||||
String tmp = pe.getOptions().get( JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION );
|
String tmp = pe.getOptions().get( JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION );
|
||||||
|
@ -194,12 +199,17 @@ public final class Context {
|
||||||
pe.getMessager().printMessage( type, message );
|
pe.getMessager().printMessage( type, message );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPersistenceUnitCompletelyXmlConfigured() {
|
public boolean isFullyXmlConfigured() {
|
||||||
return isPersistenceUnitCompletelyXmlConfigured;
|
if ( fullyXmlConfigured.isEmpty() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return !fullyXmlConfigured.contains( Boolean.FALSE );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPersistenceUnitCompletelyXmlConfigured(boolean persistenceUnitCompletelyXmlConfigured) {
|
public void mappingDocumentFullyXmlConfigured(boolean fullyXmlConfigured) {
|
||||||
isPersistenceUnitCompletelyXmlConfigured = persistenceUnitCompletelyXmlConfigured;
|
this.fullyXmlConfigured.add( fullyXmlConfigured );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccessType getPersistenceUnitDefaultAccessType() {
|
public AccessType getPersistenceUnitDefaultAccessType() {
|
||||||
|
@ -221,7 +231,7 @@ public final class Context {
|
||||||
sb.append( "{accessTypeInformation=" ).append( accessTypeInformation );
|
sb.append( "{accessTypeInformation=" ).append( accessTypeInformation );
|
||||||
sb.append( ", logDebug=" ).append( logDebug );
|
sb.append( ", logDebug=" ).append( logDebug );
|
||||||
sb.append( ", lazyXmlParsing=" ).append( lazyXmlParsing );
|
sb.append( ", lazyXmlParsing=" ).append( lazyXmlParsing );
|
||||||
sb.append( ", isPersistenceUnitCompletelyXmlConfigured=" ).append( isPersistenceUnitCompletelyXmlConfigured );
|
sb.append( ", isPersistenceUnitCompletelyXmlConfigured=" ).append( fullyXmlConfigured );
|
||||||
sb.append( ", ormXmlFiles=" ).append( ormXmlFiles );
|
sb.append( ", ormXmlFiles=" ).append( ormXmlFiles );
|
||||||
sb.append( ", persistenceXmlLocation='" ).append( persistenceXmlLocation ).append( '\'' );
|
sb.append( ", persistenceXmlLocation='" ).append( persistenceXmlLocation ).append( '\'' );
|
||||||
sb.append( '}' );
|
sb.append( '}' );
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class JpaDescriptorParser {
|
||||||
loadEntityMappings( mappingFileNames );
|
loadEntityMappings( mappingFileNames );
|
||||||
determineDefaultAccessTypeAndMetaCompleteness();
|
determineDefaultAccessTypeAndMetaCompleteness();
|
||||||
determineXmlAccessTypes();
|
determineXmlAccessTypes();
|
||||||
if ( !context.isPersistenceUnitCompletelyXmlConfigured() ) {
|
if ( !context.isFullyXmlConfigured() ) {
|
||||||
// need to take annotations into consideration, since they can override xml settings
|
// need to take annotations into consideration, since they can override xml settings
|
||||||
// we have to at least determine whether any of the xml configured entities is influenced by annotations
|
// we have to at least determine whether any of the xml configured entities is influenced by annotations
|
||||||
determineAnnotationAccessTypes();
|
determineAnnotationAccessTypes();
|
||||||
|
@ -422,7 +422,10 @@ public class JpaDescriptorParser {
|
||||||
PersistenceUnitMetadata meta = mappings.getPersistenceUnitMetadata();
|
PersistenceUnitMetadata meta = mappings.getPersistenceUnitMetadata();
|
||||||
if ( meta != null ) {
|
if ( meta != null ) {
|
||||||
if ( meta.getXmlMappingMetadataComplete() != null ) {
|
if ( meta.getXmlMappingMetadataComplete() != null ) {
|
||||||
context.setPersistenceUnitCompletelyXmlConfigured( true );
|
context.mappingDocumentFullyXmlConfigured( true );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
context.mappingDocumentFullyXmlConfigured( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistenceUnitDefaults persistenceUnitDefaults = meta.getPersistenceUnitDefaults();
|
PersistenceUnitDefaults persistenceUnitDefaults = meta.getPersistenceUnitDefaults();
|
||||||
|
@ -432,10 +435,9 @@ public class JpaDescriptorParser {
|
||||||
context.setPersistenceUnitDefaultAccessType( mapXmlAccessTypeToJpaAccessType( xmlAccessType ) );
|
context.setPersistenceUnitDefaultAccessType( mapXmlAccessTypeToJpaAccessType( xmlAccessType ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for simplicity we stop looking for PersistenceUnitMetadata instances. We assume that all files
|
}
|
||||||
// are consistent in the data specified in PersistenceUnitMetadata. If not the behaviour is not specified
|
else {
|
||||||
// anyways. It is up to the JPA provider to handle this when bootstrapping
|
context.mappingDocumentFullyXmlConfigured( false );
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class XmlMetaEntity implements MetaEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean initIsMetaComplete(Boolean metadataComplete) {
|
private boolean initIsMetaComplete(Boolean metadataComplete) {
|
||||||
return context.isPersistenceUnitCompletelyXmlConfigured() || Boolean.TRUE.equals( metadataComplete );
|
return context.isFullyXmlConfigured() || Boolean.TRUE.equals( metadataComplete );
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getCollectionTypes(String propertyName, String explicitTargetEntity, String explicitMapKeyClass, ElementKind expectedElementKind) {
|
private String[] getCollectionTypes(String propertyName, String explicitTargetEntity, String explicitMapKeyClass, ElementKind expectedElementKind) {
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// $Id:$
|
||||||
|
package org.hibernate.jpamodelgen.test.xmlmetacomplete.multiplepus;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Dummy {
|
||||||
|
@Id
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// $Id: XmlMappingTest.java 20721 2010-09-27 12:40:10Z hardy.ferentschik $
|
||||||
|
package org.hibernate.jpamodelgen.test.xmlmetacomplete.multiplepus;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor;
|
||||||
|
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||||
|
import org.hibernate.jpamodelgen.test.util.TestUtil;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class XmlMetaDataCompleteMultiplePersistenceUnitsTest extends CompilationTest {
|
||||||
|
@Test
|
||||||
|
public void testMetaModelGenerated() {
|
||||||
|
// only one of the xml files in the example uses 'xml-mapping-metadata-complete', hence annotation processing
|
||||||
|
// kicks in
|
||||||
|
assertMetamodelClassGeneratedFor( Dummy.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getPackageNameOfCurrentTest() {
|
||||||
|
return XmlMetaDataCompleteMultiplePersistenceUnitsTest.class.getPackage().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> getProcessorOptions() {
|
||||||
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
|
properties.put(
|
||||||
|
JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION,
|
||||||
|
TestUtil.fcnToPath(
|
||||||
|
XmlMetaDataCompleteMultiplePersistenceUnitsTest.class.getPackage().getName()
|
||||||
|
) + "/persistence.xml"
|
||||||
|
);
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen.test.xmlmetacomplete;
|
package org.hibernate.jpamodelgen.test.xmlmetacomplete.singlepu;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -35,5 +35,3 @@ public class Dummy {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// $Id: XmlMappingTest.java 20721 2010-09-27 12:40:10Z hardy.ferentschik $
|
// $Id: XmlMappingTest.java 20721 2010-09-27 12:40:10Z hardy.ferentschik $
|
||||||
package org.hibernate.jpamodelgen.test.xmlmetacomplete;
|
package org.hibernate.jpamodelgen.test.xmlmetacomplete.singlepu;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -32,7 +32,7 @@ import static org.hibernate.jpamodelgen.test.util.TestUtil.assertNoSourceFileGen
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class XmlMetaDataCompleteTest extends CompilationTest {
|
public class XmlMetaDataCompleteSinglePersistenceUnitTest extends CompilationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNoMetaModelGenerated() {
|
public void testNoMetaModelGenerated() {
|
||||||
// the xml mapping files used in the example say that the xml data is meta complete. For that
|
// the xml mapping files used in the example say that the xml data is meta complete. For that
|
||||||
|
@ -42,7 +42,7 @@ public class XmlMetaDataCompleteTest extends CompilationTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPackageNameOfCurrentTest() {
|
protected String getPackageNameOfCurrentTest() {
|
||||||
return XmlMetaDataCompleteTest.class.getPackage().getName();
|
return XmlMetaDataCompleteSinglePersistenceUnitTest.class.getPackage().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,7 +50,7 @@ public class XmlMetaDataCompleteTest extends CompilationTest {
|
||||||
Map<String, String> properties = new HashMap<String, String>();
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
properties.put(
|
properties.put(
|
||||||
JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION,
|
JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION,
|
||||||
TestUtil.fcnToPath( XmlMetaDataCompleteTest.class.getPackage().getName() ) + "/persistence.xml"
|
TestUtil.fcnToPath( XmlMetaDataCompleteSinglePersistenceUnitTest.class.getPackage().getName() ) + "/persistence.xml"
|
||||||
);
|
);
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ JBoss, Home of Professional Open Source
|
||||||
|
~ Copyright 2010, Red Hat Middleware LLC, and individual contributors
|
||||||
|
~ by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
~ full listing of individual contributors.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd"
|
||||||
|
version="2.1">
|
||||||
|
</entity-mappings>
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ JBoss, Home of Professional Open Source
|
||||||
|
~ Copyright 2010, Red Hat Middleware LLC, and individual contributors
|
||||||
|
~ by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
~ full listing of individual contributors.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd"
|
||||||
|
version="2.1">
|
||||||
|
<persistence-unit name="annotation-processor-1" transaction-type="JTA">
|
||||||
|
<mapping-file>/org/hibernate/jpamodelgen/test/xmlmetacomplete/multiplepus/foo.xml</mapping-file>
|
||||||
|
</persistence-unit>
|
||||||
|
<persistence-unit name="annotation-processor-2" transaction-type="JTA">
|
||||||
|
<mapping-file>/org/hibernate/jpamodelgen/test/xmlmetacomplete/multiplepus/bar.xml</mapping-file>
|
||||||
|
</persistence-unit>
|
||||||
|
</persistence>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ JBoss, Home of Professional Open Source
|
||||||
|
~ Copyright 2010, Red Hat Middleware LLC, and individual contributors
|
||||||
|
~ by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
~ full listing of individual contributors.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
|
version="2.0"
|
||||||
|
>
|
||||||
|
<persistence-unit-metadata>
|
||||||
|
<xml-mapping-metadata-complete/>
|
||||||
|
</persistence-unit-metadata>
|
||||||
|
</entity-mappings>
|
|
@ -20,6 +20,6 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence.xsd" version="2.0">
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence.xsd" version="2.0">
|
||||||
<persistence-unit name="annotation-processor" transaction-type="JTA">
|
<persistence-unit name="annotation-processor" transaction-type="JTA">
|
||||||
<mapping-file>/org/hibernate/jpamodelgen/test/xmlmetacomplete/foo.xml</mapping-file>
|
<mapping-file>/org/hibernate/jpamodelgen/test/xmlmetacomplete/singlepu/foo.xml</mapping-file>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
Loading…
Reference in New Issue