Hibernate SVN: r18614 - in core/trunk: annotations/src/main/java/org/hibernate/cfg and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-24 12:07:28 -0500 (Sun, 24 Jan 2010)
New Revision: 18614
Modified:
core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java
core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java
core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java
core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java
Log:
HHH-4659 - Add support for standard declarative cache (@Cacheable)
Modified: core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -23,15 +23,67 @@
*/
package org.hibernate.annotations;
+import org.hibernate.cache.access.AccessType;
+
/**
* Cache concurrency strategy
*
* @author Emmanuel Bernard
*/
public enum CacheConcurrencyStrategy {
- NONE,
- READ_ONLY,
- NONSTRICT_READ_WRITE,
- READ_WRITE,
- TRANSACTIONAL
+ NONE( null ),
+ READ_ONLY( AccessType.READ_ONLY ),
+ NONSTRICT_READ_WRITE( AccessType.NONSTRICT_READ_WRITE ),
+ READ_WRITE( AccessType.READ_WRITE ),
+ TRANSACTIONAL( AccessType.TRANSACTIONAL );
+
+ private final AccessType accessType;
+
+ private CacheConcurrencyStrategy(AccessType accessType) {
+ this.accessType = accessType;
+ }
+
+ public static CacheConcurrencyStrategy fromAccessType(AccessType accessType) {
+ final String name = accessType == null ? null : accessType.getName();
+ if ( AccessType.READ_ONLY.getName().equals( name ) ) {
+ return READ_ONLY;
+ }
+ else if ( AccessType.READ_WRITE.getName().equals( name ) ) {
+ return READ_WRITE;
+ }
+ else if ( AccessType.NONSTRICT_READ_WRITE.getName().equals( name ) ) {
+ return NONSTRICT_READ_WRITE;
+ }
+ else if ( AccessType.TRANSACTIONAL.getName().equals( name ) ) {
+ return TRANSACTIONAL;
+ }
+ else {
+ return NONE;
+ }
+ }
+
+ public static CacheConcurrencyStrategy parse(String name) {
+ if ( READ_ONLY.accessType.getName().equalsIgnoreCase( name ) ) {
+ return READ_ONLY;
+ }
+ else if ( READ_WRITE.accessType.getName().equalsIgnoreCase( name ) ) {
+ return READ_WRITE;
+ }
+ else if ( NONSTRICT_READ_WRITE.accessType.getName().equalsIgnoreCase( name ) ) {
+ return NONSTRICT_READ_WRITE;
+ }
+ else if ( TRANSACTIONAL.accessType.getName().equalsIgnoreCase( name ) ) {
+ return TRANSACTIONAL;
+ }
+ else if ( "none".equalsIgnoreCase( name ) ) {
+ return NONE;
+ }
+ else {
+ return null;
+ }
+ }
+
+ public AccessType toAccessType() {
+ return accessType;
+ }
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -814,12 +814,33 @@
private static CacheConcurrencyStrategy DEFAULT_CACHE_CONCURRENCY_STRATEGY;
+ static void prepareDefaultCacheConcurrencyStrategy(Properties properties) {
+ if ( DEFAULT_CACHE_CONCURRENCY_STRATEGY != null ) {
+ log.info( "Default cache concurrency strategy already defined" );
+ return;
+ }
+
+ if ( ! properties.containsKey( AnnotationConfiguration.DEFAULT_CACHE_CONCURRENCY_STRATEGY ) ) {
+ log.trace( "Given properties did not contain any default cache concurrency strategy setting" );
+ return;
+ }
+
+ final String strategyName = properties.getProperty( AnnotationConfiguration.DEFAULT_CACHE_CONCURRENCY_STRATEGY );
+ log.trace( "Discovered default cache concurrency strategy via config [" + strategyName + "]" );
+ CacheConcurrencyStrategy strategy = CacheConcurrencyStrategy.parse( strategyName );
+ if ( strategy == null ) {
+ log.trace( "Discovered default cache concurrency strategy specified nothing" );
+ return;
+ }
+
+ log.info( "Setting default cache concurrency strategy via config [" + strategy.name() + "]" );
+ DEFAULT_CACHE_CONCURRENCY_STRATEGY = strategy;
+ }
+
private static CacheConcurrencyStrategy determineCacheConcurrencyStrategy(ExtendedMappings mappings) {
if ( DEFAULT_CACHE_CONCURRENCY_STRATEGY == null ) {
-// todo need to figure out how we will determine the default cache access-type/concurrency-strategy
-// RegionFactory cacheRegionFactory = SettingsFactory.createRegionFactory( mappings.getConfigurationProperties(), true );
-// DEFAULT_CACHE_CONCURRENCY_STRATEGY = cacheRegionFactory.[getDefault...]
- DEFAULT_CACHE_CONCURRENCY_STRATEGY = CacheConcurrencyStrategy.TRANSACTIONAL;
+ final RegionFactory cacheRegionFactory = SettingsFactory.createRegionFactory( mappings.getConfigurationProperties(), true );
+ DEFAULT_CACHE_CONCURRENCY_STRATEGY = CacheConcurrencyStrategy.fromAccessType( cacheRegionFactory.getDefaultAccessType() );
}
return DEFAULT_CACHE_CONCURRENCY_STRATEGY;
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -106,6 +106,13 @@
private Logger log = LoggerFactory.getLogger( AnnotationConfiguration.class );
/**
+ * Setting used to give the name of the default {@link org.hibernate.annotations.CacheConcurrencyStrategy}
+ * to use when either {@link javax.persistence.Cacheable @Cacheable} or
+ * {@link Cache @Cache} is used. {@link Cache @Cache(strategy=".."} is used to override.
+ */
+ public static final String DEFAULT_CACHE_CONCURRENCY_STRATEGY = "org.hibernate.cache.default_cache_concurrency_strategy";
+
+ /**
* Class name of the class needed to enable Search.
*/
private static final String SEARCH_STARTUP_CLASS = "org.hibernate.search.event.EventListenerRegister";
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -771,20 +771,8 @@
}
public static String getCacheConcurrencyStrategy(CacheConcurrencyStrategy strategy) {
- switch ( strategy ) {
- case NONE:
- return null;
- case READ_ONLY:
- return org.hibernate.cache.access.AccessType.READ_ONLY.getName();
- case READ_WRITE:
- return org.hibernate.cache.access.AccessType.READ_WRITE.getName();
- case NONSTRICT_READ_WRITE:
- return org.hibernate.cache.access.AccessType.NONSTRICT_READ_WRITE.getName();
- case TRANSACTIONAL:
- return org.hibernate.cache.access.AccessType.TRANSACTIONAL.getName();
- default:
- throw new AssertionFailure( "CacheConcurrencyStrategy unknown: " + strategy );
- }
+ org.hibernate.cache.access.AccessType accessType = strategy.toAccessType();
+ return accessType == null ? null : accessType.getName();
}
public void addFilter(String name, String condition) {
Modified: core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
--- core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -18,6 +18,7 @@
import org.hibernate.cache.QueryResultsRegion;
import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.infinispan.collection.CollectionRegionImpl;
import org.hibernate.cache.infinispan.entity.EntityRegionImpl;
import org.hibernate.cache.infinispan.query.QueryResultsRegionImpl;
@@ -205,7 +206,12 @@
return true;
}
- /**
+ @Override
+ public AccessType getDefaultAccessType() {
+ return AccessType.TRANSACTIONAL;
+ }
+
+ /**
* {@inheritDoc}
*/
public long nextTimestamp() {
Modified: core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java
===================================================================
--- core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -31,6 +31,7 @@
import org.hibernate.cache.QueryResultsRegion;
import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cfg.Settings;
import org.infinispan.manager.CacheManager;
@@ -117,7 +118,12 @@
return delegate.isMinimalPutsEnabledByDefault();
}
- public long nextTimestamp() {
+ @Override
+ public AccessType getDefaultAccessType() {
+ return AccessType.TRANSACTIONAL;
+ }
+
+ public long nextTimestamp() {
return delegate.nextTimestamp();
}
}
Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -32,6 +32,7 @@
import org.hibernate.cache.QueryResultsRegion;
import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager;
import org.hibernate.cache.jbc.builder.SharedCacheInstanceManager;
import org.hibernate.cache.jbc.collection.CollectionRegionImpl;
@@ -116,7 +117,11 @@
return true;
}
- public long nextTimestamp() {
+ public AccessType getDefaultAccessType() {
+ return AccessType.TRANSACTIONAL;
+ }
+
+ public long nextTimestamp() {
return System.currentTimeMillis() / 100;
}
Modified: core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -26,6 +26,7 @@
import java.util.Properties;
+import org.hibernate.cache.access.AccessType;
import org.hibernate.cfg.Settings;
/**
@@ -77,6 +78,14 @@
public boolean isMinimalPutsEnabledByDefault();
/**
+ * Get the default access type for {@link EntityRegion entity} and
+ * {@link CollectionRegion collection} regions.
+ *
+ * @return This factory's default access type.
+ */
+ public AccessType getDefaultAccessType();
+
+ /**
* Generate a timestamp.
* <p/>
* This is generally used for cache content locking/unlocking purposes
Modified: core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, 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 Middleware LLC.
+ * 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
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.cache.impl;
@@ -34,6 +33,7 @@
import org.hibernate.cache.TimestampsRegion;
import org.hibernate.cache.NoCachingEnabledException;
import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.access.AccessType;
import org.hibernate.cfg.Settings;
/**
@@ -57,6 +57,10 @@
return false;
}
+ public AccessType getDefaultAccessType() {
+ return null;
+ }
+
public long nextTimestamp() {
return System.currentTimeMillis() / 100;
}
Modified: core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java 2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java 2010-01-24 17:07:28 UTC (rev 18614)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, 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 Middleware LLC.
+ * 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
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.cache.impl.bridge;
@@ -38,6 +37,7 @@
import org.hibernate.cache.NoCacheProvider;
import org.hibernate.cache.TimestampsRegion;
import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.access.AccessType;
import org.hibernate.util.PropertiesHelper;
import org.hibernate.util.ReflectHelper;
import org.hibernate.cfg.Environment;
@@ -81,6 +81,14 @@
return cacheProvider.isMinimalPutsEnabledByDefault();
}
+ /**
+ * {@inheritDoc}
+ */
+ public AccessType getDefaultAccessType() {
+ // we really have no idea
+ return null;
+ }
+
public long nextTimestamp() {
return cacheProvider.nextTimestamp();
}
14 years, 2 months
Hibernate SVN: r18613 - entitymanager/branches/v3_3_2_GA_CP.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-01-22 20:53:20 -0500 (Fri, 22 Jan 2010)
New Revision: 18613
Modified:
entitymanager/branches/v3_3_2_GA_CP/
Log:
ignore build directory
Property changes on: entitymanager/branches/v3_3_2_GA_CP
___________________________________________________________________
Name: svn:ignore
- .classpath
.project
+ .classpath
.project
build
14 years, 2 months
Hibernate SVN: r18612 - entitymanager/branches/v3_3_2_GA_CP/src/java/org/hibernate/engine.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-01-22 20:47:22 -0500 (Fri, 22 Jan 2010)
New Revision: 18612
Modified:
entitymanager/branches/v3_3_2_GA_CP/src/java/org/hibernate/engine/EJB3CascadeStyle.java
Log:
minor change, correct javadoc spell
Modified: entitymanager/branches/v3_3_2_GA_CP/src/java/org/hibernate/engine/EJB3CascadeStyle.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/java/org/hibernate/engine/EJB3CascadeStyle.java 2010-01-22 20:48:42 UTC (rev 18611)
+++ entitymanager/branches/v3_3_2_GA_CP/src/java/org/hibernate/engine/EJB3CascadeStyle.java 2010-01-23 01:47:22 UTC (rev 18612)
@@ -2,7 +2,7 @@
package org.hibernate.engine;
/**
- * Becasue CascadeStyle is not opened and package protected,
+ * Because CascadeStyle is not opened and package protected,
* I need to subclass and override the persist alias
*
* Note that This class has to be triggered by EJB3PersistEventListener at class loading time
14 years, 2 months
Hibernate SVN: r18611 - in jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen: xml and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-22 15:48:42 -0500 (Fri, 22 Jan 2010)
New Revision: 18611
Added:
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java
Modified:
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
Log:
METAGEN-6 Split XML parsing code out into its own class.
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-01-22 20:18:31 UTC (rev 18610)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-01-22 20:48:42 UTC (rev 18611)
@@ -17,10 +17,6 @@
*/
package org.hibernate.jpamodelgen;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
@@ -28,35 +24,19 @@
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
-import static javax.lang.model.SourceVersion.RELEASE_6;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
-import javax.lang.model.util.Elements;
-import javax.persistence.AccessType;
import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;
import javax.tools.Diagnostic;
-import javax.tools.FileObject;
-import javax.tools.StandardLocation;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import org.xml.sax.SAXException;
-
import org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity;
-import org.hibernate.jpamodelgen.xml.XmlMetaEntity;
-import org.hibernate.jpamodelgen.xml.jaxb.Entity;
-import org.hibernate.jpamodelgen.xml.jaxb.EntityMappings;
-import org.hibernate.jpamodelgen.xml.jaxb.ObjectFactory;
-import org.hibernate.jpamodelgen.xml.jaxb.Persistence;
-import org.hibernate.jpamodelgen.xml.jaxb.PersistenceUnitDefaults;
-import org.hibernate.jpamodelgen.xml.jaxb.PersistenceUnitMetadata;
+import org.hibernate.jpamodelgen.xml.XmlParser;
+import static javax.lang.model.SourceVersion.RELEASE_6;
+
/**
* Main annotation processor.
*
@@ -68,16 +48,11 @@
@SupportedSourceVersion(RELEASE_6)
public class JPAMetaModelEntityProcessor extends AbstractProcessor {
- private static final String PATH_SEPARATOR = "/";
- private static final String PERSISTENCE_XML = "/META-INF/persistence.xml";
- private static final String ORM_XML = "/META-INF/orm.xml";
+
private static final Boolean ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS = Boolean.FALSE;
private static final String ENTITY_ANN = javax.persistence.Entity.class.getName();
private static final String MAPPED_SUPERCLASS_ANN = MappedSuperclass.class.getName();
private static final String EMBEDDABLE_ANN = Embeddable.class.getName();
- private static final AccessType DEFAULT_XML_ACCESS_TYPE = AccessType.PROPERTY;
- private static final String PERSISTENCE_XML_XSD = "persistence_2_0.xsd";
- private static final String ORM_XSD = "orm_2_0.xsd";
private boolean xmlProcessed = false;
private Context context;
@@ -85,7 +60,9 @@
public void init(ProcessingEnvironment env) {
super.init( env );
context = new Context( env );
- context.logMessage( Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString() );
+ context.logMessage(
+ Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString()
+ );
}
@Override
@@ -100,7 +77,9 @@
}
if ( !xmlProcessed ) {
- parsePersistenceXml();
+ XmlParser parser = new XmlParser( context );
+ parser.parsePersistenceXml();
+ xmlProcessed = true;
}
if ( !hostJPAAnnotations( annotations ) ) {
@@ -150,164 +129,6 @@
return false;
}
- private void parsePersistenceXml() {
- Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class, PERSISTENCE_XML_XSD );
- if ( persistence != null ) {
- List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
- for ( Persistence.PersistenceUnit unit : persistenceUnits ) {
- List<String> mappingFiles = unit.getMappingFile();
- for ( String mappingFile : mappingFiles ) {
- parsingOrmXml( mappingFile );
- }
- }
- }
- parsingOrmXml( ORM_XML ); // /META-INF/orm.xml is implicit
- xmlProcessed = true;
- }
-
- private void parsingOrmXml(String resource) {
- EntityMappings mappings = parseXml( resource, EntityMappings.class, ORM_XSD );
- if ( mappings == null ) {
- return;
- }
-
- AccessType accessType = determineGlobalAccessType( mappings );
-
- parseEntities( mappings, accessType );
- parseEmbeddable( mappings, accessType );
- parseMappedSuperClass( mappings, accessType );
- }
-
- private AccessType determineGlobalAccessType(EntityMappings mappings) {
- AccessType accessType = DEFAULT_XML_ACCESS_TYPE;
-
- if ( mappings.getAccess() != null ) {
- accessType = mapXmlAccessTypeToJpaAccessType( mappings.getAccess() );
- return accessType; // no need to check persistence unit default
- }
-
- PersistenceUnitMetadata meta = mappings.getPersistenceUnitMetadata();
- if ( meta != null ) {
- PersistenceUnitDefaults persistenceUnitDefaults = meta.getPersistenceUnitDefaults();
- if ( persistenceUnitDefaults != null ) {
- org.hibernate.jpamodelgen.xml.jaxb.AccessType xmlAccessType = persistenceUnitDefaults.getAccess();
- if ( xmlAccessType != null ) {
- accessType = mapXmlAccessTypeToJpaAccessType( xmlAccessType );
- }
- }
- }
- return accessType;
- }
-
- private AccessType mapXmlAccessTypeToJpaAccessType(org.hibernate.jpamodelgen.xml.jaxb.AccessType xmlAccessType) {
- switch ( xmlAccessType ) {
- case FIELD: {
- return AccessType.FIELD;
- }
- case PROPERTY: {
- return AccessType.PROPERTY;
- }
- }
- return null;
- }
-
- private void parseEntities(EntityMappings mappings, AccessType accessType) {
- String packageName = mappings.getPackage();
- Collection<Entity> entities = mappings.getEntity();
- for ( Entity entity : entities ) {
- String fullyQualifiedClassName = packageName + "." + entity.getClazz();
-
- if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
- context.logMessage(
- Diagnostic.Kind.WARNING,
- fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
- );
- continue;
- }
-
- XmlMetaEntity metaEntity = new XmlMetaEntity(
- entity, packageName, getXmlMappedType( fullyQualifiedClassName ),
- context
- );
-
- if ( context.getMetaEntitiesToProcess().containsKey( fullyQualifiedClassName ) ) {
- context.logMessage(
- Diagnostic.Kind.WARNING,
- fullyQualifiedClassName + " was already processed once. Skipping second occurance."
- );
- }
- context.getMetaEntitiesToProcess().put( fullyQualifiedClassName, metaEntity );
- }
- }
-
- private boolean xmlMappedTypeExists(String fullyQualifiedClassName) {
- Elements utils = processingEnv.getElementUtils();
- return utils.getTypeElement( fullyQualifiedClassName ) != null;
- }
-
- private TypeElement getXmlMappedType(String fullyQualifiedClassName) {
- Elements utils = processingEnv.getElementUtils();
- return utils.getTypeElement( fullyQualifiedClassName );
- }
-
- private void parseEmbeddable(EntityMappings mappings, AccessType accessType) {
- String packageName = mappings.getPackage();
- Collection<org.hibernate.jpamodelgen.xml.jaxb.Embeddable> embeddables = mappings.getEmbeddable();
- for ( org.hibernate.jpamodelgen.xml.jaxb.Embeddable embeddable : embeddables ) {
- String fullyQualifiedClassName = packageName + "." + embeddable.getClazz();
-
- if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
- context.logMessage(
- Diagnostic.Kind.WARNING,
- fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
- );
- continue;
- }
-
- XmlMetaEntity metaEntity = new XmlMetaEntity(
- embeddable, packageName, getXmlMappedType( fullyQualifiedClassName ),
- context
- );
-
- if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
- context.logMessage(
- Diagnostic.Kind.WARNING,
- fullyQualifiedClassName + " was already processed once. Skipping second occurance."
- );
- }
- context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
- }
- }
-
- private void parseMappedSuperClass(EntityMappings mappings, AccessType accessType) {
- String packageName = mappings.getPackage();
- Collection<org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass> mappedSuperClasses = mappings.getMappedSuperclass();
- for ( org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass mappedSuperClass : mappedSuperClasses ) {
- String fullyQualifiedClassName = packageName + "." + mappedSuperClass.getClazz();
-
- if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
- context.logMessage(
- Diagnostic.Kind.WARNING,
- fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
- );
- continue;
- }
-
- XmlMetaEntity metaEntity = new XmlMetaEntity(
- mappedSuperClass, packageName, getXmlMappedType( fullyQualifiedClassName ),
- context
- );
-
- if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
- context.logMessage(
- Diagnostic.Kind.WARNING,
- fullyQualifiedClassName + " was already processed once. Skipping second occurance."
- );
- }
- context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
- }
- }
-
private void handleRootElementAnnotationMirrors(final Element element) {
List<? extends AnnotationMirror> annotationMirrors = element
@@ -332,104 +153,4 @@
}
}
}
-
- private InputStream getInputStreamForResource(String resource) {
- String pkg = getPackage( resource );
- String name = getRelativeName( resource );
- context.logMessage( Diagnostic.Kind.OTHER, "Reading resource " + resource );
- InputStream ormStream;
- try {
- FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
- ormStream = fileObject.openInputStream();
- }
- catch ( IOException e1 ) {
-// processingEnv.getMessager()
-// .printMessage(
-// Diagnostic.Kind.WARNING,
-// "Could not load " + resource + " using processingEnv.getFiler().getResource(). Using classpath..."
-// );
-
- // TODO
- // unfortunately, the Filer.getResource API seems not to be able to load from /META-INF. One gets a
- // FilerException with the message with "Illegal name /META-INF". This means that we have to revert to
- // using the classpath. This might mean that we find a persistence.xml which is 'part of another jar.
- // Not sure what else we can do here
- ormStream = this.getClass().getResourceAsStream( resource );
- }
- return ormStream;
- }
-
- /**
- * Tries to open the specified xml file and return an instance of the specified class using JAXB.
- *
- * @param resource the xml file name
- * @param clazz The type of jaxb node to return
- * @param schemaName The schema to validate against (can be {@code null});
- *
- * @return The top level jaxb instance contained in the xml file or {@code null} in case the file could not be found.
- */
- private <T> T parseXml(String resource, Class<T> clazz, String schemaName) {
-
- InputStream stream = getInputStreamForResource( resource );
-
- if ( stream == null ) {
- context.logMessage( Diagnostic.Kind.OTHER, resource + " not found." );
- return null;
- }
- try {
- JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class );
- Unmarshaller unmarshaller = jc.createUnmarshaller();
- if ( schemaName != null ) {
- unmarshaller.setSchema( getSchema( schemaName ) );
- }
- return clazz.cast( unmarshaller.unmarshal( stream ) );
- }
- catch ( JAXBException e ) {
- String message = "Error unmarshalling " + resource + " with exception :\n " + e;
- context.logMessage( Diagnostic.Kind.WARNING, message );
- return null;
- }
- catch ( Exception e ) {
- String message = "Error reading " + resource + " with exception :\n " + e;
- context.logMessage( Diagnostic.Kind.WARNING, message );
- return null;
- }
- }
-
- private String getPackage(String resourceName) {
- if ( !resourceName.contains( PATH_SEPARATOR ) ) {
- return "";
- }
- else {
- return resourceName.substring( 0, resourceName.lastIndexOf( PATH_SEPARATOR ) );
- }
- }
-
- private String getRelativeName(String resourceName) {
- if ( !resourceName.contains( PATH_SEPARATOR ) ) {
- return resourceName;
- }
- else {
- return resourceName.substring( resourceName.lastIndexOf( PATH_SEPARATOR ) + 1 );
- }
- }
-
- private Schema getSchema(String schemaName) {
- Schema schema = null;
- URL schemaUrl = this.getClass().getClassLoader().getResource( schemaName );
- if ( schemaUrl == null ) {
- return schema;
- }
-
- SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
- try {
- schema = sf.newSchema( schemaUrl );
- }
- catch ( SAXException e ) {
- context.logMessage(
- Diagnostic.Kind.WARNING, "Unable to create schema for " + schemaName + ": " + e.getMessage()
- );
- }
- return schema;
- }
}
Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java 2010-01-22 20:48:42 UTC (rev 18611)
@@ -0,0 +1,321 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.
+*/
+package org.hibernate.jpamodelgen.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.Elements;
+import javax.persistence.AccessType;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.xml.sax.SAXException;
+
+import org.hibernate.jpamodelgen.Context;
+import org.hibernate.jpamodelgen.xml.jaxb.Entity;
+import org.hibernate.jpamodelgen.xml.jaxb.EntityMappings;
+import org.hibernate.jpamodelgen.xml.jaxb.ObjectFactory;
+import org.hibernate.jpamodelgen.xml.jaxb.Persistence;
+import org.hibernate.jpamodelgen.xml.jaxb.PersistenceUnitDefaults;
+import org.hibernate.jpamodelgen.xml.jaxb.PersistenceUnitMetadata;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class XmlParser {
+
+ private static final String PERSISTENCE_XML = "/META-INF/persistence.xml";
+ private static final String ORM_XML = "/META-INF/orm.xml";
+ private static final String PERSISTENCE_XML_XSD = "persistence_2_0.xsd";
+ private static final String ORM_XSD = "orm_2_0.xsd";
+ private static final String PATH_SEPARATOR = "/";
+ private static final AccessType DEFAULT_XML_ACCESS_TYPE = AccessType.PROPERTY;
+
+ private Context context;
+
+ public XmlParser(Context context) {
+ this.context = context;
+ }
+
+ public void parsePersistenceXml() {
+ Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class, PERSISTENCE_XML_XSD );
+ if ( persistence != null ) {
+ List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
+ for ( Persistence.PersistenceUnit unit : persistenceUnits ) {
+ List<String> mappingFiles = unit.getMappingFile();
+ for ( String mappingFile : mappingFiles ) {
+ parsingOrmXml( mappingFile );
+ }
+ }
+ }
+ parsingOrmXml( ORM_XML ); // /META-INF/orm.xml is implicit
+ }
+
+ private void parsingOrmXml(String resource) {
+ EntityMappings mappings = parseXml( resource, EntityMappings.class, ORM_XSD );
+ if ( mappings == null ) {
+ return;
+ }
+
+ AccessType accessType = determineGlobalAccessType( mappings );
+
+ parseEntities( mappings, accessType );
+ parseEmbeddable( mappings, accessType );
+ parseMappedSuperClass( mappings, accessType );
+ }
+
+ private void parseEntities(EntityMappings mappings, AccessType accessType) {
+ String packageName = mappings.getPackage();
+ Collection<Entity> entities = mappings.getEntity();
+ for ( Entity entity : entities ) {
+ String fullyQualifiedClassName = packageName + "." + entity.getClazz();
+
+ if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+ context.logMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+ );
+ continue;
+ }
+
+ XmlMetaEntity metaEntity = new XmlMetaEntity(
+ entity, packageName, getXmlMappedType( fullyQualifiedClassName ),
+ context
+ );
+
+ if ( context.getMetaEntitiesToProcess().containsKey( fullyQualifiedClassName ) ) {
+ context.logMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " was already processed once. Skipping second occurance."
+ );
+ }
+ context.getMetaEntitiesToProcess().put( fullyQualifiedClassName, metaEntity );
+ }
+ }
+
+ private void parseEmbeddable(EntityMappings mappings, AccessType accessType) {
+ String packageName = mappings.getPackage();
+ Collection<org.hibernate.jpamodelgen.xml.jaxb.Embeddable> embeddables = mappings.getEmbeddable();
+ for ( org.hibernate.jpamodelgen.xml.jaxb.Embeddable embeddable : embeddables ) {
+ String fullyQualifiedClassName = packageName + "." + embeddable.getClazz();
+
+ if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+ context.logMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+ );
+ continue;
+ }
+
+ XmlMetaEntity metaEntity = new XmlMetaEntity(
+ embeddable, packageName, getXmlMappedType( fullyQualifiedClassName ),
+ context
+ );
+
+ if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
+ context.logMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " was already processed once. Skipping second occurance."
+ );
+ }
+ context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
+ }
+ }
+
+
+ private void parseMappedSuperClass(EntityMappings mappings, AccessType accessType) {
+ String packageName = mappings.getPackage();
+ Collection<org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass> mappedSuperClasses = mappings.getMappedSuperclass();
+ for ( org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass mappedSuperClass : mappedSuperClasses ) {
+ String fullyQualifiedClassName = packageName + "." + mappedSuperClass.getClazz();
+
+ if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+ context.logMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+ );
+ continue;
+ }
+
+ XmlMetaEntity metaEntity = new XmlMetaEntity(
+ mappedSuperClass, packageName, getXmlMappedType( fullyQualifiedClassName ),
+ context
+ );
+
+ if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
+ context.logMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " was already processed once. Skipping second occurance."
+ );
+ }
+ context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
+ }
+ }
+
+ /**
+ * Tries to open the specified xml file and return an instance of the specified class using JAXB.
+ *
+ * @param resource the xml file name
+ * @param clazz The type of jaxb node to return
+ * @param schemaName The schema to validate against (can be {@code null});
+ *
+ * @return The top level jaxb instance contained in the xml file or {@code null} in case the file could not be found.
+ */
+ private <T> T parseXml(String resource, Class<T> clazz, String schemaName) {
+
+ InputStream stream = getInputStreamForResource( resource );
+
+ if ( stream == null ) {
+ context.logMessage( Diagnostic.Kind.OTHER, resource + " not found." );
+ return null;
+ }
+ try {
+ JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class );
+ Unmarshaller unmarshaller = jc.createUnmarshaller();
+ if ( schemaName != null ) {
+ unmarshaller.setSchema( getSchema( schemaName ) );
+ }
+ return clazz.cast( unmarshaller.unmarshal( stream ) );
+ }
+ catch ( JAXBException e ) {
+ String message = "Error unmarshalling " + resource + " with exception :\n " + e;
+ context.logMessage( Diagnostic.Kind.WARNING, message );
+ return null;
+ }
+ catch ( Exception e ) {
+ String message = "Error reading " + resource + " with exception :\n " + e;
+ context.logMessage( Diagnostic.Kind.WARNING, message );
+ return null;
+ }
+ }
+
+ private Schema getSchema(String schemaName) {
+ Schema schema = null;
+ URL schemaUrl = this.getClass().getClassLoader().getResource( schemaName );
+ if ( schemaUrl == null ) {
+ return schema;
+ }
+
+ SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
+ try {
+ schema = sf.newSchema( schemaUrl );
+ }
+ catch ( SAXException e ) {
+ context.logMessage(
+ Diagnostic.Kind.WARNING, "Unable to create schema for " + schemaName + ": " + e.getMessage()
+ );
+ }
+ return schema;
+ }
+
+ private InputStream getInputStreamForResource(String resource) {
+ String pkg = getPackage( resource );
+ String name = getRelativeName( resource );
+ context.logMessage( Diagnostic.Kind.OTHER, "Reading resource " + resource );
+ InputStream ormStream;
+ try {
+ FileObject fileObject = context.getProcessingEnvironment()
+ .getFiler()
+ .getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
+ ormStream = fileObject.openInputStream();
+ }
+ catch ( IOException e1 ) {
+ // TODO
+ // unfortunately, the Filer.getResource API seems not to be able to load from /META-INF. One gets a
+ // FilerException with the message with "Illegal name /META-INF". This means that we have to revert to
+ // using the classpath. This might mean that we find a persistence.xml which is 'part of another jar.
+ // Not sure what else we can do here
+ ormStream = this.getClass().getResourceAsStream( resource );
+ }
+ return ormStream;
+ }
+
+ private String getPackage(String resourceName) {
+ if ( !resourceName.contains( PATH_SEPARATOR ) ) {
+ return "";
+ }
+ else {
+ return resourceName.substring( 0, resourceName.lastIndexOf( PATH_SEPARATOR ) );
+ }
+ }
+
+ private String getRelativeName(String resourceName) {
+ if ( !resourceName.contains( PATH_SEPARATOR ) ) {
+ return resourceName;
+ }
+ else {
+ return resourceName.substring( resourceName.lastIndexOf( PATH_SEPARATOR ) + 1 );
+ }
+ }
+
+ private boolean xmlMappedTypeExists(String fullyQualifiedClassName) {
+ Elements utils = context.getProcessingEnvironment().getElementUtils();
+ return utils.getTypeElement( fullyQualifiedClassName ) != null;
+ }
+
+ private TypeElement getXmlMappedType(String fullyQualifiedClassName) {
+ Elements utils = context.getProcessingEnvironment().getElementUtils();
+ return utils.getTypeElement( fullyQualifiedClassName );
+ }
+
+
+ private AccessType determineGlobalAccessType(EntityMappings mappings) {
+ AccessType accessType = DEFAULT_XML_ACCESS_TYPE;
+
+ if ( mappings.getAccess() != null ) {
+ accessType = mapXmlAccessTypeToJpaAccessType( mappings.getAccess() );
+ return accessType; // no need to check persistence unit default
+ }
+
+ PersistenceUnitMetadata meta = mappings.getPersistenceUnitMetadata();
+ if ( meta != null ) {
+ PersistenceUnitDefaults persistenceUnitDefaults = meta.getPersistenceUnitDefaults();
+ if ( persistenceUnitDefaults != null ) {
+ org.hibernate.jpamodelgen.xml.jaxb.AccessType xmlAccessType = persistenceUnitDefaults.getAccess();
+ if ( xmlAccessType != null ) {
+ accessType = mapXmlAccessTypeToJpaAccessType( xmlAccessType );
+ }
+ }
+ }
+ return accessType;
+ }
+
+ private AccessType mapXmlAccessTypeToJpaAccessType(org.hibernate.jpamodelgen.xml.jaxb.AccessType xmlAccessType) {
+ switch ( xmlAccessType ) {
+ case FIELD: {
+ return AccessType.FIELD;
+ }
+ case PROPERTY: {
+ return AccessType.PROPERTY;
+ }
+ }
+ return null;
+ }
+}
+
+
14 years, 2 months
Hibernate SVN: r18610 - in jpamodelgen/trunk: src/main/java/org/hibernate/jpamodelgen and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-22 15:18:31 -0500 (Fri, 22 Jan 2010)
New Revision: 18610
Added:
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Version.java
Modified:
jpamodelgen/trunk/pom.xml
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
Log:
METAGEN-10
Switched to using Diagnostic.Kind.OTHER for debug messages. Only message in default mode is now "Hibernate JPA 2 Static-Metamodel Generator [version]"
Modified: jpamodelgen/trunk/pom.xml
===================================================================
--- jpamodelgen/trunk/pom.xml 2010-01-22 19:21:33 UTC (rev 18609)
+++ jpamodelgen/trunk/pom.xml 2010-01-22 20:18:31 UTC (rev 18610)
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -79,6 +81,32 @@
<plugins>
<plugin>
+ <groupId>org.jboss.maven.plugins</groupId>
+ <artifactId>maven-injection-plugin</artifactId>
+ <version>1.0.2</version>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>bytecode</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <bytecodeInjections>
+ <bytecodeInjection>
+ <expression>${pom.version}</expression>
+ <targetMembers>
+ <methodBodyReturn>
+ <className>org.hibernate.jpamodelgen.Version</className>
+ <methodName>getVersionString</methodName>
+ </methodBodyReturn>
+ </targetMembers>
+ </bytecodeInjection>
+ </bytecodeInjections>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
@@ -109,6 +137,7 @@
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
+ <version>2.0.4</version>
<executions>
<execution>
<id>attach-sources</id>
@@ -121,6 +150,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
<configuration>
<systemProperties>
<property>
@@ -140,6 +170,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
+ <version>2.5</version>
<executions>
<execution>
<id>generate-test-report</id>
@@ -172,7 +203,9 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
+ <version>2.0.4</version>
<executions>
<execution>
<id>attach-sources</id>
@@ -183,7 +216,9 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-2</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dist.xml</descriptor>
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2010-01-22 19:21:33 UTC (rev 18609)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2010-01-22 20:18:31 UTC (rev 18610)
@@ -106,7 +106,7 @@
//does not work for Entity (risk of circularity)
public void processElement(TypeElement element, AccessType defaultAccessTypeForHierarchy) {
if ( elementsAlreadyProcessed.contains( element.getQualifiedName().toString() ) ) {
- logMessage( Diagnostic.Kind.WARNING, "Element already processed (ignoring): " + element );
+ logMessage( Diagnostic.Kind.OTHER, "Element already processed (ignoring): " + element );
return;
}
ClassWriter.writeFile( new AnnotationMetaEntity( element, this, defaultAccessTypeForHierarchy ), this );
@@ -115,7 +115,7 @@
}
public void logMessage(Diagnostic.Kind type, String message) {
- if ( !logDebug && type.equals( Diagnostic.Kind.NOTE ) ) {
+ if ( !logDebug && type.equals( Diagnostic.Kind.OTHER ) ) {
return;
}
pe.getMessager().printMessage( type, message );
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-01-22 19:21:33 UTC (rev 18609)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-01-22 20:18:31 UTC (rev 18610)
@@ -85,7 +85,7 @@
public void init(ProcessingEnvironment env) {
super.init( env );
context = new Context( env );
- context.logMessage( Diagnostic.Kind.NOTE, "Init Processor " + this );
+ context.logMessage( Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString() );
}
@Override
@@ -93,9 +93,9 @@
final RoundEnvironment roundEnvironment) {
if ( roundEnvironment.processingOver() ) {
- context.logMessage( Diagnostic.Kind.NOTE, "Last processing round." );
+ context.logMessage( Diagnostic.Kind.OTHER, "Last processing round." );
createMetaModelClasses();
- context.logMessage( Diagnostic.Kind.NOTE, "Finished processing" );
+ context.logMessage( Diagnostic.Kind.OTHER, "Finished processing" );
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
@@ -104,13 +104,13 @@
}
if ( !hostJPAAnnotations( annotations ) ) {
- context.logMessage( Diagnostic.Kind.NOTE, "Current processing round does not contain entities" );
+ context.logMessage( Diagnostic.Kind.OTHER, "Current processing round does not contain entities" );
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
Set<? extends Element> elements = roundEnvironment.getRootElements();
for ( Element element : elements ) {
- context.logMessage( Diagnostic.Kind.NOTE, "Processing " + element.toString() );
+ context.logMessage( Diagnostic.Kind.OTHER, "Processing " + element.toString() );
handleRootElementAnnotationMirrors( element );
}
@@ -119,7 +119,7 @@
private void createMetaModelClasses() {
for ( MetaEntity entity : context.getMetaEntitiesToProcess().values() ) {
- context.logMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
+ context.logMessage( Diagnostic.Kind.OTHER, "Writing meta model for " + entity );
ClassWriter.writeFile( entity, context );
}
@@ -129,7 +129,7 @@
}
for ( MetaEntity entity : context.getMetaSuperclassAndEmbeddableToProcess().values() ) {
- context.logMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
+ context.logMessage( Diagnostic.Kind.OTHER, "Writing meta model for " + entity );
ClassWriter.writeFile( entity, context );
}
}
@@ -336,7 +336,7 @@
private InputStream getInputStreamForResource(String resource) {
String pkg = getPackage( resource );
String name = getRelativeName( resource );
- context.logMessage( Diagnostic.Kind.NOTE, "Reading resource " + resource );
+ context.logMessage( Diagnostic.Kind.OTHER, "Reading resource " + resource );
InputStream ormStream;
try {
FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
@@ -373,7 +373,7 @@
InputStream stream = getInputStreamForResource( resource );
if ( stream == null ) {
- context.logMessage( Diagnostic.Kind.NOTE, resource + " not found." );
+ context.logMessage( Diagnostic.Kind.OTHER, resource + " not found." );
return null;
}
try {
Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Version.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Version.java (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Version.java 2010-01-22 20:18:31 UTC (rev 18610)
@@ -0,0 +1,31 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.
+*/
+package org.hibernate.jpamodelgen;
+
+/**
+ * Information about the Meta Model Generator version.
+ *
+ * @author Hardy Ferentschik
+ */
+public class Version {
+ public static String getVersionString() {
+ return "[WORKING]";
+ }
+}
+
+
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-01-22 19:21:33 UTC (rev 18609)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-01-22 20:18:31 UTC (rev 18610)
@@ -206,14 +206,14 @@
}
private AccessType getAccessTypeForClass(TypeElement searchedElement) {
- context.logMessage( Diagnostic.Kind.NOTE, "check class " + searchedElement );
+ context.logMessage( Diagnostic.Kind.OTHER, "check class " + searchedElement );
AccessType accessType = context.getAccessType( searchedElement );
if ( defaultAccessTypeForHierarchy == null ) {
this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
}
if ( accessType != null ) {
- context.logMessage( Diagnostic.Kind.NOTE, "Found in cache" + searchedElement + ":" + accessType );
+ context.logMessage( Diagnostic.Kind.OTHER, "Found in cache" + searchedElement + ":" + accessType );
return accessType;
}
@@ -224,7 +224,7 @@
final Access accessAnn = searchedElement.getAnnotation( Access.class );
AccessType forcedAccessType = accessAnn != null ? accessAnn.value() : null;
if ( forcedAccessType != null ) {
- context.logMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + forcedAccessType );
+ context.logMessage( Diagnostic.Kind.OTHER, "access type " + searchedElement + ":" + forcedAccessType );
context.addAccessType( searchedElement, forcedAccessType );
}
@@ -244,7 +244,7 @@
//FIXME consider XML
if ( annotationType.equals( Id.class.getName() )
|| annotationType.equals( EmbeddedId.class.getName() ) ) {
- context.logMessage( Diagnostic.Kind.NOTE, "Found id on" + searchedElement );
+ context.logMessage( Diagnostic.Kind.OTHER, "Found id on" + searchedElement );
final ElementKind kind = subElement.getKind();
if ( kind == ElementKind.FIELD || kind == ElementKind.METHOD ) {
accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
@@ -264,7 +264,7 @@
if ( forcedAccessType == null ) {
context.addAccessType( searchedElement, accessType );
context.logMessage(
- Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + accessType
+ Diagnostic.Kind.OTHER, "access type " + searchedElement + ":" + accessType
);
return accessType;
}
14 years, 2 months
Hibernate SVN: r18609 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/test/metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-22 14:21:33 -0500 (Fri, 22 Jan 2010)
New Revision: 18609
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/DeskWithRawType.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/EmployeeWithRawType.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
Log:
HHH-4834 Take into account that collections can be of raw type.
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-01-22 18:52:56 UTC (rev 18608)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-01-22 19:21:33 UTC (rev 18609)
@@ -734,12 +734,18 @@
ParameterizedType signatureType = getSignatureType( member );
if ( keyPersistentAttributeType == null ) {
- elementJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] );
+ elementJavaType = signatureType != null ?
+ getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
+ Object.class; //FIXME and honor targetEntity?
keyJavaType = null;
}
else {
- keyJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] );
- elementJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] );
+ keyJavaType = signatureType != null ?
+ getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
+ Object.class; //FIXME and honor targetEntity?
+ elementJavaType = signatureType != null ?
+ getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] ) :
+ Object.class; //FIXME and honor targetEntity?
}
this.elementValueContext = new ValueContext() {
@@ -836,9 +842,12 @@
}
public static ParameterizedType getSignatureType(Member member) {
- return (ParameterizedType) ( Field.class.isInstance( member )
- ? ( (Field) member ).getGenericType()
- : ( (Method) member ).getGenericReturnType());
+ final java.lang.reflect.Type type = Field.class.isInstance( member )
+ ? ( ( Field ) member ).getGenericType()
+ : ( ( Method ) member ).getGenericReturnType();
+ //this is a raw type
+ if ( type instanceof Class ) return null;
+ return (ParameterizedType) type;
}
public static PluralAttribute.CollectionType determineCollectionType(Class javaType) {
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/DeskWithRawType.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/DeskWithRawType.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/DeskWithRawType.java 2010-01-22 19:21:33 UTC (rev 18609)
@@ -0,0 +1,61 @@
+package org.hibernate.ejb.test.metadata;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class DeskWithRawType implements java.io.Serializable {
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+ public DeskWithRawType() {
+ }
+
+ @ManyToMany(targetEntity = EmployeeWithRawType.class, cascade = CascadeType.ALL)
+ @JoinTable(name = "DESK_EMPL",
+ joinColumns =
+ @JoinColumn(
+ name = "DESK_FK", referencedColumnName = "ID"),
+ inverseJoinColumns =
+ @JoinColumn(
+ name = "EMPL_FK", referencedColumnName = "ID")
+ )
+ protected Collection employees = new java.util.ArrayList();
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(Collection employees) {
+ this.employees = employees;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/EmployeeWithRawType.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/EmployeeWithRawType.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/EmployeeWithRawType.java 2010-01-22 19:21:33 UTC (rev 18609)
@@ -0,0 +1,52 @@
+package org.hibernate.ejb.test.metadata;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class EmployeeWithRawType implements java.io.Serializable {
+
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+ @ManyToMany(targetEntity = DeskWithRawType.class, mappedBy = "employees", cascade = CascadeType.ALL)
+ protected Collection desks = new java.util.ArrayList();
+
+ public EmployeeWithRawType() {
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection getDesks() {
+ return desks;
+ }
+
+ public void setDesks(Collection desks) {
+ this.desks = desks;
+ }
+}
\ No newline at end of file
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java 2010-01-22 19:21:33 UTC (rev 18609)
@@ -0,0 +1,26 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class SecondMetadataTest extends TestCase {
+
+ public void testBaseOfService() throws Exception {
+ EntityManagerFactory emf = factory;
+ assertNotNull( emf.getMetamodel() );
+ assertNotNull( emf.getMetamodel().entity( DeskWithRawType.class ) );
+ assertNotNull( emf.getMetamodel().entity( EmployeeWithRawType.class ) );
+ }
+
+ @Override
+ public Class[] getAnnotatedClasses() {
+ return new Class[] {
+ DeskWithRawType.class,
+ EmployeeWithRawType.class
+ };
+ }
+}
14 years, 2 months
Hibernate SVN: r18608 - jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-22 13:52:56 -0500 (Fri, 22 Jan 2010)
New Revision: 18608
Added:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/DeskWithRawType.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/EmployeeWithRawType.java
Removed:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java
Modified:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java
Log:
METAGEN-20 better example names
Deleted: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java 2010-01-22 18:38:53 UTC (rev 18607)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java 2010-01-22 18:52:56 UTC (rev 18608)
@@ -1,68 +0,0 @@
-package org.hibernate.jpamodelgen.test.rawTypes;
-
-import java.util.Collection;
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class A implements java.io.Serializable {
-
- @Id
- protected String id;
-
- @Basic
- protected String name;
-
- @Basic
- protected int value;
-
-
- public A() {
- }
-
- @ManyToMany(targetEntity = B.class, cascade = CascadeType.ALL)
- @JoinTable(name = "tbl_A_B",
- joinColumns =
- @JoinColumn(
- name = "A_FK", referencedColumnName = "ID"),
- inverseJoinColumns =
- @JoinColumn(
- name = "B_FK", referencedColumnName = "ID")
- )
- protected Collection bCol = new java.util.ArrayList();
-
-
- public Collection getBCol() {
- return bCol;
- }
-
- public void setBCol(Collection bCol) {
- this.bCol = bCol;
- }
-
- public String getAId() {
- return id;
- }
-
- public String getAName() {
- return name;
- }
-
- public void setAName(String aName) {
- this.name = aName;
- }
-
-
- public int getAValue() {
- return value;
- }
-}
\ No newline at end of file
Deleted: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java 2010-01-22 18:38:53 UTC (rev 18607)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java 2010-01-22 18:52:56 UTC (rev 18608)
@@ -1,54 +0,0 @@
-package org.hibernate.jpamodelgen.test.rawTypes;
-
-import java.util.Collection;
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class B implements java.io.Serializable {
-
- @Id
- protected String id;
-
- @Basic
- protected String name;
-
- @Basic
- protected int value;
-
-
- @ManyToMany(targetEntity = A.class, mappedBy = "bCol", cascade = CascadeType.ALL)
- protected Collection aCol = new java.util.ArrayList();
-
-
- public B() {
- }
-
-
- public Collection getACol() {
- return aCol;
- }
-
- public void setACol(Collection aCol) {
- this.aCol = aCol;
- }
-
- public String getBId() {
- return id;
- }
-
- public String getBName() {
- return name;
- }
-
- public int getBValue() {
- return value;
- }
-}
Copied: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/DeskWithRawType.java (from rev 18607, jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java)
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/DeskWithRawType.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/DeskWithRawType.java 2010-01-22 18:52:56 UTC (rev 18608)
@@ -0,0 +1,62 @@
+package org.hibernate.jpamodelgen.test.rawTypes;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class DeskWithRawType implements java.io.Serializable {
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+
+ public DeskWithRawType() {
+ }
+
+ @ManyToMany(targetEntity = EmployeeWithRawType.class, cascade = CascadeType.ALL)
+ @JoinTable(name = "DESK_EMPL",
+ joinColumns =
+ @JoinColumn(
+ name = "DESK_FK", referencedColumnName = "ID"),
+ inverseJoinColumns =
+ @JoinColumn(
+ name = "EMPLO_FK", referencedColumnName = "ID")
+ )
+ protected Collection employees = new java.util.ArrayList();
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(Collection employees) {
+ this.employees = employees;
+ }
+}
\ No newline at end of file
Copied: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/EmployeeWithRawType.java (from rev 18607, jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java)
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/EmployeeWithRawType.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/EmployeeWithRawType.java 2010-01-22 18:52:56 UTC (rev 18608)
@@ -0,0 +1,53 @@
+package org.hibernate.jpamodelgen.test.rawTypes;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class EmployeeWithRawType implements java.io.Serializable {
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+
+ @ManyToMany(targetEntity = DeskWithRawType.class, mappedBy = "employees", cascade = CascadeType.ALL)
+ protected Collection desks = new java.util.ArrayList();
+
+
+ public EmployeeWithRawType() {
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection getDesks() {
+ return desks;
+ }
+
+ public void setDesks(Collection desks) {
+ this.desks = desks;
+ }
+}
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java 2010-01-22 18:38:53 UTC (rev 18607)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java 2010-01-22 18:52:56 UTC (rev 18608)
@@ -30,12 +30,12 @@
@Test
public void testGenerics() {
- assertClassGenerated( A.class.getName() + "_" );
- assertClassGenerated( B.class.getName() + "_" );
+ assertClassGenerated( DeskWithRawType.class.getName() + "_" );
+ assertClassGenerated( EmployeeWithRawType.class.getName() + "_" );
}
@Override
protected String getTestPackage() {
- return A.class.getPackage().getName();
+ return DeskWithRawType.class.getPackage().getName();
}
}
\ No newline at end of file
14 years, 2 months
Hibernate SVN: r18607 - in jpamodelgen/trunk/src: main/java/org/hibernate/jpamodelgen/annotation and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-22 13:38:53 -0500 (Fri, 22 Jan 2010)
New Revision: 18607
Added:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java
Modified:
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java
Log:
METAGEN-20 support raw collections and honor targetEntity
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java 2010-01-22 12:35:15 UTC (rev 18606)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java 2010-01-22 18:38:53 UTC (rev 18607)
@@ -79,8 +79,7 @@
public static String extractClosestRealTypeAsString(TypeMirror type, Context context) {
if ( type instanceof TypeVariable ) {
final TypeMirror compositeUpperBound = ( ( TypeVariable ) type ).getUpperBound();
- final Types types = context.getProcessingEnvironment()
- .getTypeUtils();
+ final Types types = context.getProcessingEnvironment().getTypeUtils();
final List<? extends TypeMirror> upperBounds = types.directSupertypes( compositeUpperBound );
if (upperBounds.size() == 0) {
return compositeUpperBound.toString();
@@ -89,7 +88,6 @@
//take the first one
return extractClosestRealTypeAsString( upperBounds.get( 0 ), context );
}
-
}
else {
return type.toString();
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-01-22 12:35:15 UTC (rev 18606)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-01-22 18:38:53 UTC (rev 18607)
@@ -22,8 +22,10 @@
import java.util.List;
import java.util.Map;
import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.Name;
import javax.lang.model.element.PackageElement;
@@ -43,7 +45,11 @@
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
import javax.persistence.Transient;
import javax.tools.Diagnostic;
@@ -348,8 +354,11 @@
String fqElementName = returnedElement.getQualifiedName()
.toString(); // WARNING: .toString() is necessary here since Name equals does not compare to String
String collection = COLLECTIONS.get( fqElementName );
+ final List<? extends AnnotationMirror> annotations = element.getAnnotationMirrors();
+ String targetEntity = getTargetEntity( annotations );
if ( collection != null ) {
- if ( element.getAnnotation( ElementCollection.class ) != null ) {
+ if ( containsAnnotation( annotations, ElementCollection.class ) ) {
+ //FIXME I don't understand why this code is different between Elementcollection and a regular collection but it needs to take targetClass into account
TypeMirror collectionElementType = getCollectionElementType( t, fqElementName );
final TypeElement collectionElement = ( TypeElement ) context.getProcessingEnvironment()
.getTypeUtils()
@@ -361,11 +370,12 @@
}
if ( collection.equals( "javax.persistence.metamodel.MapAttribute" ) ) {
return new AnnotationMetaMap(
- parent, element, collection, getKeyType( t ), getElementType( t )
+ //FIXME support targetEntity for map's key @MapKeyClass
+ parent, element, collection, getKeyType( t ), getElementType( t, targetEntity )
);
}
else {
- return new AnnotationMetaCollection( parent, element, collection, getElementType( t ) );
+ return new AnnotationMetaCollection( parent, element, collection, getElementType( t, targetEntity ) );
}
}
else {
@@ -414,6 +424,63 @@
}
}
+ private boolean containsAnnotation(List<? extends AnnotationMirror> annotations, Class<?> annotation) {
+ String annString = annotation.getName();
+ for ( AnnotationMirror mirror : annotations ) {
+ if ( annString.equals( mirror.getAnnotationType().toString() ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns targetEntity or null if no targetEntity is here or if equals to void
+ */
+ private String getTargetEntity(List<? extends AnnotationMirror> annotations) {
+ final String elementCollection = ElementCollection.class.getName();
+
+ for ( AnnotationMirror mirror : annotations ) {
+ final String annotation = mirror.getAnnotationType().toString();
+ if ( elementCollection.equals( annotation ) ) {
+ final String targetEntity = getTargetEntity( mirror );
+ if (targetEntity != null) return targetEntity;
+ }
+ else if ( OneToMany.class.getName().equals( annotation ) ) {
+ final String targetEntity = getTargetEntity( mirror );
+ if (targetEntity != null) return targetEntity;
+ }
+ else if ( ManyToMany.class.getName().equals( annotation ) ) {
+ final String targetEntity = getTargetEntity( mirror );
+ if (targetEntity != null) return targetEntity;
+ }
+ else if ( ManyToOne.class.getName().equals( annotation ) ) {
+ final String targetEntity = getTargetEntity( mirror );
+ if (targetEntity != null) return targetEntity;
+ }
+ else if ( OneToOne.class.getName().equals( annotation ) ) {
+ final String targetEntity = getTargetEntity( mirror );
+ if (targetEntity != null) return targetEntity;
+ }
+ }
+ return null;
+ }
+
+ private String getTargetEntity(AnnotationMirror mirror) {
+ String targetEntity = null;
+ final Map<? extends ExecutableElement, ? extends AnnotationValue> attributes = mirror.getElementValues();
+ for ( Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : attributes.entrySet() ) {
+ final String simpleName = entry.getKey().getSimpleName().toString();
+ if ( "targetEntity".equals( simpleName ) ) {
+ targetEntity = entry.getValue().toString();
+ break;
+ }
+ }
+ targetEntity = ( "void.class".equals( targetEntity ) ) ? null : targetEntity;
+ return targetEntity != null && targetEntity.endsWith( ".class" ) ?
+ targetEntity.substring( 0, targetEntity.length() - 6 ) : null;
+ }
+
public String generateImports() {
return importContext.generateImports();
}
@@ -438,13 +505,23 @@
return TypeUtils.extractClosestRealTypeAsString( t.getTypeArguments().get( 0 ), context );
}
- private String getElementType(DeclaredType declaredType) {
- if ( declaredType.getTypeArguments().size() == 1 ) {
- final TypeMirror type = declaredType.getTypeArguments().get( 0 );
+ private String getElementType(DeclaredType declaredType, String targetEntity) {
+ if (targetEntity != null) return targetEntity;
+ final List<? extends TypeMirror> mirrors = declaredType.getTypeArguments();
+ if ( mirrors.size() == 1 ) {
+ final TypeMirror type = mirrors.get( 0 );
return TypeUtils.extractClosestRealTypeAsString( type, context );
}
+ else if ( mirrors.size() == 2 ) {
+ return TypeUtils.extractClosestRealTypeAsString( mirrors.get( 1 ), context );
+ }
else {
- return TypeUtils.extractClosestRealTypeAsString( declaredType.getTypeArguments().get( 1 ), context );
+ //for 0 or many
+ //0 is expected, many is not
+ if ( mirrors.size() > 2) {
+ context.logMessage( Diagnostic.Kind.WARNING, "Unable to find the closest solid type" + declaredType );
+ }
+ return "?";
}
}
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java 2010-01-22 12:35:15 UTC (rev 18606)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java 2010-01-22 18:38:53 UTC (rev 18607)
@@ -56,7 +56,7 @@
this.name = name;
}
- @OneToMany
+ @OneToMany(targetEntity = void.class)
@JoinColumn(name="parent_fk", nullable = false)
public Set<Child> getChildren() {
return children;
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/A.java 2010-01-22 18:38:53 UTC (rev 18607)
@@ -0,0 +1,68 @@
+package org.hibernate.jpamodelgen.test.rawTypes;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class A implements java.io.Serializable {
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+ @Basic
+ protected int value;
+
+
+ public A() {
+ }
+
+ @ManyToMany(targetEntity = B.class, cascade = CascadeType.ALL)
+ @JoinTable(name = "tbl_A_B",
+ joinColumns =
+ @JoinColumn(
+ name = "A_FK", referencedColumnName = "ID"),
+ inverseJoinColumns =
+ @JoinColumn(
+ name = "B_FK", referencedColumnName = "ID")
+ )
+ protected Collection bCol = new java.util.ArrayList();
+
+
+ public Collection getBCol() {
+ return bCol;
+ }
+
+ public void setBCol(Collection bCol) {
+ this.bCol = bCol;
+ }
+
+ public String getAId() {
+ return id;
+ }
+
+ public String getAName() {
+ return name;
+ }
+
+ public void setAName(String aName) {
+ this.name = aName;
+ }
+
+
+ public int getAValue() {
+ return value;
+ }
+}
\ No newline at end of file
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/B.java 2010-01-22 18:38:53 UTC (rev 18607)
@@ -0,0 +1,54 @@
+package org.hibernate.jpamodelgen.test.rawTypes;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class B implements java.io.Serializable {
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+ @Basic
+ protected int value;
+
+
+ @ManyToMany(targetEntity = A.class, mappedBy = "bCol", cascade = CascadeType.ALL)
+ protected Collection aCol = new java.util.ArrayList();
+
+
+ public B() {
+ }
+
+
+ public Collection getACol() {
+ return aCol;
+ }
+
+ public void setACol(Collection aCol) {
+ this.aCol = aCol;
+ }
+
+ public String getBId() {
+ return id;
+ }
+
+ public String getBName() {
+ return name;
+ }
+
+ public int getBValue() {
+ return value;
+ }
+}
Copied: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java (from rev 18565, jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java)
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawTypes/RawTypesTest.java 2010-01-22 18:38:53 UTC (rev 18607)
@@ -0,0 +1,41 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.
+*/
+package org.hibernate.jpamodelgen.test.rawTypes;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.jpamodelgen.test.util.CompilationTest;
+
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertClassGenerated;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class RawTypesTest extends CompilationTest {
+
+ @Test
+ public void testGenerics() {
+ assertClassGenerated( A.class.getName() + "_" );
+ assertClassGenerated( B.class.getName() + "_" );
+ }
+
+ @Override
+ protected String getTestPackage() {
+ return A.class.getPackage().getName();
+ }
+}
\ No newline at end of file
14 years, 2 months
Hibernate SVN: r18606 - core/trunk/annotations/src/main/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-22 07:35:15 -0500 (Fri, 22 Jan 2010)
New Revision: 18606
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
Log:
HHH-4659 - Add support for standard declarative cache (@Cacheable)
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-22 07:22:50 UTC (rev 18605)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-22 12:35:15 UTC (rev 18606)
@@ -780,6 +780,9 @@
SharedCacheMode mode = (SharedCacheMode) mappings.getConfigurationProperties().get(
"javax.persistence.sharedCache.mode"
);
+ if ( mode == null ) {
+ mode = SharedCacheMode.UNSPECIFIED;
+ }
switch ( mode ) {
case ALL: {
cacheAnn = buildCacheMock( clazzToProcess.getName(), mappings );
14 years, 2 months
Hibernate SVN: r18605 - in core/trunk: core/src/main/java/org/hibernate/cfg and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-22 02:22:50 -0500 (Fri, 22 Jan 2010)
New Revision: 18605
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyCacheableEntity.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyNonCacheableEntity.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/NoCacheableAnnotationEntity.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
core/trunk/core/src/main/java/org/hibernate/cfg/SettingsFactory.java
Log:
HHH-4659 - Add support for standard declarative cache (@Cacheable)
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-22 02:16:10 UTC (rev 18604)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -24,6 +24,7 @@
*/
package org.hibernate.cfg;
+import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -36,6 +37,7 @@
import java.util.Properties;
import java.util.Set;
import javax.persistence.Basic;
+import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
@@ -66,6 +68,7 @@
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.PrimaryKeyJoinColumns;
import javax.persistence.SequenceGenerator;
+import javax.persistence.SharedCacheMode;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;
@@ -86,6 +89,7 @@
import org.hibernate.MappingException;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Check;
@@ -128,6 +132,7 @@
import org.hibernate.annotations.common.reflection.XMethod;
import org.hibernate.annotations.common.reflection.XPackage;
import org.hibernate.annotations.common.reflection.XProperty;
+import org.hibernate.cache.RegionFactory;
import org.hibernate.cfg.annotations.CollectionBinder;
import org.hibernate.cfg.annotations.EntityBinder;
import org.hibernate.cfg.annotations.Nullability;
@@ -505,9 +510,9 @@
org.hibernate.annotations.Entity hibEntityAnn = clazzToProcess.getAnnotation(
org.hibernate.annotations.Entity.class
);
- org.hibernate.annotations.Cache cacheAnn = clazzToProcess.getAnnotation(
- org.hibernate.annotations.Cache.class
- );
+
+ Cache cacheAnn = determineCacheSettings( clazzToProcess, mappings );
+
EntityBinder entityBinder = new EntityBinder(
entityAnn, hibEntityAnn, clazzToProcess, persistentClass, mappings
);
@@ -765,6 +770,84 @@
}
+ private static Cache determineCacheSettings(XClass clazzToProcess, ExtendedMappings mappings) {
+ Cache cacheAnn = clazzToProcess.getAnnotation( Cache.class );
+ if ( cacheAnn != null ) {
+ return cacheAnn;
+ }
+
+ Cacheable cacheableAnn = clazzToProcess.getAnnotation( Cacheable.class );
+ SharedCacheMode mode = (SharedCacheMode) mappings.getConfigurationProperties().get(
+ "javax.persistence.sharedCache.mode"
+ );
+ switch ( mode ) {
+ case ALL: {
+ cacheAnn = buildCacheMock( clazzToProcess.getName(), mappings );
+ break;
+ }
+ case ENABLE_SELECTIVE: {
+ if ( cacheableAnn != null && cacheableAnn.value() ) {
+ cacheAnn = buildCacheMock( clazzToProcess.getName(), mappings );
+ }
+ break;
+ }
+ case DISABLE_SELECTIVE: {
+ if ( cacheableAnn == null || cacheableAnn.value() ) {
+ cacheAnn = buildCacheMock( clazzToProcess.getName(), mappings );
+ }
+ break;
+ }
+ default: {
+ // treat both NONE and UNSPECIFIED the same
+ break;
+ }
+ }
+ return cacheAnn;
+ }
+
+ private static Cache buildCacheMock(String region, ExtendedMappings mappings) {
+ return new LocalCacheAnnotationImpl( region, determineCacheConcurrencyStrategy( mappings ) );
+ }
+
+ private static CacheConcurrencyStrategy DEFAULT_CACHE_CONCURRENCY_STRATEGY;
+
+ private static CacheConcurrencyStrategy determineCacheConcurrencyStrategy(ExtendedMappings mappings) {
+ if ( DEFAULT_CACHE_CONCURRENCY_STRATEGY == null ) {
+// todo need to figure out how we will determine the default cache access-type/concurrency-strategy
+// RegionFactory cacheRegionFactory = SettingsFactory.createRegionFactory( mappings.getConfigurationProperties(), true );
+// DEFAULT_CACHE_CONCURRENCY_STRATEGY = cacheRegionFactory.[getDefault...]
+ DEFAULT_CACHE_CONCURRENCY_STRATEGY = CacheConcurrencyStrategy.TRANSACTIONAL;
+ }
+ return DEFAULT_CACHE_CONCURRENCY_STRATEGY;
+ }
+
+ @SuppressWarnings({ "ClassExplicitlyAnnotation" })
+ private static class LocalCacheAnnotationImpl implements Cache {
+ private final String region;
+ private final CacheConcurrencyStrategy usage;
+
+ private LocalCacheAnnotationImpl(String region, CacheConcurrencyStrategy usage) {
+ this.region = region;
+ this.usage = usage;
+ }
+
+ public CacheConcurrencyStrategy usage() {
+ return usage;
+ }
+
+ public String region() {
+ return region;
+ }
+
+ public String include() {
+ return "all";
+ }
+
+ public Class<? extends Annotation> annotationType() {
+ return Cache.class;
+ }
+ }
+
private static PersistentClass makePersistentClass(InheritanceState inheritanceState, PersistentClass superEntity) {
//we now know what kind of persistent entity it is
PersistentClass persistentClass;
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-22 02:16:10 UTC (rev 18604)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -68,6 +68,7 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.annotations.AnyMetaDef;
+import org.hibernate.annotations.Cache;
import org.hibernate.annotations.common.reflection.MetadataProvider;
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
import org.hibernate.annotations.common.reflection.ReflectionManager;
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-01-22 02:16:10 UTC (rev 18604)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -30,6 +30,7 @@
import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
import org.hibernate.annotations.AnyMetaDef;
+import org.hibernate.annotations.Cache;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.engine.NamedQueryDefinition;
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2010-01-22 02:16:10 UTC (rev 18604)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -474,7 +474,7 @@
/**
* <b>INTENDED FOR TESTSUITE USE ONLY!</b>
* <p/>
- * Much like {@link addCacheableFile(File)} except that here we will fail immediately if
+ * Much like {@link #addCacheableFile(File)} except that here we will fail immediately if
* the cache version cannot be found or used for whatever reason
*
* @param xmlFile The xml file, not the bin!
@@ -2797,6 +2797,10 @@
public ObjectNameNormalizer getObjectNameNormalizer() {
return normalizer;
}
+
+ public Properties getConfigurationProperties() {
+ return properties;
+ }
}
final ObjectNameNormalizer normalizer = new ObjectNameNormalizerImpl();
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java 2010-01-22 02:16:10 UTC (rev 18604)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -550,4 +550,11 @@
* @return The normalizer.
*/
public ObjectNameNormalizer getObjectNameNormalizer();
+
+ /**
+ * Retrieve the configuration properties currently in effect.
+ *
+ * @return The configuration properties
+ */
+ public Properties getConfigurationProperties();
}
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/SettingsFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/SettingsFactory.java 2010-01-22 02:16:10 UTC (rev 18604)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/SettingsFactory.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -380,7 +380,7 @@
}
}
- protected RegionFactory createRegionFactory(Properties properties, boolean cachingEnabled) {
+ public static RegionFactory createRegionFactory(Properties properties, boolean cachingEnabled) {
String regionFactoryClassName = PropertiesHelper.getString( Environment.CACHE_REGION_FACTORY, properties, null );
if ( regionFactoryClassName == null && cachingEnabled ) {
String providerClassName = PropertiesHelper.getString( Environment.CACHE_PROVIDER, properties, null );
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ConfigurationTest.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -0,0 +1,120 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.ejb.test.cacheable.annotation;
+
+import java.util.Properties;
+import javax.persistence.SharedCacheMode;
+
+import org.hibernate.ejb.AvailableSettings;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.junit.UnitTestCase;
+import org.hibernate.mapping.PersistentClass;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class ConfigurationTest extends UnitTestCase {
+ public ConfigurationTest(String string) {
+ super( string );
+ }
+
+ public void testSharedCacheModeNone() {
+ Ejb3Configuration config = buildConfiguration( SharedCacheMode.NONE );
+
+ PersistentClass pc = config.getClassMapping( ExplicitlyCacheableEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( ExplicitlyNonCacheableEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( NoCacheableAnnotationEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+ }
+
+ public void testSharedCacheModeUnspecified() {
+ Ejb3Configuration config = buildConfiguration( SharedCacheMode.UNSPECIFIED );
+
+ PersistentClass pc = config.getClassMapping( ExplicitlyCacheableEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( ExplicitlyNonCacheableEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( NoCacheableAnnotationEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+ }
+
+ public void testSharedCacheModeAll() {
+ Ejb3Configuration config = buildConfiguration( SharedCacheMode.ALL );
+
+ PersistentClass pc = config.getClassMapping( ExplicitlyCacheableEntity.class.getName() );
+ assertNotNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( ExplicitlyNonCacheableEntity.class.getName() );
+ assertNotNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( NoCacheableAnnotationEntity.class.getName() );
+ assertNotNull( pc.getCacheConcurrencyStrategy() );
+ }
+
+ public void testSharedCacheModeEnable() {
+ Ejb3Configuration config = buildConfiguration( SharedCacheMode.ENABLE_SELECTIVE );
+
+ PersistentClass pc = config.getClassMapping( ExplicitlyCacheableEntity.class.getName() );
+ assertNotNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( ExplicitlyNonCacheableEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( NoCacheableAnnotationEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+ }
+
+ public void testSharedCacheModeDisable() {
+ Ejb3Configuration config = buildConfiguration( SharedCacheMode.DISABLE_SELECTIVE );
+
+ PersistentClass pc = config.getClassMapping( ExplicitlyCacheableEntity.class.getName() );
+ assertNotNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( ExplicitlyNonCacheableEntity.class.getName() );
+ assertNull( pc.getCacheConcurrencyStrategy() );
+
+ pc = config.getClassMapping( NoCacheableAnnotationEntity.class.getName() );
+ assertNotNull( pc.getCacheConcurrencyStrategy() );
+ }
+
+ private Ejb3Configuration buildConfiguration(SharedCacheMode mode) {
+ Properties properties = new Properties();
+ properties.put( AvailableSettings.SHARED_CACHE_MODE, mode );
+ Ejb3Configuration config = new Ejb3Configuration();
+ config.setProperties( properties );
+ config.addAnnotatedClass( ExplicitlyCacheableEntity.class );
+ config.addAnnotatedClass( ExplicitlyNonCacheableEntity.class );
+ config.addAnnotatedClass( NoCacheableAnnotationEntity.class );
+ config.buildMappings();
+ return config;
+ }
+}
Copied: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyCacheableEntity.java (from rev 18603, core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/cachemodes/SimpleEntity.java)
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyCacheableEntity.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyCacheableEntity.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.ejb.test.cacheable.annotation;
+
+import javax.persistence.Cacheable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+@Cacheable
+public class ExplicitlyCacheableEntity {
+ private Long id;
+ private String name;
+
+ @Id
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
\ No newline at end of file
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyNonCacheableEntity.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyNonCacheableEntity.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/ExplicitlyNonCacheableEntity.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.ejb.test.cacheable.annotation;
+
+import javax.persistence.Cacheable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+@Cacheable(false)
+public class ExplicitlyNonCacheableEntity {
+ private Long id;
+ private String name;
+
+ @Id
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/NoCacheableAnnotationEntity.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/NoCacheableAnnotationEntity.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/annotation/NoCacheableAnnotationEntity.java 2010-01-22 07:22:50 UTC (rev 18605)
@@ -0,0 +1,56 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.ejb.test.cacheable.annotation;
+
+import javax.persistence.Cacheable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class NoCacheableAnnotationEntity {
+ private Long id;
+ private String name;
+
+ @Id
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
\ No newline at end of file
14 years, 2 months