Author: hlship
Date: Thu Mar 8 15:22:40 2007
New Revision: 516222
URL: http://svn.apache.org/viewvc?view=rev&rev=516222
Log:
Start filling in the details around Hibernate support, starting with the
creation of the SessionFactory.
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionManager.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionSource.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateMessages.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionManagerImpl.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/internal/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/internal/hibernate/
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/internal/hibernate/HibernateStrings.properties
tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/
tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/conf.apt
tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/index.apt
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/internal/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/internal/hibernate/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/app0/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/app0/entities/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/app0/entities/User.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/hibernate.cfg.xml
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/log4j.properties
Modified:
tapestry/tapestry5/tapestry-hibernate/trunk/.classpath
tapestry/tapestry5/tapestry-hibernate/trunk/pom.xml
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/site/site.xml
Modified: tapestry/tapestry5/tapestry-hibernate/trunk/.classpath
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/.classpath?view=diff&rev=516222&r1=516221&r2=516222
==============================================================================
--- tapestry/tapestry5/tapestry-hibernate/trunk/.classpath (original)
+++ tapestry/tapestry5/tapestry-hibernate/trunk/.classpath Thu Mar 8 15:22:40
2007
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="lib" path="src/test/resources"/>
+ <classpathentry kind="lib" path="src/main/resources"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: tapestry/tapestry5/tapestry-hibernate/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/pom.xml?view=diff&rev=516222&r1=516221&r2=516222
==============================================================================
--- tapestry/tapestry5/tapestry-hibernate/trunk/pom.xml (original)
+++ tapestry/tapestry5/tapestry-hibernate/trunk/pom.xml Thu Mar 8 15:22:40 2007
@@ -24,12 +24,76 @@
<dependencies>
<dependency>
<groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-ioc</artifactId>
+ <artifactId>tapestry-core</artifactId>
</dependency>
+
+ <!-- Testing -->
+
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-test</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <!-- Provided -->
+
+ <!-- The Hibernate dependencies are provided; which gives the final
application
+ the ability to choose the appropriate version. Further, in many cases
+ (such as JBoss deployment), they are, in fact, provided by the
+ container. For a Tomcat deployment, you're more likely to include
+ the hibernate JARs and dependencies inside the WAR. -->
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate</artifactId>
+ <version>3.2.2.ga</version>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>geronimo-spec</groupId>
+ <artifactId>geronimo-spec-jta</artifactId>
+ <version>1.0-M1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- The annotations 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.2.1.ga</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>c3p0</groupId>
+ <artifactId>c3p0</artifactId>
+ <version>0.9.1</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<build>
@@ -61,7 +125,7 @@
</execution>
</executions>
</plugin>
-
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -73,7 +137,7 @@
</archive>
</configuration>
</plugin>
-
+
</plugins>
</build>
<reporting>
@@ -97,6 +161,7 @@
<link>http://jakarta.apache.org/commons/logging/apidocs/</link>
<link>http://tapestry.apache.org/tapestry5/tapestry-ioc/apidocs/</link>
<link>http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/</link>
+ <link>http://www.hibernate.org/hib_docs/v3/api/</link>
</links>
<stylesheetfile>${basedir}/src/site/resources/css/jdstyle.css</stylesheetfile>
</configuration>
Modified:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java?view=diff&rev=516222&r1=516221&r2=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java
(original)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java
Thu Mar 8 15:22:40 2007
@@ -1,9 +1,117 @@
+// Copyright 2007 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.tapestry.hibernate;
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.internal.hibernate.HibernateSessionManagerImpl;
+import org.apache.tapestry.internal.hibernate.HibernateSessionSourceImpl;
+import org.apache.tapestry.internal.services.ComponentClassLocator;
+import org.apache.tapestry.ioc.Configuration;
+import org.apache.tapestry.ioc.annotations.Contribute;
import org.apache.tapestry.ioc.annotations.Id;
+import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.ioc.annotations.InjectService;
+import org.apache.tapestry.ioc.annotations.Lifecycle;
+import org.apache.tapestry.ioc.services.PropertyShadowBuilder;
+import org.apache.tapestry.ioc.services.ThreadCleanupHub;
+import org.apache.tapestry.services.ApplicationGlobals;
+import org.apache.tapestry.services.InfrastructureContribution;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
@Id("tapestry.hibernate")
public class HibernateModule
{
+ /**
+ * The HibernateSessionSource is responsible for creating Hibernate
sessions, which includes the
+ * initial configuration of Hibernate.
+ */
+ public static HibernateSessionSource buildHibernateSessionSource(Log log,
+
+ @InjectService("tapestry.internal.ComponentClassLocator")
+ ComponentClassLocator classLocator,
+
+ Collection<String> packageNames)
+ {
+ return new HibernateSessionSourceImpl(log, packageNames, classLocator);
+ }
+
+ /**
+ * Contributes the package "<root>.entities" to the configuration,
so that it will be
+ * scanned for annotated entity classes.
+ */
+ public static void contributeHibernateSessionSource(Configuration<String>
configuration,
+ @Inject("infrastructure:ApplicationGlobals")
+ ApplicationGlobals globals)
+ {
+ configuration.add(globals.getApplicationRootPackage() + ".entities");
+ }
+
+ /**
+ * The session manager manages sessions on a per-thread/per-request basis.
A [EMAIL PROTECTED] Transaction}
+ * is created initially, and is committed at the end of the request.
+ */
+ @Lifecycle("perthread")
+ public static HibernateSessionManager buildHibernateSessionManager(
+ @InjectService("HibernateSessionSource")
+ HibernateSessionSource sessionSource,
+
+ @InjectService("tapestry.ThreadCleanupHub")
+ ThreadCleanupHub threadCleanupHub)
+ {
+ HibernateSessionManagerImpl service = new
HibernateSessionManagerImpl(sessionSource);
+
+ threadCleanupHub.addThreadCleanupListener(service);
+
+ return service;
+ }
+
+ public static Session
buildSession(@InjectService("HibernateSessionManager")
+ HibernateSessionManager sessionManager,
+
+ @InjectService("tapestry.ioc.PropertyShadowBuilder")
+ 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);
+ }
+
+ /**
+ * Contributes the "session" property (type [EMAIL PROTECTED] Session}),
the Hibernate Session for the
+ * current request.
+ */
+ @Contribute("tapestry.Infrastructure")
+ public static void contributeInfrastructure(
+ Configuration<InfrastructureContribution> configuration,
+ @InjectService("Session")
+ Session session)
+ {
+ configuration.add(new InfrastructureContribution("session", session));
+ }
}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionManager.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionManager.java?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionManager.java
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionManager.java
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,52 @@
+// Copyright 2007 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.tapestry.hibernate;
+
+import org.hibernate.Session;
+
+/**
+ * Manages the Hibernate session for the current thread. This includes
creating the session as
+ * needed, allowing the session to checkpoint (commit the current transaction
and continue) and
+ * commit the transaction automatically at the end of the request.
+ * <p>
+ * Remember that in Tapestry, action requests and render requests are entirely
seperate, and you
+ * will see a seperate request and a seperate transaction for each. Care
should be taken to ensure
+ * that entity objects that are retained (in the session, as persistent field
values) between
+ * requests are handled correct (they tend to become detached instances).
+ * <p>
+ * This implementation of this service is per-thread.
+ */
+public interface HibernateSessionManager
+{
+ /**
+ * Gets the active session for this request, creating it as necessary. When
the session is first
+ * created, a transaction is started.
+ *
+ * @return the request's session
+ * @see HibernateSessionSource
+ */
+ Session getSession();
+
+ /**
+ * Commits the current transaction (which will cause a flush of data to the
database), then starts
+ * a new transaction to replace it.
+ */
+ void commit();
+
+ /**
+ * Aborts the current transaction, and starts a new tranasction to replace
it.
+ */
+ void abort();
+}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionSource.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionSource.java?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionSource.java
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateSessionSource.java
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,27 @@
+// Copyright 2007 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.tapestry.hibernate;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * Responsible for creating a Hibernate session as needed. Internally, is
responsible for Hibernate
+ * [EMAIL PROTECTED] Configuration}.
+ */
+public interface HibernateSessionSource
+{
+ Session create();
+}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateMessages.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateMessages.java?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateMessages.java
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateMessages.java
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,36 @@
+// Copyright 2007 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.tapestry.internal.hibernate;
+
+import java.util.Collection;
+
+import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
+import org.apache.tapestry.ioc.internal.util.MessagesImpl;
+
+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));
+ }
+}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionManagerImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionManagerImpl.java?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionManagerImpl.java
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionManagerImpl.java
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,58 @@
+// Copyright 2007 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.tapestry.internal.hibernate;
+
+import org.apache.tapestry.hibernate.HibernateSessionManager;
+import org.apache.tapestry.hibernate.HibernateSessionSource;
+import org.apache.tapestry.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();
+
+ _transaction = _session.beginTransaction();
+ }
+
+ public void abort()
+ {
+ _transaction.rollback();
+ _transaction.begin();
+ }
+
+ public void commit()
+ {
+ _transaction.commit();
+ _transaction.begin();
+ }
+
+ public Session getSession()
+ {
+ return _session;
+ }
+
+ public void threadDidCleanup()
+ {
+ _transaction.commit();
+ }
+
+}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,79 @@
+// Copyright 2007 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.tapestry.internal.hibernate;
+
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.hibernate.HibernateSessionSource;
+import org.apache.tapestry.internal.services.ComponentClassLocator;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+
+public class HibernateSessionSourceImpl implements HibernateSessionSource
+{
+ private SessionFactory _sessionFactory;
+
+ public HibernateSessionSourceImpl(Log log, Collection<String> packageNames,
+ ComponentClassLocator classLocator)
+ {
+ ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
+ long startTime = System.currentTimeMillis();
+
+ AnnotationConfiguration configuration = new AnnotationConfiguration();
+
+ // Perform normal configuration.
+
+ configuration.configure();
+
+ for (String packageName : packageNames)
+ {
+ configuration.addPackage(packageName);
+
+ for (String className :
classLocator.locateComponentClassNames(packageName))
+ {
+ try
+ {
+ Class entityClass =
contextClassLoader.loadClass(className);
+
+ configuration.addAnnotatedClass(entityClass);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+
+ long configurationComplete = System.currentTimeMillis();
+
+ _sessionFactory = configuration.buildSessionFactory();
+
+ long factoryCreated = System.currentTimeMillis();
+
+ log.info(HibernateMessages.startupTiming(configurationComplete -
startTime, factoryCreated
+ - startTime));
+
+
log.info(HibernateMessages.entityCatalog(_sessionFactory.getAllClassMetadata().keySet()));
+
+ }
+
+ public Session create()
+ {
+ return _sessionFactory.openSession();
+ }
+
+}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/internal/hibernate/HibernateStrings.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/internal/hibernate/HibernateStrings.properties?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/internal/hibernate/HibernateStrings.properties
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/resources/org/apache/tapestry/internal/hibernate/HibernateStrings.properties
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,16 @@
+# Copyright 2007 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.
+
+startup-timing=Hibernate startup: %,d ms to configure, %,d ms overall.
+entity-catalog=Configured Hibernate entities: %s
\ No newline at end of file
Added: tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/conf.apt
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/conf.apt?view=auto&rev=516222
==============================================================================
--- tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/conf.apt (added)
+++ tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/conf.apt Thu Mar
8 15:22:40 2007
@@ -0,0 +1,10 @@
+ ----
+ 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.
+
+
\ No newline at end of file
Added: tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/index.apt
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/index.apt?view=auto&rev=516222
==============================================================================
--- tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/index.apt (added)
+++ tapestry/tapestry5/tapestry-hibernate/trunk/src/site/apt/index.apt Thu Mar
8 15:22:40 2007
@@ -0,0 +1,14 @@
+ ----
+ About Tapestry/Hibernate
+ ----
+
+Tapestry/Hibernate Integration Library
+
+ This library integrates into Tapestry 5 to provide out-of-the-box support
for using Hibernate 3 as the backend for
+ normal CRUD style applications.
+
+ For at least, the first pass, this will represent access to the native
Hibernate interfaces, exposed in a
+ 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. For the meantime, this library is focused on
\ No newline at end of file
Modified: tapestry/tapestry5/tapestry-hibernate/trunk/src/site/site.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/site/site.xml?view=diff&rev=516222&r1=516221&r2=516222
==============================================================================
--- tapestry/tapestry5/tapestry-hibernate/trunk/src/site/site.xml (original)
+++ tapestry/tapestry5/tapestry-hibernate/trunk/src/site/site.xml Thu Mar 8
15:22:40 2007
@@ -41,6 +41,8 @@
</links>
<menu name="Quick Links">
+ <item name="About" href="index.html"/>
+ <item name="Configuration" href="conf.html"/>
<item name="Download" href="http://tapestry.apache.org/download.html"/>
</menu>
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,44 @@
+// Copyright 2007 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.tapestry.internal.hibernate;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tapestry.hibernate.HibernateSessionSource;
+import org.apache.tapestry.internal.services.ComponentClassLocatorImpl;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.test.TapestryTestCase;
+import org.testng.annotations.Test;
+
+public class HibernateSessionSourceImplTest extends TapestryTestCase
+{
+ private final Log _log =
LogFactory.getLog("tapestry.hibernate.HibernateSessionSourceTest");
+
+ @Test
+ public void startup_without_packages()
+ {
+ Collection<String> packageNames = CollectionFactory.newList(
+ "org.example.myapp.entities",
+ "org.example.app0.entities");
+
+ HibernateSessionSource source = new HibernateSessionSourceImpl(_log,
packageNames,
+ new ComponentClassLocatorImpl());
+
+ assertNotNull(source.create());
+ }
+}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/app0/entities/User.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/app0/entities/User.java?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/app0/entities/User.java
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/java/org/example/app0/entities/User.java
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,87 @@
+// Copyright 2007 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.Id;
+import javax.persistence.Version;
+
[EMAIL PROTECTED]
+public class User
+{
+ @Id
+ 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)
+ {
+ _email = email;
+ }
+
+ public void setEncodedPassword(String encodedPassword)
+ {
+ _encodedPassword = encodedPassword;
+ }
+
+ public void setFirstName(String firstName)
+ {
+ _firstName = firstName;
+ }
+
+ public void setLastName(String lastName)
+ {
+ _lastName = lastName;
+ }
+}
Added:
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/hibernate.cfg.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/hibernate.cfg.xml?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/hibernate.cfg.xml
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/hibernate.cfg.xml
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,42 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!--
+ Copyright 2007 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:file:target/unit-testdb</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="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/tapestry-hibernate/trunk/src/test/resources/log4j.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/log4j.properties?view=auto&rev=516222
==============================================================================
---
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/log4j.properties
(added)
+++
tapestry/tapestry5/tapestry-hibernate/trunk/src/test/resources/log4j.properties
Thu Mar 8 15:22:40 2007
@@ -0,0 +1,29 @@
+# Copyright 2007 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.tapestry.TapestryFilter=info
+log4j.category.org.apache.tapestry=error
+log4j.category.tapestry=error
+log4j.category.tapestry.ioc.ClassFactory=error
+
+log4j.category.tapestry.hibernate=info