You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by gm...@apache.org on 2014/06/29 21:09:13 UTC
svn commit: r1606568 [1/2] - in
/roller/trunk/app/src/main/java/org/apache/roller: planet/business/jpa/
weblogger/business/ weblogger/business/jpa/ weblogger/business/pings/
weblogger/pojos/ weblogger/ui/rendering/model/
Author: gmazza
Date: Sun Jun 29 19:09:13 2014
New Revision: 1606568
URL: http://svn.apache.org/r1606568
Log:
ROL-1995 Switch from Query to typesafe TypedQuery in our JPA* classes.
Modified:
roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java
roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/UserManager.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAAutoPingManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAOAuthManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingQueueManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingTargetManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPropertiesManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAThreadManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/pings/AutoPingManager.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/StatCountCountComparator.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/TagStatComparator.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/TagStatCountComparator.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/PlanetModel.java
Modified: roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java Sun Jun 29 19:09:13 2014
@@ -107,7 +107,7 @@ public class JPAPlanetImpl extends Abstr
/**
- * @see org.apache.roller.business.Roller#getBookmarkManager()
+ * @see org.apache.roller.weblogger.business.Weblogger#getBookmarkManager()
*/
public PlanetManager getWebloggerManager() {
return planetManager;
@@ -115,7 +115,7 @@ public class JPAPlanetImpl extends Abstr
/**
- * @see org.apache.roller.business.Roller#getBookmarkManager()
+ * @see org.apache.roller.weblogger.business.Weblogger#getBookmarkManager()
*/
public PropertiesManager getPropertiesManager() {
return propertiesManager;
Modified: roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.List;
import javax.persistence.NoResultException;
import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -94,10 +95,10 @@ public class JPAPlanetManagerImpl extend
public Subscription getSubscription(String feedUrl)
throws RollerException {
- Query q = strategy.getNamedQuery("Subscription.getByFeedURL");
+ TypedQuery<Subscription> q = strategy.getNamedQuery("Subscription.getByFeedURL", Subscription.class);
q.setParameter(1, feedUrl);
try {
- return (Subscription)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -112,7 +113,7 @@ public class JPAPlanetManagerImpl extend
public Iterator getAllSubscriptions() {
try {
return (strategy.getNamedQuery(
- "Subscription.getAll").getResultList()).iterator();
+ "Subscription.getAll", Subscription.class).getResultList()).iterator();
} catch (Exception e) {
throw new RuntimeException(
"ERROR fetching subscription collection", e);
@@ -120,7 +121,7 @@ public class JPAPlanetManagerImpl extend
}
public int getSubscriptionCount() throws RollerException {
- Query q = strategy.getNamedQuery("Subscription.getAll");
+ Query q = strategy.getNamedQuery("Subscription.getAll", Subscription.class);
return q.getResultList().size();
}
@@ -136,8 +137,8 @@ public class JPAPlanetManagerImpl extend
PlanetGroup group, int offset, int len) throws RollerException {
List<Subscription> result;
if (group != null) {
- Query q = strategy.getNamedQuery(
- "Subscription.getByGroupOrderByInboundBlogsDesc");
+ TypedQuery<Subscription> q = strategy.getNamedQuery(
+ "Subscription.getByGroupOrderByInboundBlogsDesc", Subscription.class);
q.setParameter(1, group);
if (offset != 0) {
q.setFirstResult(offset);
@@ -147,8 +148,8 @@ public class JPAPlanetManagerImpl extend
}
result = q.getResultList();
} else {
- Query q = strategy.getNamedQuery(
- "Subscription.getAllOrderByInboundBlogsDesc");
+ TypedQuery<Subscription> q = strategy.getNamedQuery(
+ "Subscription.getAllOrderByInboundBlogsDesc", Subscription.class);
if (offset != 0) {
q.setFirstResult(offset);
}
@@ -161,10 +162,10 @@ public class JPAPlanetManagerImpl extend
}
public PlanetGroup getGroup(String handle) throws RollerException {
- Query q = strategy.getNamedQuery("PlanetGroup.getByHandle");
+ TypedQuery<PlanetGroup> q = strategy.getNamedQuery("PlanetGroup.getByHandle", PlanetGroup.class);
q.setParameter(1, handle);
try {
- return (PlanetGroup)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -182,10 +183,10 @@ public class JPAPlanetManagerImpl extend
}
public Planet getWeblogger(String handle) throws RollerException {
- Query q = strategy.getNamedQuery("Planet.getByHandle");
+ TypedQuery<Planet> q = strategy.getNamedQuery("Planet.getByHandle", Planet.class);
q.setParameter(1, handle);
try {
- return (Planet)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -196,7 +197,7 @@ public class JPAPlanetManagerImpl extend
}
public List<Planet> getWebloggers() throws RollerException {
- return strategy.getNamedQuery("Planet.getAll").getResultList();
+ return strategy.getNamedQuery("Planet.getAll", Planet.class).getResultList();
}
public List<String> getGroupHandles(Planet planet) throws RollerException {
@@ -208,17 +209,17 @@ public class JPAPlanetManagerImpl extend
}
public List<PlanetGroup> getGroups(Planet planet) throws RollerException {
- Query q = strategy.getNamedQuery("PlanetGroup.getByPlanet");
+ TypedQuery<PlanetGroup> q = strategy.getNamedQuery("PlanetGroup.getByPlanet", PlanetGroup.class);
q.setParameter(1, planet.getHandle());
return q.getResultList();
}
public PlanetGroup getGroup(Planet planet, String handle) throws RollerException {
- Query q = strategy.getNamedQuery("PlanetGroup.getByPlanetAndHandle");
+ TypedQuery<PlanetGroup> q = strategy.getNamedQuery("PlanetGroup.getByPlanetAndHandle", PlanetGroup.class);
q.setParameter(1, planet.getHandle());
q.setParameter(2, handle);
try {
- return (PlanetGroup)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -238,7 +239,7 @@ public class JPAPlanetManagerImpl extend
}
public List<Subscription> getSubscriptions() throws RollerException {
- Query q = strategy.getNamedQuery("Subscription.getAllOrderByFeedURL");
+ TypedQuery<Subscription> q = strategy.getNamedQuery("Subscription.getAllOrderByFeedURL", Subscription.class);
return q.getResultList();
}
@@ -250,7 +251,7 @@ public class JPAPlanetManagerImpl extend
if (sub == null) {
throw new WebloggerException("subscription cannot be null");
}
- Query q = strategy.getNamedQuery("SubscriptionEntry.getBySubscription");
+ TypedQuery<SubscriptionEntry> q = strategy.getNamedQuery("SubscriptionEntry.getBySubscription", SubscriptionEntry.class);
q.setParameter(1, sub);
if (offset != 0) {
q.setFirstResult(offset);
@@ -271,7 +272,7 @@ public class JPAPlanetManagerImpl extend
throw new WebloggerException("group cannot be null or empty");
}
- List<SubscriptionEntry> ret = null;
+ List<SubscriptionEntry> ret;
try {
long startTime = System.currentTimeMillis();
@@ -294,7 +295,7 @@ public class JPAPlanetManagerImpl extend
}
sb.append(" ORDER BY e.pubTime DESC");
- Query query = strategy.getDynamicQuery(sb.toString());
+ TypedQuery<SubscriptionEntry> query = strategy.getDynamicQuery(sb.toString(), SubscriptionEntry.class);
for (int i=0; i<params.size(); i++) {
query.setParameter(i+1, params.get(i));
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/UserManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/UserManager.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/UserManager.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/UserManager.java Sun Jun 29 19:09:13 2014
@@ -147,10 +147,10 @@ public interface UserManager {
/**
* Get map with 26 entries, one for each letter A-Z and
- * containing integers reflecting the number of users whose
+ * containing Longs reflecting the number of users whose
* names start with each letter.
*/
- Map getUserNameLetterMap() throws WebloggerException;
+ Map<String, Long> getUserNameLetterMap() throws WebloggerException;
/**
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java Sun Jun 29 19:09:13 2014
@@ -142,7 +142,7 @@ public interface WeblogManager {
* containing integers reflecting the number of weblogs whose
* names start with each letter.
*/
- Map getWeblogHandleLetterMap() throws WebloggerException;
+ Map<String, Long> getWeblogHandleLetterMap() throws WebloggerException;
/**
@@ -196,7 +196,7 @@ public interface WeblogManager {
/**
* Save template code
*/
- void saveTemplateCode(WeblogThemeTemplateCode templateCode) throws WebloggerException;
+ void saveTemplateCode(WeblogThemeTemplateCode templateCode) throws WebloggerException;
/**
* Get website's pages
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAAutoPingManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAAutoPingManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAAutoPingManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAAutoPingManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -30,6 +30,7 @@ import org.apache.roller.weblogger.pojos
import java.util.Collection;
import java.util.List;
import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.roller.weblogger.business.Weblogger;
/*
@@ -76,12 +77,12 @@ public class JPAAutoPingManagerImpl impl
q.executeUpdate();
}
- public void removeAutoPings(Collection autopings) throws WebloggerException {
+ public void removeAutoPings(Collection<AutoPing> autopings) throws WebloggerException {
strategy.removeAll(autopings);
}
public void removeAllAutoPings() throws WebloggerException {
- Query q = strategy.getNamedUpdate("AutoPing.getAll");
+ TypedQuery<AutoPing> q = strategy.getNamedQueryCommitFirst("AutoPing.getAll", AutoPing.class);
removeAutoPings(q.getResultList());
}
@@ -101,13 +102,13 @@ public class JPAAutoPingManagerImpl impl
}
public List<AutoPing> getAutoPingsByWebsite(Weblog website) throws WebloggerException {
- Query q = strategy.getNamedQuery("AutoPing.getByWebsite");
+ TypedQuery<AutoPing> q = strategy.getNamedQuery("AutoPing.getByWebsite", AutoPing.class);
q.setParameter(1, website);
return q.getResultList();
}
public List<AutoPing> getAutoPingsByTarget(PingTarget pingTarget) throws WebloggerException {
- Query q = strategy.getNamedQuery("AutoPing.getByPingTarget");
+ TypedQuery<AutoPing> q = strategy.getNamedQuery("AutoPing.getByPingTarget", AutoPing.class);
q.setParameter(1, pingTarget);
return q.getResultList();
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -21,7 +21,7 @@ package org.apache.roller.weblogger.busi
import java.io.StringReader;
import java.util.List;
import javax.persistence.NoResultException;
-import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -172,7 +172,6 @@ public class JPABookmarkManagerImpl impl
url = null!=htmlUrl ? htmlUrl : url;
// better to truncate imported OPML fields than to fail import or drop whole bookmark
- // TODO: add way to notify user that fields were truncated
int maxLength = RollerConstants.TEXTWIDTH_255;
if (title != null && title.length() > maxLength) {
@@ -219,10 +218,10 @@ public class JPABookmarkManagerImpl impl
*/
public List<WeblogBookmark> getBookmarks(WeblogBookmarkFolder folder)
throws WebloggerException {
- Query query;
+ TypedQuery<WeblogBookmark> query;
List<WeblogBookmark> results;
- query = strategy.getNamedQuery("BookmarkData.getByFolder");
+ query = strategy.getNamedQuery("BookmarkData.getByFolder", WeblogBookmark.class);
query.setParameter(1, folder);
results = query.getResultList();
@@ -233,11 +232,12 @@ public class JPABookmarkManagerImpl impl
throws WebloggerException {
// Do simple lookup by name
- Query query = strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite&Name");
+ TypedQuery<WeblogBookmarkFolder> query = strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite&Name",
+ WeblogBookmarkFolder.class);
query.setParameter(1, website);
query.setParameter(2, name);
try {
- return (WeblogBookmarkFolder) query.getSingleResult();
+ return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -250,11 +250,12 @@ public class JPABookmarkManagerImpl impl
throw new WebloggerException("weblog is null");
}
- Query q = strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite&Name");
+ TypedQuery<WeblogBookmarkFolder> q = strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite&Name",
+ WeblogBookmarkFolder.class);
q.setParameter(1, weblog);
q.setParameter(2, "default");
try {
- return (WeblogBookmarkFolder)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -266,7 +267,8 @@ public class JPABookmarkManagerImpl impl
throw new WebloggerException("Website is null");
}
- Query q = strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite");
+ TypedQuery<WeblogBookmarkFolder> q = strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite",
+ WeblogBookmarkFolder.class);
q.setParameter(1, website);
return q.getResultList();
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -31,17 +31,14 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
-import java.util.StringTokenizer;
import javax.imageio.ImageIO;
import javax.persistence.NoResultException;
-import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -143,7 +140,6 @@ public class JPAMediaFileManagerImpl imp
/**
* {@inheritDoc}
- // TODO: Remove this method?
*/
public void createMediaFileDirectory(MediaFileDirectory directory)
throws WebloggerException {
@@ -360,12 +356,12 @@ public class JPAMediaFileManagerImpl imp
log.debug("Looking up weblog|media file directory: " + weblog.getHandle() + "|" + name);
- Query q = this.strategy
- .getNamedQuery("MediaFileDirectory.getByWeblogAndName");
+ TypedQuery<MediaFileDirectory> q = this.strategy
+ .getNamedQuery("MediaFileDirectory.getByWeblogAndName", MediaFileDirectory.class);
q.setParameter(1, weblog);
q.setParameter(2, name);
try {
- return (MediaFileDirectory) q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -406,13 +402,13 @@ public class JPAMediaFileManagerImpl imp
origpath = "/" + origpath;
}
- Query q = this.strategy
- .getNamedQuery("MediaFile.getByWeblogAndOrigpath");
+ TypedQuery<MediaFile> q = this.strategy
+ .getNamedQuery("MediaFile.getByWeblogAndOrigpath", MediaFile.class);
q.setParameter(1, weblog);
q.setParameter(2, origpath);
MediaFile mf;
try {
- mf = (MediaFile) q.getSingleResult();
+ mf = q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -447,7 +443,8 @@ public class JPAMediaFileManagerImpl imp
public List<MediaFileDirectory> getMediaFileDirectories(Weblog weblog)
throws WebloggerException {
- Query q = this.strategy.getNamedQuery("MediaFileDirectory.getByWeblog");
+ TypedQuery<MediaFileDirectory> q = this.strategy.getNamedQuery("MediaFileDirectory.getByWeblog",
+ MediaFileDirectory.class);
q.setParameter(1, weblog);
return q.getResultList();
}
@@ -483,12 +480,8 @@ public class JPAMediaFileManagerImpl imp
public List<MediaFile> fetchRecentPublicMediaFiles(int length)
throws WebloggerException {
- StringBuilder queryString = new StringBuilder();
-
- queryString
- .append("SELECT m FROM MediaFile m WHERE m.sharedForGallery = true");
- queryString.append(" order by m.dateUploaded");
- Query query = strategy.getDynamicQuery(queryString.toString());
+ String queryString = "SELECT m FROM MediaFile m WHERE m.sharedForGallery = true order by m.dateUploaded";
+ TypedQuery<MediaFile> query = strategy.getDynamicQuery(queryString, MediaFile.class);
query.setFirstResult(0);
query.setMaxResults(length);
return query.getResultList();
@@ -502,12 +495,10 @@ public class JPAMediaFileManagerImpl imp
List<Object> params = new ArrayList<Object>();
int size = 0;
- StringBuilder queryString = new StringBuilder();
+ String queryString = "SELECT m FROM MediaFile m WHERE ";
StringBuilder whereClause = new StringBuilder();
StringBuilder orderBy = new StringBuilder();
- queryString.append("SELECT m FROM MediaFile m WHERE ");
-
params.add(size++, weblog);
whereClause.append("m.directory.weblog = ?").append(size);
@@ -596,8 +587,8 @@ public class JPAMediaFileManagerImpl imp
orderBy.append(" order by m.name");
}
- Query query = strategy.getDynamicQuery(queryString.toString()
- + whereClause.toString() + orderBy.toString());
+ TypedQuery<MediaFile> query = strategy.getDynamicQuery(queryString
+ + whereClause.toString() + orderBy.toString(), MediaFile.class);
for (int i = 0; i < params.size(); i++) {
query.setParameter(i + 1, params.get(i));
}
@@ -650,12 +641,12 @@ public class JPAMediaFileManagerImpl imp
File uploadsDir = new File(oldDirName);
File[] dirs = uploadsDir.listFiles();
if (null != dirs) {
- for (int i = 0; i < dirs.length; i++) {
+ for (File dir : dirs) {
- if (dirs[i].isDirectory()) {
+ if (dir.isDirectory()) {
WeblogManager wmgr = this.roller.getWeblogManager();
Weblog weblog = wmgr.getWeblogByHandle(
- dirs[i].getName(), null);
+ dir.getName(), null);
if (weblog != null) {
log.info("Migrating weblog: "
@@ -688,7 +679,7 @@ public class JPAMediaFileManagerImpl imp
weblog,
chosenUser,
new File(oldDirName + FS
- + dirs[i].getName()), root);
+ + dir.getName()), root);
} catch (Exception e) {
log.error("ERROR upgading weblog", e);
@@ -725,80 +716,82 @@ public class JPAMediaFileManagerImpl imp
int dirCount = 0;
int fileCount = 0;
File[] files = oldDir.listFiles();
- for (int i = 0; i < files.length; i++) {
-
- // a directory: go recursive
- if (files[i].isDirectory()) {
+ if (files != null) {
+ for (File file: files) {
- if (weblog.hasMediaFileDirectory(files[i].getName())) {
- // already have a mediafile directory for that
- upgradeUploadsDir(weblog, user, files[i],
- weblog.getMediaFileDirectory(files[i].getName()));
+ // a directory: go recursive
+ if (file.isDirectory()) {
- } else {
- // need to create a new mediafile directory
- MediaFileDirectory secondDir = null;
- try {
- secondDir = new MediaFileDirectory(weblog, files[i].getName(), null);
- roller.getMediaFileManager().createMediaFileDirectory(secondDir);
- roller.flush();
- dirCount++;
- } catch (WebloggerException ex) {
- log.error("ERROR creating directory: "
- + newDir.getName() + "/" + files[i].getName());
+ if (weblog.hasMediaFileDirectory(file.getName())) {
+ // already have a mediafile directory for that
+ upgradeUploadsDir(weblog, user, file,
+ weblog.getMediaFileDirectory(file.getName()));
+
+ } else {
+ // need to create a new mediafile directory
+ MediaFileDirectory secondDir = null;
+ try {
+ secondDir = new MediaFileDirectory(weblog, file.getName(), null);
+ roller.getMediaFileManager().createMediaFileDirectory(secondDir);
+ roller.flush();
+ dirCount++;
+ } catch (WebloggerException ex) {
+ log.error("ERROR creating directory: "
+ + newDir.getName() + "/" + file.getName());
+ }
+ upgradeUploadsDir(weblog, user, file, secondDir);
}
- upgradeUploadsDir(weblog, user, files[i], secondDir);
- }
-
- } else {
- // a file: create a database record for it
- // check to make sure that file does not already exist
- if (newDir.hasMediaFile(files[i].getName())) {
- log.debug(" Skipping file that already exists: "
- + files[i].getName());
} else {
-
- String originalPath = "/" + newDir.getName() + "/" + files[i].getName();
- log.debug("Upgrade file with original path: " + originalPath);
-
- MediaFile mf = new MediaFile();
- try {
- mf.setName(files[i].getName());
- mf.setDescription(files[i].getName());
- mf.setOriginalPath(originalPath);
-
- mf.setDateUploaded(new Timestamp(files[i]
- .lastModified()));
- mf.setLastUpdated(new Timestamp(files[i].lastModified()));
-
- mf.setDirectory(newDir);
- mf.setWeblog(weblog);
- mf.setCreatorUserName(user.getUserName());
- mf.setSharedForGallery(Boolean.FALSE);
-
- mf.setLength(files[i].length());
- mf.setInputStream(new FileInputStream(files[i]));
- mf.setContentType(Utilities
- .getContentTypeFromFileName(files[i].getName()));
-
- // Create
- this.roller.getMediaFileManager().createMediaFile(
- weblog, mf, messages);
- newDir.getMediaFiles().add(mf);
-
- log.info(messages.toString());
-
- fileCount++;
-
- } catch (WebloggerException ex) {
- log.error("ERROR writing file to new storage system: "
- + files[i].getAbsolutePath(), ex);
-
- } catch (java.io.FileNotFoundException ex) {
- log.error(
- "ERROR reading file from old storage system: "
- + files[i].getAbsolutePath(), ex);
+ // a file: create a database record for it
+ // check to make sure that file does not already exist
+ if (newDir.hasMediaFile(file.getName())) {
+ log.debug(" Skipping file that already exists: "
+ + file.getName());
+
+ } else {
+
+ String originalPath = "/" + newDir.getName() + "/" + file.getName();
+ log.debug("Upgrade file with original path: " + originalPath);
+
+ MediaFile mf = new MediaFile();
+ try {
+ mf.setName(file.getName());
+ mf.setDescription(file.getName());
+ mf.setOriginalPath(originalPath);
+
+ mf.setDateUploaded(new Timestamp(file
+ .lastModified()));
+ mf.setLastUpdated(new Timestamp(file.lastModified()));
+
+ mf.setDirectory(newDir);
+ mf.setWeblog(weblog);
+ mf.setCreatorUserName(user.getUserName());
+ mf.setSharedForGallery(Boolean.FALSE);
+
+ mf.setLength(file.length());
+ mf.setInputStream(new FileInputStream(file));
+ mf.setContentType(Utilities
+ .getContentTypeFromFileName(file.getName()));
+
+ // Create
+ this.roller.getMediaFileManager().createMediaFile(
+ weblog, mf, messages);
+ newDir.getMediaFiles().add(mf);
+
+ log.info(messages.toString());
+
+ fileCount++;
+
+ } catch (WebloggerException ex) {
+ log.error("ERROR writing file to new storage system: "
+ + file.getAbsolutePath(), ex);
+
+ } catch (java.io.FileNotFoundException ex) {
+ log.error(
+ "ERROR reading file from old storage system: "
+ + file.getAbsolutePath(), ex);
+ }
}
}
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAOAuthManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAOAuthManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAOAuthManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAOAuthManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -22,7 +22,7 @@ import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
-import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import net.oauth.OAuthAccessor;
import net.oauth.OAuthConsumer;
import net.oauth.OAuthException;
@@ -81,15 +81,14 @@ public class JPAOAuthManagerImpl impleme
OAuthMessage requestMessage)
throws IOException, OAuthProblemException {
- OAuthConsumer consumer = null;
+ OAuthConsumer consumer;
// try to load from local cache if not throw exception
String consumer_key = requestMessage.getConsumerKey();
consumer = getConsumerByKey(consumer_key);
if(consumer == null) {
- OAuthProblemException problem = new OAuthProblemException("token_rejected");
- throw problem;
+ throw new OAuthProblemException("token_rejected");
}
return consumer;
@@ -106,9 +105,8 @@ public class JPAOAuthManagerImpl impleme
if (StringUtils.isNotEmpty(consumerToken)) {
// caller provided a token, it better be good or else
accessor = getAccessorByToken(consumerToken);
- if (accessor == null){
- OAuthProblemException problem = new OAuthProblemException("token_expired");
- throw problem;
+ if (accessor == null) {
+ throw new OAuthProblemException("token_expired");
}
}
@@ -146,7 +144,7 @@ public class JPAOAuthManagerImpl impleme
throws OAuthException {
// generate oauth_token and oauth_secret
- String consumer_key = (String) accessor.consumer.consumerKey;
+ String consumer_key = accessor.consumer.consumerKey;
// generate token and secret based on consumer_key
// for now use md5 of name + current time as token
@@ -174,7 +172,7 @@ public class JPAOAuthManagerImpl impleme
try {
// generate oauth_token and oauth_secret
// generate token and secret based on consumer_key
- String consumer_key = (String) accessor.consumer.consumerKey;
+ String consumer_key = accessor.consumer.consumerKey;
OAuthAccessorRecord record = (OAuthAccessorRecord) strategy.load(
OAuthAccessorRecord.class, accessor.consumer.consumerKey);
@@ -205,13 +203,10 @@ public class JPAOAuthManagerImpl impleme
throw new OAuthException("ERROR storing accessor", ex);
}
- OAuthConsumer consumer = new OAuthConsumer(
- null,
+ return new OAuthConsumer(null,
record.getConsumerKey(),
record.getConsumerSecret(),
getServiceProvider());
-
- return consumer;
}
public OAuthConsumer addConsumer(String consumerKey)
@@ -226,19 +221,19 @@ public class JPAOAuthManagerImpl impleme
public OAuthConsumer getConsumer() throws WebloggerException {
OAuthConsumerRecord record = null;
try {
- Query q = strategy.getNamedQuery("OAuthConsumerRecord.getSiteWideConsumer");
- record = (OAuthConsumerRecord)q.getSingleResult();
+ TypedQuery<OAuthConsumerRecord> q = strategy.getNamedQuery("OAuthConsumerRecord.getSiteWideConsumer",
+ OAuthConsumerRecord.class);
+ record = q.getSingleResult();
} catch (Exception ex) {
log.debug("ERROR fetching site-wide consumer", ex);
}
if (record != null) {
- OAuthConsumer consumer = new OAuthConsumer(
+ return new OAuthConsumer(
null,
record.getConsumerKey(),
record.getConsumerSecret(),
getServiceProvider());
- return consumer;
}
return null;
}
@@ -246,9 +241,10 @@ public class JPAOAuthManagerImpl impleme
public OAuthConsumer getConsumerByUsername(String username) throws WebloggerException {
OAuthConsumerRecord record = null;
try {
- Query q = strategy.getNamedQuery("OAuthConsumerRecord.getByUsername");
+ TypedQuery<OAuthConsumerRecord> q = strategy.getNamedQuery("OAuthConsumerRecord.getByUsername",
+ OAuthConsumerRecord.class);
q.setParameter(1, username);
- record = (OAuthConsumerRecord)q.getSingleResult();
+ record = q.getSingleResult();
} catch (Exception ex) {
log.debug("ERROR fetching consumer", ex);
@@ -304,9 +300,10 @@ public class JPAOAuthManagerImpl impleme
OAuthConsumer getConsumerByKey(String consumerKey) {
OAuthConsumerRecord record = null;
try {
- Query q = strategy.getNamedQuery("OAuthConsumerRecord.getByConsumerKey");
+ TypedQuery<OAuthConsumerRecord> q = strategy.getNamedQuery("OAuthConsumerRecord.getByConsumerKey",
+ OAuthConsumerRecord.class);
q.setParameter(1, consumerKey);
- record = (OAuthConsumerRecord)q.getSingleResult();
+ record = q.getSingleResult();
} catch (Exception ex) {
log.debug("ERROR fetching consumer", ex);
@@ -350,9 +347,10 @@ public class JPAOAuthManagerImpl impleme
OAuthAccessor getAccessorByKey(String consumerKey) {
OAuthAccessorRecord record = null;
try {
- Query q = strategy.getNamedQuery("OAuthAccessorRecord.getByKey");
+ TypedQuery<OAuthAccessorRecord> q = strategy.getNamedQuery("OAuthAccessorRecord.getByKey",
+ OAuthAccessorRecord.class);
q.setParameter(1, consumerKey);
- record = (OAuthAccessorRecord)q.getSingleResult();
+ record = q.getSingleResult();
} catch (Exception ex) {
log.debug("ERROR fetching accessor", ex);
@@ -363,9 +361,10 @@ public class JPAOAuthManagerImpl impleme
OAuthAccessor getAccessorByToken(String token) {
OAuthAccessorRecord record = null;
try {
- Query q = strategy.getNamedQuery("OAuthAccessorRecord.getByToken");
+ TypedQuery<OAuthAccessorRecord> q = strategy.getNamedQuery("OAuthAccessorRecord.getByToken",
+ OAuthAccessorRecord.class);
q.setParameter(1, token);
- record = (OAuthAccessorRecord)q.getSingleResult();
+ record = q.getSingleResult();
} catch (Exception ex) {
log.debug("ERROR fetching accessor", ex);
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java Sun Jun 29 19:09:13 2014
@@ -21,10 +21,6 @@ package org.apache.roller.weblogger.busi
import java.util.Collection;
import java.util.Enumeration;
import java.util.Properties;
-import java.io.InputStream;
-import java.io.IOException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.WebloggerException;
@@ -37,6 +33,7 @@ import javax.persistence.PersistenceExce
import javax.persistence.Query;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import javax.persistence.TypedQuery;
import org.apache.roller.weblogger.business.DatabaseProvider;
@@ -53,7 +50,7 @@ public class JPAPersistenceStrategy {
/**
* The thread local EntityManager.
*/
- private final ThreadLocal threadLocalEntityManager = new ThreadLocal();
+ private final ThreadLocal<EntityManager> threadLocalEntityManager = new ThreadLocal<EntityManager>();
/**
* The EntityManagerFactory for this Roller instance.
@@ -222,10 +219,7 @@ public class JPAPersistenceStrategy {
* transaction
*/
private boolean isTransactionActive(EntityManager em) {
- if (em == null) {
- return false;
- }
- return em.getTransaction().isActive();
+ return em != null && em.getTransaction().isActive();
}
/**
@@ -246,7 +240,7 @@ public class JPAPersistenceStrategy {
* Get the current ThreadLocal EntityManager
*/
private EntityManager getThreadLocalEntityManager() {
- EntityManager em = (EntityManager) threadLocalEntityManager.get();
+ EntityManager em = threadLocalEntityManager.get();
if (em == null) {
em = emf.createEntityManager();
threadLocalEntityManager.set(em);
@@ -257,12 +251,12 @@ public class JPAPersistenceStrategy {
/**
* Set the current ThreadLocal EntityManager
*/
- private void setThreadLocalEntityManager(Object em) {
+ private void setThreadLocalEntityManager(EntityManager em) {
threadLocalEntityManager.set(em);
}
/**
- * Get named query with FlushModeType.COMMIT
+ * Get named query that won't commit changes to DB first (FlushModeType.COMMIT)
* @param queryName the name of the query
* @throws org.apache.roller.weblogger.WebloggerException on any error
*/
@@ -270,27 +264,78 @@ public class JPAPersistenceStrategy {
throws WebloggerException {
EntityManager em = getEntityManager(false);
Query q = em.createNamedQuery(queryName);
- // Never flush for queries. Roller code assumes this behavior
+ // For performance, never flush/commit prior to running queries.
+ // Roller code assumes this behavior
q.setFlushMode(FlushModeType.COMMIT);
return q;
}
-
+
+ /**
+ * Get named TypedQuery that won't commit changes to DB first (FlushModeType.COMMIT)
+ * Preferred over getNamedQuery(String) due to it being typesafe.
+ * @param queryName the name of the query
+ * @param resultClass return type of query
+ * @throws org.apache.roller.weblogger.WebloggerException on any error
+ */
+ public <T> TypedQuery<T> getNamedQuery(String queryName, Class<T> resultClass)
+ throws WebloggerException {
+ EntityManager em = getEntityManager(false);
+ TypedQuery<T> q = em.createNamedQuery(queryName, resultClass);
+ // For performance, never flush/commit prior to running queries.
+ // Roller code assumes this behavior
+ q.setFlushMode(FlushModeType.COMMIT);
+ return q;
+ }
+
/**
- * Create query from queryString with FlushModeType.COMMIT
- * @param queryString the quuery
+ * Get named query with default flush mode (usually FlushModeType.AUTO)
+ * FlushModeType.AUTO commits changes to DB prior to running statement
+ *
+ * @param queryName the name of the query
+ * @param resultClass return type of query
+ * @throws org.apache.roller.weblogger.WebloggerException on any error
+ */
+ public <T> TypedQuery<T> getNamedQueryCommitFirst(String queryName, Class<T> resultClass)
+ throws WebloggerException {
+ EntityManager em = getEntityManager(true);
+ return em.createNamedQuery(queryName, resultClass);
+ }
+
+ /**
+ * Create query from queryString that won't commit changes to DB first (FlushModeType.COMMIT)
+ * @param queryString the query
* @throws org.apache.roller.weblogger.WebloggerException on any error
*/
public Query getDynamicQuery(String queryString)
throws WebloggerException {
EntityManager em = getEntityManager(false);
Query q = em.createQuery(queryString);
- // Never flush for queries. Roller code assumes this behavior
+ // For performance, never flush/commit prior to running queries.
+ // Roller code assumes this behavior
q.setFlushMode(FlushModeType.COMMIT);
return q;
}
-
+
/**
- * Get named update query with default flush mode
+ * Create TypedQuery from queryString that won't commit changes to DB first (FlushModeType.COMMIT)
+ * Preferred over getDynamicQuery(String) due to it being typesafe.
+ * @param queryString the query
+ * @param resultClass return type of query
+ * @throws org.apache.roller.weblogger.WebloggerException on any error
+ */
+ public <T> TypedQuery<T> getDynamicQuery(String queryString, Class<T> resultClass)
+ throws WebloggerException {
+ EntityManager em = getEntityManager(false);
+ TypedQuery<T> q = em.createQuery(queryString, resultClass);
+ // For performance, never flush/commit prior to running queries.
+ // Roller code assumes this behavior
+ q.setFlushMode(FlushModeType.COMMIT);
+ return q;
+ }
+
+ /**
+ * Get named update query with default flush mode (usually FlushModeType.AUTO)
+ * FlushModeType.AUTO commits changes to DB prior to running statement
* @param queryName the name of the query
* @throws org.apache.roller.weblogger.WebloggerException on any error
*/
@@ -299,49 +344,5 @@ public class JPAPersistenceStrategy {
EntityManager em = getEntityManager(true);
return em.createNamedQuery(queryName);
}
-
- /**
- * Loads properties from given resourceName using given class loader
- * @param resourceName The name of the resource containing properties
- * @param cl Classloeder to be used to locate the resouce
- * @return A properties object
- * @throws WebloggerException
- */
- private static Properties loadPropertiesFromResourceName(
- String resourceName, ClassLoader cl) throws WebloggerException {
- Properties props = new Properties();
- InputStream in;
- in = cl.getResourceAsStream(resourceName);
- if (in == null) {
- throw new WebloggerException(
- "Could not locate properties to load " + resourceName);
- }
- try {
- props.load(in);
- } catch (IOException ioe) {
- throw new WebloggerException(
- "Could not load properties from " + resourceName);
- } finally {
- try {
- in.close();
- } catch (IOException ioe) {
- }
- }
-
- return props;
- }
-
- /**
- * Get the context class loader associated with the current thread. This is
- * done in a doPrivileged block because it is a secure method.
- * @return the current thread's context class loader.
- */
- private static ClassLoader getContextClassLoader() {
- return (ClassLoader) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
+
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingQueueManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingQueueManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingQueueManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingQueueManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -20,7 +20,7 @@ package org.apache.roller.weblogger.busi
import java.sql.Timestamp;
import java.util.List;
-import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -95,8 +95,8 @@ public class JPAPingQueueManagerImpl imp
public List<PingQueueEntry> getAllQueueEntries()
throws WebloggerException {
- return (List<PingQueueEntry>) strategy.getNamedQuery(
- "PingQueueEntry.getAllOrderByEntryTime").getResultList();
+ return strategy.getNamedQuery("PingQueueEntry.getAllOrderByEntryTime",
+ PingQueueEntry.class).getResultList();
}
// private helper to determine if an has already been queued
@@ -104,7 +104,8 @@ public class JPAPingQueueManagerImpl imp
private boolean isAlreadyQueued(AutoPing autoPing)
throws WebloggerException {
// first, determine if an entry already exists
- Query q = strategy.getNamedQuery("PingQueueEntry.getByPingTarget&Website");
+ TypedQuery<PingQueueEntry> q = strategy.getNamedQuery("PingQueueEntry.getByPingTarget&Website",
+ PingQueueEntry.class);
q.setParameter(1, autoPing.getPingTarget());
q.setParameter(2, autoPing.getWebsite());
return q.getResultList().size() > 0;
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingTargetManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingTargetManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingTargetManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPingTargetManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -24,6 +24,7 @@ import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;
import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.pings.PingTargetManager;
@@ -151,8 +152,8 @@ public class JPAPingTargetManagerImpl im
public List<PingTarget> getCommonPingTargets()
throws WebloggerException {
- Query q = strategy.getNamedQuery(
- "PingTarget.getPingTargetsOrderByName");
+ TypedQuery<PingTarget> q = strategy.getNamedQuery(
+ "PingTarget.getPingTargetsOrderByName", PingTarget.class);
return q.getResultList();
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPropertiesManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPropertiesManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPropertiesManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPropertiesManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -105,7 +105,8 @@ public class JPAPropertiesManagerImpl im
public Map<String, RuntimeConfigProperty> getProperties() throws WebloggerException {
HashMap<String, RuntimeConfigProperty> props = new HashMap<String, RuntimeConfigProperty>();
- List<RuntimeConfigProperty> list = strategy.getNamedQuery("RuntimeConfigProperty.getAll").getResultList();
+ List<RuntimeConfigProperty> list = strategy.getNamedQuery("RuntimeConfigProperty.getAll",
+ RuntimeConfigProperty.class).getResultList();
/*
* for convenience sake we are going to put the list of props
* into a map for users to access it. The value element of the
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAThreadManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAThreadManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAThreadManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAThreadManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -22,11 +22,11 @@ import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.NoResultException;
import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.util.DateUtil;
import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.Weblogger;
import org.apache.roller.weblogger.business.runnable.ThreadManagerImpl;
import org.apache.roller.weblogger.business.runnable.RollerTask;
import org.apache.roller.weblogger.pojos.TaskLock;
@@ -47,7 +47,7 @@ public class JPAThreadManagerImpl extend
@com.google.inject.Inject
- protected JPAThreadManagerImpl(Weblogger roller, JPAPersistenceStrategy strat) {
+ protected JPAThreadManagerImpl(JPAPersistenceStrategy strat) {
super();
LOG.debug("Instantiating JPA Thread Manager");
@@ -68,7 +68,7 @@ public class JPAThreadManagerImpl extend
Date currentTime = new Date();
// query for existing lease record first
- TaskLock taskLock = null;
+ TaskLock taskLock;
try {
taskLock = getTaskLockByName(task.getName());
if(taskLock == null) {
@@ -88,7 +88,7 @@ public class JPAThreadManagerImpl extend
// calculate run time for task, this is expected time, not actual time
// i.e. if a task is meant to run daily at midnight this should
// reflect 00:00:00 on the current day
- Date runTime = currentTime;
+ Date runTime;
if("startOfDay".equals(task.getStartTimeDesc())) {
// start of today
runTime = DateUtil.getStartOfDay(currentTime);
@@ -111,7 +111,7 @@ public class JPAThreadManagerImpl extend
Query q = strategy.getNamedUpdate(
"TaskLock.updateClient&Timeacquired&Timeleased&LastRunByName&Timeacquired");
q.setParameter(1, task.getClientId());
- q.setParameter(2, Integer.valueOf(task.getLeaseTime()));
+ q.setParameter(2, task.getLeaseTime());
q.setParameter(3, new Timestamp(runTime.getTime()));
q.setParameter(4, task.getName());
q.setParameter(5, taskLock.getTimeAcquired());
@@ -140,7 +140,7 @@ public class JPAThreadManagerImpl extend
public boolean unregisterLease(RollerTask task) {
// query for existing lease record first
- TaskLock taskLock = null;
+ TaskLock taskLock;
try {
taskLock = this.getTaskLockByName(task.getName());
@@ -161,7 +161,7 @@ public class JPAThreadManagerImpl extend
try {
Query q = strategy.getNamedUpdate(
"TaskLock.updateTimeLeasedByName&Client");
- q.setParameter(1, Integer.valueOf(0));
+ q.setParameter(1, 0);
q.setParameter(2, task.getName());
q.setParameter(3, task.getClientId());
int result = q.executeUpdate();
@@ -190,10 +190,10 @@ public class JPAThreadManagerImpl extend
*/
public TaskLock getTaskLockByName(String name) throws WebloggerException {
// do lookup
- Query q = strategy.getNamedQuery("TaskLock.getByName");
+ TypedQuery<TaskLock> q = strategy.getNamedQuery("TaskLock.getByName", TaskLock.class);
q.setParameter(1, name);
try {
- return (TaskLock)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java?rev=1606568&r1=1606567&r2=1606568&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java Sun Jun 29 19:09:13 2014
@@ -32,7 +32,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import javax.persistence.Query;
+import javax.persistence.TypedQuery;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.GlobalPermission;
import org.apache.roller.weblogger.pojos.RollerPermission;
@@ -97,7 +97,6 @@ public class JPAUserManagerImpl implemen
throw new WebloggerException("cannot add null user");
}
- // TODO BACKEND: we must do this in a better fashion, like getUserCnt()?
boolean adminUser = false;
List existingUsers = this.getUsers(Boolean.TRUE, null, null, 0, 1);
boolean firstUserAdmin = WebloggerConfig.getBooleanProperty("users.firstUserAdmin");
@@ -149,7 +148,7 @@ public class JPAUserManagerImpl implemen
if(this.userNameToIdMap.containsKey(userName)) {
User user = this.getUser(
- (String) this.userNameToIdMap.get(userName));
+ this.userNameToIdMap.get(userName));
if(user != null) {
// only return the user if the enabled status matches
if(enabled == null || enabled.equals(user.getEnabled())) {
@@ -163,15 +162,15 @@ public class JPAUserManagerImpl implemen
}
// cache failed, do lookup
- Query query;
+ TypedQuery<User> query;
Object[] params;
if (enabled != null) {
query = strategy.getNamedQuery(
- "User.getByUserName&Enabled");
+ "User.getByUserName&Enabled", User.class);
params = new Object[] {userName, enabled};
} else {
query = strategy.getNamedQuery(
- "User.getByUserName");
+ "User.getByUserName", User.class);
params = new Object[] {userName};
}
for (int i=0; i<params.length; i++) {
@@ -179,89 +178,24 @@ public class JPAUserManagerImpl implemen
}
User user;
try {
- user = (User)query.getSingleResult();
+ user = query.getSingleResult();
} catch (NoResultException e) {
user = null;
}
// add mapping to cache
if(user != null) {
- log.debug("userNameToIdMap CACHE MISS - "+userName);
+ log.debug("userNameToIdMap CACHE MISS - " + userName);
this.userNameToIdMap.put(user.getUserName(), user.getId());
}
return user;
}
- public List<User> getUsers(Weblog weblog, Boolean enabled, Date startDate,
- Date endDate, int offset, int length)
- throws WebloggerException {
- Query query;
-
- List<Object> params = new ArrayList<Object>();
- int size = 0;
- StringBuilder queryString = new StringBuilder();
- StringBuilder whereClause = new StringBuilder();
-
- if (weblog != null) {
- queryString.append("SELECT u FROM User u JOIN u.permissions p ");
- params.add(size++, weblog);
- whereClause.append(" WHERE p.website = ?").append(size);
- } else {
- queryString.append("SELECT u FROM User u ");
- }
-
- if (enabled != null) {
- if (whereClause.length() == 0) {
- whereClause.append(" WHERE ");
- } else {
- whereClause.append(" AND ");
- }
- params.add(size++, enabled);
- whereClause.append("u.enabled = ?").append(size);
- }
-
- if (startDate != null) {
- if (whereClause.length() == 0) {
- whereClause.append(" WHERE ");
- } else {
- whereClause.append(" AND ");
- }
-
- Timestamp start = new Timestamp(startDate.getTime());
- // if we are doing date range then we must have an end date
- // TODO: why? confirm end date needed
- Timestamp end = new Timestamp(endDate != null ? endDate.getTime() : new Date().getTime());
- params.add(size++, start);
- whereClause.append("u.dateCreated > ?").append(size);
- params.add(size++, end);
- whereClause.append(" AND u.dateCreated < ?").append(size);
- }
- whereClause.append(" ORDER BY u.dateCreated DESC");
- query = strategy.getDynamicQuery(queryString.toString() + whereClause.toString());
-
- if (offset != 0) {
- query.setFirstResult(offset);
- }
- if (length != -1) {
- query.setMaxResults(length);
- }
- for (int i=0; i<params.size(); i++) {
- query.setParameter(i+1, params.get(i));
- }
- return query.getResultList();
- }
-
-
- public List<User> getUsers(int offset, int length) throws WebloggerException {
- return getUsers(Boolean.TRUE, null, null, offset, length);
- }
-
-
public List<User> getUsers(Boolean enabled, Date startDate, Date endDate,
int offset, int length)
throws WebloggerException {
- Query query;
+ TypedQuery<User> query;
Timestamp end = new Timestamp(endDate != null ? endDate.getTime() : new Date().getTime());
@@ -269,13 +203,13 @@ public class JPAUserManagerImpl implemen
if (startDate != null) {
Timestamp start = new Timestamp(startDate.getTime());
query = strategy.getNamedQuery(
- "User.getByEnabled&EndDate&StartDateOrderByStartDateDesc");
+ "User.getByEnabled&EndDate&StartDateOrderByStartDateDesc", User.class);
query.setParameter(1, enabled);
query.setParameter(2, end);
query.setParameter(3, start);
} else {
query = strategy.getNamedQuery(
- "User.getByEnabled&EndDateOrderByStartDateDesc");
+ "User.getByEnabled&EndDateOrderByStartDateDesc", User.class);
query.setParameter(1, enabled);
query.setParameter(2, end);
}
@@ -283,12 +217,12 @@ public class JPAUserManagerImpl implemen
if (startDate != null) {
Timestamp start = new Timestamp(startDate.getTime());
query = strategy.getNamedQuery(
- "User.getByEndDate&StartDateOrderByStartDateDesc");
+ "User.getByEndDate&StartDateOrderByStartDateDesc", User.class);
query.setParameter(1, end);
query.setParameter(2, start);
} else {
query = strategy.getNamedQuery(
- "User.getByEndDateOrderByStartDateDesc");
+ "User.getByEndDateOrderByStartDateDesc", User.class);
query.setParameter(1, end);
}
}
@@ -301,63 +235,29 @@ public class JPAUserManagerImpl implemen
return query.getResultList();
}
-
- /**
- * Get users of a website
- */
- public List<User> getUsers(Weblog website, Boolean enabled, int offset, int length) throws WebloggerException {
- Query query;
-
- if (enabled != null) {
- if (website != null) {
- query = strategy.getNamedQuery("User.getByEnabled&Permissions.website");
- query.setParameter(1, enabled);
- query.setParameter(2, website);
- } else {
- query = strategy.getNamedQuery("User.getByEnabled");
- query.setParameter(1, enabled);
- }
- } else {
- if (website != null) {
- query = strategy.getNamedQuery("User.getByPermissions.website");
- query.setParameter(1, website);
- } else {
- query = strategy.getNamedQuery("User.getAll");
- }
- }
- if (offset != 0) {
- query.setFirstResult(offset);
- }
- if (length != -1) {
- query.setMaxResults(length);
- }
- return query.getResultList();
- }
-
-
public List<User> getUsersStartingWith(String startsWith, Boolean enabled,
int offset, int length) throws WebloggerException {
- Query query;
+ TypedQuery<User> query;
if (enabled != null) {
if (startsWith != null) {
query = strategy.getNamedQuery(
- "User.getByEnabled&UserNameOrEmailAddressStartsWith");
+ "User.getByEnabled&UserNameOrEmailAddressStartsWith", User.class);
query.setParameter(1, enabled);
query.setParameter(2, startsWith + '%');
query.setParameter(3, startsWith + '%');
} else {
query = strategy.getNamedQuery(
- "User.getByEnabled");
+ "User.getByEnabled", User.class);
query.setParameter(1, enabled);
}
} else {
if (startsWith != null) {
query = strategy.getNamedQuery(
- "User.getByUserNameOrEmailAddressStartsWith");
+ "User.getByUserNameOrEmailAddressStartsWith", User.class);
query.setParameter(1, startsWith + '%');
} else {
- query = strategy.getNamedQuery("User.getAll");
+ query = strategy.getNamedQuery("User.getAll", User.class);
}
}
if (offset != 0) {
@@ -370,11 +270,11 @@ public class JPAUserManagerImpl implemen
}
- public Map getUserNameLetterMap() throws WebloggerException {
+ public Map<String, Long> getUserNameLetterMap() throws WebloggerException {
String lc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- Map results = new TreeMap();
- Query query = strategy.getNamedQuery(
- "User.getCountByUserNameLike");
+ Map<String, Long> results = new TreeMap<String, Long>();
+ TypedQuery<Long> query = strategy.getNamedQuery(
+ "User.getCountByUserNameLike", Long.class);
for (int i=0; i<26; i++) {
char currentChar = lc.charAt(i);
query.setParameter(1, currentChar + "%");
@@ -386,10 +286,10 @@ public class JPAUserManagerImpl implemen
}
- public List getUsersByLetter(char letter, int offset, int length)
+ public List<User> getUsersByLetter(char letter, int offset, int length)
throws WebloggerException {
- Query query = strategy.getNamedQuery(
- "User.getByUserNameOrderByUserName");
+ TypedQuery<User> query = strategy.getNamedQuery(
+ "User.getByUserNameOrderByUserName", User.class);
query.setParameter(1, letter + "%");
if (offset != 0) {
query.setFirstResult(offset);
@@ -405,13 +305,10 @@ public class JPAUserManagerImpl implemen
* Get count of users, enabled only
*/
public long getUserCount() throws WebloggerException {
- long ret = 0;
- Query q = strategy.getNamedQuery("User.getCountEnabledDistinct");
+ TypedQuery<Long> q = strategy.getNamedQuery("User.getCountEnabledDistinct", Long.class);
q.setParameter(1, Boolean.TRUE);
- List results = q.getResultList();
- ret =((Long)results.get(0));
-
- return ret;
+ List<Long> results = q.getResultList();
+ return results.get(0);
}
@@ -429,32 +326,33 @@ public class JPAUserManagerImpl implemen
String[] parts = value.split("&");
value = parts[0];
- Query query;
- query = strategy.getNamedQuery("UserAttribute.getByAttrNameAndAttrValue");
- query.setParameter(1, name);
- query.setParameter(2, value);
- UserAttribute attribute = null;
+ TypedQuery<UserAttribute> attrQuery = strategy.getNamedQuery("UserAttribute.getByAttrNameAndAttrValue",
+ UserAttribute.class);
+ attrQuery.setParameter(1, name);
+ attrQuery.setParameter(2, value);
+ UserAttribute attribute;
try {
- attribute = (UserAttribute) query.getSingleResult();
+ attribute = attrQuery.getSingleResult();
} catch (NoResultException e) {
return null;
}
Object[] params;
+ TypedQuery<User> userQuery;
if (enabled != null) {
- query = strategy.getNamedQuery("User.getByUserName&Enabled");
+ userQuery = strategy.getNamedQuery("User.getByUserName&Enabled", User.class);
params = new Object[]{attribute.getUserName(), enabled};
} else {
- query = strategy.getNamedQuery("User.getByUserName");
+ userQuery = strategy.getNamedQuery("User.getByUserName", User.class);
params = new Object[]{attribute.getUserName()};
}
for (int i = 0; i < params.length; i++) {
- query.setParameter(i + 1, params[i]);
+ userQuery.setParameter(i + 1, params[i]);
}
User user;
try {
- user = (User) query.getSingleResult();
+ user = userQuery.getSingleResult();
} catch (NoResultException e) {
user = null;
}
@@ -464,11 +362,11 @@ public class JPAUserManagerImpl implemen
public UserAttribute getUserAttribute(String userName, String attribute) throws WebloggerException {
- Query q = strategy.getNamedQuery("UserAttribute.getByUserNameAndAttrName");
+ TypedQuery<UserAttribute> q = strategy.getNamedQuery("UserAttribute.getByUserNameAndAttrName", UserAttribute.class);
q.setParameter(1, userName);
q.setParameter(2, attribute);
try {
- return (UserAttribute) q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -476,10 +374,10 @@ public class JPAUserManagerImpl implemen
public List<UserAttribute> getUserAttributes(String userName) throws WebloggerException {
- Query q = strategy.getNamedQuery("UserAttribute.getByUserName");
+ TypedQuery<UserAttribute> q = strategy.getNamedQuery("UserAttribute.getByUserName", UserAttribute.class);
q.setParameter(1, userName);
try {
- return (List<UserAttribute>)q.getResultList();
+ return q.getResultList();
} catch (NoResultException e) {
return null;
}
@@ -488,11 +386,12 @@ public class JPAUserManagerImpl implemen
public void setUserAttribute(String userName, String attribute, String value) throws WebloggerException {
UserAttribute userAttribute = null;
- Query q = strategy.getNamedQuery("UserAttribute.getByUserNameAndAttrName");
+ TypedQuery<UserAttribute> q = strategy.getNamedQuery("UserAttribute.getByUserNameAndAttrName",
+ UserAttribute.class);
q.setParameter(1, userName);
q.setParameter(2, attribute);
try {
- userAttribute = (UserAttribute) q.getSingleResult();
+ userAttribute = q.getSingleResult();
} catch (NoResultException ignored) {
}
if (userAttribute != null) {
@@ -513,10 +412,10 @@ public class JPAUserManagerImpl implemen
if (activationCode == null) {
throw new WebloggerException("activationcode is null");
}
- Query q = strategy.getNamedQuery("User.getUserByActivationCode");
+ TypedQuery<User> q = strategy.getNamedQuery("User.getUserByActivationCode", User.class);
q.setParameter(1, activationCode);
try {
- return (User)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
@@ -554,22 +453,24 @@ public class JPAUserManagerImpl implemen
public WeblogPermission getWeblogPermission(Weblog weblog, User user) throws WebloggerException {
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogId");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogId"
+ , WeblogPermission.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, weblog.getHandle());
try {
- return (WeblogPermission)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException ignored) {
return null;
}
}
public WeblogPermission getWeblogPermissionIncludingPending(Weblog weblog, User user) throws WebloggerException {
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, weblog.getHandle());
try {
- return (WeblogPermission)q.getSingleResult();
+ return q.getSingleResult();
} catch (NoResultException ignored) {
return null;
}
@@ -578,12 +479,13 @@ public class JPAUserManagerImpl implemen
public void grantWeblogPermission(Weblog weblog, User user, List<String> actions) throws WebloggerException {
// first, see if user already has a permission for the specified object
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, weblog.getHandle());
WeblogPermission existingPerm = null;
try {
- existingPerm = (WeblogPermission)q.getSingleResult();
+ existingPerm = q.getSingleResult();
} catch (NoResultException ignored) {}
// permission already exists, so add any actions specified in perm argument
@@ -601,12 +503,13 @@ public class JPAUserManagerImpl implemen
public void grantWeblogPermissionPending(Weblog weblog, User user, List<String> actions) throws WebloggerException {
// first, see if user already has a permission for the specified object
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, weblog.getHandle());
WeblogPermission existingPerm = null;
try {
- existingPerm = (WeblogPermission)q.getSingleResult();
+ existingPerm = q.getSingleResult();
} catch (NoResultException ignored) {}
// permission already exists, so complain
@@ -625,12 +528,13 @@ public class JPAUserManagerImpl implemen
public void confirmWeblogPermission(Weblog weblog, User user) throws WebloggerException {
// get specified permission
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, weblog.getHandle());
WeblogPermission existingPerm;
try {
- existingPerm = (WeblogPermission)q.getSingleResult();
+ existingPerm = q.getSingleResult();
} catch (NoResultException ignored) {
throw new WebloggerException("ERROR: permission not found");
@@ -644,12 +548,13 @@ public class JPAUserManagerImpl implemen
public void declineWeblogPermission(Weblog weblog, User user) throws WebloggerException {
// get specified permission
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, weblog.getHandle());
WeblogPermission existingPerm;
try {
- existingPerm = (WeblogPermission)q.getSingleResult();
+ existingPerm = q.getSingleResult();
} catch (NoResultException ignored) {
throw new WebloggerException("ERROR: permission not found");
}
@@ -661,12 +566,13 @@ public class JPAUserManagerImpl implemen
public void revokeWeblogPermission(Weblog weblog, User user, List<String> actions) throws WebloggerException {
// get specified permission
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&WeblogIdIncludingPending",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, weblog.getHandle());
WeblogPermission oldperm;
try {
- oldperm = (WeblogPermission)q.getSingleResult();
+ oldperm = q.getSingleResult();
} catch (NoResultException ignored) {
throw new WebloggerException("ERROR: permission not found");
}
@@ -685,33 +591,38 @@ public class JPAUserManagerImpl implemen
public List<WeblogPermission> getWeblogPermissions(User user) throws WebloggerException {
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
- return (List<WeblogPermission>)q.getResultList();
+ return q.getResultList();
}
public List<WeblogPermission> getWeblogPermissions(Weblog weblog) throws WebloggerException {
- Query q = strategy.getNamedQuery("WeblogPermission.getByWeblogId");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByWeblogId",
+ WeblogPermission.class);
q.setParameter(1, weblog.getHandle());
- return (List<WeblogPermission>)q.getResultList();
+ return q.getResultList();
}
public List<WeblogPermission> getWeblogPermissionsIncludingPending(Weblog weblog) throws WebloggerException {
- Query q = strategy.getNamedQuery("WeblogPermission.getByWeblogIdIncludingPending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByWeblogIdIncludingPending",
+ WeblogPermission.class);
q.setParameter(1, weblog.getHandle());
- return (List<WeblogPermission>)q.getResultList();
+ return q.getResultList();
}
public List<WeblogPermission> getPendingWeblogPermissions(User user) throws WebloggerException {
- Query q = strategy.getNamedQuery("WeblogPermission.getByUserName&Pending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByUserName&Pending",
+ WeblogPermission.class);
q.setParameter(1, user.getUserName());
- return (List<WeblogPermission>)q.getResultList();
+ return q.getResultList();
}
public List<WeblogPermission> getPendingWeblogPermissions(Weblog weblog) throws WebloggerException {
- Query q = strategy.getNamedQuery("WeblogPermission.getByWeblogId&Pending");
+ TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByWeblogId&Pending",
+ WeblogPermission.class);
q.setParameter(1, weblog.getHandle());
- return (List<WeblogPermission>)q.getResultList();
+ return q.getResultList();
}
//-------------------------------------------------------------- role CRUD
@@ -721,7 +632,7 @@ public class JPAUserManagerImpl implemen
* Returns true if user has role specified.
*/
public boolean hasRole(String roleName, User user) throws WebloggerException {
- Query q = strategy.getNamedQuery("UserRole.getByUserNameAndRole");
+ TypedQuery<UserRole> q = strategy.getNamedQuery("UserRole.getByUserNameAndRole", UserRole.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, roleName);
try {
@@ -737,7 +648,7 @@ public class JPAUserManagerImpl implemen
* Get all of user's roles.
*/
public List<String> getRoles(User user) throws WebloggerException {
- Query q = strategy.getNamedQuery("UserRole.getByUserName");
+ TypedQuery<UserRole> q = strategy.getNamedQuery("UserRole.getByUserName", UserRole.class);
q.setParameter(1, user.getUserName());
List<UserRole> roles = q.getResultList();
List<String> roleNames = new ArrayList<String>();
@@ -761,11 +672,11 @@ public class JPAUserManagerImpl implemen
public void revokeRole(String roleName, User user) throws WebloggerException {
- Query q = strategy.getNamedQuery("UserRole.getByUserNameAndRole");
+ TypedQuery<UserRole> q = strategy.getNamedQuery("UserRole.getByUserNameAndRole", UserRole.class);
q.setParameter(1, user.getUserName());
q.setParameter(2, roleName);
try {
- UserRole role = (UserRole)q.getSingleResult();
+ UserRole role = q.getSingleResult();
this.strategy.remove(role);
} catch (NoResultException e) {