You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/12/01 20:22:55 UTC
svn commit: r722189 [2/3] - in /tapestry/tapestry5/trunk: ./ quickstart/
tapestry-component-report/ tapestry-hibernate-core/
tapestry-hibernate-core/src/ tapestry-hibernate-core/src/main/
tapestry-hibernate-core/src/main/java/ tapestry-hibernate-core/s...
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/annotations/CommitAfter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/annotations/CommitAfter.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/annotations/CommitAfter.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/annotations/CommitAfter.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,36 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.hibernate.annotations;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a method of a service (or a component method) as transactional: the active transaction should {@linkplain
+ * org.apache.tapestry5.hibernate.HibernateSessionManager#commit() commit} after invoking the method. Runtime
+ * exceptions will abort the transaction, checked exceptions will <em>also commit</em> the transaction.
+ *
+ * @see org.apache.tapestry5.hibernate.HibernateTransactionDecorator
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface CommitAfter
+{
+
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,40 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.hibernate.HibernateConfigurer;
+import org.apache.tapestry5.hibernate.HibernateConstants;
+import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * Simply calls configure() to do the default Hibernate configuration. This will read the hibernate.cfg.xml file.
+ */
+public final class DefaultHibernateConfigurer implements HibernateConfigurer
+{
+ private final boolean defaultConfiguration;
+
+ public DefaultHibernateConfigurer(
+ @Symbol(HibernateConstants.DEFAULT_CONFIGURATION)
+ boolean defaultConfiguration)
+ {
+ this.defaultConfiguration = defaultConfiguration;
+ }
+
+ public void configure(Configuration configuration)
+ {
+ if (defaultConfiguration) configuration.configure();
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateCoreMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateCoreMessages.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateCoreMessages.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateCoreMessages.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,41 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.internal.util.MessagesImpl;
+
+import java.util.Collection;
+
+public class HibernateCoreMessages
+{
+ private static final Messages MESSAGES = MessagesImpl.forClass(HibernateCoreMessages.class);
+
+ static String configurationImmutable()
+ {
+ return MESSAGES.get("configuration-immutable");
+ }
+
+ static String startupTiming(long toConfigure, long overall)
+ {
+ return MESSAGES.format("startup-timing", toConfigure, overall);
+ }
+
+ static String entityCatalog(Collection entityNames)
+ {
+ return MESSAGES.format("entity-catalog", InternalUtils.joinSorted(entityNames));
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionManagerImpl.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionManagerImpl.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionManagerImpl.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,69 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.hibernate.HibernateSessionManager;
+import org.apache.tapestry5.hibernate.HibernateSessionSource;
+import org.apache.tapestry5.ioc.services.ThreadCleanupListener;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+public class HibernateSessionManagerImpl implements HibernateSessionManager, ThreadCleanupListener
+{
+ private final Session session;
+
+ private Transaction transaction;
+
+ public HibernateSessionManagerImpl(HibernateSessionSource source)
+ {
+ session = source.create();
+
+ startNewTransaction();
+ }
+
+ private void startNewTransaction()
+ {
+ transaction = session.beginTransaction();
+ }
+
+ public void abort()
+ {
+ transaction.rollback();
+ startNewTransaction();
+ }
+
+ public void commit()
+ {
+ transaction.commit();
+ startNewTransaction();
+ }
+
+ public Session getSession()
+ {
+ return session;
+ }
+
+ /**
+ * Rollsback the transaction at the end of the request, then closes the session. This means that any uncommitted
+ * changes are lost; code should inject the HSM and invoke {@link #commit()} after making any changes, if they
+ * should persist.
+ */
+ public void threadDidCleanup()
+ {
+ transaction.rollback();
+
+ session.close();
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImpl.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImpl.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImpl.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,78 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.hibernate.HibernateConfigurer;
+import org.apache.tapestry5.hibernate.HibernateSessionSource;
+import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.slf4j.Logger;
+
+import java.util.List;
+
+public class HibernateSessionSourceImpl implements HibernateSessionSource, RegistryShutdownListener
+{
+ private final SessionFactory sessionFactory;
+
+ private final Configuration configuration;
+
+ public HibernateSessionSourceImpl(Logger logger, List<HibernateConfigurer> hibernateConfigurers)
+ {
+ long startTime = System.currentTimeMillis();
+
+ Configuration configuration = new AnnotationConfiguration();
+
+ for (HibernateConfigurer configurer : hibernateConfigurers)
+ configurer.configure(configuration);
+
+ long configurationComplete = System.currentTimeMillis();
+
+ sessionFactory = configuration.buildSessionFactory();
+ this.configuration = new ImmutableConfiguration(configuration);
+
+ long factoryCreated = System.currentTimeMillis();
+
+ logger.info(HibernateCoreMessages.startupTiming(
+ configurationComplete - startTime,
+ factoryCreated - startTime));
+
+ logger
+ .info(HibernateCoreMessages.entityCatalog(sessionFactory.getAllClassMetadata()
+ .keySet()));
+ }
+
+ public Session create()
+ {
+ return sessionFactory.openSession();
+ }
+
+ public SessionFactory getSessionFactory()
+ {
+ return sessionFactory;
+ }
+
+ public Configuration getConfiguration()
+ {
+ return configuration;
+ }
+
+ public void registryDidShutdown()
+ {
+ sessionFactory.close();
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImpl.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImpl.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImpl.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,88 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.hibernate.HibernateSessionManager;
+import org.apache.tapestry5.hibernate.HibernateTransactionDecorator;
+import org.apache.tapestry5.hibernate.annotations.CommitAfter;
+import org.apache.tapestry5.ioc.Invocation;
+import org.apache.tapestry5.ioc.MethodAdvice;
+import org.apache.tapestry5.ioc.internal.util.Defense;
+import org.apache.tapestry5.ioc.services.AspectDecorator;
+import org.apache.tapestry5.ioc.services.AspectInterceptorBuilder;
+
+import java.lang.reflect.Method;
+
+public class HibernateTransactionDecoratorImpl implements HibernateTransactionDecorator
+{
+ private final AspectDecorator aspectDecorator;
+
+ private final HibernateSessionManager manager;
+
+ /**
+ * The rules for advice are the same for any method: commit on success or checked exception, abort on thrown
+ * exception ... so we can use a single shared advice object.
+ */
+ private final MethodAdvice advice = new MethodAdvice()
+ {
+ public void advise(Invocation invocation)
+ {
+ try
+ {
+ invocation.proceed();
+ }
+ catch (RuntimeException ex)
+ {
+ manager.abort();
+
+ throw ex;
+ }
+
+ // For success or checked exception, commit the transaction.
+
+ manager.commit();
+ }
+ };
+
+ public HibernateTransactionDecoratorImpl(AspectDecorator aspectDecorator, HibernateSessionManager manager)
+ {
+ this.aspectDecorator = aspectDecorator;
+
+ this.manager = manager;
+ }
+
+ public <T> T build(Class<T> serviceInterface, T delegate, String serviceId)
+ {
+ Defense.notNull(serviceInterface, "serviceInterface");
+ Defense.notNull(delegate, "delegate");
+ Defense.notBlank(serviceId, "serviceId");
+
+ String description = String.format("<Hibernate Transaction interceptor for %s(%s)>",
+ serviceId,
+ serviceInterface.getName());
+
+ AspectInterceptorBuilder<T> builder = aspectDecorator.createBuilder(serviceInterface, delegate, description);
+
+ for (Method m : serviceInterface.getMethods())
+ {
+ if (m.getAnnotation(CommitAfter.class) != null)
+ {
+ builder.adviseMethod(m, advice);
+ }
+ }
+
+ return builder.build();
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/ImmutableConfiguration.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/ImmutableConfiguration.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/ImmutableConfiguration.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/ImmutableConfiguration.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,498 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.dom4j.Document;
+import org.hibernate.HibernateException;
+import org.hibernate.Interceptor;
+import org.hibernate.MappingException;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Mappings;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.cfg.Settings;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.engine.FilterDefinition;
+import org.hibernate.engine.Mapping;
+import org.hibernate.event.EventListeners;
+import org.hibernate.mapping.AuxiliaryDatabaseObject;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.proxy.EntityNotFoundDelegate;
+import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
+import org.xml.sax.EntityResolver;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Delegates all method calls to another instance. Any calls that modify state or return objects that are meant to be
+ * used to change state will throw an {@link UnsupportedOperationException}. This class is specifically final because
+ * there are protected methods that cannot be called on the contained instance (because they are protected).
+ * <p/>
+ * Note that this class does not guarantee that the objects returned are mutable thus changes to the configuration are
+ * still possible.
+ */
+@SuppressWarnings("unchecked")
+final class ImmutableConfiguration extends Configuration
+{
+ private static final long serialVersionUID = -4039250481581260132L;
+
+ private final Configuration config;
+
+ public ImmutableConfiguration(Configuration configuration)
+ {
+ config = configuration;
+ }
+
+ @Override
+ protected void add(Document doc) throws MappingException
+ {
+ unsupported();
+ }
+
+ /**
+ * Throws an exception. Has a return value for convenience.
+ *
+ * @return nothing because it always throws an exception
+ */
+ private <T> T unsupported()
+ {
+ throw new UnsupportedOperationException(HibernateCoreMessages.configurationImmutable());
+ }
+
+ @Override
+ public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object)
+ {
+ unsupported();
+ }
+
+ @Override
+ public Configuration addCacheableFile(File xmlFile) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addCacheableFile(String xmlFile) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addClass(Class persistentClass) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addDirectory(File dir) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addDocument(org.w3c.dom.Document doc) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addFile(File xmlFile) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addFile(String xmlFile) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public void addFilterDefinition(FilterDefinition definition)
+ {
+ unsupported();
+ }
+
+ @Override
+ public Configuration addInputStream(InputStream xmlInputStream) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addJar(File jar) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addProperties(Properties extraProperties)
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addResource(String resourceName, ClassLoader classLoader) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addResource(String resourceName) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public void addSqlFunction(String functionName, SQLFunction function)
+ {
+ unsupported();
+ }
+
+ @Override
+ public Configuration addURL(URL url) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration addXML(String xml) throws MappingException
+ {
+ return unsupported();
+ }
+
+ /* Since this is called from the constructor of the superclass, it calls
+ * the superclass method rather than delegating to the contained instance.
+ * We could also just not override the method but for completeness I'll
+ * leave it in.
+ * It's unfortunate that Configuration isn't an interface.
+ */
+ @Override
+ public Mapping buildMapping()
+ {
+ return super.buildMapping();
+ }
+
+ @Override
+ public void buildMappings()
+ {
+ config.buildMappings();
+ }
+
+ @Override
+ public SessionFactory buildSessionFactory() throws HibernateException
+ {
+ return config.buildSessionFactory();
+ }
+
+ @Override
+ public Settings buildSettings() throws HibernateException
+ {
+ return config.buildSettings();
+ }
+
+ @Override
+ public Settings buildSettings(Properties props) throws HibernateException
+ {
+ return config.buildSettings(props);
+ }
+
+ @Override
+ public Configuration configure() throws HibernateException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration configure(org.w3c.dom.Document document) throws HibernateException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration configure(File configFile) throws HibernateException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration configure(String resource) throws HibernateException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration configure(URL url) throws HibernateException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Mappings createMappings()
+ {
+ return unsupported();
+ }
+
+ @Override
+ protected Configuration doConfigure(Document doc) throws HibernateException
+ {
+ return unsupported();
+ }
+
+ @Override
+ protected Configuration doConfigure(InputStream stream, String resourceName) throws HibernateException
+ {
+ return unsupported();
+ }
+
+ @Override
+ protected Document findPossibleExtends()
+ {
+ return unsupported();
+ }
+
+ @Override
+ public String[] generateDropSchemaScript(Dialect dialect) throws HibernateException
+ {
+ return config.generateDropSchemaScript(dialect);
+ }
+
+ @Override
+ public String[] generateSchemaCreationScript(Dialect dialect) throws HibernateException
+ {
+ return config.generateSchemaCreationScript(dialect);
+ }
+
+ @Override
+ public String[] generateSchemaUpdateScript(Dialect dialect, DatabaseMetadata databaseMetadata)
+ throws HibernateException
+ {
+ return config.generateSchemaUpdateScript(dialect, databaseMetadata);
+ }
+
+ @Override
+ public PersistentClass getClassMapping(String entityName)
+ {
+ return config.getClassMapping(entityName);
+ }
+
+ @Override
+ public Iterator getClassMappings()
+ {
+ return config.getClassMappings();
+ }
+
+ @Override
+ public Collection getCollectionMapping(String role)
+ {
+ return config.getCollectionMapping(role);
+ }
+
+ @Override
+ public Iterator getCollectionMappings()
+ {
+ return config.getCollectionMappings();
+ }
+
+ @Override
+ public EntityNotFoundDelegate getEntityNotFoundDelegate()
+ {
+ return config.getEntityNotFoundDelegate();
+ }
+
+ @Override
+ public EntityResolver getEntityResolver()
+ {
+ return config.getEntityResolver();
+ }
+
+ @Override
+ public EventListeners getEventListeners()
+ {
+ return config.getEventListeners();
+ }
+
+ @Override
+ public Map getFilterDefinitions()
+ {
+ return config.getFilterDefinitions();
+ }
+
+ @Override
+ public Map getImports()
+ {
+ return config.getImports();
+ }
+
+ @Override
+ public Interceptor getInterceptor()
+ {
+ return config.getInterceptor();
+ }
+
+ @Override
+ public Map getNamedQueries()
+ {
+ return config.getNamedQueries();
+ }
+
+ @Override
+ public Map getNamedSQLQueries()
+ {
+ return config.getNamedSQLQueries();
+ }
+
+ @Override
+ public NamingStrategy getNamingStrategy()
+ {
+ return config.getNamingStrategy();
+ }
+
+ @Override
+ public Properties getProperties()
+ {
+ return config.getProperties();
+ }
+
+ @Override
+ public String getProperty(String propertyName)
+ {
+ return config.getProperty(propertyName);
+ }
+
+ @Override
+ public Map getSqlFunctions()
+ {
+ return config.getSqlFunctions();
+ }
+
+ @Override
+ public Map getSqlResultSetMappings()
+ {
+ return config.getSqlResultSetMappings();
+ }
+
+ @Override
+ public Iterator getTableMappings()
+ {
+ return config.getTableMappings();
+ }
+
+ @Override
+ public Configuration mergeProperties(Properties properties)
+ {
+ return unsupported();
+ }
+
+ @Override
+ public void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String region)
+ throws MappingException
+ {
+ unsupported();
+ }
+
+ @Override
+ public Configuration setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy) throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String region)
+ throws MappingException
+ {
+ unsupported();
+ }
+
+ @Override
+ public Configuration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy)
+ throws MappingException
+ {
+ return unsupported();
+ }
+
+ @Override
+ public void setEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate)
+ {
+ unsupported();
+ }
+
+ @Override
+ public void setEntityResolver(EntityResolver entityResolver)
+ {
+ unsupported();
+ }
+
+ @Override
+ public Configuration setInterceptor(Interceptor interceptor)
+ {
+ return unsupported();
+ }
+
+ @Override
+ public void setListener(String type, Object listener)
+ {
+ unsupported();
+ }
+
+ @Override
+ public void setListeners(String type, Object[] listeners)
+ {
+ unsupported();
+ }
+
+ @Override
+ public void setListeners(String type, String[] listenerClasses)
+ {
+ unsupported();
+ }
+
+ @Override
+ public Configuration setNamingStrategy(NamingStrategy namingStrategy)
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration setProperties(Properties properties)
+ {
+ return unsupported();
+ }
+
+ @Override
+ public Configuration setProperty(String propertyName, String value)
+ {
+ return unsupported();
+ }
+
+ @Override
+ public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException
+ {
+ config.validateSchema(dialect, databaseMetadata);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ImmutableConfiguration[" + config + "]";
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/PackageNameHibernateConfigurer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/PackageNameHibernateConfigurer.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/PackageNameHibernateConfigurer.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/PackageNameHibernateConfigurer.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,66 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.hibernate.HibernateConfigurer;
+import org.apache.tapestry5.hibernate.HibernateEntityPackageManager;
+import org.apache.tapestry5.ioc.internal.util.Defense;
+import org.apache.tapestry5.ioc.services.ClassNameLocator;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * Adds entity classes from a given set of packages to the configuration.
+ */
+public final class PackageNameHibernateConfigurer implements HibernateConfigurer
+{
+ private final HibernateEntityPackageManager packageManager;
+
+ private final ClassNameLocator classNameLocator;
+
+ public PackageNameHibernateConfigurer(HibernateEntityPackageManager packageManager,
+ ClassNameLocator classNameLocator)
+ {
+ this.packageManager = packageManager;
+ this.classNameLocator = classNameLocator;
+ }
+
+ public void configure(Configuration configuration)
+ {
+ Defense.cast(configuration, AnnotationConfiguration.class, "configuration");
+ AnnotationConfiguration cfg = (AnnotationConfiguration) configuration;
+
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+
+ for (String packageName : packageManager.getPackageNames())
+ {
+ cfg.addPackage(packageName);
+
+ for (String className : classNameLocator.locateClassNames(packageName))
+ {
+ try
+ {
+ Class entityClass = contextClassLoader.loadClass(className);
+
+ cfg.addAnnotatedClass(entityClass);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateCoreStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateCoreStrings.properties?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateCoreStrings.properties (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateCoreStrings.properties Mon Dec 1 11:22:52 2008
@@ -0,0 +1,17 @@
+# Copyright 2008 The Apache Software Foundation
+#
+# 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.
+
+configuration-immutable=The Hibernate configuration is now immutable since the SessionFactory has already been created.
+startup-timing=Hibernate startup: %,d ms to configure, %,d ms overall.
+entity-catalog=Configured Hibernate entities: %s
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt Mon Dec 1 11:22:52 2008
@@ -0,0 +1,68 @@
+ ----
+ Configuration
+ ----
+
+Configuring Hibernate
+
+ The Tapestry Hibernate Library is responsible for configuring Hibernate for you. This is done in a just-in-time manner, the first time
+ a Hibernate Session is required.
+
+* HibernateSessionSource Configuration
+
+ One way to configure hibernate is to create a <<<hibernate.cfg.xml>>> file and place it in the root of your application (i.e., under src/main/resources). Most Hibernate-specific
+ configuration occurs in this file. Another way is to contribute objects that perform configuration (such as setting event listeners). Example:
+
++----+
+public static void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> config)
+{
+ config.add("Widget", new WidgetHibernateConfigurer());
+}
++----+
+
+ Note that the configuration is an OrderedConfiguration. The library contributes two configurers by default:
+
+ * <<Default>> - performs default hibernate configuration
+
+ * <<PackageName>> - loads entities by package name as contributed to the HibernateEntityPackageManager service
+
+* HibernateEntityPackageManager Configuration
+
+ This configuration is a set of package names, identifying where to search for entity classes.
+
+ For each package contributed, the library will:
+
+ * {{{http://www.hibernate.org/hib_docs/annotations/api/org/hibernate/cfg/AnnotationConfiguration.html#addPackage(java.lang.String)}Add the package to the configuration}},
+ which will load annotations from the package-info class within the named package, if present.
+
+ * Every Java class in the package (or any subpackage) will be {{{http://www.hibernate.org/hib_docs/annotations/api/org/hibernate/cfg/AnnotationConfiguration.html#addAnnotatedClass(java.lang.Class)}added as an annotated class}}.
+ This excludes inner classes, but includes all other classes.
+
+ []
+
+ By default, the package <application-root-package>.entities is scanned as described above. If you have additional packages containing
+ entities, you must
+ {{{../tapestry-ioc/configuration.html}contribute}} them to the tapestry.hibernate.HibernateEntityPackageManager
+ service configuration.
+
+ Example:
+
++----+
+public static void contributeHibernateEntityPackageManager(Configuration<String> configuration)
+{
+ configuration.add("org.example.myapp.domain");
+}
++----+
+
+ You may add as many packages in this manner as you wish. This option is most often used when the entities themselves are contained in a library included
+ within an application, rather than part of the application directly.
+
+Hibernate Symbols
+
+ The Hibernate integration includes a number of {{{../tapestry-ioc/symbols.html}symbols}} used to control certain features:
+
+ [tapestry.hibernate.provide-entity-value-encoders] If true (the default) then ValueEncoders are automatically provided for all Hibernate entities (ValueEncoders are used
+ to encode the primary keys of entities as strings that can be included in URLs). Set to false if you
+ want direct control over this feature.
+
+ [tapestry.hibernate.default-configuration] If true (the default), then the application must include a <<<hibernate.cfg.xml>>> file. If your application configures
+ itself entirely in code, you should set this symbol to false.
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/index.apt?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/index.apt (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/index.apt Mon Dec 1 11:22:52 2008
@@ -0,0 +1,23 @@
+ ----
+ About Core Hibernate Support
+ ----
+
+Core Hibernate Support
+
+ This library contains basic Hibernate support package without dependencies on the
+ {{{../tapestry-core/}tapestry-core}} module
+ (the web framework part of Tapestry); it only requires
+ the
+ {{{../tapestry-ioc/}tapestry-ioc}} module. This makes it useful in non-web applications, such as back-end processing.
+
+ The {{{../tapestry-hibernate/}tapestry-hibernate}} module extends this further, adding features to support the
+ creation of CRUD (Create/Read/Update/Delete) database applications in Tapestry.
+
+Licensing Issues
+
+ Hibernate is licensed under the Lesser GNU Public License. This is more restrictive license than the Apache Software
+ License used by the rest of Tapestry. The restrictions mostly apply to redistricuting Hibernate, especially in
+ any altered form, and will likely be irrelvant to the vast majority of users, but you should be aware.
+
+ This library is compiled against version <<3.3.1.GA>> of Hibernate (and version 3.4.0.GA of hibernate-annotations),
+ but should work with more recent versions.
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/site.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/site.xml?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/site.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/site.xml Mon Dec 1 11:22:52 2008
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Copyright 2008 The Apache Software Foundation
+
+ 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.
+-->
+
+<project name="Core Hibernate Support">
+ <bannerLeft>
+ <name>Tapestry 5</name>
+ <href>http://tapestry.apache.org/tapestry5/</href>
+ <src>images/tapestry_banner.gif</src>
+ </bannerLeft>
+ <bannerRight>
+ <name>Apache</name>
+ <href>http://www.apache.org</href>
+ <src>images/asf_logo_wide.gif</src>
+ </bannerRight>
+ <skin>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>maven-skin</artifactId>
+ <version>1.1</version>
+ </skin>
+
+ <publishDate format="dd MMM yyyy"/>
+ <version/>
+
+ <body>
+
+ <menu ref="parent"/>
+
+ <menu name="Quick Links">
+ <item name="About" href="index.html"/>
+ <item name="Configuration" href="conf.html"/>
+ <item name="User guide" href="../tapestry-hibernate/userguide.html"/>
+ <item name="Download" href="http://tapestry.apache.org/download.html"/>
+ </menu>
+
+ <menu ref="reports"/>
+
+ </body>
+</project>
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/conf/testng.xml?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/conf/testng.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/conf/testng.xml Mon Dec 1 11:22:52 2008
@@ -0,0 +1,24 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<!--
+ Copyright 2008 The Apache Software Foundation
+
+ 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.
+-->
+
+<suite name="Core Hibernate" parallel="false" thread-count="10" annotations="1.5" verbose="2">
+ <test name="Tapestry Hibernate Internal APIs">
+ <packages>
+ <package name="org.apache.tapestry5.internal.hibernate"/>
+ </packages>
+ </test>
+</suite>
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,48 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.*;
+import org.hibernate.cfg.Configuration;
+import org.testng.annotations.Test;
+
+@Test
+public class DefaultHibernateConfigurerFilterTest
+{
+ public void configure_with_default_configuration_on() throws Exception
+ {
+ Configuration config = createMock(Configuration.class);
+ expect(config.configure()).andReturn(config);
+
+
+ replay(config);
+
+ new DefaultHibernateConfigurer(true).configure(config);
+
+ verify(config);
+ }
+
+ public void configure_with_default_configuration_off() throws Exception
+ {
+ Configuration config = createMock(Configuration.class);
+
+ replay(config);
+
+ new DefaultHibernateConfigurer(false).configure(config);
+
+ verify(config);
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,99 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.hibernate.HibernateConfigurer;
+import org.apache.tapestry5.hibernate.HibernateEntityPackageManager;
+import org.apache.tapestry5.hibernate.HibernateSessionSource;
+import org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl;
+import org.apache.tapestry5.ioc.internal.services.ClasspathURLConverterImpl;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.test.IOCTestCase;
+import org.apache.tapestry5.ioc.test.TestBase;
+import org.example.app0.entities.User;
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.metadata.ClassMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+public class HibernateSessionSourceImplTest extends IOCTestCase
+{
+ private final Logger log = LoggerFactory
+ .getLogger("tapestry.hibernate.HibernateSessionSourceTest");
+
+ @Test
+ public void startup_without_packages()
+ {
+ Collection<String> packageNames = CollectionFactory.newList(
+ "org.example.myapp.entities",
+ "org.example.app0.entities");
+ HibernateEntityPackageManager packageManager = newMock(HibernateEntityPackageManager.class);
+ TestBase.expect(packageManager.getPackageNames()).andReturn(packageNames);
+
+ List<HibernateConfigurer> filters = Arrays.asList(
+ new DefaultHibernateConfigurer(true),
+ new PackageNameHibernateConfigurer(packageManager,
+ new ClassNameLocatorImpl(new ClasspathURLConverterImpl())));
+
+ replay();
+ HibernateSessionSource source = new HibernateSessionSourceImpl(log, filters);
+
+ Session session = source.create();
+ Assert.assertNotNull(session);
+
+ // make sure it found the entity in the package
+ ClassMetadata meta = session.getSessionFactory().getClassMetadata(User.class);
+ Assert.assertEquals(meta.getEntityName(), "org.example.app0.entities.User");
+
+ verify();
+ }
+
+ @Test
+ public void get_configuration()
+ {
+ HibernateConfigurer configurer = new HibernateConfigurer()
+ {
+ public void configure(Configuration configuration)
+ {
+ configuration.setProperty("foo", "bar");
+ configuration.configure();
+ }
+ };
+ HibernateSessionSource source = new HibernateSessionSourceImpl(log, Arrays
+ .asList(configurer));
+
+ Configuration config = source.getConfiguration();
+ Assert.assertNotNull(config);
+ Assert.assertEquals("bar", config.getProperty("foo"));
+
+ // configuration should be immutable
+ try
+ {
+ config.setProperty("hibernate.dialect", "foo");
+ Assert.fail("did not throw");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ Assert.assertTrue(e.getMessage().contains("immutable"));
+ }
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImplTest.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImplTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateTransactionDecoratorImplTest.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,267 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// 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.apache.tapestry5.internal.hibernate;
+
+import org.apache.tapestry5.hibernate.HibernateSessionManager;
+import org.apache.tapestry5.hibernate.HibernateTransactionDecorator;
+import org.apache.tapestry5.hibernate.annotations.CommitAfter;
+import org.apache.tapestry5.ioc.IOCUtilities;
+import org.apache.tapestry5.ioc.Registry;
+import org.apache.tapestry5.ioc.services.AspectDecorator;
+import org.apache.tapestry5.ioc.test.IOCTestCase;
+import org.apache.tapestry5.ioc.test.TestBase;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.sql.SQLException;
+
+@SuppressWarnings({"ThrowableInstanceNeverThrown"})
+public class HibernateTransactionDecoratorImplTest extends IOCTestCase
+{
+ private Registry registry;
+
+ private AspectDecorator aspectDecorator;
+
+ @BeforeClass
+ public void setup()
+ {
+ registry = IOCUtilities.buildDefaultRegistry();
+
+ aspectDecorator = registry.getService(AspectDecorator.class);
+ }
+
+
+ @AfterClass
+ public void shutdown()
+ {
+ registry.shutdown();
+
+ aspectDecorator = null;
+ registry = null;
+ }
+
+ @Test
+ public void undecorated()
+ {
+ VoidService delegate = newMock(VoidService.class);
+ HibernateSessionManager manager = newMock(HibernateSessionManager.class);
+ HibernateTransactionDecorator decorator = newHibernateSessionManagerDecorator(manager);
+ VoidService interceptor = decorator.build(VoidService.class, delegate, "foo.Bar");
+
+ delegate.undecorated();
+
+ replay();
+ interceptor.undecorated();
+ verify();
+
+ assertToString(interceptor);
+ }
+
+ @Test
+ public void void_method()
+ {
+ VoidService delegate = newMock(VoidService.class);
+ HibernateSessionManager manager = newMock(HibernateSessionManager.class);
+ HibernateTransactionDecorator decorator = newHibernateSessionManagerDecorator(manager);
+ VoidService interceptor = decorator.build(VoidService.class, delegate, "foo.Bar");
+
+ delegate.voidMethod();
+ manager.commit();
+
+ replay();
+ interceptor.voidMethod();
+ verify();
+
+ assertToString(interceptor);
+ }
+
+ @Test
+ public void void_method_with_param()
+ {
+ VoidService delegate = newMock(VoidService.class);
+ HibernateSessionManager manager = newMock(HibernateSessionManager.class);
+ HibernateTransactionDecorator decorator = newHibernateSessionManagerDecorator(manager);
+ VoidService interceptor = decorator.build(VoidService.class, delegate, "foo.Bar");
+
+ delegate.voidMethodWithParam(777);
+ manager.commit();
+
+ replay();
+ interceptor.voidMethodWithParam(777);
+ verify();
+
+ assertToString(interceptor);
+ }
+
+ @Test
+ public void runtime_exception_will_abort_transaction() throws Exception
+ {
+ Performer delegate = newMock(Performer.class);
+ HibernateSessionManager manager = newMock(HibernateSessionManager.class);
+ HibernateTransactionDecorator decorator = newHibernateSessionManagerDecorator(manager);
+ RuntimeException re = new RuntimeException("Unexpected.");
+
+ delegate.perform();
+ TestBase.setThrowable(re);
+ manager.abort();
+
+ replay();
+
+ Performer interceptor = decorator.build(Performer.class, delegate, "foo.Bar");
+
+ try
+ {
+ interceptor.perform();
+ TestBase.unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ Assert.assertSame(ex, re);
+ }
+
+ verify();
+ }
+
+ @Test
+ public void checked_exception_will_commit_transaction() throws Exception
+ {
+ Performer delegate = newMock(Performer.class);
+ HibernateSessionManager manager = newMock(HibernateSessionManager.class);
+ HibernateTransactionDecorator decorator = newHibernateSessionManagerDecorator(manager);
+ SQLException se = new SQLException("Checked.");
+
+ delegate.perform();
+ TestBase.setThrowable(se);
+ manager.commit();
+
+ replay();
+
+ Performer interceptor = decorator.build(Performer.class, delegate, "foo.Bar");
+
+ try
+ {
+ interceptor.perform();
+ TestBase.unreachable();
+ }
+ catch (SQLException ex)
+ {
+ Assert.assertSame(ex, se);
+ }
+
+ verify();
+ }
+
+ @Test
+ public void return_type_method()
+ {
+ ReturnTypeService delegate = newTestService();
+ HibernateSessionManager manager = newMock(HibernateSessionManager.class);
+ HibernateTransactionDecorator decorator = newHibernateSessionManagerDecorator(manager);
+ ReturnTypeService interceptor = decorator.build(ReturnTypeService.class, delegate, "foo.Bar");
+
+ delegate.returnTypeMethod();
+
+ manager.commit();
+
+ replay();
+ Assert.assertEquals(interceptor.returnTypeMethod(), "Foo");
+ verify();
+ }
+
+ @Test
+ public void return_type_method_with_param()
+ {
+ ReturnTypeService delegate = newTestService();
+ HibernateSessionManager manager = newMock(HibernateSessionManager.class);
+ HibernateTransactionDecorator decorator = newHibernateSessionManagerDecorator(manager);
+ ReturnTypeService interceptor = decorator.build(ReturnTypeService.class, delegate, "foo.Bar");
+
+ delegate.returnTypeMethodWithParam(5, 3);
+
+ manager.commit();
+
+ replay();
+ Assert.assertEquals(interceptor.returnTypeMethodWithParam(5, 3), 8);
+ verify();
+
+ Assert.assertEquals(
+ interceptor.toString(),
+ "Baz");
+ }
+
+ private HibernateTransactionDecorator newHibernateSessionManagerDecorator(HibernateSessionManager manager)
+ {
+ return new HibernateTransactionDecoratorImpl(aspectDecorator, manager);
+ }
+
+ private void assertToString(VoidService interceptor)
+ {
+ Assert.assertEquals(
+ interceptor.toString(),
+ "<Hibernate Transaction interceptor for foo.Bar(" + getClass().getName() + "$VoidService)>");
+ }
+
+ private ReturnTypeService newTestService()
+ {
+ return new ReturnTypeService()
+ {
+
+ public String returnTypeMethod()
+ {
+ return "Foo";
+ }
+
+ public int returnTypeMethodWithParam(int first, int second)
+ {
+ return first + second;
+ }
+
+ public String toString()
+ {
+ return "Baz";
+ }
+ };
+ }
+
+ public interface ReturnTypeService
+ {
+ @CommitAfter
+ String returnTypeMethod();
+
+ @CommitAfter
+ int returnTypeMethodWithParam(int first, int second);
+
+ String toString();
+ }
+
+ public interface VoidService
+ {
+ void undecorated();
+
+ @CommitAfter
+ void voidMethod();
+
+ @CommitAfter
+ void voidMethodWithParam(long id);
+ }
+
+ public interface Performer
+ {
+ @CommitAfter
+ void perform() throws SQLException;
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/example/app0/entities/User.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/example/app0/entities/User.java?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/example/app0/entities/User.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/java/org/example/app0/entities/User.java Mon Dec 1 11:22:52 2008
@@ -0,0 +1,90 @@
+// Copyright 2007, 2008 The Apache Software Foundation
+//
+// 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.example.app0.entities;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+public class User
+{
+ // NOTE: Hibernate doesn't understand the '_' syntax. It will end up putting underscores on all the properties
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String firstName;
+
+ private String lastName;
+
+ private String email;
+
+ private String encodedPassword;
+
+ @Version
+ private int version;
+
+ public String getEmail()
+ {
+ return email;
+ }
+
+ public String getEncodedPassword()
+ {
+ return encodedPassword;
+ }
+
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public String getLastName()
+ {
+ return lastName;
+ }
+
+ public int getVersion()
+ {
+ return version;
+ }
+
+ public void setEmail(String email)
+ {
+ this.email = email;
+ }
+
+ public void setEncodedPassword(String encodedPassword)
+ {
+ this.encodedPassword = encodedPassword;
+ }
+
+ public void setFirstName(String firstName)
+ {
+ this.firstName = firstName;
+ }
+
+ public void setLastName(String lastName)
+ {
+ this.lastName = lastName;
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/hibernate.cfg.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/hibernate.cfg.xml?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/hibernate.cfg.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/hibernate.cfg.xml Mon Dec 1 11:22:52 2008
@@ -0,0 +1,42 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!--
+ Copyright 2007, 2008 The Apache Software Foundation
+
+ 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.
+-->
+
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+
+ <session-factory>
+ <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
+ <property name="hibernate.connection.url">jdbc:hsqldb:mem:test</property>
+ <property name="hibernate.connection.username">sa</property>
+ <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
+
+ <property name="show_sql">true</property>
+ <property name="format_sql">true</property>
+ <property name="hbm2ddl.auto">update</property>
+
+ <property name="hibernate.c3p0.min_size">5</property>
+ <property name="hibernate.c3p0.max_size">20</property>
+ <property name="hibernate.c3p0.timeout">300</property>
+ <property name="hibernate.c3p0.max_statements">50</property>
+ <property name="hibernate.c3p0.idle_test_period">3000</property>
+ </session-factory>
+
+
+</hibernate-configuration>
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/log4j.properties?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/log4j.properties (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/test/resources/log4j.properties Mon Dec 1 11:22:52 2008
@@ -0,0 +1,29 @@
+# Copyright 2007, 2008 The Apache Software Foundation
+#
+# 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.
+
+log4j.rootCategory=WARN, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=[%p] %c{1} %m%n
+
+log4j.category.org.apache.tapestry5.TapestryFilter=info
+log4j.category.org.apache.tapestry=error
+log4j.category.tapestry=error
+log4j.category.tapestry.ioc.ClassFactory=error
+
+log4j.category.tapestry.hibernate=info
Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/tapestry-hibernate-core.iml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/tapestry-hibernate-core.iml?rev=722189&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/tapestry-hibernate-core.iml (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/tapestry-hibernate-core.iml Mon Dec 1 11:22:52 2008
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="tapestry-ioc" exported="" />
+ <orderEntry type="module" module-name="tapestry-annotations" exported="" />
+ <orderEntry type="library" exported="" name="Maven: javassist:javassist:3.8.0.GA" level="project" />
+ <orderEntry type="library" exported="" name="Maven: org.slf4j:slf4j-api:1.5.2" level="project" />
+ <orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
+ <orderEntry type="library" exported="" name="Maven: org.slf4j:slf4j-log4j12:1.5.2" level="project" />
+ <orderEntry type="module" module-name="tapestry-test" />
+ <orderEntry type="library" name="Maven: org.openqa.selenium.client-drivers:selenium-java-client-driver:1.0-beta-1" level="project" />
+ <orderEntry type="library" name="Maven: org.openqa.selenium.core:selenium-core:1.0-beta-1" level="project" />
+ <orderEntry type="library" name="Maven: org.openqa.selenium.server:selenium-server-coreless:1.0-beta-1" level="project" />
+ <orderEntry type="library" name="Maven: ant:ant:1.6.5" level="project" />
+ <orderEntry type="library" name="Maven: jetty:org.mortbay.jetty:5.1.10" level="project" />
+ <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
+ <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
+ <orderEntry type="library" name="Maven: junit:junit:3.8.1" level="project" />
+ <orderEntry type="library" name="Maven: org.openqa.selenium.server:selenium-server:standalone:1.0-beta-1" level="project" />
+ <orderEntry type="library" name="Maven: org.openqa.selenium.server:selenium-server:1.0-beta-1" level="project" />
+ <orderEntry type="library" name="Maven: bouncycastle:bcprov-jdk15:135" level="project" />
+ <orderEntry type="library" name="Maven: org.testng:testng:jdk15:5.7" level="project" />
+ <orderEntry type="library" name="Maven: org.easymock:easymock:2.4" level="project" />
+ <orderEntry type="library" name="Maven: org.easymock:easymockclassextension:2.2.2" level="project" />
+ <orderEntry type="library" name="Maven: cglib:cglib-nodep:2.1_3" level="project" />
+ <orderEntry type="library" name="Maven: hsqldb:hsqldb:1.8.0.7" level="project" />
+ <orderEntry type="library" exported="" name="Maven: org.hibernate:hibernate-core:3.3.1.GA" level="project" />
+ <orderEntry type="library" exported="" name="Maven: antlr:antlr:2.7.6" level="project" />
+ <orderEntry type="library" exported="" name="Maven: commons-collections:commons-collections:3.1" level="project" />
+ <orderEntry type="library" exported="" name="Maven: dom4j:dom4j:1.6.1" level="project" />
+ <orderEntry type="library" exported="" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
+ <orderEntry type="library" exported="" name="Maven: geronimo-spec:geronimo-spec-jta:1.0-M1" level="project" />
+ <orderEntry type="library" exported="" name="Maven: org.hibernate:hibernate-annotations:3.4.0.GA" level="project" />
+ <orderEntry type="library" exported="" name="Maven: org.hibernate:ejb3-persistence:1.0.2.GA" level="project" />
+ <orderEntry type="library" exported="" name="Maven: org.hibernate:hibernate-commons-annotations:3.1.0.GA" level="project" />
+ <orderEntry type="library" exported="" name="Maven: org.hibernate:hibernate-c3p0:3.3.1.GA" level="project" />
+ <orderEntry type="library" exported="" name="Maven: c3p0:c3p0:0.9.1" level="project" />
+ </component>
+</module>
+
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/pom.xml?rev=722189&r1=722188&r2=722189&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/pom.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/pom.xml Mon Dec 1 11:22:52 2008
@@ -22,6 +22,12 @@
<artifactId>tapestry-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-hibernate-core</artifactId>
+ </dependency>
+
+
<!-- Testing -->
<dependency>
@@ -51,51 +57,6 @@
<scope>test</scope>
</dependency>
- <!-- This is the default version of Hibernate used; Maven provides the ability to override this dependency, though
- it can be tricky because there are overlapping third-party dependencies with slightly different version numbers. -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>3.3.1.GA</version>
- <exclusions>
- <exclusion>
- <groupId>javax.transaction</groupId>
- <artifactId>jta</artifactId>
- </exclusion>
- <!-- Make sure we use the version defined by tapestry-ioc. -->
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>geronimo-spec</groupId>
- <artifactId>geronimo-spec-jta</artifactId>
- <version>1.0-M1</version>
- </dependency>
-
- <!-- The annotation should be compatible with the 3.2.2.ga release of the
- core package. -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-annotations</artifactId>
- <version>3.4.0.GA</version>
- <exclusions>
- <!-- Make sure we use the version defined by tapestry-ioc. -->
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-c3p0</artifactId>
- <version>3.3.1.GA</version>
- </dependency>
</dependencies>
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java?rev=722189&r1=722188&r2=722189&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java Mon Dec 1 11:22:52 2008
@@ -16,51 +16,36 @@
import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.internal.InternalConstants;
-import org.apache.tapestry5.internal.hibernate.*;
-import org.apache.tapestry5.ioc.*;
+import org.apache.tapestry5.internal.hibernate.CommitAfterWorker;
+import org.apache.tapestry5.internal.hibernate.EntityPersistentFieldStrategy;
+import org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder;
+import org.apache.tapestry5.ioc.Configuration;
+import org.apache.tapestry5.ioc.LoggerSource;
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.annotations.Local;
-import org.apache.tapestry5.ioc.annotations.Scope;
import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.services.*;
+import org.apache.tapestry5.ioc.services.PropertyAccess;
+import org.apache.tapestry5.ioc.services.TypeCoercer;
import org.apache.tapestry5.services.AliasContribution;
import org.apache.tapestry5.services.ComponentClassTransformWorker;
import org.apache.tapestry5.services.PersistentFieldStrategy;
import org.apache.tapestry5.services.ValueEncoderFactory;
import org.hibernate.Session;
import org.hibernate.mapping.PersistentClass;
-import org.slf4j.Logger;
-import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
+/**
+ * Supplements the services defined by {@link org.apache.tapestry5.hibernate.HibernateCoreModule} with additional
+ * services and configuration specific to Tapestry web application.
+ */
@SuppressWarnings({"JavaDoc"})
public class HibernateModule
{
-
- public static void bind(ServiceBinder binder)
- {
- binder.bind(HibernateTransactionDecorator.class, HibernateTransactionDecoratorImpl.class);
- binder.bind(HibernateConfigurer.class, DefaultHibernateConfigurer.class).withId("DefaultHibernateConfigurer");
- }
-
public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
{
configuration.add(HibernateConstants.PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL, "true");
- configuration.add(HibernateConstants.DEFAULT_CONFIGURATION, "true");
- }
-
- public static HibernateEntityPackageManager buildHibernateEntityPackageManager(
- final Collection<String> packageNames)
- {
- return new HibernateEntityPackageManager()
- {
- public Collection<String> getPackageNames()
- {
- return packageNames;
- }
- };
}
/**
@@ -76,65 +61,12 @@
configuration.add(appRootPackage + ".entities");
}
- /**
- * The session manager manages sessions on a per-thread/per-request basis. A {@link org.hibernate.Transaction} is
- * created initially, and is committed at the end of the request.
- */
- @Scope(ScopeConstants.PERTHREAD)
- public static HibernateSessionManager buildHibernateSessionManager(HibernateSessionSource sessionSource,
- PerthreadManager perthreadManager)
- {
- HibernateSessionManagerImpl service = new HibernateSessionManagerImpl(sessionSource);
-
- perthreadManager.addThreadCleanupListener(service);
-
- return service;
- }
- public static Session buildSession(HibernateSessionManager sessionManager,
- PropertyShadowBuilder propertyShadowBuilder)
- {
- // Here's the thing: the tapestry.hibernate.Session class doesn't have to be per-thread,
- // since
- // it will invoke getSession() on the HibernateSessionManager service (which is per-thread).
- // On
- // first invocation per request,
- // this forces the HSM into existence (which creates the session and begins the
- // transaction).
- // Thus we don't actually create
- // a session until we first try to access it, then the session continues to exist for the
- // rest
- // of the request.
-
- return propertyShadowBuilder.build(sessionManager, "session", Session.class);
- }
-
- public static void contributeAlias(Configuration<AliasContribution> configuration, @Local Session session)
+ public static void contributeAlias(Configuration<AliasContribution> configuration, @HibernateCore Session session)
{
configuration.add(AliasContribution.create(Session.class, session));
}
- public static HibernateSessionSource buildHibernateSessionSource(Logger logger, List<HibernateConfigurer> config,
- RegistryShutdownHub hub)
- {
- HibernateSessionSourceImpl hss = new HibernateSessionSourceImpl(logger, config);
-
- hub.addRegistryShutdownListener(hss);
-
- return hss;
- }
-
- /**
- * Adds the following configurers: <dl> <dt>Default <dd> performs default hibernate configuration <dt>PackageName
- * <dd> loads entities by package name</dl>
- */
- public static void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> config,
-
- HibernateConfigurer defaultHibernateConfigurer)
- {
- config.add("Default", defaultHibernateConfigurer);
- config.addInstance("PackageName", PackageNameHibernateConfigurer.class);
- }
/**
* Contributes {@link ValueEncoderFactory}s for all registered Hibernate entity classes. Encoding and decoding are
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateMessages.java?rev=722189&r1=722188&r2=722189&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateMessages.java Mon Dec 1 11:22:52 2008
@@ -15,30 +15,12 @@
package org.apache.tapestry5.internal.hibernate;
import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.MessagesImpl;
-import java.util.Collection;
-
class HibernateMessages
{
private static final Messages MESSAGES = MessagesImpl.forClass(HibernateMessages.class);
- static String startupTiming(long toConfigure, long overall)
- {
- return MESSAGES.format("startup-timing", toConfigure, overall);
- }
-
- static String entityCatalog(Collection entityNames)
- {
- return MESSAGES.format("entity-catalog", InternalUtils.joinSorted(entityNames));
- }
-
- static String configurationImmutable()
- {
- return MESSAGES.get("configuration-immutable");
- }
-
static String sessionPersistedEntityLoadFailure(String entityName, Object id, Throwable cause)
{
return MESSAGES.format("session-persisted-entity-load-failure", entityName, id, cause);
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateStrings.properties?rev=722189&r1=722188&r2=722189&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/main/resources/org/apache/tapestry5/internal/hibernate/HibernateStrings.properties Mon Dec 1 11:22:52 2008
@@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-startup-timing=Hibernate startup: %,d ms to configure, %,d ms overall.
-entity-catalog=Configured Hibernate entities: %s
-configuration-immutable=The Hibernate configuration is now immutable since the SessionFactory has already been created.
session-persisted-entity-load-failure=Failed to load session-persisted entity %s(%s): %s
entity-not-attached=Failed persisting an entity in the session. Only entities attached to a Hibernate Session can be persisted. entity: %s
commit-transaction-interceptor=<Hibernate Transaction interceptor for %s(%s)>
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/index.apt?rev=722189&r1=722188&r2=722189&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/index.apt Mon Dec 1 11:22:52 2008
@@ -11,7 +11,10 @@
thread-safe manner, within a <session-per-request> strategy.
A number of more esoteric ideas in Hibernate are not supported, including nested transactions and supporting multiple
- persistence units.
+ persistence units.
+
+ The {{{../tapestry-hibernate-core/}tapestry-hibernate-core}} module allows non-Tapestry applications to access
+ Hibernate.
Licensing Issues
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/site/site.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/site/site.xml?rev=722189&r1=722188&r2=722189&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/site/site.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/site/site.xml Mon Dec 1 11:22:52 2008
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
- Copyright 2007 The Apache Software Foundation
+ Copyright 2007, 2008 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@
<menu name="Quick Links">
<item name="About" href="index.html"/>
- <item name="Configuration" href="conf.html"/>
+ <item name="Configuration" href="../tapestry-hibernate-core/conf.html"/>
<item name="User guide" href="userguide.html"/>
<item name="Download" href="http://tapestry.apache.org/download.html"/>
</menu>
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/resources/log4j.properties?rev=722189&r1=722188&r2=722189&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/test/resources/log4j.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/test/resources/log4j.properties Mon Dec 1 11:22:52 2008
@@ -1,4 +1,4 @@
-# Copyright 2007 The Apache Software Foundation
+# Copyright 2007, 2008 The Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-log4j.rootCategory=WARN, A1
+log4j.rootCategory=info, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
@@ -26,4 +26,3 @@
log4j.category.tapestry=error
log4j.category.tapestry.ioc.ClassFactory=error
-log4j.category.tapestry.hibernate=info