You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by hu...@apache.org on 2007/11/20 08:38:01 UTC
svn commit: r596559 [2/2] - in /struts/sandbox/trunk/jpa-mailreader: ./ src/
src/main/ src/main/java/ src/main/java/META-INF/ src/main/java/action/
src/main/java/action/user/ src/main/java/action/user/subscription/
src/main/java/entity/ src/main/java/e...
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,163 @@
+/*
+ * 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 entity;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.NoResultException;
+import javax.persistence.PersistenceException;
+import javax.persistence.Query;
+import java.util.UUID;
+
+/**
+ * <p>
+ * Custom CRUD operations involving the <code>User</code> object.
+ * <p>
+ *
+ */
+public class EntityManagerSuperclass {
+
+ // --- STATICS ----
+
+ /**
+ * <p>
+ * Error message to post when create fails.
+ * </p>
+ */
+ public static final String CREATE_ERROR = "Exception in create()";
+
+ /**
+ * <p>
+ * Error message to post when delete fails.
+ * </p>
+ */
+ public static final String DELETE_ERROR = "Exception in delete()";
+
+ /**
+ * <p>
+ * Error message to post when update fails.
+ * </p>
+ */
+ public static final String UPDATE_ERROR = "Exception in update()";
+
+ // --- METHODS ----
+
+ public Object createEntity(EntitySuperclass value) {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ EntityTransaction transaction = null;
+ try {
+ transaction = manager.getTransaction();
+ transaction.begin();
+ String id = UUID.randomUUID().toString();
+ value.setId(id);
+ manager.persist(value);
+ transaction.commit();
+ } catch (Exception e) {
+ EntityManagerHelper.log(CREATE_ERROR, e);
+ throw new PersistenceException(e);
+ } finally {
+ if ((transaction != null) && transaction.isActive()) {
+ transaction.rollback();
+ }
+ manager.close();
+ }
+ return value;
+ }
+
+ public void delete(Object value) throws Exception {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ EntityTransaction transaction = null;
+ try {
+ transaction = manager.getTransaction();
+ transaction.begin();
+ manager.merge(value);
+ manager.remove(value);
+ transaction.commit();
+ } catch (Exception e) {
+ EntityManagerHelper.log(DELETE_ERROR, e);
+ throw new PersistenceException(e);
+ } finally {
+ if ((transaction != null) && transaction.isActive()) {
+ transaction.rollback();
+ }
+ manager.close();
+ }
+ }
+
+ public Object findEntity(Class entity, String id) {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ Object result = null;
+ try {
+ result = manager.find(entity, id);
+ return result;
+ } catch (NoResultException e) {
+ return null;
+ } finally {
+ manager.close();
+ }
+ }
+
+ public Object findEntityByName(String namedQuery, String parameterName,
+ String value) {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ Object result = null;
+ try {
+ Query query = manager.createNamedQuery(namedQuery);
+ query.setParameter(parameterName, value);
+ result = query.getSingleResult();
+ return result;
+ } catch (NoResultException e) {
+ return null;
+ } finally {
+ manager.close();
+ }
+ }
+
+ public boolean entityHasId(EntitySuperclass value) {
+ if (value == null)
+ return false;
+ String id = value.getId();
+ boolean result = ((id != null) && (id.length() > 0));
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IUserManager#update(entity.User)
+ */
+ public void updateEntity(Object value) throws Exception {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ EntityTransaction transaction = null;
+ try {
+ transaction = manager.getTransaction();
+ transaction.begin();
+ manager.merge(value);
+ transaction.commit();
+ } catch (Exception e) {
+ EntityManagerHelper.log(UPDATE_ERROR, e);
+ throw new PersistenceException(e);
+ } finally {
+ if ((transaction != null) && transaction.isActive()) {
+ transaction.rollback();
+ }
+ manager.close();
+ }
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,83 @@
+/*
+ * 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 entity;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Transient;
+import javax.persistence.Version;
+
+import entity.user.User;
+
+@MappedSuperclass
+public class EntitySuperclass implements Serializable {
+
+ @Transient
+ private UUID uuid;
+
+ @Id
+ @Column(length = 36)
+ private String id;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String value) {
+ id = value;
+ }
+
+ @Version()
+ private Timestamp last_update;
+
+ public Timestamp getLastUpdate() {
+ return last_update;
+ }
+
+ public void setLastUpdate(Timestamp value) {
+ last_update = value;
+ }
+
+ public boolean equals(Object obj) {
+ if ((obj instanceof EntitySuperclass) && (getId() != null)) {
+ return getId().equals(((User) obj).getId());
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ if (getId() != null) {
+ if (uuid == null)
+ uuid = UUID.fromString(id);
+ return uuid.hashCode();
+ } else {
+ return super.hashCode();
+ }
+ }
+
+ public String toString() {
+ return "entity.EntitySuperclass[id=" + getId() + "']";
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/ExpiredPasswordException.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/ExpiredPasswordException.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/ExpiredPasswordException.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/ExpiredPasswordException.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,52 @@
+/*
+ * 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 entity;
+
+/**
+ * <p>
+ * Signal that a password has expired and needs to be changed before principal
+ * can be authorized for any other operation.
+ * </p>
+ */
+public class ExpiredPasswordException extends Exception {
+
+ /**
+ * <p>
+ * Instantiate a new <code>ExpiredPasswordException</code>, utilizing the
+ * specified username.
+ * </p>
+ *
+ * @param username
+ * Username whose password has expired
+ */
+ public ExpiredPasswordException(String username) {
+ super("Password for " + username + " has expired.");
+ }
+
+ /**
+ * <p>
+ * Instantiate a new <code>ExpiredPasswordException</code>.
+ * </p>
+ *
+ */
+ public ExpiredPasswordException() {
+ super("Your password has expired.");
+ }
+
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/Protocol.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/Protocol.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/Protocol.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/Protocol.java Mon Nov 19 23:37:56 2007
@@ -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.
+ */
+// This Java class is based on the "org.apache.mailreaderjpa" class
+// and has been edited to fit this MailReader implementation.
+package entity.protocol;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import entity.EntitySuperclass;
+
+/**
+ * <p>
+ * Describes an email server protocol, such as POP or SMTP.
+ * </p>
+ * <p>
+ * JPA entity class for the <code>APP_PROTOCOL</code> table. This class is
+ * kept simple to allow for easier regeneration.
+ * </p>
+ */
+@Entity(name = "APP_PROTOCOL")
+@NamedQueries( { @NamedQuery(name = Protocol.FIND_ALL, query = "SELECT p FROM APP_PROTOCOL p") })
+public class Protocol extends EntitySuperclass implements Serializable {
+
+ // ---- STATICS ----
+
+ /**
+ * <p>
+ * Named query for selecting all <code>Protocol</code> instances.
+ * </p>
+ */
+ public static final String FIND_ALL = "Protocol.FIND_ALL";
+
+ // ---- FIELDS ----
+
+ @Column(nullable = false)
+ private String description;
+
+ // ---- PROPERTIES ----
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ // ---- METHODS ----
+
+ /**
+ * <p>
+ * Instantiate a default <code>Protocol</code> object.
+ * </p>
+ */
+ public Protocol() {
+ }
+
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManager.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManager.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManager.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManager.java Mon Nov 19 23:37:56 2007
@@ -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 entity.protocol;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import entity.EntityManagerHelper;
+import entity.EntityManagerSuperclass;
+
+/**
+ * <p>
+ * Custom persistence operations involving the <code>Protocol</code> object.
+ * <p>
+ */
+public class ProtocolManager extends EntityManagerSuperclass implements
+ ProtocolManagerInterface {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IProtocolManager#find(java.lang.String)
+ */
+ public Protocol find(String value) {
+ Protocol result = (Protocol) findEntity(Protocol.class, value);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IProtocolManager#findAll()
+ */
+ public List<Protocol> findAll() {
+ EntityManager em = EntityManagerHelper.getEntityManager();
+ try {
+ List<Protocol> protocols = em.createNamedQuery(Protocol.FIND_ALL)
+ .getResultList();
+ if (protocols == null) {
+ protocols = new ArrayList<Protocol>();
+ }
+ return protocols;
+ } finally {
+ em.close();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IProtocolManager#findAllAsMap()
+ */
+ public Map findAllAsMap() {
+ List<Protocol> items = findAll();
+ Map map = new LinkedHashMap(items.size());
+ for (Protocol item : items) {
+ map.put(String.valueOf(item.getId()), item.getDescription());
+ }
+ return map;
+ }
+
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java Mon Nov 19 23:37:56 2007
@@ -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 entity.protocol;
+
+import java.util.List;
+import java.util.Map;
+
+public interface ProtocolManagerInterface {
+
+ /**
+ * <p>
+ * Retrieve the <code>Protocol</code> with the specified id, if any;
+ * otherwise, return <code>null</code>.
+ * </p>
+ *
+ * @param id
+ * Protocol id to look up
+ */
+ public abstract Protocol find(String value);
+
+ /**
+ * <p>
+ * Retrieve a <code>List</code> of the valid <code>Protocol</code>s for
+ * this application. If no valid protocols are defined, a zero length list
+ * will be returned.
+ * </p>
+ */
+ public abstract List<Protocol> findAll();
+
+ /**
+ * <p>
+ * Retrieve a <code>Map</code> of the valid <code>Protocol</code>s for
+ * this application. If no valid protocols are defined, an empty map will be
+ * returned.
+ * </p>
+ */
+ public abstract Map findAllAsMap();
+
+}
\ No newline at end of file
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolTypeConverter.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolTypeConverter.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolTypeConverter.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolTypeConverter.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,53 @@
+/*
+ * 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 entity.protocol;
+
+import java.util.Map;
+
+import org.apache.struts2.util.StrutsTypeConverter;
+
+/**
+ * <p>
+ * Retrieve a <code>Protocol</code> entity from its String ID, or return the
+ * String ID for a <code>Protocol</code> entity.
+ * </p>
+ *
+ */
+public class ProtocolTypeConverter extends StrutsTypeConverter {
+
+ /**
+ * Given a String ID, retrieve the corresponding <code>Protocol</code>
+ * entity from the persistence database.
+ */
+ public Object convertFromString(Map context, String[] values, Class toClass) {
+ ProtocolManagerInterface manager = new ProtocolManager();
+ String id = values[0];
+ Protocol target = manager.find(id);
+ return target;
+ }
+
+ /**
+ * Provide the String ID for a <code>Protocol</code> object.
+ */
+ public String convertToString(Map context, Object o) {
+ Protocol value = (Protocol) o;
+ String id = value.getId();
+ return id;
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/Subscription.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/Subscription.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/Subscription.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/Subscription.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,170 @@
+/*
+ * 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.
+ */
+// This Java class is based on the "org.apache.mailreaderjpa" class
+// and has been edited to fit this MailReader implementation.
+package entity.subscription;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+
+import entity.EntitySuperclass;
+import entity.protocol.Protocol;
+import entity.user.User;
+
+/**
+ * <p>
+ * Describes an email account.
+ * </p>
+ *
+ * <p>
+ * JPA entity class for the <code>APP_SUBSCRIPTION</code> table. This class is
+ * kept simple to allow for easier regeneration.
+ * </p>
+ */
+@Entity(name = "APP_SUBSCRIPTION")
+@NamedQueries( {
+ @NamedQuery(name = Subscription.FIND_ALL, query = "SELECT s FROM APP_SUBSCRIPTION s"),
+ @NamedQuery(name = Subscription.FIND_BY_NAME, query = "SELECT s FROM APP_SUBSCRIPTION s WHERE s.host = :host"),
+ @NamedQuery(name = Subscription.FIND_BY_USER_ID, query = "SELECT s FROM APP_SUBSCRIPTION s WHERE s.user = :id"), })
+public class Subscription extends EntitySuperclass implements Serializable {
+
+ // ---- STATICS ----
+
+ /**
+ * <p>
+ * Named query for finding a <code>User</code> by username.
+ * </p>
+ */
+ public static final String FIND_ALL = "Subscription.FIND_ALL";
+
+ /**
+ * <p>
+ * Named query for finding a <code>Subscription</code> by host.
+ * </p>
+ */
+ public static final String FIND_BY_HOST = "Subscription.FIND_BY_HOST";
+
+ /**
+ * <p>
+ * Named query for finding a <code>User</code> by username.
+ * </p>
+ */
+ public static final String FIND_BY_USER_ID = "Subscription.FIND_BY_USER_ID";
+
+ /**
+ * <p>
+ * Named query for finding a <code>User</code> by username.
+ * </p>
+ */
+ public static final String FIND_BY_NAME = "Subscription.FIND_BY_HOST";
+
+ /**
+ * <p>
+ * Token represnting the "host" attribute.
+ * </p>
+ */
+ public static final String HOST = "host";
+
+ // ---- FIELDS ----
+
+ @Column
+ private boolean auto_connect;
+
+ @Column(nullable = false)
+ private String host;
+
+ @Column(nullable = false)
+ private String password;
+
+ @JoinColumn(name = "protocol_id")
+ @OneToOne
+ private Protocol protocol_id;
+
+ @JoinColumn(name = "user_id", nullable = false)
+ @ManyToOne
+ private User user;
+
+ @Column(nullable = false)
+ private String username;
+
+ // ---- PROPERTIES ----
+
+ public boolean isAutoConnect() {
+ return auto_connect;
+ }
+
+ public void setAutoConnect(boolean value) {
+ auto_connect = value;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String value) {
+ host = value;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String value) {
+ password = value;
+ }
+
+ public Protocol getProtocol() {
+ return protocol_id;
+ }
+
+ public void setProtocol(Protocol value) {
+ protocol_id = value;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User value) {
+ user = value;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String value) {
+ username = value;
+ }
+
+ // ---- METHODS ----
+
+ /**
+ * <p>
+ * Instantiate a default <code>Subscription</code> object.
+ * </p>
+ */
+ public Subscription() {
+ }
+
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManager.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManager.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManager.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManager.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,114 @@
+/*
+ * 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 entity.subscription;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.PersistenceException;
+
+import entity.EntityManagerHelper;
+import entity.EntityManagerSuperclass;
+
+/**
+ * <p>
+ * Custom persistence operations involving the <code>Subscription</code>
+ * object.
+ * <p>
+ */
+public class SubscriptionManager extends EntityManagerSuperclass implements
+ SubscriptionManagerInterface {
+
+ // ---- METHODS ----
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.ISubscriptionManager#create(entity.Subscription)
+ */
+ public Subscription create(Subscription value) {
+ Subscription result = (Subscription) createEntity(value);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.ISubscriptionManager#delete(entity.Subscription)
+ */
+ public void delete(Subscription value) throws Exception {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ EntityTransaction transaction = null;
+ try {
+ transaction = manager.getTransaction();
+ transaction.begin();
+ manager.merge(value);
+ value.getUser().removeSubscription(value);
+ manager.remove(value);
+ transaction.commit();
+ } catch (Exception e) {
+ EntityManagerHelper.log(DELETE_ERROR, e);
+ throw new PersistenceException(e);
+ } finally {
+ if ((transaction != null) && transaction.isActive()) {
+ transaction.rollback();
+ }
+ manager.close();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.ISubscriptionManager#find(java.lang.String)
+ */
+ public Subscription find(String value) {
+ Subscription result = (Subscription) findEntity(Subscription.class,
+ value);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.ISubscriptionManager#findByName(java.lang.String)
+ */
+ public Subscription findByName(String value) {
+ Subscription result = (Subscription) findEntityByName(
+ Subscription.FIND_BY_HOST, Subscription.HOST, value);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.ISubscriptionManager#hasId(entity.Subscription)
+ */
+ public boolean hasId(Subscription value) {
+ return entityHasId(value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.ISubscriptionManager#update(entity.Subscription)
+ */
+ public void update(Subscription value) throws Exception {
+ updateEntity(value);
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManagerInterface.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManagerInterface.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManagerInterface.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManagerInterface.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,90 @@
+/*
+ * 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 entity.subscription;
+
+public interface SubscriptionManagerInterface {
+
+ /**
+ * <p>
+ * Insert the specified <code>Subscription</code> into the persistent
+ * database.
+ * </p>
+ *
+ * @param value
+ * Subscription to insert
+ */
+ public abstract Subscription create(Subscription value);
+
+ /**
+ * <p>
+ * Merge changes to the specified Subscription object into the persistance
+ * database.
+ * </p>
+ *
+ * @param value
+ * Subscription instance to delete
+ */
+ public abstract void delete(Subscription value) throws Exception;
+
+ /**
+ * <p>
+ * Retrieve the <code>Subscription</code> matching the specified host, if
+ * any; otherwise, return <code>null</code>.
+ * </p>
+ *
+ * @param value
+ * Host to match
+ */
+ public abstract Subscription find(String value);
+
+ /**
+ * <p>
+ * Retrieve the <code>Subscription</code> matching the specified host id,
+ * if any; otherwise, return <code>null</code>.
+ * </p>
+ *
+ * @param id
+ * Subscription id to match
+ */
+ public abstract Subscription findByName(String value);
+
+ /**
+ * <p>
+ * Determine if the <code>Subscription</code> object has been assigned an
+ * ID value.
+ * </p>
+ *
+ * @param value
+ * Subscription object to examine
+ * @return True if the Subscription object has an ID value
+ */
+ public abstract boolean hasId(Subscription value);
+
+ /**
+ * <p>
+ * Merge changes to the specified Subscription object into the persistance
+ * database.
+ * </p>
+ *
+ * @param user
+ * Copy of Subscription instance to match and update
+ */
+ public abstract void update(Subscription value) throws Exception;
+
+}
\ No newline at end of file
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionTypeConverter.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionTypeConverter.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionTypeConverter.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionTypeConverter.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,51 @@
+/*
+ * 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 entity.subscription;
+
+import java.util.Map;
+import org.apache.struts2.util.StrutsTypeConverter;
+
+/**
+ * <p>
+ * Retrieve a <code>Subscription</code> entity from by its host name, or
+ * return the host name for a <code>Subscription</code> entity.
+ * </p>
+ *
+ */
+public class SubscriptionTypeConverter extends StrutsTypeConverter {
+
+ /**
+ * Given a host name, retrieve the corresponding <code>Subscription</code>
+ * entity from the persistence database.
+ */
+ public Object convertFromString(Map context, String[] values, Class toClass) {
+ SubscriptionManagerInterface manager = new SubscriptionManager();
+ String name = String.valueOf(values[0]);
+ Subscription result = manager.findByName(name);
+ return result;
+ }
+
+ /**
+ * Provide the host name for a <code>Subscription</code> object.
+ */
+ public String convertToString(Map context, Object o) {
+ Subscription value = (Subscription) o;
+ return value.getHost();
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/User.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/User.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/User.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/User.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,220 @@
+/*
+ * 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.
+ */
+// This Java class is based on the "org.apache.mailreaderjpa" class
+// and has been edited to fit this MailReader implementation.
+package entity.user;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.Transient;
+import javax.persistence.Version;
+
+import entity.EntitySuperclass;
+import entity.subscription.Subscription;
+
+/**
+ * <p>
+ * Describes an account that maintains zero or more <code>Subscription</code>s.
+ * </p>
+ * <p>
+ * JPA entity class for the <code>APP_USER</code> table. This class is kept
+ * simple to allow for easier regeneration.
+ * </p>
+ */
+@Entity(name = "APP_USER")
+@NamedQueries( {
+ @NamedQuery(name = User.FIND_ALL, query = "SELECT u FROM APP_USER u"),
+ @NamedQuery(name = User.FIND_BY_NAME, query = "SELECT u FROM APP_USER u WHERE u.username = :username"), })
+public class User extends EntitySuperclass implements Serializable {
+
+ // ---- STATICS ----
+
+ /**
+ * <p>
+ * Named query for finding a <code>User</code> by username.
+ * </p>
+ */
+ public static final String FIND_ALL = "User.FIND_ALL";
+
+ /**
+ * <p>
+ * Named query for finding a <code>User</code> by username.
+ * </p>
+ */
+ public static final String FIND_BY_NAME = "User.FIND_BY_USERNAME";
+
+ /**
+ * <p>
+ * Token representation the "username" attribute.
+ * </p>
+ */
+ public static final String NAME = "username";
+
+ // --- FIELDS ----
+
+ @Column(length = 64)
+ private String from_address;
+
+ @Column(length = 64)
+ private String full_name;
+
+ @Column(length = 16, nullable = false)
+ private String password;
+
+ @Column(length = 64)
+ private String reply_to_address;
+
+ @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
+ private List<Subscription> subscriptions;
+
+ @Column(length = 16, nullable = false, unique = true)
+ private String username;
+
+ @Version()
+ private Timestamp last_update;
+
+ // ---- PROPERTIES ----
+
+ public String getFromAddress() {
+ return from_address;
+ }
+
+ public void setFromAddress(String value) {
+ from_address = value;
+ }
+
+ public String getFullName() {
+ return full_name;
+ }
+
+ public void setFullName(String value) {
+ full_name = value;
+ }
+
+ public Timestamp getLastUpdate() {
+ return last_update;
+ }
+
+ public void setLastUpdate(Timestamp value) {
+ last_update = value;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String value) {
+ password = value;
+ }
+
+ public String getReplyToAddress() {
+ return reply_to_address;
+ }
+
+ public void setReplyToAddress(String value) {
+ reply_to_address = value;
+ }
+
+ public List<Subscription> getSubscriptions() {
+ return subscriptions;
+ }
+
+ public void setSubscriptions(List<Subscription> value) {
+ subscriptions = value;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String value) {
+ username = value;
+ }
+
+ @Transient
+ private String password1 = null;
+
+ public String getPassword1() {
+ return password1;
+ }
+
+ public void setPassword1(String value) {
+ password1 = value;
+ }
+
+ @Transient
+ private String password2 = null;
+
+ public String getPassword2() {
+ return password2;
+ }
+
+ public void setPassword2(String value) {
+ password2 = value;
+ }
+
+ // ---- METHODS ----
+
+ /**
+ * <p>
+ * Add the specified <code>Subscription</code> to the set of subscriptions
+ * associated with this <code>User</code>.
+ * </p>
+ * <p>
+ * A duplicate <code>Subscription</code> is not added but quietly ignored.
+ * </p>
+ */
+ public void addSubscription(Subscription subscription) {
+ List<Subscription> subscriptions = getSubscriptions();
+ if (!subscriptions.contains(subscription)) {
+ subscription.setUser(this);
+ subscriptions.add(subscription);
+ }
+ }
+
+ /**
+ * <p>
+ * Remove the specified <code>Subscription</code> from the set of
+ * subscriptions associated with this <code>User</code>.
+ * </p>
+ * <p>
+ * A duplicate <code>Subscription</code> is not added but quietly ignored.
+ * </p>
+ */
+ public void removeSubscription(Subscription subscription) {
+ List<Subscription> subscriptions = getSubscriptions();
+ if (subscriptions.contains(subscription)) {
+ subscriptions.remove(subscription);
+ }
+ }
+
+ /**
+ * <p>
+ * Instantiate a default <code>User</code> object.
+ * </p>
+ */
+ public User() {
+ }
+
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManager.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManager.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManager.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManager.java Mon Nov 19 23:37:56 2007
@@ -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 entity.user;
+
+import entity.EntityManagerSuperclass;
+
+/**
+ * <p>
+ * Custom CRUD operations involving the <code>User</code> object.
+ * <p>
+ *
+ */
+public class UserManager extends EntityManagerSuperclass implements
+ UserManagerInterface {
+
+ // --- METHODS ----
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IUserManager#create(entity.User)
+ */
+ public User create(User value) {
+ User result = (User) createEntity(value);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IUserManager#find(java.lang.String)
+ */
+ public User find(String value) {
+ User result = (User) findEntity(User.class, value);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IUserManager#findByName(java.lang.String)
+ */
+ public User findByName(String value) {
+ User result = (User) findEntityByName(User.FIND_BY_NAME, User.NAME,
+ value);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IUserManager#hasId(entity.User)
+ */
+ public boolean hasId(User value) {
+ return entityHasId(value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see entity.IUserManager#update(entity.User)
+ */
+ public void update(User value) throws Exception {
+ updateEntity(value);
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManagerInterface.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManagerInterface.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManagerInterface.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManagerInterface.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,78 @@
+/*
+ * 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 entity.user;
+
+public interface UserManagerInterface {
+
+ /**
+ * <p>
+ * Insert the specified <code>User</code> (and any associated child
+ * <code>Subscription</code>s) into the persistent database.
+ * </p>
+ *
+ * @param value
+ * User instance to be added
+ */
+ public abstract User create(User value);
+
+ /**
+ * <p>
+ * Retrieve the <code>User</code> matching the specified username, if any;
+ * otherwise, return <code>null</code>.
+ * </p>
+ *
+ * @param value
+ * Username to match
+ */
+ public abstract User find(String value);
+
+ /**
+ * <p>
+ * Retrieve the <code>User</code> matching the specified username, if any;
+ * otherwise, return <code>null</code>.
+ * </p>
+ *
+ * @param value
+ * Username to match
+ */
+ public abstract User findByName(String value);
+
+ /**
+ * <p>
+ * Determine if the <code>User</code> object has been assigned an ID
+ * value.
+ *
+ * @param value
+ * User object to examine
+ * @return True if the User object has an ID value
+ */
+ public abstract boolean hasId(User value);
+
+ /**
+ * <p>
+ * Persist changes to the specified User object into the persistance
+ * database.
+ * </p>
+ *
+ * @param value
+ * Copy of User instance to match and update
+ */
+ public abstract void update(User value) throws Exception;
+
+}
\ No newline at end of file
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserTypeConverter.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserTypeConverter.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserTypeConverter.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserTypeConverter.java Mon Nov 19 23:37:56 2007
@@ -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 entity.user;
+
+import java.util.Map;
+import org.apache.struts2.util.StrutsTypeConverter;
+
+/**
+ * <p>
+ * Retrieve a <code>User</code> entity from its username, or return the
+ * username for a <code>User</code> entity.
+ * </p>
+ *
+ */
+public class UserTypeConverter extends StrutsTypeConverter {
+
+ /**
+ * <p>
+ * Given a <code>username</code>, retrieve the corresponding
+ * <code>User</code> entity from the persistence database.
+ * </p>
+ */
+ public Object convertFromString(Map context, String[] values, Class toClass) {
+ UserManagerInterface manager = new UserManager();
+ String name = values[0];
+ User result = manager.findByName(name);
+ return result;
+ }
+
+ /**
+ * <p>
+ * Provide the <code>username</code> for a <code>User</code> object.
+ * </p>
+ */
+ public String convertToString(Map context, Object o) {
+ User value = (User) o;
+ return value.getUsername();
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml Mon Nov 19 23:37:56 2007
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
+
+<struts>
+
+ <constant name="struts.devMode" value="false" />
+ <constant name="struts.action.extension" value="" />
+
+ <!-- Alternative way to support message resources without wrapper classes or annotations.
+ <constant name="struts.custom.i18n.resources" value="action.package" />
+ -->
+ <!-- include file="" / -->
+ <!-- Add packages here -->
+
+</struts>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/xwork-conversion.properties
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/xwork-conversion.properties?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/xwork-conversion.properties (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/xwork-conversion.properties Mon Nov 19 23:37:56 2007
@@ -0,0 +1,3 @@
+entity.protocol.Protocol = entity.protocol.ProtocolTypeConverter
+entity.subscription.Subscription = entity.subscription.SubscriptionTypeConverter
+entity.user.User = entity.user.UserTypeConverter
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/META-INF/MANIFEST.MF?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/META-INF/MANIFEST.MF (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/META-INF/MANIFEST.MF Mon Nov 19 23:37:56 2007
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/WEB-INF/web.xml?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/WEB-INF/web.xml (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/WEB-INF/web.xml Mon Nov 19 23:37:56 2007
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <filter>
+ <filter-name>
+ struts2
+ </filter-name>
+ <filter-class>
+ org.apache.struts2.dispatcher.FilterDispatcher
+ </filter-class>
+ <init-param>
+ <param-name>actionPackages</param-name>
+ <param-value>action</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>
+ struts2
+ </filter-name>
+ <url-pattern>
+ /*
+ </url-pattern>
+ </filter-mapping>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+</web-app>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/assets/focus-first-input.js
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/assets/focus-first-input.js?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/assets/focus-first-input.js (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/assets/focus-first-input.js Mon Nov 19 23:37:56 2007
@@ -0,0 +1,24 @@
+ // http://www.codeproject.com/jscript/FocusFirstInput.asp
+ var bFound = false;
+ for (f=0; f < document.forms.length; f++)
+ {
+ for(i=0; i < document.forms[f].length; i++)
+ {
+ if (document.forms[f][i].type != "hidden")
+ {
+ if (document.forms[f][i].disabled !== true)
+ {
+ document.forms[f][i].focus();
+ bFound = true;
+ }
+ }
+ if (bFound === true)
+ {
+ break;
+ }
+ }
+ if (bFound === true)
+ {
+ break;
+ }
+ }
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.html?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.html (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.html Mon Nov 19 23:37:56 2007
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <META HTTP-EQUIV="Refresh" CONTENT="0;URL=/index">
+</head>
+
+<body>
+<p>Loading ...</p>
+</body>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/index.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,39 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+ <head>
+ <title><s:text name="index.title"/></title>
+ </head>
+
+ <body>
+ <h3><s:text name="index.heading"/></h3>
+
+ <ul>
+ <li><a href="<s:url namespace="/user" action="create" method="input" />"><s:text name="index.register"/></a></li>
+ <li><a href="<s:url namespace="/user" action="login" method="input"/>"><s:text name="index.login"/></a></li>
+ </ul>
+
+ <h3>Language Options</h3>
+ <ul>
+ <li>
+ <s:url id="en" action="index">
+ <s:param name="request_locale">en</s:param>
+ </s:url>
+ <s:a href="%{en}">English</s:a>
+ </li>
+ <li>
+ <s:url id="ja" action="index">
+ <s:param name="request_locale">ja</s:param>
+ </s:url>
+ <s:a href="%{ja}">Japanese</s:a>
+ </li>
+ <li>
+ <s:url id="ru" action="index">
+ <s:param name="request_locale">ru</s:param>
+ </s:url>
+ <s:a href="%{ru}">Russian</s:a>
+ </li>
+ </ul>
+
+ </body>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/@form.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/%40form.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/@form.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/@form.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,33 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<s:actionerror/>
+<s:form action="index" validate="true">
+ <s:hidden name="input"/>
+ <s:if test="input == 'create'">
+ <s:textfield key="user.username"/>
+ </s:if>
+ <s:else>
+ <s:label key="user.username"/>
+ <s:hidden name="user"/>
+ </s:else>
+
+ <s:password key="user.password1"/>
+
+ <s:password key="user.password2"/>
+
+ <s:textfield key="user.fullName"/>
+
+ <s:textfield key="user.fromAddress"/>
+
+ <s:textfield key="user.replyToAddress"/>
+
+ <s:if test="input == 'create'">
+ <s:submit key="button.update" action="create" />
+ <s:submit key="button.cancel" action="create" method="cancel" onclick="form.onsubmit=null"/>
+ </s:if>
+ <s:else>
+ <s:submit key="button.update" action="update"/>
+ <s:submit key="button.cancel" action="update" method="cancel" onclick="form.onsubmit=null"/>
+ </s:else>
+ <s:reset key="button.reset"/>
+ <script src="/assets/focus-first-input.js" type="text/javascript"></script>
+</s:form>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/create-input.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/create-input.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/create-input.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/create-input.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,13 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title>
+ <s:text name="user.title.create"/>
+ </title>
+</head>
+<body>
+ <s:include value="@form.jsp" />
+</body>
+ <script src="<s:url value="/assets/focus-first-input.js"/>" type="text/javascript"></script>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/index.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/index.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/index.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/index.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,22 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title><s:text name="user.index.title"/></title>
+</head>
+
+<body>
+<h3><s:text name="user.index.heading"/>
+ <s:property value="user.fullName"/>
+</h3>
+<ul>
+ <li><a href="<s:url action="update" method="input"/>">
+ <s:text name="user.index.register"/>
+ </a>
+ </li>
+ <li><a href="<s:url action="logout"/>">
+ <s:text name="user.index.logout"/>
+ </a>
+</ul>
+</body>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/login-input.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/login-input.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/login-input.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/login-input.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,23 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title><s:text name="index.login.title"/></title>
+</head>
+
+<body>
+
+<s:actionerror/>
+<s:form action="login">
+ <s:textfield key="user.username"/>
+
+ <s:password key="user.password1" showPassword="true"/>
+
+ <s:submit key="button.update"/>
+
+ <s:submit key="button.cancel" method="cancel" onclick="form.onsubmit=null"/>
+</s:form>
+
+</body>
+<script src="assets/focus-first-input.js" type="text/javascript"></script>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/@form.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/%40form.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/@form.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/@form.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,38 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<s:actionerror/>
+
+<s:form validate="true">
+ <s:hidden name="input"/>
+ <s:hidden name="user"/>
+ <s:label key="user.username"/>
+ <s:if test="input == 'create'">
+ <s:textfield key="subscription.host"/>
+ </s:if>
+ <s:else>
+ <s:label key="subscription.host"/>
+ <s:hidden name="subscription"/>
+ </s:else>
+
+ <s:textfield key="subscription.username"/>
+
+ <s:textfield key="subscription.password"/>
+
+ <s:select key="subscription.protocol" list="protocols"/>
+
+ <s:checkbox key="subscription.autoConnect"/>
+
+ <!-- Struts tags disallow expressions as values, so we restort to JSTL for a hidden tag -->
+ <s:if test="input == 'create'">
+ <input type="hidden" name="subscription.user" value="${user.username}" id="create_subscription_user"/>
+ <s:submit key="button.update" action="create" />
+ <s:submit key="button.cancel" action="create" method="cancel" onclick="form.onsubmit=null"/>
+ </s:if>
+ <s:else>
+ <s:hidden name="subscription.user"/>
+ <s:submit key="button.update" action="update" />
+ <s:submit key="button.cancel" action="update" method="cancel" onclick="form.onsubmit=null"/>
+ </s:else>
+
+ <s:reset key="button.reset"/>
+
+</s:form>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/create-input.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/create-input.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/create-input.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/create-input.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,16 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title>
+ <s:text name="subscription.title.create"/>
+ </title>
+</head>
+
+<body>
+
+ <s:include value="@form.jsp" />
+
+</body>
+ <script src="<s:url value="/assets/focus-first-input.js"/>" type="text/javascript"></script>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/delete-input.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/delete-input.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/delete-input.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/delete-input.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,26 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title>
+ <s:text name="subscription.title.delete"/>
+ </title>
+</head>
+
+<body>
+
+<s:actionerror/>
+<s:form validate="true">
+ <s:hidden name="input"/>
+ <s:hidden name="subscription"/>
+ <s:label key="user.username" name="subscription.user.username"/>
+ <s:label key="subscription.username"/>
+ <s:label key="subscription.password"/>
+ <s:label key="subscription.protocol" name="subscription.protocol.description"/>
+ <s:label key="subscription.autoConnect"/>
+ <s:submit key="button.confirm" action="delete" />
+ <s:submit key="button.cancel" action="delete" method="cancel" onclick="form.onsubmit=null"/>
+</s:form>
+ <script src="<s:url value="/assets/focus-first-input.js"/>" type="text/javascript"></script>
+</body>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/update-input.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/update-input.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/update-input.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/subscription/update-input.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,16 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title>
+ <s:text name="subscription.title.update"/>
+ </title>
+</head>
+
+<body>
+
+ <s:include value="@form.jsp" />
+
+</body>
+ <script src="<s:url value="/assets/focus-first-input.js"/>" type="text/javascript"></script>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/update-input.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/update-input.jsp?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/update-input.jsp (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/update-input.jsp Mon Nov 19 23:37:56 2007
@@ -0,0 +1,83 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+ <head>
+ <title>
+ <s:text name="user.title.update"/>
+ </title>
+ </head>
+ <body>
+
+ <s:include value="@form.jsp" />
+
+ <div align="center">
+ <h3>
+ <s:text name="heading.subscriptions"/>
+ </h3>
+ </div>
+
+ <table border="1" width="100%">
+
+ <tr>
+ <th align="center">
+ <s:text name="subscription.host"/>
+ </th>
+ <th align="center">
+ <s:text name="subscription.username"/>
+ </th>
+ <th align="center">
+ <s:text name="subscription.password"/>
+ </th>
+ <th align="center">
+ <s:text name="subscription.protocol"/>
+ </th>
+ <th align="center">
+ <s:text name="subscription.autoConnect"/>
+ </th>
+ <th align="center">
+ <s:text name="heading.action"/>
+ </th>
+ </tr>
+
+ <s:iterator value="user.subscriptions">
+ <tr>
+ <td align="left">
+ <s:property value="host"/>
+ </td>
+ <td align="left">
+ <s:property value="username"/>
+ </td>
+ <td align="left">
+ <s:property value="password"/>
+ </td>
+ <td align="center">
+ <s:property value="protocol.description"/>
+ </td>
+ <td align="center">
+ <s:property value="autoConnect"/>
+ </td>
+ <td align="center">
+
+ <a href="<s:url namespace="subscription" action="delete" method="input">
+ <s:param name="subscription" value="host"/></s:url>">
+ <s:text name="heading.delete"/>
+ </a>
+
+ <a href="<s:url namespace="subscription" action="update" method="input">
+ <s:param name="subscription" value="host"/></s:url>">
+ <s:text name="heading.update"/>
+ </a>
+
+ </td>
+ </tr>
+ </s:iterator>
+
+ </table>
+
+ <a href="<s:url namespace="subscription" action="create" method="input"/>">
+ <s:text name="heading.create"/>
+ </a>
+
+ </body>
+ <script src="<s:url value="/assets/focus-first-input.js"/>" type="text/javascript"></script>
+</html>
Added: struts/sandbox/trunk/jpa-mailreader/src/test/java/action/HelloTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/test/java/action/HelloTest.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/test/java/action/HelloTest.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/test/java/action/HelloTest.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,36 @@
+/*
+ * 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 action;
+
+import junit.framework.TestCase;
+
+/**
+ * An example text class to verify the configuration.
+ */
+public class HelloTest extends TestCase {
+
+ /**
+ * An example test that asserts true.
+ *
+ * @throws Exception On invalid assertions
+ */
+ public void testTestCase() throws Exception {
+ assertTrue(true);
+ }
+}
Added: struts/sandbox/trunk/jpa-mailreader/src/test/java/action/RetainTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/test/java/action/RetainTest.java?rev=596559&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/test/java/action/RetainTest.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/test/java/action/RetainTest.java Mon Nov 19 23:37:56 2007
@@ -0,0 +1,111 @@
+/*
+ * 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 action;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import entity.EntityManagerHelper;
+import entity.protocol.Protocol;
+import entity.subscription.Subscription;
+import entity.user.User;
+
+import junit.framework.TestCase;
+
+public class RetainTest extends TestCase {
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private String getUUID() {
+ return UUID.randomUUID().toString();
+ }
+
+ public void testBootstrap() throws Exception {
+
+ EntityManager em = EntityManagerHelper.getEntityManager();
+ EntityTransaction et = null;
+
+ // Test empty (FIXME: Throws exception when actually empty!)
+ // List<Protocol> protocols =
+ // em.createNamedQuery("Protocol.findAll").getResultList();
+ // boolean not_empty = ((protocols != null) && (protocols.size() > 0));
+ // assertFalse("Data exists!",not_empty);
+
+ // Start a transaction since we will be updating the database
+ et = em.getTransaction();
+ et.begin();
+
+ // Create the basic protocol data
+ Protocol protocol1 = null;
+ protocol1 = new Protocol();
+ protocol1.setId(getUUID());
+ protocol1.setDescription("IMAP Protocol");
+ em.persist(protocol1);
+ Protocol protocol2 = new Protocol();
+ protocol2.setId(getUUID());
+ protocol2.setDescription("POP3 Protocol");
+ em.persist(protocol2);
+
+ // Set up the initial user and subscriptions
+ User user = new User();
+ user.setId(getUUID());
+ user.setUsername("user");
+ user.setPassword("pass");
+ user.setFullName("John Q. User");
+ user.setFromAddress("John.User@somewhere.com");
+ List<Subscription> list = new ArrayList<Subscription>();
+ user.setSubscriptions(list);
+ Subscription sub = null;
+ sub = new Subscription();
+ sub.setId(getUUID());
+ sub.setUser(user);
+ sub.setHost("mail.yahoo.com");
+ sub.setProtocol(protocol1);
+ sub.setUsername("jquser");
+ sub.setPassword("foo");
+ list.add(sub);
+ sub = new Subscription();
+ sub.setId(getUUID());
+ sub.setUser(user);
+ sub.setHost("mail.hotmail.com");
+ sub.setProtocol(protocol2);
+ sub.setUsername("user1234");
+ sub.setPassword("bar");
+ list.add(sub);
+ em.persist(user);
+
+ // Commit the database updates
+ et.commit();
+
+ // Test commit
+ List<Protocol> protocols2 = em.createNamedQuery(Protocol.FIND_ALL)
+ .getResultList();
+ boolean updated = ((protocols2 != null) && (protocols2.size() > 0));
+ assertTrue("Commit not successful!", updated);
+
+ em.close();
+
+ }
+}
\ No newline at end of file