[Amavisadmin-svn] SF.net SVN: amavisadmin: [22] amavisadmin/branches/UNI/src/java/de/sreindl/ amavi
Status: Beta
Brought to you by:
streindl
From: <str...@us...> - 2007-01-17 18:37:42
|
Revision: 22 http://amavisadmin.svn.sourceforge.net/amavisadmin/?rev=22&view=rev Author: streindl Date: 2007-01-17 10:37:34 -0800 (Wed, 17 Jan 2007) Log Message: ----------- Merged from trunk Added Paths: ----------- amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/ amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java Removed Paths: ------------- amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java Copied: amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration (from rev 21, amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration) Deleted: amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java =================================================================== --- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java 2007-01-17 18:27:34 UTC (rev 21) +++ amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java 2007-01-17 18:37:34 UTC (rev 22) @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2007 Stephen Reindl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/* - * MigrateV0toV1.java - * - * Created on 16. Januar 2007, 19:24 - * - */ - -package de.sreindl.amavisadmin.migration; - -import de.sreindl.amavisadmin.db.MailAddress; -import de.sreindl.amavisadmin.db.MailAddressDAO; -import de.sreindl.amavisadmin.db.User; -import de.sreindl.amavisadmin.db.UserDAO; -import de.sreindl.amavisadmin.db.util.HibernateSessionFactory; -import java.util.Iterator; -import java.util.List; -import javax.swing.text.rtf.RTFEditorKit; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.Transaction; - -/** - * The following activities are performed here: - *<ul> - *<li> Create default user if not already there </li> - *<li> Update table maddr table to include the user email addresses of - * the already registered users (if any).</li> - *</ul> - * @author sreindl - */ -public class MigrateV0toV1 implements MigrationJob { - - private static Log log = LogFactory.getLog(MigrateV0toV1.class); - - /** Creates a new instance of MigrateV0toV1 */ - public MigrateV0toV1() { - } - - /** - * Perform Migration - */ - public void migrate() throws Exception { - log.info("Migrate from DB Version 0 to DB Version 1"); - migrateUsers(); - addDefaultUser(); - log.info("Job migration successfully performed"); - } - - private void migrateUsers() { - MailAddressDAO dao = new MailAddressDAO(); - MailAddress entry = null; - Session session = HibernateSessionFactory.getSession(); - Query qry = session.createQuery("from User"); - Iterator i = qry.iterate(); - while (i.hasNext()) { - User user = (User)i.next(); - if (user.getEmail() == null || user.getEmail().equals(defaultUserEmail)) { - continue; // skip - } - entry = dao.findByEmail(user.getEmail()); - if (entry == null) { - log.info("New entry for user " + user.getUsername()); - // add new entry - entry = new MailAddress(user.getEmail(), - MailAddressDAO.generateDomain(user.getEmail())); - entry.setUser(user); - session.save(entry); - } else if (entry.getUser() != null && entry.getUser().equals(user)) { - log.info("Mail Entry for user " + user.getUsername() + " already exists"); - } else { - log.info("Mail Entry for user " + user.getUsername() + " updated."); - // update existing - entry.setUser(user); - session.update(entry); - } - } - } - - private void addDefaultUser() { - UserDAO dao = new UserDAO(); - MailAddress entry = null; - List ent = dao.findByEmail(defaultUserEmail); - if (ent.size() > 0) { - // already there -> ok - return; - } - log.info ("Adding default user"); - // add new default entry - Session session = HibernateSessionFactory.getSession(); - User user = new User(1, 1, defaultUserEmail, "Global Match", null, "", 0, "", false); - session.save(user); - } - - /** - * Default match - */ - private static final String defaultUserEmail = "@."; -} Copied: amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java (from rev 21, amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java) =================================================================== --- amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java (rev 0) +++ amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java 2007-01-17 18:37:34 UTC (rev 22) @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2007 Stephen Reindl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * MigrateV0toV1.java + * + * Created on 16. Januar 2007, 19:24 + * + */ + +package de.sreindl.amavisadmin.migration; + +import de.sreindl.amavisadmin.db.MailAddress; +import de.sreindl.amavisadmin.db.MailAddressDAO; +import de.sreindl.amavisadmin.db.User; +import de.sreindl.amavisadmin.db.UserDAO; +import de.sreindl.amavisadmin.db.util.HibernateSessionFactory; +import java.util.Iterator; +import java.util.List; +import javax.swing.text.rtf.RTFEditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * The following activities are performed here: + *<ul> + *<li> Create default user if not already there </li> + *<li> Update table maddr table to include the user email addresses of + * the already registered users (if any).</li> + *</ul> + * @author sreindl + */ +public class MigrateV0toV1 implements MigrationJob { + + private static Log log = LogFactory.getLog(MigrateV0toV1.class); + + /** Creates a new instance of MigrateV0toV1 */ + public MigrateV0toV1() { + } + + /** + * Perform Migration + */ + public void migrate() throws Exception { + log.info("Migrate from DB Version 0 to DB Version 1"); + migrateUsers(); + addDefaultUser(); + log.info("Job migration successfully performed"); + } + + private void migrateUsers() { + MailAddressDAO dao = new MailAddressDAO(); + MailAddress entry = null; + Session session = HibernateSessionFactory.getSession(); + Query qry = session.createQuery("from User"); + Iterator i = qry.iterate(); + while (i.hasNext()) { + User user = (User)i.next(); + if (user.getEmail() == null || user.getEmail().equals(defaultUserEmail)) { + continue; // skip + } + entry = dao.findByEmail(user.getEmail()); + if (entry == null) { + log.info("New entry for user " + user.getUsername()); + // add new entry + entry = new MailAddress(user.getEmail(), + MailAddressDAO.generateDomain(user.getEmail())); + entry.setUser(user); + session.save(entry); + } else if (entry.getUser() != null && entry.getUser().equals(user)) { + log.info("Mail Entry for user " + user.getUsername() + " already exists"); + } else { + log.info("Mail Entry for user " + user.getUsername() + " updated."); + // update existing + entry.setUser(user); + session.update(entry); + } + } + } + + private void addDefaultUser() { + UserDAO dao = new UserDAO(); + MailAddress entry = null; + List ent = dao.findByEmail(defaultUserEmail); + if (ent.size() > 0) { + // already there -> ok + return; + } + log.info ("Adding default user"); + // add new default entry + Session session = HibernateSessionFactory.getSession(); + User user = new User(1, 1, defaultUserEmail, "Global Match", null, "", 0, "", false); + session.save(user); + } + + /** + * Default match + */ + private static final String defaultUserEmail = "@."; +} Deleted: amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java =================================================================== --- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java 2007-01-17 18:27:34 UTC (rev 21) +++ amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java 2007-01-17 18:37:34 UTC (rev 22) @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007 Stephen Reindl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/* - * MigrationJob.java - * - * Created on 16. Januar 2007, 19:29 - */ - -package de.sreindl.amavisadmin.migration; - -/** - * Interface that is used to describe jobs that need to be started during - * database migration. - * - * @author sreindl - */ -public interface MigrationJob { - /** - * Migration job. - */ - public void migrate() throws Exception; -} Copied: amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java (from rev 21, amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java) =================================================================== --- amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java (rev 0) +++ amavisadmin/branches/UNI/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java 2007-01-17 18:37:34 UTC (rev 22) @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2007 Stephen Reindl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * MigrationJob.java + * + * Created on 16. Januar 2007, 19:29 + */ + +package de.sreindl.amavisadmin.migration; + +/** + * Interface that is used to describe jobs that need to be started during + * database migration. + * + * @author sreindl + */ +public interface MigrationJob { + /** + * Migration job. + */ + public void migrate() throws Exception; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |