Repository: james-project Updated Branches: refs/heads/master 35858f70d -> 1fa297ce3
JAMES-1906 Factorize mailbox EntityManagerFactory creation (JPA) Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4655ab37 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4655ab37 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4655ab37 Branch: refs/heads/master Commit: 4655ab378f78ce668bf83b8afcd529ded238bbc2 Parents: 131c011 Author: Benoit Tellier <[email protected]> Authored: Thu Dec 29 09:54:44 2016 +0700 Committer: Benoit Tellier <[email protected]> Committed: Wed Jan 11 17:46:50 2017 +0700 ---------------------------------------------------------------------- backends-common/jpa/pom.xml | 39 ++++++++++ .../james/backends/jpa/JpaTestCluster.java | 82 ++++++++++++++++++++ backends-common/pom.xml | 1 + mailbox/jpa/pom.xml | 10 ++- .../james/mailbox/jpa/JPAMailboxFixture.java | 45 +++++++++++ .../mailbox/jpa/JPAMailboxManagerTest.java | 28 +------ .../mailbox/jpa/JPASubscriptionManagerTest.java | 42 ++-------- .../mailbox/jpa/mail/JPAMapperProvider.java | 51 +++--------- mailbox/pom.xml | 21 +++-- mailbox/tool/pom.xml | 12 +-- mpt/app/dependency-reduced-pom.xml | 4 +- mpt/impl/imap-mailbox/jpa/pom.xml | 17 ++++ .../mpt/imapmailbox/jpa/host/JPAHostSystem.java | 54 ++----------- mpt/impl/imap-mailbox/lucenesearch/pom.xml | 11 +++ .../host/LuceneSearchHostSystem.java | 43 ++-------- mpt/pom.xml | 13 ++++ server/container/guice/jpa-guice/pom.xml | 8 -- server/container/spring/pom.xml | 4 - server/data/data-jpa/pom.xml | 29 +++---- .../rrt/jpa/model/JPARecipientRewrite.java | 4 +- .../james/domainlist/jpa/JPADomainListTest.java | 24 +----- .../rrt/jpa/JPARecipientRewriteTableTest.java | 33 +------- .../org/apache/james/rrt/jpa/JPAStepdefs.java | 29 ++----- .../james/user/jpa/JpaUsersRepositoryTest.java | 49 +----------- server/pom.xml | 25 +++--- 25 files changed, 307 insertions(+), 371 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/backends-common/jpa/pom.xml ---------------------------------------------------------------------- diff --git a/backends-common/jpa/pom.xml b/backends-common/jpa/pom.xml new file mode 100644 index 0000000..ba951cf --- /dev/null +++ b/backends-common/jpa/pom.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>james-backends-common</artifactId> + <groupId>org.apache.james</groupId> + <version>3.0.0-beta6-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>apache-james-backends-jpa</artifactId> + + <dependencies> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + <dependency> + <groupId>org.apache.openjpa</groupId> + <artifactId>openjpa</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jpa_2.0_spec</artifactId> + <version>1.1</version> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + <version>1.3.170</version> + </dependency> + + </dependencies> + + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/backends-common/jpa/src/test/java/org/apache/james/backends/jpa/JpaTestCluster.java ---------------------------------------------------------------------- diff --git a/backends-common/jpa/src/test/java/org/apache/james/backends/jpa/JpaTestCluster.java b/backends-common/jpa/src/test/java/org/apache/james/backends/jpa/JpaTestCluster.java new file mode 100644 index 0000000..0ade077 --- /dev/null +++ b/backends-common/jpa/src/test/java/org/apache/james/backends/jpa/JpaTestCluster.java @@ -0,0 +1,82 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you 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.james.backends.jpa; + +import java.util.Arrays; +import java.util.HashMap; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +import org.apache.openjpa.persistence.OpenJPAPersistence; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.FluentIterable; + +public class JpaTestCluster { + + public static JpaTestCluster create(Class... clazz) { + HashMap<String, String> properties = new HashMap<String, String>(); + properties.put("openjpa.ConnectionDriverName", org.h2.Driver.class.getName()); + properties.put("openjpa.ConnectionURL", "jdbc:h2:mem:mailboxintegration;DB_CLOSE_DELAY=-1"); // Memory H2 database + properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); // Create Foreign Keys + properties.put("openjpa.jdbc.MappingDefaults", "ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"); + properties.put("openjpa.jdbc.SchemaFactory", "native(ForeignKeys=true)"); + properties.put("openjpa.jdbc.MappingDefaults", "ForeignKeyDeleteAction=cascade, JoinForeignKeyDeleteAction=cascade"); + properties.put("openjpa.jdbc.QuerySQLCache", "false"); + properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); + properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); + properties.put("openjpa.MetaDataFactory", "jpa(Types=" + + Joiner.on(";").join( + FluentIterable.from(Arrays.asList(clazz)) + .transform(toFQDN())) + + ")"); + return new JpaTestCluster(OpenJPAPersistence.getEntityManagerFactory(properties)); + } + + private static Function<Class, String> toFQDN() { + return new Function<Class, String>() { + @Override + public String apply(Class input) { + return input.getName(); + } + }; + } + + private final EntityManagerFactory entityManagerFactory; + + private JpaTestCluster(EntityManagerFactory entityManagerFactory) { + this.entityManagerFactory = entityManagerFactory; + } + + public EntityManagerFactory getEntityManagerFactory() { + return entityManagerFactory; + } + + public void clear(String... tables) { + EntityManager entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + for(String tableName: tables) { + entityManager.createNativeQuery("TRUNCATE table " + tableName).executeUpdate(); + } + entityManager.getTransaction().commit(); + entityManager.close(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/backends-common/pom.xml ---------------------------------------------------------------------- diff --git a/backends-common/pom.xml b/backends-common/pom.xml index d8d3794..34df193 100644 --- a/backends-common/pom.xml +++ b/backends-common/pom.xml @@ -39,6 +39,7 @@ <modules> <module>cassandra</module> + <module>jpa</module> </modules> <dependencyManagement> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mailbox/jpa/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/jpa/pom.xml b/mailbox/jpa/pom.xml index 1217b3d..906d820 100644 --- a/mailbox/jpa/pom.xml +++ b/mailbox/jpa/pom.xml @@ -41,12 +41,14 @@ <artifactId>apache-james-mailbox-store</artifactId> </dependency> <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <type>test-jar</type> + <scope>test</scope> </dependency> <dependency> <groupId>${javax.mail.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java new file mode 100644 index 0000000..7278c43 --- /dev/null +++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java @@ -0,0 +1,45 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you 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.james.mailbox.jpa; + +import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; +import org.apache.james.mailbox.jpa.mail.model.JPAMailboxAnnotation; +import org.apache.james.mailbox.jpa.mail.model.JPAProperty; +import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag; +import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage; +import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage; +import org.apache.james.mailbox.jpa.user.model.JPASubscription; + +public interface JPAMailboxFixture { + + Class[] MAILBOX_PERSISTANCE_CLASSES = new Class[] {JPAMailbox.class, + AbstractJPAMailboxMessage.class, + JPAMailboxMessage.class, + JPAProperty.class, + JPAUserFlag.class, + JPAMailboxAnnotation.class, + JPASubscription.class}; + + String[] MAILBOX_TABLE_NAMES = new String[] {"JAMES_MAIL_USERFLAG", + "JAMES_MAIL_PROPERTY", + "JAMES_MAILBOX_ANNOTATION", + "JAMES_MAILBOX", + "JAMES_MAIL"}; +} http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java index c496704..f9d19dc 100644 --- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java +++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java @@ -18,10 +18,9 @@ ****************************************************************/ package org.apache.james.mailbox.jpa; -import java.util.HashMap; - import javax.persistence.EntityManagerFactory; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.acl.GroupMembershipResolver; import org.apache.james.mailbox.acl.MailboxACLResolver; @@ -30,17 +29,10 @@ import org.apache.james.mailbox.acl.UnionMailboxACLResolver; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.jpa.mail.JPAModSeqProvider; import org.apache.james.mailbox.jpa.mail.JPAUidProvider; -import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; -import org.apache.james.mailbox.jpa.mail.model.JPAProperty; -import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag; -import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage; -import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage; import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager; -import org.apache.james.mailbox.jpa.user.model.JPASubscription; import org.apache.james.mailbox.store.JVMMailboxPathLocker; import org.apache.james.mailbox.store.mail.model.DefaultMessageId; import org.apache.james.mailbox.store.mail.model.impl.MessageParser; -import org.apache.openjpa.persistence.OpenJPAPersistence; import org.junit.runner.RunWith; import org.slf4j.LoggerFactory; import org.xenei.junit.contract.Contract; @@ -54,6 +46,8 @@ import com.google.common.base.Throwables; @ContractImpl(OpenJPAMailboxManager.class) public class JPAMailboxManagerTest { + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES); + /** * The entity manager factory. */ @@ -65,21 +59,7 @@ public class JPAMailboxManagerTest { @Override public OpenJPAMailboxManager newInstance() { - HashMap<String, String> properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", "org.h2.Driver"); - properties.put("openjpa.ConnectionURL", "jdbc:h2:mem:imap;DB_CLOSE_DELAY=-1"); - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + - JPAMailbox.class.getName() + ";" + - AbstractJPAMailboxMessage.class.getName() + ";" + - JPAMailboxMessage.class.getName() + ";" + - JPAProperty.class.getName() + ";" + - JPAUserFlag.class.getName() + ";" + - JPASubscription.class.getName() + ")"); - - entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties); + entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory(); JVMMailboxPathLocker locker = new JVMMailboxPathLocker(); JPAMailboxSessionMapperFactory mf = new JPAMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(locker, entityManagerFactory), new JPAModSeqProvider(locker, entityManagerFactory)); http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java index de40714..8b8dc61 100644 --- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java +++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPASubscriptionManagerTest.java @@ -18,56 +18,29 @@ ****************************************************************/ package org.apache.james.mailbox.jpa; -import java.util.HashMap; +import javax.persistence.EntityManagerFactory; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.mailbox.AbstractSubscriptionManagerTest; import org.apache.james.mailbox.SubscriptionManager; import org.apache.james.mailbox.exception.SubscriptionException; import org.apache.james.mailbox.jpa.mail.JPAModSeqProvider; import org.apache.james.mailbox.jpa.mail.JPAUidProvider; -import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; -import org.apache.james.mailbox.jpa.mail.model.JPAProperty; -import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag; -import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage; -import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage; -import org.apache.james.mailbox.jpa.user.model.JPASubscription; import org.apache.james.mailbox.store.JVMMailboxPathLocker; -import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; -import org.apache.openjpa.persistence.OpenJPAPersistence; import org.junit.After; -import org.junit.Before; public class JPASubscriptionManagerTest extends AbstractSubscriptionManagerTest{ - private OpenJPAEntityManagerFactory entityManagerFactory; - - @Before - public void setup() { - - HashMap<String, String> properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", "org.h2.Driver"); - properties.put("openjpa.ConnectionURL", "jdbc:h2:mem:imap;DB_CLOSE_DELAY=-1"); - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + - JPAMailbox.class.getName() + ";" + - AbstractJPAMailboxMessage.class.getName() + ";" + - JPAMailboxMessage.class.getName() + ";" + - JPAProperty.class.getName() + ";" + - JPAUserFlag.class.getName() + ";" + - JPASubscription.class.getName() + ")"); - - entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties); - - super.setup(); - } + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES); @Override public SubscriptionManager createSubscriptionManager() { JVMMailboxPathLocker locker = new JVMMailboxPathLocker(); - JPAMailboxSessionMapperFactory mf = new JPAMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(locker, entityManagerFactory), new JPAModSeqProvider(locker, entityManagerFactory)); + EntityManagerFactory entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory(); + JPAMailboxSessionMapperFactory mf = new JPAMailboxSessionMapperFactory(entityManagerFactory, + new JPAUidProvider(locker, entityManagerFactory), + new JPAModSeqProvider(locker, entityManagerFactory)); return new JPASubscriptionManager(mf); } @@ -75,6 +48,5 @@ public class JPASubscriptionManagerTest extends AbstractSubscriptionManagerTest{ @After public void teardown() throws SubscriptionException { super.teardown(); - entityManagerFactory.close(); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java index df37f39..4a742a6 100644 --- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java +++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java @@ -19,24 +19,17 @@ package org.apache.james.mailbox.jpa.mail; -import java.util.HashMap; import java.util.List; import java.util.Random; -import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import org.apache.commons.lang.NotImplementedException; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.mailbox.MessageUid; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.jpa.JPAId; -import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; -import org.apache.james.mailbox.jpa.mail.model.JPAMailboxAnnotation; -import org.apache.james.mailbox.jpa.mail.model.JPAProperty; -import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag; -import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage; -import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage; -import org.apache.james.mailbox.jpa.user.model.JPASubscription; +import org.apache.james.mailbox.jpa.JPAMailboxFixture; import org.apache.james.mailbox.mock.MockMailboxSession; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MessageId; @@ -49,20 +42,21 @@ import org.apache.james.mailbox.store.mail.MessageMapper; import org.apache.james.mailbox.store.mail.model.DefaultMessageId; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.MapperProvider; -import org.apache.openjpa.persistence.OpenJPAPersistence; import com.google.common.collect.ImmutableList; public class JPAMapperProvider implements MapperProvider { + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES); + @Override public MailboxMapper createMailboxMapper() throws MailboxException { - return new TransactionalMailboxMapper(new JPAMailboxMapper(createEntityManagerFactory())); + return new TransactionalMailboxMapper(new JPAMailboxMapper(JPA_TEST_CLUSTER.getEntityManagerFactory())); } @Override public MessageMapper createMessageMapper() throws MailboxException { - EntityManagerFactory entityManagerFactory = createEntityManagerFactory(); + EntityManagerFactory entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory(); JVMMailboxPathLocker locker = new JVMMailboxPathLocker(); JPAMessageMapper messageMapper = new JPAMessageMapper(new MockMailboxSession("benwa"), @@ -70,7 +64,7 @@ public class JPAMapperProvider implements MapperProvider { new JPAModSeqProvider(locker, entityManagerFactory), entityManagerFactory); - return new TransactionalMessageMapper((JPAMessageMapper)messageMapper); + return new TransactionalMessageMapper(messageMapper); } @Override @@ -80,7 +74,7 @@ public class JPAMapperProvider implements MapperProvider { @Override public AnnotationMapper createAnnotationMapper() throws MailboxException { - return new TransactionalAnnotationMapper(new JPAAnnotationMapper(createEntityManagerFactory())); + return new TransactionalAnnotationMapper(new JPAAnnotationMapper(JPA_TEST_CLUSTER.getEntityManagerFactory())); } @Override @@ -95,15 +89,7 @@ public class JPAMapperProvider implements MapperProvider { @Override public void clearMapper() throws MailboxException { - EntityManager entityManager = createEntityManagerFactory().createEntityManager(); - entityManager.getTransaction().begin(); - entityManager.createNativeQuery("TRUNCATE table JAMES_MAIL_USERFLAG;").executeUpdate(); - entityManager.createNativeQuery("TRUNCATE table JAMES_MAIL_PROPERTY;").executeUpdate(); - entityManager.createNativeQuery("TRUNCATE table JAMES_MAILBOX_ANNOTATION;").executeUpdate(); - entityManager.createNativeQuery("TRUNCATE table JAMES_MAILBOX;").executeUpdate(); - entityManager.createNativeQuery("TRUNCATE table JAMES_MAIL;").executeUpdate(); - entityManager.getTransaction().commit(); - entityManager.close(); + JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES); } @Override @@ -116,25 +102,6 @@ public class JPAMapperProvider implements MapperProvider { return false; } - private EntityManagerFactory createEntityManagerFactory() { - HashMap<String, String> properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", "org.h2.Driver"); - properties.put("openjpa.ConnectionURL", "jdbc:h2:mem:imap;DB_CLOSE_DELAY=-1"); - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + - JPAMailbox.class.getName() + ";" + - AbstractJPAMailboxMessage.class.getName() + ";" + - JPAMailboxMessage.class.getName() + ";" + - JPAProperty.class.getName() + ";" + - JPAUserFlag.class.getName() + ";" + - JPAMailboxAnnotation.class.getName() + ";" + - JPASubscription.class.getName() + ")"); - - return OpenJPAPersistence.getEntityManagerFactory(properties); - } - @Override public List<Capabilities> getSupportedCapabilities() { return ImmutableList.of(Capabilities.ANNOTATION, Capabilities.MAILBOX, Capabilities.MESSAGE); http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mailbox/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/pom.xml b/mailbox/pom.xml index 9a5ee30..c4699f6 100644 --- a/mailbox/pom.xml +++ b/mailbox/pom.xml @@ -84,7 +84,6 @@ <javax.activation.artifactId>activation</javax.activation.artifactId> <javax.mail.groupId>javax.mail</javax.mail.groupId> <javax.mail.artifactId>mail</javax.mail.artifactId> - <openjpa.version>2.2.1</openjpa.version> <javax.persistence.version>1.0.2</javax.persistence.version> <javax.inject.version>1</javax.inject.version> <apache-mime4j.version>0.8.0</apache-mime4j.version> @@ -103,7 +102,6 @@ <commons-beanutils-core.version>1.8.3</commons-beanutils-core.version> <h2.version>1.3.170</h2.version> <derby.version>10.9.1.0</derby.version> - <geronimo-jpa-spec.version>1.1</geronimo-jpa-spec.version> <jcr.version>2.0</jcr.version> <jackrabbit.version>2.5.2</jackrabbit.version> <lucene.version>3.6.0</lucene.version> @@ -460,20 +458,27 @@ START OpenJPA --> <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> - <version>${openjpa.version}</version> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - <version>${geronimo-jpa-spec.version}</version> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <version>${project.version}</version> + <type>test-jar</type> </dependency> <dependency> <groupId>org.jasypt</groupId> <artifactId>jasypt</artifactId> <version>${jasypt.version}</version> </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + <version>${h2.version}</version> + </dependency> <!-- END OpenJPA http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mailbox/tool/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/tool/pom.xml b/mailbox/tool/pom.xml index 02606a5..6e7673a 100644 --- a/mailbox/tool/pom.xml +++ b/mailbox/tool/pom.xml @@ -34,6 +34,10 @@ <dependencies> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-api</artifactId> </dependency> <dependency> @@ -53,14 +57,6 @@ <artifactId>slf4j-simple</artifactId> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-annotation_1.0_spec</artifactId> - </dependency> - <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mpt/app/dependency-reduced-pom.xml ---------------------------------------------------------------------- diff --git a/mpt/app/dependency-reduced-pom.xml b/mpt/app/dependency-reduced-pom.xml index 6156d59..9815884 100644 --- a/mpt/app/dependency-reduced-pom.xml +++ b/mpt/app/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ <parent> <artifactId>apache-james-mpt</artifactId> <groupId>org.apache.james</groupId> - <version>0.2-SNAPSHOT</version> + <version>3.0.0-beta6-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>apache-james-mpt-app</artifactId> @@ -87,7 +87,7 @@ interfaces to the MPT library.</description> <dependency> <groupId>org.apache.james</groupId> <artifactId>apache-james-mpt-core</artifactId> - <version>0.2-SNAPSHOT</version> + <version>3.0.0-beta6-SNAPSHOT</version> <type>test-jar</type> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mpt/impl/imap-mailbox/jpa/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/impl/imap-mailbox/jpa/pom.xml b/mpt/impl/imap-mailbox/jpa/pom.xml index 959794d..da6a8a5 100644 --- a/mpt/impl/imap-mailbox/jpa/pom.xml +++ b/mpt/impl/imap-mailbox/jpa/pom.xml @@ -33,6 +33,12 @@ <dependencies> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mpt-imapmailbox-core</artifactId> </dependency> <dependency> @@ -41,6 +47,17 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-store</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-jpa</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java ---------------------------------------------------------------------- diff --git a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java index 2f13699..42082f1 100644 --- a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java +++ b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java @@ -20,11 +20,11 @@ package org.apache.james.mpt.imapmailbox.jpa.host; import java.io.File; -import java.util.HashMap; import javax.persistence.EntityManagerFactory; import org.apache.commons.io.FileUtils; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.imap.api.process.ImapProcessor; import org.apache.james.imap.encode.main.DefaultImapEncoderFactory; import org.apache.james.imap.main.DefaultImapDecoderFactory; @@ -35,18 +35,12 @@ import org.apache.james.mailbox.acl.GroupMembershipResolver; import org.apache.james.mailbox.acl.MailboxACLResolver; import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; import org.apache.james.mailbox.acl.UnionMailboxACLResolver; +import org.apache.james.mailbox.jpa.JPAMailboxFixture; import org.apache.james.mailbox.jpa.JPAMailboxSessionMapperFactory; import org.apache.james.mailbox.jpa.JPASubscriptionManager; import org.apache.james.mailbox.jpa.mail.JPAModSeqProvider; import org.apache.james.mailbox.jpa.mail.JPAUidProvider; -import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; -import org.apache.james.mailbox.jpa.mail.model.JPAMailboxAnnotation; -import org.apache.james.mailbox.jpa.mail.model.JPAProperty; -import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag; -import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage; -import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage; import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager; -import org.apache.james.mailbox.jpa.user.model.JPASubscription; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.store.FakeAuthenticator; import org.apache.james.mailbox.store.JVMMailboxPathLocker; @@ -58,11 +52,12 @@ import org.apache.james.mpt.api.ImapFeatures; import org.apache.james.mpt.api.ImapFeatures.Feature; import org.apache.james.mpt.host.JamesImapHostSystem; import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate; -import org.apache.openjpa.persistence.OpenJPAPersistence; import org.slf4j.LoggerFactory; public class JPAHostSystem extends JamesImapHostSystem { + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES); + public static final String META_DATA_DIRECTORY = "target/user-meta-data"; private static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT, Feature.USER_FLAGS_SUPPORT, Feature.ANNOTATION_SUPPORT); @@ -75,48 +70,9 @@ public class JPAHostSystem extends JamesImapHostSystem { private final EntityManagerFactory entityManagerFactory; public JPAHostSystem() throws Exception { - - HashMap<String, String> properties = new HashMap<String, String>(); - - // Configure OpenJPA for H2 Memory Database - properties.put("openjpa.ConnectionDriverName", org.h2.Driver.class.getName()); - properties.put("openjpa.ConnectionURL", "jdbc:h2:mem:mailboxintegration;DB_CLOSE_DELAY=-1"); // Memory H2 database - - // Configure OpenJPA for Derby Memory Database - // properties.put("openjpa.ConnectionDriverName", org.apache.derby.jdbc.EmbeddedDriver.class.getName()); - // properties.put("openjpa.ConnectionURL", "jdbc:derby:memory:mailboxintegration;create=true"); // Memory Derby database - - // Configure OpenJPA for Derby Embedded Database - //properties.put("openjpa.ConnectionURL", "jdbc:derby:test;create=true"); - //properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - - // Configure OpenJPA Tables creation - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); // Create Foreign Keys - properties.put("openjpa.jdbc.MappingDefaults", "ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"); - properties.put("openjpa.jdbc.SchemaFactory", "native(ForeignKeys=true)"); - properties.put("openjpa.jdbc.MappingDefaults", "ForeignKeyDeleteAction=cascade, JoinForeignKeyDeleteAction=cascade"); - - - // Configure OpenJPA Cache - properties.put("openjpa.jdbc.QuerySQLCache", "false"); - - // Configure OpenJPA Log - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - //properties.put("openjpa.Log", "SQL=TRACE"); // Use SQL=TRACE to trace SQL. - //properties.put("openjpa.Log", "DefaultLevel=TRACE"); // Use the DefaultLevel=TRACE to trace all. - - // Configure OpenJPA Metadata - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + - JPAMailbox.class.getName() + ";" + - AbstractJPAMailboxMessage.class.getName() + ";" + - JPAMailboxMessage.class.getName() + ";" + - JPAProperty.class.getName() + ";" + - JPAUserFlag.class.getName() + ";" + - JPASubscription.class.getName() + ";" + - JPAMailboxAnnotation.class.getName() + ")"); userManager = new FakeAuthenticator(); - entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties); + entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory(); JVMMailboxPathLocker locker = new JVMMailboxPathLocker(); JPAUidProvider uidProvider = new JPAUidProvider(locker, entityManagerFactory); JPAModSeqProvider modSeqProvider = new JPAModSeqProvider(locker, entityManagerFactory); http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mpt/impl/imap-mailbox/lucenesearch/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/impl/imap-mailbox/lucenesearch/pom.xml b/mpt/impl/imap-mailbox/lucenesearch/pom.xml index 2476d6a..0a8ee99 100644 --- a/mpt/impl/imap-mailbox/lucenesearch/pom.xml +++ b/mpt/impl/imap-mailbox/lucenesearch/pom.xml @@ -33,6 +33,12 @@ <dependencies> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-api</artifactId> </dependency> <dependency> @@ -50,6 +56,11 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-jpa</artifactId> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-store</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java ---------------------------------------------------------------------- diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java index ec669fd..dd237d5 100644 --- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java +++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java @@ -21,11 +21,11 @@ package org.apache.james.mpt.imapmailbox.lucenesearch.host; import java.io.File; import java.io.IOException; -import java.util.HashMap; import javax.persistence.EntityManagerFactory; import org.apache.commons.io.FileUtils; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.imap.api.process.ImapProcessor; import org.apache.james.imap.encode.main.DefaultImapEncoderFactory; import org.apache.james.imap.main.DefaultImapDecoderFactory; @@ -39,17 +39,12 @@ import org.apache.james.mailbox.acl.UnionMailboxACLResolver; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.jpa.JPAId; import org.apache.james.mailbox.jpa.JPAId.Factory; +import org.apache.james.mailbox.jpa.JPAMailboxFixture; import org.apache.james.mailbox.jpa.JPAMailboxSessionMapperFactory; import org.apache.james.mailbox.jpa.JPASubscriptionManager; import org.apache.james.mailbox.jpa.mail.JPAModSeqProvider; import org.apache.james.mailbox.jpa.mail.JPAUidProvider; -import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; -import org.apache.james.mailbox.jpa.mail.model.JPAProperty; -import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag; -import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage; -import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage; import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager; -import org.apache.james.mailbox.jpa.user.model.JPASubscription; import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageId; @@ -64,7 +59,6 @@ import org.apache.james.mpt.api.ImapFeatures.Feature; import org.apache.james.mpt.host.JamesImapHostSystem; import org.apache.james.mpt.imapmailbox.MailboxCreationDelegate; import org.apache.lucene.store.FSDirectory; -import org.apache.openjpa.persistence.OpenJPAPersistence; import org.slf4j.LoggerFactory; import com.google.common.base.Throwables; @@ -73,6 +67,8 @@ import com.google.common.io.Files; public class LuceneSearchHostSystem extends JamesImapHostSystem { public static final String META_DATA_DIRECTORY = "target/user-meta-data"; private static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT); + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES); + private File tempFile; private OpenJPAMailboxManager mailboxManager; @@ -112,37 +108,8 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem { } private void initFields() { - HashMap<String, String> properties = new HashMap<String, String>(); - - // Configure OpenJPA for H2 Memory Database - properties.put("openjpa.ConnectionDriverName", org.h2.Driver.class.getName()); - properties.put("openjpa.ConnectionURL", "jdbc:h2:mem:mailboxintegration;DB_CLOSE_DELAY=-1"); // Memory H2 database - - // Configure OpenJPA Tables creation - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); // Create Foreign Keys - properties.put("openjpa.jdbc.MappingDefaults", "ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"); - properties.put("openjpa.jdbc.SchemaFactory", "native(ForeignKeys=true)"); - properties.put("openjpa.jdbc.MappingDefaults", "ForeignKeyDeleteAction=cascade, JoinForeignKeyDeleteAction=cascade"); - - - // Configure OpenJPA Cache - properties.put("openjpa.jdbc.QuerySQLCache", "false"); - - // Configure OpenJPA Log - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - //properties.put("openjpa.RuntimeUnenhancedClasses", "warn"); - - // Configure OpenJPA Metadata - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + - JPAMailbox.class.getName() + ";" + - AbstractJPAMailboxMessage.class.getName() + ";" + - JPAMailboxMessage.class.getName() + ";" + - JPAProperty.class.getName() + ";" + - JPAUserFlag.class.getName() + ";" + - JPASubscription.class.getName() + ")"); - userManager = new FakeAuthenticator(); - entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties); + entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory(); JVMMailboxPathLocker locker = new JVMMailboxPathLocker(); JPAUidProvider uidProvider = new JPAUidProvider(locker, entityManagerFactory); JPAModSeqProvider modSeqProvider = new JPAModSeqProvider(locker, entityManagerFactory); http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/mpt/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/pom.xml b/mpt/pom.xml index a8feadb..4b5a519 100644 --- a/mpt/pom.xml +++ b/mpt/pom.xml @@ -169,6 +169,12 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <type>test-jar</type> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-api</artifactId> <version>${project.version}</version> </dependency> @@ -209,6 +215,13 @@ <artifactId>apache-james-mailbox-jpa</artifactId> <version>${project.version}</version> </dependency> + + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-jpa</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + </dependency> <dependency> <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-lucene</artifactId> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/container/guice/jpa-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/pom.xml b/server/container/guice/jpa-guice/pom.xml index e9d1f62..f02b70c 100644 --- a/server/container/guice/jpa-guice/pom.xml +++ b/server/container/guice/jpa-guice/pom.xml @@ -254,14 +254,6 @@ <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - </dependency> </dependencies> </profile> <profile> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/container/spring/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/spring/pom.xml b/server/container/spring/pom.xml index f6f9e12..65c3c0c 100644 --- a/server/container/spring/pom.xml +++ b/server/container/spring/pom.xml @@ -137,10 +137,6 @@ <artifactId>log4j</artifactId> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj-1.version}</version> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/data/data-jpa/pom.xml ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/pom.xml b/server/data/data-jpa/pom.xml index 770268c..a40850b 100644 --- a/server/data/data-jpa/pom.xml +++ b/server/data/data-jpa/pom.xml @@ -35,6 +35,16 @@ <dependencies> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>james-server-lifecycle-api</artifactId> </dependency> <dependency> @@ -69,14 +79,6 @@ <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-annotation_1.1_spec</artifactId> - </dependency> <!-- Test dependencies --> <dependency> @@ -106,11 +108,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.apache.james</groupId> <artifactId>james-server-dnsservice-api</artifactId> <scope>test</scope> @@ -131,11 +128,7 @@ <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> - <scope>test</scope> + <version>${h2.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/model/JPARecipientRewrite.java ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/model/JPARecipientRewrite.java b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/model/JPARecipientRewrite.java index 7efcdf4..c6296d5 100644 --- a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/model/JPARecipientRewrite.java +++ b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/model/JPARecipientRewrite.java @@ -35,7 +35,7 @@ import javax.persistence.Table; * persistence. */ @Entity(name = "JamesRecipientRewrite") -@Table(name = "JAMES_RECIPIENT_REWRITE") +@Table(name = JPARecipientRewrite.JAMES_RECIPIENT_REWRITE) @NamedQueries({ @NamedQuery(name = "selectMappings", query = "SELECT rrt FROM JamesRecipientRewrite rrt WHERE (rrt.user LIKE :user OR rrt.user='*') and (rrt.domain like :domain or rrt.domain='*') ORDER BY rrt.domain DESC"), @NamedQuery(name = "selectExactMappings", query = "SELECT rrt FROM JamesRecipientRewrite rrt WHERE (rrt.user LIKE :user) and (rrt.domain like :domain) ORDER BY rrt.domain DESC"), @@ -46,6 +46,8 @@ import javax.persistence.Table; @IdClass(JPARecipientRewrite.RecipientRewriteTableId.class) public class JPARecipientRewrite { + public static final String JAMES_RECIPIENT_REWRITE = "JAMES_RECIPIENT_REWRITE"; + public static class RecipientRewriteTableId implements Serializable { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java b/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java index ec1d5b6..6e5d9a0 100644 --- a/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java +++ b/server/data/data-jpa/src/test/java/org/apache/james/domainlist/jpa/JPADomainListTest.java @@ -18,13 +18,10 @@ ****************************************************************/ package org.apache.james.domainlist.jpa; -import java.util.HashMap; - +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.domainlist.api.DomainList; import org.apache.james.domainlist.jpa.model.JPADomain; import org.apache.james.domainlist.lib.AbstractDomainListTest; -import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; -import org.apache.openjpa.persistence.OpenJPAPersistence; import org.slf4j.LoggerFactory; /** @@ -32,31 +29,18 @@ import org.slf4j.LoggerFactory; */ public class JPADomainListTest extends AbstractDomainListTest { + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPADomain.class); + @Override protected DomainList createDomainList() { - // Use a memory database. - HashMap<String, String> properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", org.apache.derby.jdbc.EmbeddedDriver.class.getName()); - properties.put("openjpa.ConnectionURL", "jdbc:derby:memory:JPADomainListTestDB;create=true"); - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + JPADomain.class.getName() + ")"); - /* - The OpenJPA Entity Manager used for the tests. - */ - OpenJPAEntityManagerFactory factory = OpenJPAPersistence.getEntityManagerFactory(properties); - - // Initialize the JPADomainList (no autodetect,...). JPADomainList jpaDomainList = new JPADomainList(); jpaDomainList.setLog(LoggerFactory.getLogger("JPADomainListMockLog")); jpaDomainList.setDNSService(getDNSServer("localhost")); jpaDomainList.setAutoDetect(false); jpaDomainList.setAutoDetectIP(false); - jpaDomainList.setEntityManagerFactory(factory); + jpaDomainList.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory()); return jpaDomainList; - } } http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java index 131e7f3..1a32d5f 100644 --- a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java +++ b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java @@ -18,15 +18,12 @@ ****************************************************************/ package org.apache.james.rrt.jpa; -import java.util.HashMap; import org.apache.commons.configuration.DefaultConfigurationBuilder; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.rrt.api.RecipientRewriteTableException; import org.apache.james.rrt.jpa.model.JPARecipientRewrite; import org.apache.james.rrt.lib.AbstractRecipientRewriteTable; import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest; -import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; -import org.apache.openjpa.persistence.OpenJPAPersistence; -import org.junit.Before; import org.slf4j.LoggerFactory; /** @@ -34,37 +31,13 @@ import org.slf4j.LoggerFactory; */ public class JPARecipientRewriteTableTest extends AbstractRecipientRewriteTableTest { - /** - * The OpenJPA Entity Manager used for the tests. - */ - private OpenJPAEntityManagerFactory factory; - - @Before - @Override - public void setUp() throws Exception { - - // Use a memory database. - /* - The properties for the OpenJPA Entity Manager. - */ - HashMap<String, String> properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", "org.h2.Driver"); - properties.put("openjpa.ConnectionURL", "jdbc:h2:target/users/db"); - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + JPARecipientRewrite.class.getName() + ")"); - - factory = OpenJPAPersistence.getEntityManagerFactory(properties); - - super.setUp(); - } + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPARecipientRewrite.class); @Override protected AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception { JPARecipientRewriteTable localVirtualUserTable = new JPARecipientRewriteTable(); localVirtualUserTable.setLog(LoggerFactory.getLogger("MockLog")); - localVirtualUserTable.setEntityManagerFactory(factory); + localVirtualUserTable.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory()); DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder(); localVirtualUserTable.configure(defaultConfiguration); return localVirtualUserTable; http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java index f4ecf5e..214c367 100644 --- a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java +++ b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java @@ -18,21 +18,20 @@ ****************************************************************/ package org.apache.james.rrt.jpa; -import java.util.HashMap; -import java.util.UUID; - import org.apache.commons.configuration.DefaultConfigurationBuilder; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.rrt.jpa.model.JPARecipientRewrite; import org.apache.james.rrt.lib.AbstractRecipientRewriteTable; import org.apache.james.rrt.lib.RewriteTablesStepdefs; -import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; -import org.apache.openjpa.persistence.OpenJPAPersistence; import org.slf4j.LoggerFactory; +import cucumber.api.java.After; import cucumber.api.java.Before; public class JPAStepdefs { + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPARecipientRewrite.class); + private final RewriteTablesStepdefs mainStepdefs; public JPAStepdefs(RewriteTablesStepdefs mainStepdefs) { @@ -44,27 +43,15 @@ public class JPAStepdefs { mainStepdefs.rewriteTable = getRecipientRewriteTable(); } - private OpenJPAEntityManagerFactory managerFactory() throws Exception { - - // Use a memory database. - /* - The properties for the OpenJPA Entity Manager. - */ - HashMap<String, String> properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", "org.h2.Driver"); - properties.put("openjpa.ConnectionURL", "jdbc:h2:target/users/" + UUID.randomUUID()); - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + JPARecipientRewrite.class.getName() + ")"); - - return OpenJPAPersistence.getEntityManagerFactory(properties); + @After + public void tearDown() { + JPA_TEST_CLUSTER.clear(JPARecipientRewrite.JAMES_RECIPIENT_REWRITE); } private AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception { JPARecipientRewriteTable localVirtualUserTable = new JPARecipientRewriteTable(); localVirtualUserTable.setLog(LoggerFactory.getLogger("MockLog")); - localVirtualUserTable.setEntityManagerFactory(managerFactory()); + localVirtualUserTable.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory()); DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder(); localVirtualUserTable.configure(defaultConfiguration); return localVirtualUserTable; http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/data/data-jpa/src/test/java/org/apache/james/user/jpa/JpaUsersRepositoryTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/src/test/java/org/apache/james/user/jpa/JpaUsersRepositoryTest.java b/server/data/data-jpa/src/test/java/org/apache/james/user/jpa/JpaUsersRepositoryTest.java index 6b9c872..0ba2aee 100644 --- a/server/data/data-jpa/src/test/java/org/apache/james/user/jpa/JpaUsersRepositoryTest.java +++ b/server/data/data-jpa/src/test/java/org/apache/james/user/jpa/JpaUsersRepositoryTest.java @@ -18,70 +18,29 @@ ****************************************************************/ package org.apache.james.user.jpa; -import java.util.HashMap; - import org.apache.commons.configuration.DefaultConfigurationBuilder; +import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.user.jpa.model.JPAUser; import org.apache.james.user.lib.AbstractUsersRepository; import org.apache.james.user.lib.AbstractUsersRepositoryTest; -import org.apache.openjpa.persistence.OpenJPAEntityManager; -import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; -import org.apache.openjpa.persistence.OpenJPAEntityTransaction; -import org.apache.openjpa.persistence.OpenJPAPersistence; import org.junit.After; -import org.junit.Before; import org.slf4j.LoggerFactory; public class JpaUsersRepositoryTest extends AbstractUsersRepositoryTest { - private HashMap<String, String> properties; - private OpenJPAEntityManagerFactory factory; - - @Before - @Override - public void setUp() throws Exception { - properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", "org.h2.Driver"); - properties.put("openjpa.ConnectionURL", "jdbc:h2:target/users/db"); - properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.MetaDataFactory", "jpa(Types=" + JPAUser.class.getName() + ")"); - super.setUp(); - deleteAll(); - } + private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAUser.class); @After @Override public void tearDown() throws Exception { - deleteAll(); - super.tearDown(); - - } - - private void deleteAll() { - OpenJPAEntityManager manager = factory.createEntityManager(); - final OpenJPAEntityTransaction transaction = manager.getTransaction(); - try { - transaction.begin(); - manager.createQuery("DELETE FROM JamesUser user").executeUpdate(); - transaction.commit(); - } catch (Exception e) { - e.printStackTrace(); - if (transaction.isActive()) { - transaction.rollback(); - } - } finally { - manager.close(); - } + JPA_TEST_CLUSTER.clear("JAMES_USER"); } @Override protected AbstractUsersRepository getUsersRepository() throws Exception { - factory = OpenJPAPersistence.getEntityManagerFactory(properties); JPAUsersRepository repos = new JPAUsersRepository(); repos.setLog(LoggerFactory.getLogger("JPA")); - repos.setEntityManagerFactory(factory); + repos.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory()); repos.configure(new DefaultConfigurationBuilder()); return repos; } http://git-wip-us.apache.org/repos/asf/james-project/blob/4655ab37/server/pom.xml ---------------------------------------------------------------------- diff --git a/server/pom.xml b/server/pom.xml index 8065656..0395fa4 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -161,8 +161,6 @@ <jmock.version>2.6.0</jmock.version> <concurrent.version>1.3.4</concurrent.version> <log4j.version>1.2.17</log4j.version> - <openjpa.version>2.2.1</openjpa.version> - <geronimo-jpa-spec.version>1.1</geronimo-jpa-spec.version> <jcr.version>2.0</jcr.version> <xbean-spring.version>3.12</xbean-spring.version> <netty.version>3.10.5.Final</netty.version> @@ -342,6 +340,17 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-backends-jpa</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-mailet-api</artifactId> <version>${project.version}</version> <exclusions> @@ -1212,18 +1221,6 @@ </dependency> <dependency> - <groupId>org.apache.openjpa</groupId> - <artifactId>openjpa</artifactId> - <version>${openjpa.version}</version> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - <version>${geronimo-jpa-spec.version}</version> - </dependency> - - <dependency> <groupId>javax.jcr</groupId> <artifactId>jcr</artifactId> <version>${jcr.version}</version> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
