Skip to content

Commit

Permalink
Added table prefix to SearchFrom native query
Browse files Browse the repository at this point in the history
Removed sorting from totalCount calculation at BaseDao
  • Loading branch information
recep committed Sep 8, 2016
1 parent 7926ab7 commit 14cc46c
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

<packaging>pom</packaging>
<name>Robe Project</name>
Expand Down
2 changes: 1 addition & 1 deletion robe-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-assets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>

Expand Down
2 changes: 1 addition & 1 deletion robe-convert/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>

Expand Down
2 changes: 1 addition & 1 deletion robe-crud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-guice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-hibernate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class RobeHibernateBundle<T extends Configuration & HasHibernateConfigura
private static final Logger LOGGER = LoggerFactory.getLogger(RobeHibernateBundle.class);

private static RobeHibernateBundle instance;
private org.hibernate.cfg.Configuration configuration;


private RobeHibernateBundle(ImmutableList<Class<?>> entities, SessionFactoryFactory sessionFactoryFactory) {
super(entities, sessionFactoryFactory);
Expand Down Expand Up @@ -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;
}

}
Expand Down
13 changes: 11 additions & 2 deletions robe-hibernate/src/main/java/io/robe/hibernate/dao/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +36,8 @@
public class BaseDao<T extends BaseEntity> extends AbstractDAO<T> {

private static final ConcurrentHashMap<String, Field[]> fieldCache = new ConcurrentHashMap<>();

@Inject
RobeHibernateBundle bundle;

/**
* Constructor with session factory injection by guice
Expand Down Expand Up @@ -115,6 +117,7 @@ public List<T> findAll(SearchModel search) {
List<T> 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);
Expand All @@ -131,6 +134,7 @@ public List<T> findAllWithSearchFrom(SearchModel search) {
List<T> 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);
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion robe-mail/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-quartz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1036</version>
<version>0.5.0.0-1037</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down

0 comments on commit 14cc46c

Please sign in to comment.