From 14cc46cc72253fc0c04413464312ac841c1a86fd Mon Sep 17 00:00:00 2001 From: recep Date: Thu, 8 Sep 2016 15:19:23 +0300 Subject: [PATCH] Added table prefix to SearchFrom native query Removed sorting from totalCount calculation at BaseDao --- pom.xml | 2 +- robe-admin/pom.xml | 2 +- robe-assets/pom.xml | 2 +- robe-auth/pom.xml | 2 +- robe-common/pom.xml | 2 +- robe-convert/pom.xml | 2 +- robe-crud/pom.xml | 2 +- robe-guice/pom.xml | 2 +- robe-hibernate/pom.xml | 2 +- .../java/io/robe/hibernate/RobeHibernateBundle.java | 6 ++++++ .../main/java/io/robe/hibernate/dao/BaseDao.java | 13 +++++++++++-- robe-mail/pom.xml | 2 +- robe-quartz/pom.xml | 2 +- robe-servlet/pom.xml | 2 +- 14 files changed, 29 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index a266b2b4..46e5f52b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 pom Robe Project diff --git a/robe-admin/pom.xml b/robe-admin/pom.xml index a7070a42..23217a64 100644 --- a/robe-admin/pom.xml +++ b/robe-admin/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-assets/pom.xml b/robe-assets/pom.xml index 490c6480..a3c14530 100644 --- a/robe-assets/pom.xml +++ b/robe-assets/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-auth/pom.xml b/robe-auth/pom.xml index 0c9cd059..8952082b 100644 --- a/robe-auth/pom.xml +++ b/robe-auth/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-common/pom.xml b/robe-common/pom.xml index 5734f752..33930459 100644 --- a/robe-common/pom.xml +++ b/robe-common/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 diff --git a/robe-convert/pom.xml b/robe-convert/pom.xml index 666a8c24..c0c334be 100644 --- a/robe-convert/pom.xml +++ b/robe-convert/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 diff --git a/robe-crud/pom.xml b/robe-crud/pom.xml index 1fa04ec8..629058c2 100644 --- a/robe-crud/pom.xml +++ b/robe-crud/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-guice/pom.xml b/robe-guice/pom.xml index 9f47ef30..97f13d9b 100644 --- a/robe-guice/pom.xml +++ b/robe-guice/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-hibernate/pom.xml b/robe-hibernate/pom.xml index 0cc49f34..e2586dfe 100644 --- a/robe-hibernate/pom.xml +++ b/robe-hibernate/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-hibernate/src/main/java/io/robe/hibernate/RobeHibernateBundle.java b/robe-hibernate/src/main/java/io/robe/hibernate/RobeHibernateBundle.java index 2ca3745c..58cf4475 100644 --- a/robe-hibernate/src/main/java/io/robe/hibernate/RobeHibernateBundle.java +++ b/robe-hibernate/src/main/java/io/robe/hibernate/RobeHibernateBundle.java @@ -24,6 +24,8 @@ public class RobeHibernateBundle> entities, SessionFactoryFactory sessionFactoryFactory) { super(entities, sessionFactoryFactory); @@ -96,7 +98,11 @@ public PooledDataSourceFactory getDataSourceFactory(T configuration) { protected void configure(org.hibernate.cfg.Configuration configuration) { + this.configuration = configuration; + } + public org.hibernate.cfg.Configuration getConfiguration() { + return configuration; } } diff --git a/robe-hibernate/src/main/java/io/robe/hibernate/dao/BaseDao.java b/robe-hibernate/src/main/java/io/robe/hibernate/dao/BaseDao.java index 8b1a8353..cc8d353c 100644 --- a/robe-hibernate/src/main/java/io/robe/hibernate/dao/BaseDao.java +++ b/robe-hibernate/src/main/java/io/robe/hibernate/dao/BaseDao.java @@ -9,6 +9,7 @@ import io.robe.common.service.search.SearchableEnum; import io.robe.common.service.search.model.SearchModel; import io.robe.common.utils.StringsOperations; +import io.robe.hibernate.RobeHibernateBundle; import io.robe.hibernate.entity.BaseEntity; import org.hibernate.Criteria; import org.hibernate.SessionFactory; @@ -35,7 +36,8 @@ public class BaseDao extends AbstractDAO { private static final ConcurrentHashMap fieldCache = new ConcurrentHashMap<>(); - + @Inject + RobeHibernateBundle bundle; /** * Constructor with session factory injection by guice @@ -115,6 +117,7 @@ public List findAll(SearchModel search) { List list = buildCriteria(search).list(); search.setLimit(null); search.setOffset(null); + search.setSort(null); long totalCount = (Long) buildCriteria(search).setProjection(Projections.rowCount()).uniqueResult(); search.setTotalCount(totalCount); ResponseHeadersUtil.addTotalCount(search); @@ -131,6 +134,7 @@ public List findAllWithSearchFrom(SearchModel search) { List list = addSearchFromProjection(buildCriteria(search)).list(); search.setLimit(null); search.setOffset(null); + search.setSort(null); long totalCount = (Long) buildCriteria(search).setProjection(Projections.rowCount()).uniqueResult(); search.setTotalCount(totalCount); ResponseHeadersUtil.addTotalCount(search); @@ -152,7 +156,12 @@ public Criteria addSearchFromProjection(Criteria criteria) { else sqlBuilder.append("group_concat(").append(target).append(")"); - sqlBuilder.append(" from ").append(searchFrom.entity().getSimpleName()); + String prefix = bundle.getConfiguration().getProperty("hibernate.prefix"); + if (prefix != null) + sqlBuilder.append(" from ").append(prefix).append(searchFrom.entity().getSimpleName()); + else + sqlBuilder.append(" from ").append(searchFrom.entity().getSimpleName()); + if (searchFrom.localId().isEmpty()) { sqlBuilder.append(" where ").append(searchFrom.id()).append('=').append(field.getName()).append(") as ").append(alias); } else { diff --git a/robe-mail/pom.xml b/robe-mail/pom.xml index 9d46b256..27080147 100644 --- a/robe-mail/pom.xml +++ b/robe-mail/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-quartz/pom.xml b/robe-quartz/pom.xml index 7b99e638..07627637 100644 --- a/robe-quartz/pom.xml +++ b/robe-quartz/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0 diff --git a/robe-servlet/pom.xml b/robe-servlet/pom.xml index 7d01598c..f8791a75 100644 --- a/robe-servlet/pom.xml +++ b/robe-servlet/pom.xml @@ -5,7 +5,7 @@ io.robe robe-parent - 0.5.0.0-1036 + 0.5.0.0-1037 4.0.0