Details
diff --git a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java
index b042bb2..f5d5ef7 100755
--- a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java
+++ b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java
@@ -9,8 +9,6 @@
*******************************************************************************/
package eu.cloudscale.showcase.db.dao.hibernate.impl;
-import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
-
import java.util.List;
import org.hibernate.Query;
@@ -41,26 +39,22 @@ public class CustomerDaoImpl extends DaoImpl<ICustomer> implements ICustomerDao
super( sessionFactory );
}
- public static APLCache<ICustomer> getUserByCache = new APLCache<>("CustomerDaoImpl.getUserBy");
-
@SuppressWarnings( "rawtypes" )
@Override
public ICustomer getUserBy(String username, String password)
{
- return getUserByCache.computeIfAbsent(Thread.currentThread(), new Object[]{username, password}, () -> {
- String query = "SELECT C FROM Customer as C WHERE C.CUname = :username AND C.CPasswd = :passwd";
-
- Query q = getCurrentSession().createQuery( query );
- q.setMaxResults( 1 );
- q.setParameter( "username", username );
- q.setParameter( "passwd", password );
- List res = q.list();
-
- if( res.isEmpty() )
- return null;
-
- return (ICustomer) res.get( 0 );
- }, 86400000);
+ String query = "SELECT C FROM Customer as C WHERE C.CUname = :username AND C.CPasswd = :passwd";
+
+ Query q = getCurrentSession().createQuery( query );
+ q.setMaxResults( 1 );
+ q.setParameter( "username", username );
+ q.setParameter( "passwd", password );
+ List res = q.list();
+
+ if( res.isEmpty() )
+ return null;
+
+ return (ICustomer) res.get( 0 );
}
diff --git a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java
index cefc318..cbfa916 100755
--- a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java
+++ b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java
@@ -13,8 +13,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
-import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
-
// import org.hibernate.CacheMode;
import org.hibernate.Hibernate;
import org.hibernate.Query;
@@ -59,25 +57,21 @@ public class ItemDaoImpl extends DaoImpl<IItem> implements IItemDao
return (List<IItem>) q.list();
}
- public static APLCache<IItem> findByIdCache = new APLCache<>("ItemDaoImpl.findById");
-
@SuppressWarnings( "unused" )
@Override
public IItem findById(int id)
{
- return findByIdCache.computeIfAbsent(Thread.currentThread(), new Object[]{id}, () -> {
- String hql = "SELECT I, A FROM Item I, Author A WHERE I.IId = :itemId AND A.AId = I.author.AId";
- Query q = getCurrentSession().createQuery( hql );
- q.setParameter( "itemId", id );
- List res = q.list();
- if ( res != null && res.get( 0 ) == null )
- return null;
-
- IItem item = (Item) ( (Object[]) res.get( 0 ) )[0];
- // Hibernate.initialize( item.getShoppingCartLines() );
- // Hibernate.initialize( item.getOrderLines());
- return item;
- }, 86400000);
+ String hql = "SELECT I, A FROM Item I, Author A WHERE I.IId = :itemId AND A.AId = I.author.AId";
+ Query q = getCurrentSession().createQuery( hql );
+ q.setParameter( "itemId", id );
+ List res = q.list();
+ if ( res != null && res.get( 0 ) == null )
+ return null;
+
+ IItem item = (Item) ( (Object[]) res.get( 0 ) )[0];
+ // Hibernate.initialize( item.getShoppingCartLines() );
+ // Hibernate.initialize( item.getOrderLines());
+ return item;
}
@@ -144,29 +138,25 @@ public class ItemDaoImpl extends DaoImpl<IItem> implements IItemDao
return results;
}
-public static APLCache<List<IItem>> getNewProductsCache = new APLCache<>("ItemDaoImpl.getNewProducts");
-
@SuppressWarnings( "unchecked" )
@Override
// @Transactional( readOnly = true )
public List<IItem> getNewProducts(String category)
{
- return getNewProductsCache.computeIfAbsent(Thread.currentThread(), new Object[]{category}, () -> {
- Session session = getCurrentSession();
- Query query = session
- .createQuery( "SELECT I, A FROM Item as I, Author as A WHERE I.author.AId = A.AId AND I.ISubject = :category "
- + "ORDER BY I.IPubDate DESC, I.ITitle" );
- query.setString( "category", category );
- query.setMaxResults( 50 );
- ArrayList<IItem> newProducts = new ArrayList<IItem>();
-
- List<Object[]> res = query.list();
- for ( int i = 0; i < res.size(); i++ )
- {
- newProducts.add( (Item) ( res.get( i )[0] ) );
- }
- return newProducts;
- }, 86400000);
+ Session session = getCurrentSession();
+ Query query = session
+ .createQuery( "SELECT I, A FROM Item as I, Author as A WHERE I.author.AId = A.AId AND I.ISubject = :category "
+ + "ORDER BY I.IPubDate DESC, I.ITitle" );
+ query.setString( "category", category );
+ query.setMaxResults( 50 );
+ ArrayList<IItem> newProducts = new ArrayList<IItem>();
+
+ List<Object[]> res = query.list();
+ for ( int i = 0; i < res.size(); i++ )
+ {
+ newProducts.add( (Item) ( res.get( i )[0] ) );
+ }
+ return newProducts;
}
@SuppressWarnings( "unchecked" )
@@ -232,81 +222,69 @@ public static APLCache<List<IItem>> getNewProductsCache = new APLCache<>("ItemDa
return new Item();
}
-public static APLCache<List<IItem>> findAllByAuthorCache = new APLCache<>("ItemDaoImpl.findAllByAuthor");
-
@SuppressWarnings( "unchecked" )
@Override
public List<IItem> findAllByAuthor(IAuthor author)
{
- return findAllByAuthorCache.computeIfAbsent(Thread.currentThread(), new Object[]{author}, () -> {
- String hql = "SELECT I FROM Item as I WHERE I.author = :author ORDER BY I.ITitle";
- Query query = getCurrentSession().createQuery( hql );
+ String hql = "SELECT I FROM Item as I WHERE I.author = :author ORDER BY I.ITitle";
+ Query query = getCurrentSession().createQuery( hql );
- query.setParameter( "author", author );
- query.setMaxResults( 50 );
- // query.setCacheable( true );
+ query.setParameter( "author", author );
+ query.setMaxResults( 50 );
+ // query.setCacheable( true );
- List<IItem> res = query.list();
+ List<IItem> res = query.list();
- ArrayList<IItem> items = new ArrayList<IItem>();
- for ( IItem item : res )
- {
- Hibernate.initialize( item.getAuthor() );
- items.add( item );
- }
+ ArrayList<IItem> items = new ArrayList<IItem>();
+ for ( IItem item : res )
+ {
+ Hibernate.initialize( item.getAuthor() );
+ items.add( item );
+ }
- return items;
- }, 86400000);
+ return items;
}
-public static APLCache<List<IItem>> findAllByTitleCache = new APLCache<>("ItemDaoImpl.findAllByTitle");
-
@SuppressWarnings( "unchecked" )
@Override
public List<IItem> findAllByTitle(String keyword)
{
- return findAllByTitleCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
- String hql = "SELECT I FROM Item as I, Author as A WHERE I.author.AId = A.AId AND substring(soundex(I.ITitle), 0, 4) = substring(soundex(:title), 0, 4) ORDER BY I.ITitle";
+ String hql = "SELECT I FROM Item as I, Author as A WHERE I.author.AId = A.AId AND substring(soundex(I.ITitle), 0, 4) = substring(soundex(:title), 0, 4) ORDER BY I.ITitle";
- Query query = getCurrentSession().createQuery( hql );
+ Query query = getCurrentSession().createQuery( hql );
- query.setParameter( "title", keyword );
- query.setMaxResults( 50 );
- // query.setCacheable( true );
+ query.setParameter( "title", keyword );
+ query.setMaxResults( 50 );
+ // query.setCacheable( true );
- List<IItem> res = query.list();
+ List<IItem> res = query.list();
- for ( IItem item : res )
- {
- Hibernate.initialize( item.getAuthor() );
- }
+ for ( IItem item : res )
+ {
+ Hibernate.initialize( item.getAuthor() );
+ }
- return res;
- }, 86400000);
+ return res;
}
-public static APLCache<List<IItem>> findAllBySubjectCache = new APLCache<>("ItemDaoImpl.findAllBySubject");
-
@SuppressWarnings( "unchecked" )
@Override
public List<IItem> findAllBySubject(String keyword)
{
- return findAllBySubjectCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
- String hql = "SELECT I FROM Item as I WHERE I.ISubject = :subject ORDER BY I.ITitle";
+ String hql = "SELECT I FROM Item as I WHERE I.ISubject = :subject ORDER BY I.ITitle";
- Query query = getCurrentSession().createQuery( hql );
+ Query query = getCurrentSession().createQuery( hql );
- query.setParameter( "subject", keyword );
- query.setMaxResults( 50 );
- // query.setCacheable( true );
+ query.setParameter( "subject", keyword );
+ query.setMaxResults( 50 );
+ // query.setCacheable( true );
- List<IItem> res = query.list();
- for ( IItem item : res )
- {
- Hibernate.initialize( item.getAuthor() );
- }
+ List<IItem> res = query.list();
+ for ( IItem item : res )
+ {
+ Hibernate.initialize( item.getAuthor() );
+ }
- return res;
- }, 86400000);
+ return res;
}
}
diff --git a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java
index 6a7f817..8b9c459 100755
--- a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java
+++ b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java
@@ -11,8 +11,6 @@ package eu.cloudscale.showcase.db.dao.hibernate.impl;
import java.util.List;
-import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
-
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@@ -41,25 +39,21 @@ public class ShoppingCartLineDaoImpl extends DaoImpl<IShoppingCartLine> implemen
super( sessionFactory );
}
- public static APLCache<IShoppingCartLine> getBySCandItemCache = new APLCache<>("ShoppingCartLineDaoImpl.getBySCandItem");
-
@SuppressWarnings( "unchecked" )
@Override
public IShoppingCartLine getBySCandItem(Integer shoppingId, int itemId)
{
- return getBySCandItemCache.computeIfAbsent(Thread.currentThread(), new Object[]{shoppingId, itemId}, () -> {
- String hql1 = "SELECT SCL FROM ShoppingCartLine as SCL WHERE SCL.shoppingCart.scId = :scId AND SCL.item.IId = :itemId";
- Query q1 = getCurrentSession().createQuery( hql1 );
- q1.setMaxResults( 1 );
- q1.setParameter( "scId", shoppingId );
- q1.setParameter( "itemId", itemId);
-
- List<Object> res = q1.list();
- if( res.isEmpty() )
- return null;
-
- return (IShoppingCartLine) res.get( 0 );
- }, 86400000);
+ String hql1 = "SELECT SCL FROM ShoppingCartLine as SCL WHERE SCL.shoppingCart.scId = :scId AND SCL.item.IId = :itemId";
+ Query q1 = getCurrentSession().createQuery( hql1 );
+ q1.setMaxResults( 1 );
+ q1.setParameter( "scId", shoppingId );
+ q1.setParameter( "itemId", itemId);
+
+ List<Object> res = q1.list();
+ if( res.isEmpty() )
+ return null;
+
+ return (IShoppingCartLine) res.get( 0 );
}
@Override
diff --git a/src/main/java/eu/cloudscale/showcase/db/services/AService.java b/src/main/java/eu/cloudscale/showcase/db/services/AService.java
index 0a68826..9f72371 100755
--- a/src/main/java/eu/cloudscale/showcase/db/services/AService.java
+++ b/src/main/java/eu/cloudscale/showcase/db/services/AService.java
@@ -496,15 +496,11 @@ public abstract class AService implements IService
ICountry country1 = countryDao.getByName( country );
return country1 == null;
}
-
- public static APLCache<ICustomer> getUserByCache = new APLCache<>("AService.getUserBy");
@Override
public ICustomer getUserBy(String uname, String passwd)
{
- return getUserByCache.computeIfAbsent(Thread.currentThread(), new Object[]{uname, passwd}, () -> {
- return customerDao.getUserBy( uname, passwd );
- }, 86400000);
+ return customerDao.getUserBy( uname, passwd );
}
@Override
@@ -561,31 +557,23 @@ public abstract class AService implements IService
{
return itemDao.getBestSellers( category );
}
-
- public static APLCache<List<IItem>> searchByTitleCache = new APLCache<>("AService.searchByTitle");
@Override
// @Cacheable("search")
public List<IItem> searchByTitle(String keyword)
{
- return searchByTitleCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
- List<IItem> items = itemDao.findAllByTitle( keyword );
-
- return items;
- }, 86400000);
+ List<IItem> items = itemDao.findAllByTitle( keyword );
+
+ return items;
}
- public static APLCache<List<IItem>> searchBySubjectCache = new APLCache<>("AService.searchBySubject");
-
@Override
// @Cacheable("search")
public List<IItem> searchBySubject(String keyword)
{
- return searchBySubjectCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
- List<IItem> items = itemDao.findAllBySubject( keyword );
-
- return items;
- }, 86400000);
+ List<IItem> items = itemDao.findAllBySubject( keyword );
+
+ return items;
}
@Override
@@ -600,14 +588,10 @@ public abstract class AService implements IService
return orderLineDao.findAllByOrder( order );
}
- public static APLCache<IItem> findItemByIdCache = new APLCache<>("AService.findItemById");
-
@Override
public IItem findItemById(Integer itemId)
{
- return findItemByIdCache.computeIfAbsent(Thread.currentThread(), new Object[]{itemId}, () -> {
- return itemDao.findById( itemId );
- }, 86400000);
+ return itemDao.findById( itemId );
}
@Override
diff --git a/src/main/java/eu/cloudscale/showcase/servlets/AController.java b/src/main/java/eu/cloudscale/showcase/servlets/AController.java
index c59fe9c..dd15f39 100755
--- a/src/main/java/eu/cloudscale/showcase/servlets/AController.java
+++ b/src/main/java/eu/cloudscale/showcase/servlets/AController.java
@@ -12,7 +12,6 @@ package eu.cloudscale.showcase.servlets;
import java.io.IOException;
import java.util.Properties;
-import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
import br.ufrgs.inf.prosoft.cache.GetterCache;
import javax.servlet.http.HttpServletRequest;
@@ -69,24 +68,20 @@ public abstract class AController
return url;
}
- public static APLCache<String> getUrl1Cache = new APLCache<>("AController.getUrl1");
-
protected String getUrl1(Integer shoppingId, Integer customerId, String url1)
{
- return getUrl1Cache.computeIfAbsent(Thread.currentThread(), new Object[]{shoppingId, customerId, url1}, () -> {
- String url = new String(url1);
- if( shoppingId != null )
- {
- url += "&SHOPPING_ID=" + shoppingId;
- }
-
- if( customerId != null )
- {
- url += "&C_ID=" + customerId;
- }
-
- return url;
- }, 86400000);
+ String url = new String(url1);
+ if( shoppingId != null )
+ {
+ url += "&SHOPPING_ID=" + shoppingId;
+ }
+
+ if( customerId != null )
+ {
+ url += "&C_ID=" + customerId;
+ }
+
+ return url;
}
protected String getShoppingCartUrl(Integer shoppingId, Integer customerId)