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/26 01:59:06 UTC
svn commit: r598100 - in /struts/sandbox/trunk/jpa-mailreader/src:
main/java/META-INF/ main/java/action/user/
main/java/action/user/subscription/ main/java/entity/
main/java/entity/protocol/ main/java/entity/subscription/
main/java/entity/user/ test/ja...
Author: husted
Date: Sun Nov 25 16:59:04 2007
New Revision: 598100
URL: http://svn.apache.org/viewvc?rev=598100&view=rev
Log:
WW-1399 Refactor EntityManagers to EntityHelpers, and other class naming conventions.
Added:
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityHelper.java
- copied, changed from r598053, struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/UuidEntity.java
- copied, changed from r598053, struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelper.java
- copied, changed from r598053, struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelperImpl.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelper.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelperImpl.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelper.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelperImpl.java
struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntityHelperTest.java
- copied, changed from r598053, struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntitySuperclassTest.java
Removed:
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManager.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManager.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionManagerInterface.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManager.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserManagerInterface.java
struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntitySuperclassTest.java
Modified:
struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml
struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/Index.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/subscription/Index.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/Protocol.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolTypeConverter.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/Subscription.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionTypeConverter.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/User.java
struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserTypeConverter.java
struts/sandbox/trunk/jpa-mailreader/src/test/java/action/user/autenticateTest.java
struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/user/UserManagerTest.java
Modified: struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml?rev=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml Sun Nov 25 16:59:04 2007
@@ -6,7 +6,6 @@
<provider>
oracle.toplink.essentials.PersistenceProvider
</provider>
- <class>entity.EntitySuperclass</class>
<class>entity.protocol.Protocol</class>
<class>entity.subscription.Subscription</class>
<class>entity.user.User</class>
@@ -22,7 +21,6 @@
<persistence-unit name="entity" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>entity.EntitySuperclass</class>
<class>entity.protocol.Protocol</class>
<class>entity.subscription.Subscription</class>
<class>entity.user.User</class>
Modified: struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/Index.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/Index.java?rev=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/Index.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/Index.java Sun Nov 25 16:59:04 2007
@@ -19,8 +19,8 @@
package action.user;
import entity.user.User;
-import entity.user.UserManager;
-import entity.user.UserManagerInterface;
+import entity.user.UserHelperImpl;
+import entity.user.UserHelper;
public class Index extends action.Index {
@@ -42,7 +42,7 @@
// ---- PROPERTIES ----
- UserManagerInterface manager;
+ UserHelper manager;
public String getLocation() {
return "/WEB-INF/results/user/";
@@ -122,7 +122,7 @@
* </p>
*/
public Index() {
- manager = new UserManager();
+ manager = new UserHelperImpl();
}
/**
@@ -133,7 +133,7 @@
* @param manager
* IUserManager instance
*/
- public Index(UserManagerInterface manager) {
+ public Index(UserHelper manager) {
this.manager = manager;
}
Modified: struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/subscription/Index.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/subscription/Index.java?rev=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/subscription/Index.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/action/user/subscription/Index.java Sun Nov 25 16:59:04 2007
@@ -30,11 +30,11 @@
import com.opensymphony.xwork2.validator.annotations.Validation;
import com.opensymphony.xwork2.validator.annotations.Validations;
-import entity.protocol.ProtocolManager;
-import entity.protocol.ProtocolManagerInterface;
+import entity.protocol.ProtocolHelperImpl;
+import entity.protocol.ProtocolHelper;
import entity.subscription.Subscription;
-import entity.subscription.SubscriptionManager;
-import entity.subscription.SubscriptionManagerInterface;
+import entity.subscription.SubscriptionHelperImpl;
+import entity.subscription.SubscriptionHelper;
import entity.user.User;
@Results( {
@@ -54,8 +54,8 @@
static final String ERROR_CREDENTIALS_MISMATCH = "error.password.mismatch";
- protected SubscriptionManagerInterface manager;
- private ProtocolManagerInterface protocolManager;
+ protected SubscriptionHelper manager;
+ private ProtocolHelper protocolManager;
private Map<String, String> protocols;
@@ -82,7 +82,7 @@
Subscription foundValue = manager.findByName(name);
boolean isNameInUse = (foundValue != null);
if (isNameInUse)
- addFieldError(Subscription.HOST, getText(ERROR_HOST_UNIQUE));
+ addFieldError(Subscription.NAME, getText(ERROR_HOST_UNIQUE));
return NotErrors();
}
@@ -91,7 +91,7 @@
if (needUser) {
User defaultUser = getUser();
if (defaultUser == null) {
- addFieldError(Subscription.HOST,
+ addFieldError(Subscription.NAME,
getText(ERROR_CREDENTIALS_MISMATCH));
} else {
value.setUser(getUser());
@@ -159,8 +159,8 @@
* </p>
*/
public Index() {
- manager = new SubscriptionManager();
- protocolManager = new ProtocolManager();
+ manager = new SubscriptionHelperImpl();
+ protocolManager = new ProtocolHelperImpl();
}
/**
@@ -172,8 +172,7 @@
* @param manager
* IUserManager instance
*/
- public Index(SubscriptionManagerInterface manager,
- ProtocolManagerInterface protocolManager) {
+ public Index(SubscriptionHelper manager, ProtocolHelper protocolManager) {
this.manager = manager;
this.protocolManager = protocolManager;
}
Copied: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityHelper.java (from r598053, 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/EntityHelper.java?p2=struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityHelper.java&p1=struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java&r1=598053&r2=598100&rev=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityManagerSuperclass.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntityHelper.java Sun Nov 25 16:59:04 2007
@@ -34,41 +34,39 @@
* </p>
*
*/
-public class EntityManagerSuperclass {
+public class EntityHelper {
- public void createEntity(EntitySuperclass value)
- throws PersistenceException {
+ public void createEntity(Object value) throws PersistenceException {
EntityManager manager = EntityManagerHelper.getEntityManager();
manager.persist(value);
}
- public void deleteEntity(EntitySuperclass value)
- throws PersistenceException {
+ public void deleteEntity(Object value) throws PersistenceException {
EntityManager manager = EntityManagerHelper.getEntityManager();
manager.merge(value);
manager.remove(value);
}
- @SuppressWarnings("unchecked")
- public Object findEntity(Class entity, String id) {
+ public Object findEntity(String namedQuery, String parameterName,
+ String value) {
EntityManager manager = EntityManagerHelper.getEntityManager();
Object result = null;
+ Query query = manager.createNamedQuery(namedQuery);
+ query.setParameter(parameterName, value);
try {
- manager.find(entity, id);
+ result = query.getSingleResult();
} catch (NoResultException e) {
result = null;
}
return result;
}
- public Object findEntityByName(String namedQuery, String parameterName,
- String value) {
+ @SuppressWarnings("unchecked")
+ public Object readEntity(Class entity, String id) {
EntityManager manager = EntityManagerHelper.getEntityManager();
Object result = null;
- Query query = manager.createNamedQuery(namedQuery);
- query.setParameter(parameterName, value);
try {
- result = query.getSingleResult();
+ manager.find(entity, id);
} catch (NoResultException e) {
result = null;
}
Copied: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/UuidEntity.java (from r598053, 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/UuidEntity.java?p2=struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/UuidEntity.java&p1=struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java&r1=598053&r2=598100&rev=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/EntitySuperclass.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/UuidEntity.java Sun Nov 25 16:59:04 2007
@@ -29,7 +29,20 @@
import javax.persistence.Version;
@MappedSuperclass
-public class EntitySuperclass implements Serializable {
+/**
+ * <p>
+ * Define a POJO that utilizes an ID property based on a universally unique
+ * identifier (UUID).
+ * </p>
+ * <p>
+ * UUIDs are particulary useful in RESTful application designs, since an object
+ * instance can assign its own primary key without interacting with a
+ * persistence unit. This base class is intended as a convenience only, and the
+ * class type should not be referred by the API. Instances of this class should
+ * be treated as ordinary POJOs (which they are!).
+ * </p>
+ */
+public class UuidEntity implements Serializable {
@Transient
private UUID uuid;
@@ -58,8 +71,8 @@
}
public boolean equals(Object obj) {
- if ((obj instanceof EntitySuperclass) && (getId() != null)) {
- return getId().equals(((EntitySuperclass) obj).getId());
+ if ((obj instanceof UuidEntity) && (getId() != null)) {
+ return getId().equals(((UuidEntity) obj).getId());
} else {
return false;
}
@@ -76,10 +89,10 @@
}
public String toString() {
- return "entity.EntitySuperclass[id=" + getId() + "]";
+ return "entity.UuidEntity[id=" + getId() + "]";
}
- public EntitySuperclass() {
+ public UuidEntity() {
String id = UUID.randomUUID().toString();
setId(id);
}
Modified: 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=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/Protocol.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/Protocol.java Sun Nov 25 16:59:04 2007
@@ -23,7 +23,7 @@
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
-import entity.EntitySuperclass;
+import entity.UuidEntity;
/**
* <p>
@@ -32,12 +32,12 @@
* <p>
* JPA entity class for the <code>APP_PROTOCOL</code> table. This class
* contains sufficient detail to regenerate the database schema (top-down
- * development).
+ * development). The annotation mode is by field.
* </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 {
+public class Protocol extends UuidEntity implements Serializable {
// ---- STATICS ----
Copied: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelper.java (from r598053, 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/ProtocolHelper.java?p2=struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelper.java&p1=struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java&r1=598053&r2=598100&rev=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolManagerInterface.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelper.java Sun Nov 25 16:59:04 2007
@@ -21,7 +21,7 @@
import java.util.List;
import java.util.Map;
-public interface ProtocolManagerInterface {
+public interface ProtocolHelper {
/**
* <p>
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelperImpl.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelperImpl.java?rev=598100&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelperImpl.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolHelperImpl.java Sun Nov 25 16:59:04 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.EntityHelper;
+
+/**
+ * <p>
+ * Custom persistence operations involving the <code>Protocol</code> object.
+ * <p>
+ */
+public class ProtocolHelperImpl extends EntityHelper implements ProtocolHelper {
+
+ public Protocol find(String value) {
+ Protocol result = (Protocol) readEntity(Protocol.class, value);
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Protocol> findAll() {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ List<Protocol> protocols = manager.createNamedQuery(Protocol.FIND_ALL)
+ .getResultList();
+ if (protocols == null) {
+ protocols = new ArrayList<Protocol>();
+ }
+ return protocols;
+ }
+
+ public Map<String, String> findAllAsMap() {
+ List<Protocol> items = findAll();
+ Map<String, String> map = new LinkedHashMap<String, String>(items
+ .size());
+ for (Protocol item : items) {
+ map.put(String.valueOf(item.getId()), item.getDescription());
+ }
+ return map;
+ }
+
+}
Modified: 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=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolTypeConverter.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/protocol/ProtocolTypeConverter.java Sun Nov 25 16:59:04 2007
@@ -37,7 +37,7 @@
* entity from the persistence database.
*/
public Object convertFromString(Map context, String[] values, Class toClass) {
- ProtocolManagerInterface manager = new ProtocolManager();
+ ProtocolHelper manager = new ProtocolHelperImpl();
String id = values[0];
Protocol target = manager.find(id);
return target;
Modified: 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=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/Subscription.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/Subscription.java Sun Nov 25 16:59:04 2007
@@ -27,7 +27,7 @@
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
-import entity.EntitySuperclass;
+import entity.UuidEntity;
import entity.protocol.Protocol;
import entity.user.User;
@@ -39,14 +39,13 @@
* <p>
* JPA entity class for the <code>APP_SUBSCRIPTION</code> table. TThis class
* contains sufficient detail to regenerate the database schema (top-down
- * development).
+ * development). The annotation mode is by field.
*/
-@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 {
+ @NamedQuery(name = Subscription.FIND_ALL, query = Subscription.FIND_ALL_QUERY),
+ @NamedQuery(name = Subscription.FIND_BY_NAME, query = Subscription.FIND_BY_NAME_QUERY) })
+@Entity(name = "APP_SUBSCRIPTION")
+public class Subscription extends UuidEntity implements Serializable {
// ---- STATICS ----
@@ -55,35 +54,35 @@
* Named query for finding a <code>User</code> by username.
* </p>
*/
- public static final String FIND_ALL = "Subscription.FIND_ALL";
+ static final String FIND_ALL = "Subscription.FIND_ALL";
/**
* <p>
- * Named query for finding a <code>Subscription</code> by host.
+ * Query for finding a <code>User</code> by username.
* </p>
*/
- public static final String FIND_BY_HOST = "Subscription.FIND_BY_HOST";
+ static final String FIND_ALL_QUERY = "SELECT s FROM APP_SUBSCRIPTION s";
/**
* <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";
+ static final String FIND_BY_NAME = "Subscription.FIND_BY_HOST";
/**
* <p>
- * Named query for finding a <code>User</code> by username.
+ * Query for finding a <code>User</code> by username.
* </p>
*/
- public static final String FIND_BY_NAME = "Subscription.FIND_BY_HOST";
+ static final String FIND_BY_NAME_QUERY = "SELECT s FROM APP_SUBSCRIPTION s WHERE s.host = :host";
/**
* <p>
- * Token represnting the "host" attribute.
+ * Token represnting the "host" or "name" attribute.
* </p>
*/
- public static final String HOST = "host";
+ public static final String NAME = "host";
// ---- FIELDS ----
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelper.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelper.java?rev=598100&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelper.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelper.java Sun Nov 25 16:59:04 2007
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+/**
+ * <p>
+ * Custom persistence operations involving the <code>Subscription</code>
+ * object.
+ * <p>
+ */
+public interface SubscriptionHelper {
+
+ /**
+ * <p>
+ * Insert the specified <code>Subscription</code> into the persistent
+ * database.
+ * </p>
+ *
+ * @param value
+ * Subscription to insert
+ */
+ void create(Subscription value);
+
+ /**
+ * <p>
+ * Merge changes to the specified Subscription object into the persistance
+ * database.
+ * </p>
+ *
+ * @param value
+ * Subscription instance to delete
+ */
+ 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
+ */
+ 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
+ */
+ Subscription findByName(String value);
+
+ /**
+ * <p>
+ * Merge changes to the specified Subscription object into the persistance
+ * database.
+ * </p>
+ *
+ * @param user
+ * Copy of Subscription instance to match and update
+ */
+ void update(Subscription value) throws Exception;
+
+}
\ No newline at end of file
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelperImpl.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelperImpl.java?rev=598100&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelperImpl.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionHelperImpl.java Sun Nov 25 16:59:04 2007
@@ -0,0 +1,60 @@
+/*
+ * 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 entity.EntityHelper;
+import entity.EntityManagerHelper;
+
+/**
+ * <p>
+ * Default JPA implementation of <code>UserHelper</code>.
+ * </p>
+ */
+public class SubscriptionHelperImpl extends EntityHelper implements
+ SubscriptionHelper {
+
+ public void create(Subscription value) {
+ createEntity(value);
+ }
+
+ public void delete(Subscription value) throws Exception {
+ EntityManager manager = EntityManagerHelper.getEntityManager();
+ manager.merge(value);
+ value.getUser().removeSubscription(value);
+ manager.remove(value);
+ }
+
+ public Subscription find(String value) {
+ Subscription result = (Subscription) readEntity(Subscription.class,
+ value);
+ return result;
+ }
+
+ public Subscription findByName(String value) {
+ Subscription result = (Subscription) findEntity(
+ Subscription.FIND_BY_NAME, Subscription.NAME, value);
+ return result;
+ }
+
+ public void update(Subscription value) throws Exception {
+ updateEntity(value);
+ }
+}
Modified: 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=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionTypeConverter.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/subscription/SubscriptionTypeConverter.java Sun Nov 25 16:59:04 2007
@@ -36,7 +36,7 @@
* entity from the persistence database.
*/
public Object convertFromString(Map context, String[] values, Class toClass) {
- SubscriptionManagerInterface manager = new SubscriptionManager();
+ SubscriptionHelper manager = new SubscriptionHelperImpl();
String name = String.valueOf(values[0]);
Subscription result = manager.findByName(name);
return result;
Modified: 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=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/User.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/User.java Sun Nov 25 16:59:04 2007
@@ -30,7 +30,7 @@
import javax.persistence.OneToMany;
import javax.persistence.Transient;
-import entity.EntitySuperclass;
+import entity.UuidEntity;
import entity.subscription.Subscription;
/**
@@ -40,13 +40,14 @@
* <p>
* JPA entity class for the <code>APP_USER</code> table. This class contains
* sufficient detail to regenerate the database schema (top-down development).
+ * The annotation mode is by field.
* </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 {
+ @NamedQuery(name = User.FIND_ALL, query = User.FIND_ALL_QUERY),
+ @NamedQuery(name = User.FIND_BY_NAME, query = User.FIND_BY_NAME_QUERY) })
+public class User extends UuidEntity implements Serializable {
// ---- STATICS ----
@@ -55,21 +56,35 @@
* Named query for finding a <code>User</code> by username.
* </p>
*/
- public static final String FIND_ALL = "User.FIND_ALL";
+ static final String FIND_ALL = "User.FIND_ALL";
+
+ /**
+ * <p>
+ * Query for finding a <code>User</code> by username.
+ * </p>
+ */
+ static final String FIND_ALL_QUERY = "SELECT u FROM APP_USER u";
/**
* <p>
* Named query for finding a <code>User</code> by username.
* </p>
*/
- public static final String FIND_BY_NAME = "User.FIND_BY_USERNAME";
+ static final String FIND_BY_NAME = "User.FIND_BY_USERNAME";
+
+ /**
+ * <p>
+ * Query for finding a <code>User</code> by username.
+ * </p>
+ */
+ static final String FIND_BY_NAME_QUERY = "SELECT u FROM APP_USER u WHERE u.username = :username";
/**
* <p>
* Token representation the "username" attribute.
* </p>
*/
- public static final String NAME = "username";
+ static final String NAME = "username";
// --- FIELDS ----
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelper.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelper.java?rev=598100&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelper.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelper.java Sun Nov 25 16:59:04 2007
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+/**
+ * <p>
+ * Custom operations involving the <code>User</code> object.
+ * </p>
+ *
+ */
+public interface UserHelper {
+
+ /**
+ * <p>
+ * Insert the specified <code>User</code> into the persistent database.
+ * </p>
+ *
+ * @param value
+ * User to insert
+ */
+ void create(User value);
+
+ /**
+ * <p>
+ * Merge changes to the specified User object into the persistance database.
+ * </p>
+ *
+ * @param value
+ * User instance to delete
+ */
+ void delete(User value) throws Exception;
+
+ /**
+ * <p>
+ * Retrieve the <code>User</code> matching the specified user ID, if any;
+ * otherwise, return <code>null</code>.
+ * </p>
+ *
+ * @param value
+ * ID to match
+ */
+ 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
+ */
+ User findByName(String value);
+
+ /**
+ * <p>
+ * Merge changes to the specified User object into the persistance database.
+ * </p>
+ *
+ * @param user
+ * Copy of User instance to match and update
+ */
+ void update(User value) throws Exception;
+
+}
\ No newline at end of file
Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelperImpl.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelperImpl.java?rev=598100&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelperImpl.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserHelperImpl.java Sun Nov 25 16:59:04 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.user;
+
+import javax.persistence.PersistenceException;
+import entity.EntityHelper;
+
+/**
+ * <p>
+ * Default JPA implementation of <code>UserHelper</code>.
+ * </p>
+ */
+public class UserHelperImpl extends EntityHelper implements UserHelper {
+
+ public void create(User value) throws PersistenceException {
+ createEntity(value);
+ }
+
+ public void delete(User value) throws PersistenceException {
+ deleteEntity(value);
+ }
+
+ public User find(String value) {
+ User result = (User) readEntity(User.class, value);
+ return result;
+ }
+
+ public User findByName(String value) {
+ User result = (User) findEntity(User.FIND_BY_NAME, User.NAME, value);
+ return result;
+ }
+
+ public void update(User value) throws PersistenceException {
+ updateEntity(value);
+ }
+}
Modified: 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=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserTypeConverter.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/entity/user/UserTypeConverter.java Sun Nov 25 16:59:04 2007
@@ -38,7 +38,7 @@
* </p>
*/
public Object convertFromString(Map context, String[] values, Class toClass) {
- UserManagerInterface manager = new UserManager();
+ UserHelper manager = new UserHelperImpl();
String name = values[0];
User result = manager.findByName(name);
return result;
Modified: struts/sandbox/trunk/jpa-mailreader/src/test/java/action/user/autenticateTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/test/java/action/user/autenticateTest.java?rev=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/test/java/action/user/autenticateTest.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/test/java/action/user/autenticateTest.java Sun Nov 25 16:59:04 2007
@@ -2,20 +2,20 @@
import junit.framework.TestCase;
import entity.user.User;
-import entity.user.UserManager;
-import entity.user.UserManagerInterface;
+import entity.user.UserHelper;
+import entity.user.UserHelperImpl;
public class autenticateTest extends TestCase {
- UserManagerInterface manager;
+ UserHelper helper;
public void setUp() throws Exception {
super.setUp();
- manager = new UserManager();
+ helper = new UserHelperImpl();
}
private boolean authenticate(String username, String password) {
- User foundValue = manager.findByName(username);
+ User foundValue = (User) helper.findByName(username);
if ((foundValue != null) && !foundValue.getPassword().equals(password)) {
foundValue = null;
}
Copied: struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntityHelperTest.java (from r598053, struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntitySuperclassTest.java)
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntityHelperTest.java?p2=struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntityHelperTest.java&p1=struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntitySuperclassTest.java&r1=598053&r2=598100&rev=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntitySuperclassTest.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/EntityHelperTest.java Sun Nov 25 16:59:04 2007
@@ -8,15 +8,15 @@
* </p>
*
*/
-public class EntitySuperclassTest extends TestCase {
+public class EntityHelperTest extends TestCase {
- EntitySuperclass entity;
- EntitySuperclass entity2;
+ UuidEntity entity;
+ UuidEntity entity2;
public void setUp() throws Exception {
super.setUp();
- entity = new EntitySuperclass();
- entity2 = new EntitySuperclass();
+ entity = new UuidEntity();
+ entity2 = new UuidEntity();
}
public void testId() {
@@ -44,10 +44,10 @@
}
public void testToString() {
- EntitySuperclass entity3 = new EntitySuperclass();
+ UuidEntity entity3 = new UuidEntity();
entity3.setId("55ba338a-97fa-44ce-bdad-80236d9404d0");
String value = entity3.toString();
- String TO_STRING = "entity.EntitySuperclass[id=55ba338a-97fa-44ce-bdad-80236d9404d0]";
+ String TO_STRING = "entity.UuidEntity[id=55ba338a-97fa-44ce-bdad-80236d9404d0]";
assertEquals(TO_STRING, value);
}
Modified: struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/user/UserManagerTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/user/UserManagerTest.java?rev=598100&r1=598099&r2=598100&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/user/UserManagerTest.java (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/test/java/entity/user/UserManagerTest.java Sun Nov 25 16:59:04 2007
@@ -6,13 +6,13 @@
import entity.EntityTestCase;
import entity.protocol.Protocol;
-import entity.protocol.ProtocolManager;
-import entity.protocol.ProtocolManagerInterface;
+import entity.protocol.ProtocolHelperImpl;
+import entity.protocol.ProtocolHelper;
import entity.subscription.Subscription;
public class UserManagerTest extends EntityTestCase {
- UserManagerInterface manager;
+ UserHelper helper;
Random generator;
String base;
@@ -23,7 +23,7 @@
public void setUp() throws Exception {
super.setUp();
- manager = new UserManager();
+ helper = new UserHelperImpl();
generator = new Random();
base = nextBase();
}
@@ -40,13 +40,13 @@
User user = newUser();
String before = user.getId();
assertTrue("ID not assigned on New", isNotEmpty(before));
- manager.create(user);
+ helper.create(user);
String after = user.getId();
assertTrue("Initial ID changed on Create", before.equals(after));
}
private List<Subscription> getSubscriptions(User user) {
- ProtocolManagerInterface protocolManager = new ProtocolManager();
+ ProtocolHelper protocolManager = new ProtocolHelperImpl();
boolean autoConnect = false;
List<Protocol> protocols = protocolManager.findAll();
int protocolMax = protocols.size();
@@ -64,12 +64,12 @@
return subscriptions;
}
- public void testCreateWithSubscriptions() {
+ public void testCreateWithSubscriptions() throws Exception {
User user = newUser();
- manager.create(user);
+ helper.create(user);
List<Subscription> subscriptions = getSubscriptions(user);
user.addSubscriptions(subscriptions);
- manager.update(user);
+ helper.update(user);
assertTrue("Expected ID", user.getId() != null);
assertTrue(user.getSubscriptions() != null);
}
@@ -78,8 +78,8 @@
User user = new User();
user.setUsername("user_" + base);
user.setPassword("pass_" + base);
- manager.create(user);
- manager.delete(user);
+ helper.create(user);
+ helper.delete(user);
}
}