You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/08/29 03:14:30 UTC
[02/34] james-project git commit: JAMES-2521 Move JPA migrator utils
as a separate tool project
JAMES-2521 Move JPA migrator utils as a separate tool project
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a937a334
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a937a334
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a937a334
Branch: refs/heads/master
Commit: a937a334211d9a7f643b70d54f4a00a92cb7212f
Parents: 77fdac5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 14 17:31:30 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Aug 29 10:11:46 2018 +0700
----------------------------------------------------------------------
mailbox/tool/pom.xml | 4 -
.../james/mailbox/jpa/migrator/JpaMigrator.java | 75 ---------
.../command/IMAP165JpaMigrateCommand.java | 42 -----
.../command/IMAP168JpaMigrateCommand.java | 120 --------------
.../command/IMAP172JpaMigrateCommand.java | 41 -----
.../command/IMAP176JpaMigrateCommand.java | 40 -----
.../command/IMAP180JpaMigrateCommand.java | 158 -------------------
.../command/IMAP184JpaMigrateCommand.java | 40 -----
.../jpa/migrator/command/JpaMigrateCommand.java | 41 -----
.../jpa/migrator/command/JpaMigrateQuery.java | 39 -----
.../migrator/exception/JpaMigrateException.java | 47 ------
.../mailbox/jpa/migrator/JpaMigratorTest.java | 55 -------
mailbox/tools/jpa-migrator/pom.xml | 45 ++++++
.../mailbox/tools/jpa/migrator/JpaMigrator.java | 75 +++++++++
.../command/IMAP165JpaMigrateCommand.java | 42 +++++
.../command/IMAP168JpaMigrateCommand.java | 120 ++++++++++++++
.../command/IMAP172JpaMigrateCommand.java | 41 +++++
.../command/IMAP176JpaMigrateCommand.java | 40 +++++
.../command/IMAP180JpaMigrateCommand.java | 158 +++++++++++++++++++
.../command/IMAP184JpaMigrateCommand.java | 40 +++++
.../jpa/migrator/command/JpaMigrateCommand.java | 41 +++++
.../jpa/migrator/command/JpaMigrateQuery.java | 39 +++++
.../migrator/exception/JpaMigrateException.java | 47 ++++++
.../tools/jpa/migrator/JpaMigratorTest.java | 55 +++++++
mailbox/tools/pom.xml | 1 +
server/container/spring/pom.xml | 4 +
26 files changed, 748 insertions(+), 702 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/tool/pom.xml b/mailbox/tool/pom.xml
index 240294d..74aef43 100644
--- a/mailbox/tool/pom.xml
+++ b/mailbox/tool/pom.xml
@@ -34,10 +34,6 @@
<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
- <artifactId>apache-james-backends-jpa</artifactId>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
<artifactId>apache-james-mailbox-api</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/JpaMigrator.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/JpaMigrator.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/JpaMigrator.java
deleted file mode 100644
index a557acc..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/JpaMigrator.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************
- * 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.migrator;
-
-import java.util.Locale;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-
-import org.apache.james.mailbox.jpa.migrator.command.JpaMigrateCommand;
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The class that will manage the migration commands for the James JPA database.
- * All SQL commands should be moved from JAVA code to a separate file.
- */
-public class JpaMigrator {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(JpaMigrator.class);
-
- /**
- * The package name where all commands reside.
- */
- private static final String JPA_MIGRATION_COMMAND_PACKAGE = JpaMigrateCommand.class.getPackage().getName();
-
- /**<p>Executes the database migration for the provided JIRAs numbers.
- * For example, for the https://issues.apache.org/jira/browse/IMAP-165 JIRA, simply invoke
- * with IMAP165 as parameter.
- * You can also invoke with many JIRA at once. They will be all serially executed.</p>
- *
- * TODO Extract the SQL in JAVA classes to XML file.
- *
- * @param jiras the JIRAs numbers
- * @throws JpaMigrateException
- */
- public static void main(String[] jiras) throws JpaMigrateException {
-
- try {
- EntityManagerFactory factory = Persistence.createEntityManagerFactory("JamesMigrator");
- EntityManager em = factory.createEntityManager();
-
- for (String jira: jiras) {
- JpaMigrateCommand jiraJpaMigratable = (JpaMigrateCommand) Class.forName(JPA_MIGRATION_COMMAND_PACKAGE + "." + jira.toUpperCase(Locale.US) + JpaMigrateCommand.class.getSimpleName()).newInstance();
- LOGGER.info("Now executing {} migration", jira);
- em.getTransaction().begin();
- jiraJpaMigratable.migrate(em);
- em.getTransaction().commit();
- LOGGER.info("{} migration is successfully achieved", jira);
- }
- } catch (Throwable t) {
- throw new JpaMigrateException(t);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP165JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP165JpaMigrateCommand.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP165JpaMigrateCommand.java
deleted file mode 100644
index c17c7ed..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP165JpaMigrateCommand.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import javax.persistence.EntityManager;
-
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-
-/**
- * JIRA IMAP-165 is "Add index annotation on frequently used columns".
- *
- * Add 3 indexes for the DELETED, SEEN and RECENT columns of MEMBERSHIP table.
- *
- * @link https://issues.apache.org/jira/browse/IMAP-165
- *
- */
-public class IMAP165JpaMigrateCommand implements JpaMigrateCommand {
-
- @Override
- public void migrate(EntityManager em) throws JpaMigrateException {
- JpaMigrateQuery.executeUpdate(em, "CREATE INDEX I_MMBRSHP_SEEN ON MEMBERSHIP (SEEN)");
- JpaMigrateQuery.executeUpdate(em, "CREATE INDEX I_MMBRSHP_RECENT ON MEMBERSHIP (RECENT)");
- JpaMigrateQuery.executeUpdate(em, "CREATE INDEX I_MMBRSHP_DELETED ON MEMBERSHIP (DELETED)");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP168JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP168JpaMigrateCommand.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP168JpaMigrateCommand.java
deleted file mode 100644
index cadfc83..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP168JpaMigrateCommand.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-
-/**
- * <p>
- * JIRA IMAP-168 is "mailboxes can't be identified 100% unambiguously using virtual hosting".
- *
- * MAILBOX.NAME contains data such as
- * "#mail.eric@localhost.net"
- * "#mail.eric@localhost.net.INBOX"
- * "#mail.eric@localhost.net.INBOX.test"
- * "#mail.eric@localhost.net.Trash"
- *
- * It needs to be splitted into MAILBOX.NAMESPACE | MAILBOX.USER0 | MAILBOX.NAME with
- * "#mail" | "eric@localhost.net" | "" ==> was created before, but is not used anymore
- * "#mail" | "eric@localhost.net" | "INBOX"
- * "#mail" | "eric@localhost.net" | "INBOX.test"
- * "#mail" | "eric@localhost.net" | "Trash"
- *</p>
- *
- * @link https://issues.apache.org/jira/browse/IMAP-168
- *
- */
-public class IMAP168JpaMigrateCommand implements JpaMigrateCommand {
-
- @Override
- public void migrate(EntityManager em) throws JpaMigrateException {
-
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX ADD COLUMN NAMESPACE VARCHAR(255)");
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX ADD COLUMN USER0 VARCHAR(255)");
-
- Query query = em.createNativeQuery("SELECT NAME FROM MAILBOX");
-
- @SuppressWarnings("unchecked")
- List<String> nameList = query.getResultList();
- System.out.println("getResultList returned a result=" + nameList.size());
- for (String name: nameList) {
- MailboxPath mailboxPath = new MailboxPath(name);
- System.out.println(mailboxPath);
- Query update = em.createNativeQuery("UPDATE MAILBOX SET NAMESPACE = ?, USER0 = ?, NAME = ? WHERE NAME = ?");
- update.setParameter(1, mailboxPath.namespace);
- update.setParameter(2, mailboxPath.userName);
- update.setParameter(3, mailboxPath.mailboxName);
- update.setParameter(4, name);
- int resultUpdate = update.executeUpdate();
- System.out.println("ExecuteUpdate returned a result=" + resultUpdate);
- }
-
- }
-
- /**
- *
- */
- private class MailboxPath {
-
- protected String namespace;
- protected String userName;
- protected String mailboxName;
-
- /**
- * @param name
- */
- public MailboxPath(String name) {
-
- if (! name.startsWith("#mail")) {
- throw new IllegalArgumentException("The name must begin with #private");
- }
-
- namespace = "#mail";
-
- name = name.substring(6);
-
- int atIndex = name.indexOf("@");
- int firstDotIndex = name.indexOf(".", atIndex);
- int secondDotIndex = name.indexOf(".", firstDotIndex + 1);
-
- if (secondDotIndex > 0) {
- userName = name.substring(0, secondDotIndex);
- mailboxName = name.substring(userName.length() + 1);
- } else {
- // We don't have a mailbox name...
- userName = name.substring(0);
- mailboxName = "";
- }
-
- }
-
- @Override
- public String toString() {
- return "MailboxPath [namespace=" + namespace +
- ", userName=" + userName + ", mailboxName=" + mailboxName + "]";
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP172JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP172JpaMigrateCommand.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP172JpaMigrateCommand.java
deleted file mode 100644
index f74df60..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP172JpaMigrateCommand.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import javax.persistence.EntityManager;
-
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-
-/**
- * JIRA IMAP-172 is "Cleanup JPAMailbox".
- *
- * Simply drop the MAILBOX.MESSAGECOUNT and MAILBOX.SIZE columns.
- *
- * @link https://issues.apache.org/jira/browse/IMAP-172
- *
- */
-public class IMAP172JpaMigrateCommand implements JpaMigrateCommand {
-
- @Override
- public void migrate(EntityManager em) throws JpaMigrateException {
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX DROP COLUMN MESSAGECOUNT");
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX DROP COLUMN SIZE");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP176JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP176JpaMigrateCommand.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP176JpaMigrateCommand.java
deleted file mode 100644
index d919c8f..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP176JpaMigrateCommand.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import javax.persistence.EntityManager;
-
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-
-/**
- * JIRA 176 is "Change users' namespace to #private".
- *
- * Simply update the MAILBOX.NAMESPACE column with "#private" value.
- *
- * @link https://issues.apache.org/jira/browse/IMAP-176
- *
- */
-public class IMAP176JpaMigrateCommand implements JpaMigrateCommand {
-
- @Override
- public void migrate(EntityManager em) throws JpaMigrateException {
- JpaMigrateQuery.executeUpdate(em, "UPDATE MAILBOX SET NAMESPACE = '#private'");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP180JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP180JpaMigrateCommand.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP180JpaMigrateCommand.java
deleted file mode 100644
index 71d2bb4..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP180JpaMigrateCommand.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-import org.apache.openjpa.kernel.DelegatingResultList;
-import org.apache.openjpa.lib.rop.ResultList;
-
-/**
- * JIRA IMAP-180 is "Add @ElementJoinColumn for Property and Header tables".
- *
- * 1. Add the needed columns on HEADER and PROPERTY
- * ALTER TABLE HEADER ADD COLUMN MESSAGE_ID BIGINT
- * ALTER TABLE PROPERTY ADD COLUMN MESSAGE_ID BIGINT
- *
- * 2. Link the HEADER/PROPERTY tables with the MESSAGE table
- * SELECT * FROM MESSAGE_HEADER / MESSAGE_HEADER
- *
- * 3. Add the needed FK and indexes on HEADER and PROPERTY
- * CREATE INDEX SQL100727182411700 ON HEADER(MESSAGE_ID)
- * ALTER TABLE HEADER ADD CONSTRAINT SQL100727182411700 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)
- * CREATE INDEX SQL100727182411780 ON PROPERTY(MESSAGE_ID)
- * ALTER TABLE PROPERTY ADD CONSTRAINT SQL100727182411780 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)
- *
- * 4. Drop the MESSAGE_HEADER and MESSAGE_PROPERY tables
- * DROP TABLE MESSAGE_HEADER
- * DROP TABLE MESSAGE_PROPERTY
- *
- * @link https://issues.apache.org/jira/browse/IMAP-180
- *
- */
-public class IMAP180JpaMigrateCommand implements JpaMigrateCommand {
-
- @Override
- public void migrate(EntityManager em) throws JpaMigrateException {
- em.getTransaction().commit();
- migrateHeaders(em);
- // Commit after header migration.
- migrateProperties(em);
- em.getTransaction().begin();
- }
-
- /**
- * Migrate the headers.
- */
- @SuppressWarnings("rawtypes")
- private static void migrateHeaders(EntityManager em) {
-
- em.getTransaction().begin();
- Query headerCountQuery = em.createNativeQuery("SELECT COUNT(MESSAGE_ID) FROM MESSAGE_HEADER", Integer.class);
- Integer headerCount = (Integer) headerCountQuery.getResultList().get(0);
- System.out.println("Number of headers=" + headerCount);
-
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE HEADER ADD COLUMN MESSAGE_ID BIGINT");
-
- Query headerQuery = em.createNativeQuery("SELECT MESSAGE_ID, HEADERS_ID FROM MESSAGE_HEADER");
- em.getTransaction().commit();
-
- DelegatingResultList headerNameList = (DelegatingResultList) headerQuery.getResultList();
- ResultList rl = headerNameList.getDelegate();
- for (int i = 0; i < rl.size(); i++) {
- Object[] results = (Object[]) rl.get(i);
- Long messageId = (Long) results[0];
- Long headerId = (Long) results[1];
- em.getTransaction().begin();
- Query update = em.createNativeQuery("UPDATE HEADER SET MESSAGE_ID = ? WHERE ID = ?");
- update.setParameter(1, messageId);
- update.setParameter(2, headerId);
- int result = update.executeUpdate();
- System.out.printf("ExecuteUpdate returned a result=" + result + " for header %d of %d\n", i + 1, headerCount);
- em.getTransaction().commit();
- }
-
- em.getTransaction().begin();
- System.out.println("Creating index.");
- JpaMigrateQuery.executeUpdate(em, "CREATE INDEX SQL100727182411700 ON HEADER(MESSAGE_ID)");
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- System.out.println("Creating foreign key.");
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE HEADER ADD CONSTRAINT SQL100727182411700 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)");
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- System.out.println("Dropping table.");
- JpaMigrateQuery.executeUpdate(em, "DROP TABLE MESSAGE_HEADER");
- em.getTransaction().commit();
-
- }
-
- /**
- * Migrate the properties.
- */
- @SuppressWarnings("rawtypes")
- private static void migrateProperties(EntityManager em) {
-
- em.getTransaction().begin();
- Query propertyCountQuery = em.createNativeQuery("SELECT COUNT(MESSAGE_ID) FROM MESSAGE_PROPERTY", Integer.class);
- Integer propertyCount = (Integer) propertyCountQuery.getResultList().get(0);
- System.out.println("Number of headers=" + propertyCount);
-
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE PROPERTY ADD COLUMN MESSAGE_ID BIGINT");
-
- Query propertyQuery = em.createNativeQuery("SELECT MESSAGE_ID, PROPERTIES_ID FROM MESSAGE_PROPERTY");
- em.getTransaction().commit();
-
- DelegatingResultList propertyNameList = (DelegatingResultList) propertyQuery.getResultList();
- ResultList rl = propertyNameList.getDelegate();
- for (int i = 0; i < rl.size(); i++) {
- Object[] results = (Object[]) rl.get(i);
- Long messageId = (Long) results[0];
- Long propertyId = (Long) results[1];
- em.getTransaction().begin();
- Query update = em.createNativeQuery("UPDATE PROPERTY SET MESSAGE_ID = ? WHERE ID = ?");
- update.setParameter(1, messageId);
- update.setParameter(2, propertyId);
- int result = update.executeUpdate();
- System.out.printf("ExecuteUpdate returned a result=" + result + " for property %d of %d\n", i + 1, propertyCount);
- em.getTransaction().commit();
- }
-
- em.getTransaction().begin();
- System.out.println("Creating index.");
- JpaMigrateQuery.executeUpdate(em, "CREATE INDEX SQL100727182411780 ON PROPERTY(MESSAGE_ID)");
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- System.out.println("Creating foreign key.");
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE PROPERTY ADD CONSTRAINT SQL100727182411780 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)");
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- System.out.println("Dropping table.");
- JpaMigrateQuery.executeUpdate(em, "DROP TABLE MESSAGE_PROPERTY");
- em.getTransaction().commit();
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP184JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP184JpaMigrateCommand.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP184JpaMigrateCommand.java
deleted file mode 100644
index 9904736..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/IMAP184JpaMigrateCommand.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import javax.persistence.EntityManager;
-
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-
-/**
- * JIRA IMAP-184 is "Remove size of MailboxMembership".
- *
- * Simply drop the MAILBOXMEMBERSHIP.SIZE column.
- *
- * @link https://issues.apache.org/jira/browse/IMAP-184
- *
- */
-public class IMAP184JpaMigrateCommand implements JpaMigrateCommand {
-
- @Override
- public void migrate(EntityManager em) throws JpaMigrateException {
- JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOXMEMBERSHIP DROP COLUMN SIZE");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateCommand.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateCommand.java
deleted file mode 100644
index 6198826..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateCommand.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import javax.persistence.EntityManager;
-
-import org.apache.james.mailbox.jpa.migrator.exception.JpaMigrateException;
-
-/**
- * A command that apply to James database the needed updates.
- */
-public interface JpaMigrateCommand {
-
- /**
- * Executes the needed SQL commands on the database via the provided JPA entity manager.
- * A transaction on the provided entity manager must be begun by the caller.
- * It is also the reponsibility of the caller to commit the opened transaction after
- * calling the migrate method.
- *
- * @param em the provided Entity Manager
- * @throws JpaMigrateException
- */
- void migrate(EntityManager em) throws JpaMigrateException;
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateQuery.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateQuery.java
deleted file mode 100644
index 752c3ff..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/command/JpaMigrateQuery.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/****************************************************************
- * 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.migrator.command;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-/**
- *
- */
-public class JpaMigrateQuery {
-
- /**
- * @param em
- * @param update
- */
- public static void executeUpdate(EntityManager em, String update) {
- Query query = em.createNativeQuery(update);
- int result = query.executeUpdate();
- System.out.println("ExecuteUpdate returned a result=" + result);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/exception/JpaMigrateException.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/exception/JpaMigrateException.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/exception/JpaMigrateException.java
deleted file mode 100644
index 4c83e18..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/jpa/migrator/exception/JpaMigrateException.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/****************************************************************
- * 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.migrator.exception;
-
-/**
- * Exception to be thrown when a problem occurs in the migration process.
- *
- */
-public class JpaMigrateException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public JpaMigrateException() {
- }
-
- public JpaMigrateException(String message) {
- super(message);
- }
-
- public JpaMigrateException(Throwable cause) {
- super(cause);
- }
-
- public JpaMigrateException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tool/src/test/java/org/apache/james/mailbox/jpa/migrator/JpaMigratorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/test/java/org/apache/james/mailbox/jpa/migrator/JpaMigratorTest.java b/mailbox/tool/src/test/java/org/apache/james/mailbox/jpa/migrator/JpaMigratorTest.java
deleted file mode 100644
index bd47945..0000000
--- a/mailbox/tool/src/test/java/org/apache/james/mailbox/jpa/migrator/JpaMigratorTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************
- * 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.migrator;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-@Ignore("This class needs to be reviewed")
-public class JpaMigratorTest {
- @Test
- public void testImap165() throws Exception {
- JpaMigrator.main(new String[]{"IMAP165"});
- }
-
- @Test
- public void testImap168() throws Exception {
- JpaMigrator.main(new String[]{"IMAP168"});
- }
-
- @Test
- public void testImap172() throws Exception {
- JpaMigrator.main(new String[]{"IMAP172"});
- }
-
- @Test
- public void testImap176() throws Exception {
- JpaMigrator.main(new String[]{"IMAP176"});
- }
-
- @Test
- public void testImap180() throws Exception {
- JpaMigrator.main(new String[]{"IMAP180"});
- }
-
- @Test
- public void testImap184() throws Exception {
- JpaMigrator.main(new String[]{"IMAP184"});
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/pom.xml b/mailbox/tools/jpa-migrator/pom.xml
new file mode 100644
index 0000000..1a15887
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>apache-james-mailbox-tools</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>apache-james-mailbvox-tools-jpa-migrator</artifactId>
+
+ <name>Apache James :: Mailbox :: Tools :: JPA migrator</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-backends-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigrator.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigrator.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigrator.java
new file mode 100644
index 0000000..20ec314
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigrator.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.tools.jpa.migrator;
+
+import java.util.Locale;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import org.apache.james.mailbox.tools.jpa.migrator.command.JpaMigrateCommand;
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The class that will manage the migration commands for the James JPA database.
+ * All SQL commands should be moved from JAVA code to a separate file.
+ */
+public class JpaMigrator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(JpaMigrator.class);
+
+ /**
+ * The package name where all commands reside.
+ */
+ private static final String JPA_MIGRATION_COMMAND_PACKAGE = JpaMigrateCommand.class.getPackage().getName();
+
+ /**<p>Executes the database migration for the provided JIRAs numbers.
+ * For example, for the https://issues.apache.org/jira/browse/IMAP-165 JIRA, simply invoke
+ * with IMAP165 as parameter.
+ * You can also invoke with many JIRA at once. They will be all serially executed.</p>
+ *
+ * TODO Extract the SQL in JAVA classes to XML file.
+ *
+ * @param jiras the JIRAs numbers
+ * @throws JpaMigrateException
+ */
+ public static void main(String[] jiras) throws JpaMigrateException {
+
+ try {
+ EntityManagerFactory factory = Persistence.createEntityManagerFactory("JamesMigrator");
+ EntityManager em = factory.createEntityManager();
+
+ for (String jira: jiras) {
+ JpaMigrateCommand jiraJpaMigratable = (JpaMigrateCommand) Class.forName(JPA_MIGRATION_COMMAND_PACKAGE + "." + jira.toUpperCase(Locale.US) + JpaMigrateCommand.class.getSimpleName()).newInstance();
+ LOGGER.info("Now executing {} migration", jira);
+ em.getTransaction().begin();
+ jiraJpaMigratable.migrate(em);
+ em.getTransaction().commit();
+ LOGGER.info("{} migration is successfully achieved", jira);
+ }
+ } catch (Throwable t) {
+ throw new JpaMigrateException(t);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP165JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP165JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP165JpaMigrateCommand.java
new file mode 100644
index 0000000..7ba0c98
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP165JpaMigrateCommand.java
@@ -0,0 +1,42 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import javax.persistence.EntityManager;
+
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+
+/**
+ * JIRA IMAP-165 is "Add index annotation on frequently used columns".
+ *
+ * Add 3 indexes for the DELETED, SEEN and RECENT columns of MEMBERSHIP table.
+ *
+ * @link https://issues.apache.org/jira/browse/IMAP-165
+ *
+ */
+public class IMAP165JpaMigrateCommand implements JpaMigrateCommand {
+
+ @Override
+ public void migrate(EntityManager em) throws JpaMigrateException {
+ JpaMigrateQuery.executeUpdate(em, "CREATE INDEX I_MMBRSHP_SEEN ON MEMBERSHIP (SEEN)");
+ JpaMigrateQuery.executeUpdate(em, "CREATE INDEX I_MMBRSHP_RECENT ON MEMBERSHIP (RECENT)");
+ JpaMigrateQuery.executeUpdate(em, "CREATE INDEX I_MMBRSHP_DELETED ON MEMBERSHIP (DELETED)");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java
new file mode 100644
index 0000000..8f67357
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP168JpaMigrateCommand.java
@@ -0,0 +1,120 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+
+/**
+ * <p>
+ * JIRA IMAP-168 is "mailboxes can't be identified 100% unambiguously using virtual hosting".
+ *
+ * MAILBOX.NAME contains data such as
+ * "#mail.eric@localhost.net"
+ * "#mail.eric@localhost.net.INBOX"
+ * "#mail.eric@localhost.net.INBOX.test"
+ * "#mail.eric@localhost.net.Trash"
+ *
+ * It needs to be splitted into MAILBOX.NAMESPACE | MAILBOX.USER0 | MAILBOX.NAME with
+ * "#mail" | "eric@localhost.net" | "" ==> was created before, but is not used anymore
+ * "#mail" | "eric@localhost.net" | "INBOX"
+ * "#mail" | "eric@localhost.net" | "INBOX.test"
+ * "#mail" | "eric@localhost.net" | "Trash"
+ *</p>
+ *
+ * @link https://issues.apache.org/jira/browse/IMAP-168
+ *
+ */
+public class IMAP168JpaMigrateCommand implements JpaMigrateCommand {
+
+ @Override
+ public void migrate(EntityManager em) throws JpaMigrateException {
+
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX ADD COLUMN NAMESPACE VARCHAR(255)");
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX ADD COLUMN USER0 VARCHAR(255)");
+
+ Query query = em.createNativeQuery("SELECT NAME FROM MAILBOX");
+
+ @SuppressWarnings("unchecked")
+ List<String> nameList = query.getResultList();
+ System.out.println("getResultList returned a result=" + nameList.size());
+ for (String name: nameList) {
+ MailboxPath mailboxPath = new MailboxPath(name);
+ System.out.println(mailboxPath);
+ Query update = em.createNativeQuery("UPDATE MAILBOX SET NAMESPACE = ?, USER0 = ?, NAME = ? WHERE NAME = ?");
+ update.setParameter(1, mailboxPath.namespace);
+ update.setParameter(2, mailboxPath.userName);
+ update.setParameter(3, mailboxPath.mailboxName);
+ update.setParameter(4, name);
+ int resultUpdate = update.executeUpdate();
+ System.out.println("ExecuteUpdate returned a result=" + resultUpdate);
+ }
+
+ }
+
+ /**
+ *
+ */
+ private class MailboxPath {
+
+ protected String namespace;
+ protected String userName;
+ protected String mailboxName;
+
+ /**
+ * @param name
+ */
+ public MailboxPath(String name) {
+
+ if (! name.startsWith("#mail")) {
+ throw new IllegalArgumentException("The name must begin with #private");
+ }
+
+ namespace = "#mail";
+
+ name = name.substring(6);
+
+ int atIndex = name.indexOf("@");
+ int firstDotIndex = name.indexOf(".", atIndex);
+ int secondDotIndex = name.indexOf(".", firstDotIndex + 1);
+
+ if (secondDotIndex > 0) {
+ userName = name.substring(0, secondDotIndex);
+ mailboxName = name.substring(userName.length() + 1);
+ } else {
+ // We don't have a mailbox name...
+ userName = name.substring(0);
+ mailboxName = "";
+ }
+
+ }
+
+ @Override
+ public String toString() {
+ return "MailboxPath [namespace=" + namespace +
+ ", userName=" + userName + ", mailboxName=" + mailboxName + "]";
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP172JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP172JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP172JpaMigrateCommand.java
new file mode 100644
index 0000000..3c153be
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP172JpaMigrateCommand.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import javax.persistence.EntityManager;
+
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+
+/**
+ * JIRA IMAP-172 is "Cleanup JPAMailbox".
+ *
+ * Simply drop the MAILBOX.MESSAGECOUNT and MAILBOX.SIZE columns.
+ *
+ * @link https://issues.apache.org/jira/browse/IMAP-172
+ *
+ */
+public class IMAP172JpaMigrateCommand implements JpaMigrateCommand {
+
+ @Override
+ public void migrate(EntityManager em) throws JpaMigrateException {
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX DROP COLUMN MESSAGECOUNT");
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOX DROP COLUMN SIZE");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP176JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP176JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP176JpaMigrateCommand.java
new file mode 100644
index 0000000..6c31bd0
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP176JpaMigrateCommand.java
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import javax.persistence.EntityManager;
+
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+
+/**
+ * JIRA 176 is "Change users' namespace to #private".
+ *
+ * Simply update the MAILBOX.NAMESPACE column with "#private" value.
+ *
+ * @link https://issues.apache.org/jira/browse/IMAP-176
+ *
+ */
+public class IMAP176JpaMigrateCommand implements JpaMigrateCommand {
+
+ @Override
+ public void migrate(EntityManager em) throws JpaMigrateException {
+ JpaMigrateQuery.executeUpdate(em, "UPDATE MAILBOX SET NAMESPACE = '#private'");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP180JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP180JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP180JpaMigrateCommand.java
new file mode 100644
index 0000000..cc99930
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP180JpaMigrateCommand.java
@@ -0,0 +1,158 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+import org.apache.openjpa.kernel.DelegatingResultList;
+import org.apache.openjpa.lib.rop.ResultList;
+
+/**
+ * JIRA IMAP-180 is "Add @ElementJoinColumn for Property and Header tables".
+ *
+ * 1. Add the needed columns on HEADER and PROPERTY
+ * ALTER TABLE HEADER ADD COLUMN MESSAGE_ID BIGINT
+ * ALTER TABLE PROPERTY ADD COLUMN MESSAGE_ID BIGINT
+ *
+ * 2. Link the HEADER/PROPERTY tables with the MESSAGE table
+ * SELECT * FROM MESSAGE_HEADER / MESSAGE_HEADER
+ *
+ * 3. Add the needed FK and indexes on HEADER and PROPERTY
+ * CREATE INDEX SQL100727182411700 ON HEADER(MESSAGE_ID)
+ * ALTER TABLE HEADER ADD CONSTRAINT SQL100727182411700 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)
+ * CREATE INDEX SQL100727182411780 ON PROPERTY(MESSAGE_ID)
+ * ALTER TABLE PROPERTY ADD CONSTRAINT SQL100727182411780 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)
+ *
+ * 4. Drop the MESSAGE_HEADER and MESSAGE_PROPERY tables
+ * DROP TABLE MESSAGE_HEADER
+ * DROP TABLE MESSAGE_PROPERTY
+ *
+ * @link https://issues.apache.org/jira/browse/IMAP-180
+ *
+ */
+public class IMAP180JpaMigrateCommand implements JpaMigrateCommand {
+
+ @Override
+ public void migrate(EntityManager em) throws JpaMigrateException {
+ em.getTransaction().commit();
+ migrateHeaders(em);
+ // Commit after header migration.
+ migrateProperties(em);
+ em.getTransaction().begin();
+ }
+
+ /**
+ * Migrate the headers.
+ */
+ @SuppressWarnings("rawtypes")
+ private static void migrateHeaders(EntityManager em) {
+
+ em.getTransaction().begin();
+ Query headerCountQuery = em.createNativeQuery("SELECT COUNT(MESSAGE_ID) FROM MESSAGE_HEADER", Integer.class);
+ Integer headerCount = (Integer) headerCountQuery.getResultList().get(0);
+ System.out.println("Number of headers=" + headerCount);
+
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE HEADER ADD COLUMN MESSAGE_ID BIGINT");
+
+ Query headerQuery = em.createNativeQuery("SELECT MESSAGE_ID, HEADERS_ID FROM MESSAGE_HEADER");
+ em.getTransaction().commit();
+
+ DelegatingResultList headerNameList = (DelegatingResultList) headerQuery.getResultList();
+ ResultList rl = headerNameList.getDelegate();
+ for (int i = 0; i < rl.size(); i++) {
+ Object[] results = (Object[]) rl.get(i);
+ Long messageId = (Long) results[0];
+ Long headerId = (Long) results[1];
+ em.getTransaction().begin();
+ Query update = em.createNativeQuery("UPDATE HEADER SET MESSAGE_ID = ? WHERE ID = ?");
+ update.setParameter(1, messageId);
+ update.setParameter(2, headerId);
+ int result = update.executeUpdate();
+ System.out.printf("ExecuteUpdate returned a result=" + result + " for header %d of %d\n", i + 1, headerCount);
+ em.getTransaction().commit();
+ }
+
+ em.getTransaction().begin();
+ System.out.println("Creating index.");
+ JpaMigrateQuery.executeUpdate(em, "CREATE INDEX SQL100727182411700 ON HEADER(MESSAGE_ID)");
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ System.out.println("Creating foreign key.");
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE HEADER ADD CONSTRAINT SQL100727182411700 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)");
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ System.out.println("Dropping table.");
+ JpaMigrateQuery.executeUpdate(em, "DROP TABLE MESSAGE_HEADER");
+ em.getTransaction().commit();
+
+ }
+
+ /**
+ * Migrate the properties.
+ */
+ @SuppressWarnings("rawtypes")
+ private static void migrateProperties(EntityManager em) {
+
+ em.getTransaction().begin();
+ Query propertyCountQuery = em.createNativeQuery("SELECT COUNT(MESSAGE_ID) FROM MESSAGE_PROPERTY", Integer.class);
+ Integer propertyCount = (Integer) propertyCountQuery.getResultList().get(0);
+ System.out.println("Number of headers=" + propertyCount);
+
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE PROPERTY ADD COLUMN MESSAGE_ID BIGINT");
+
+ Query propertyQuery = em.createNativeQuery("SELECT MESSAGE_ID, PROPERTIES_ID FROM MESSAGE_PROPERTY");
+ em.getTransaction().commit();
+
+ DelegatingResultList propertyNameList = (DelegatingResultList) propertyQuery.getResultList();
+ ResultList rl = propertyNameList.getDelegate();
+ for (int i = 0; i < rl.size(); i++) {
+ Object[] results = (Object[]) rl.get(i);
+ Long messageId = (Long) results[0];
+ Long propertyId = (Long) results[1];
+ em.getTransaction().begin();
+ Query update = em.createNativeQuery("UPDATE PROPERTY SET MESSAGE_ID = ? WHERE ID = ?");
+ update.setParameter(1, messageId);
+ update.setParameter(2, propertyId);
+ int result = update.executeUpdate();
+ System.out.printf("ExecuteUpdate returned a result=" + result + " for property %d of %d\n", i + 1, propertyCount);
+ em.getTransaction().commit();
+ }
+
+ em.getTransaction().begin();
+ System.out.println("Creating index.");
+ JpaMigrateQuery.executeUpdate(em, "CREATE INDEX SQL100727182411780 ON PROPERTY(MESSAGE_ID)");
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ System.out.println("Creating foreign key.");
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE PROPERTY ADD CONSTRAINT SQL100727182411780 FOREIGN KEY (MESSAGE_ID) REFERENCES MESSAGE(ID)");
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ System.out.println("Dropping table.");
+ JpaMigrateQuery.executeUpdate(em, "DROP TABLE MESSAGE_PROPERTY");
+ em.getTransaction().commit();
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP184JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP184JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP184JpaMigrateCommand.java
new file mode 100644
index 0000000..0a7e7e2
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/IMAP184JpaMigrateCommand.java
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import javax.persistence.EntityManager;
+
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+
+/**
+ * JIRA IMAP-184 is "Remove size of MailboxMembership".
+ *
+ * Simply drop the MAILBOXMEMBERSHIP.SIZE column.
+ *
+ * @link https://issues.apache.org/jira/browse/IMAP-184
+ *
+ */
+public class IMAP184JpaMigrateCommand implements JpaMigrateCommand {
+
+ @Override
+ public void migrate(EntityManager em) throws JpaMigrateException {
+ JpaMigrateQuery.executeUpdate(em, "ALTER TABLE MAILBOXMEMBERSHIP DROP COLUMN SIZE");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateCommand.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateCommand.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateCommand.java
new file mode 100644
index 0000000..73a64e4
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateCommand.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import javax.persistence.EntityManager;
+
+import org.apache.james.mailbox.tools.jpa.migrator.exception.JpaMigrateException;
+
+/**
+ * A command that apply to James database the needed updates.
+ */
+public interface JpaMigrateCommand {
+
+ /**
+ * Executes the needed SQL commands on the database via the provided JPA entity manager.
+ * A transaction on the provided entity manager must be begun by the caller.
+ * It is also the reponsibility of the caller to commit the opened transaction after
+ * calling the migrate method.
+ *
+ * @param em the provided Entity Manager
+ * @throws JpaMigrateException
+ */
+ void migrate(EntityManager em) throws JpaMigrateException;
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateQuery.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateQuery.java
new file mode 100644
index 0000000..4aa98f6
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/command/JpaMigrateQuery.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.command;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+/**
+ *
+ */
+public class JpaMigrateQuery {
+
+ /**
+ * @param em
+ * @param update
+ */
+ public static void executeUpdate(EntityManager em, String update) {
+ Query query = em.createNativeQuery(update);
+ int result = query.executeUpdate();
+ System.out.println("ExecuteUpdate returned a result=" + result);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/exception/JpaMigrateException.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/exception/JpaMigrateException.java b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/exception/JpaMigrateException.java
new file mode 100644
index 0000000..9f454b4
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/main/java/org/apache/james/mailbox/tools/jpa/migrator/exception/JpaMigrateException.java
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.tools.jpa.migrator.exception;
+
+/**
+ * Exception to be thrown when a problem occurs in the migration process.
+ *
+ */
+public class JpaMigrateException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public JpaMigrateException() {
+ }
+
+ public JpaMigrateException(String message) {
+ super(message);
+ }
+
+ public JpaMigrateException(Throwable cause) {
+ super(cause);
+ }
+
+ public JpaMigrateException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java b/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java
new file mode 100644
index 0000000..cc8bb94
--- /dev/null
+++ b/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.tools.jpa.migrator;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore("This class needs to be reviewed")
+public class JpaMigratorTest {
+ @Test
+ public void testImap165() throws Exception {
+ JpaMigrator.main(new String[]{"IMAP165"});
+ }
+
+ @Test
+ public void testImap168() throws Exception {
+ JpaMigrator.main(new String[]{"IMAP168"});
+ }
+
+ @Test
+ public void testImap172() throws Exception {
+ JpaMigrator.main(new String[]{"IMAP172"});
+ }
+
+ @Test
+ public void testImap176() throws Exception {
+ JpaMigrator.main(new String[]{"IMAP176"});
+ }
+
+ @Test
+ public void testImap180() throws Exception {
+ JpaMigrator.main(new String[]{"IMAP180"});
+ }
+
+ @Test
+ public void testImap184() throws Exception {
+ JpaMigrator.main(new String[]{"IMAP184"});
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/mailbox/tools/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/tools/pom.xml b/mailbox/tools/pom.xml
index 64c3fb7..978e9a3 100644
--- a/mailbox/tools/pom.xml
+++ b/mailbox/tools/pom.xml
@@ -32,6 +32,7 @@
<name>Apache James :: Mailbox :: Tools</name>
<modules>
+ <module>jpa-migrator</module>
<module>maildir-utils</module>
</modules>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/a937a334/server/container/spring/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/pom.xml b/server/container/spring/pom.xml
index a4cf595..cb430c4 100644
--- a/server/container/spring/pom.xml
+++ b/server/container/spring/pom.xml
@@ -35,6 +35,10 @@
<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-backends-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>apache-james-mailbox-api</artifactId>
</dependency>
<dependency>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org