Rename package to conform to standards
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.baeldung</groupId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>spring-hibernate4</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.dao;
|
||||
|
||||
import com.baeldung.persistence.dao.common.IAuditOperations;
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
|
||||
public interface IBarAuditableDao extends IBarDao, IAuditOperations<Bar> {
|
||||
//
|
||||
}
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
package org.baeldung.persistence.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.baeldung.persistence.model.Bar;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface IBarCrudRepository extends CrudRepository<Bar, Serializable> {
|
||||
//
|
||||
}
|
||||
package com.baeldung.persistence.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface IBarCrudRepository extends CrudRepository<Bar, Serializable> {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.dao;
|
||||
|
||||
import com.baeldung.persistence.dao.common.IOperations;
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
|
||||
public interface IBarDao extends IOperations<Bar> {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.dao;
|
||||
|
||||
import com.baeldung.persistence.model.Child;
|
||||
import com.baeldung.persistence.dao.common.IOperations;
|
||||
|
||||
public interface IChildDao extends IOperations<Child> {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.dao;
|
||||
|
||||
import com.baeldung.persistence.dao.common.IAuditOperations;
|
||||
import com.baeldung.persistence.model.Foo;
|
||||
|
||||
public interface IFooAuditableDao extends IFooDao, IAuditOperations<Foo> {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.dao;
|
||||
|
||||
import com.baeldung.persistence.model.Foo;
|
||||
import com.baeldung.persistence.dao.common.IOperations;
|
||||
|
||||
public interface IFooDao extends IOperations<Foo> {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.dao;
|
||||
|
||||
import com.baeldung.persistence.model.Parent;
|
||||
import com.baeldung.persistence.dao.common.IOperations;
|
||||
|
||||
public interface IParentDao extends IOperations<Parent> {
|
||||
//
|
||||
}
|
||||
+14
-14
@@ -1,14 +1,14 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
public abstract class AbstractDao<T extends Serializable> implements IOperations<T> {
|
||||
|
||||
protected Class<T> clazz;
|
||||
|
||||
protected final void setClazz(final Class<T> clazzToSet) {
|
||||
clazz = Preconditions.checkNotNull(clazzToSet);
|
||||
}
|
||||
}
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
public abstract class AbstractDao<T extends Serializable> implements IOperations<T> {
|
||||
|
||||
protected Class<T> clazz;
|
||||
|
||||
protected final void setClazz(final Class<T> clazzToSet) {
|
||||
clazz = Preconditions.checkNotNull(clazzToSet);
|
||||
}
|
||||
}
|
||||
+37
-37
@@ -1,37 +1,37 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.envers.AuditReader;
|
||||
import org.hibernate.envers.AuditReaderFactory;
|
||||
import org.hibernate.envers.query.AuditQuery;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AbstractHibernateAuditableDao<T extends Serializable> extends AbstractHibernateDao<T> implements IAuditOperations<T> {
|
||||
|
||||
@Override
|
||||
public List<T> getEntitiesAtRevision(final Number revision) {
|
||||
final AuditReader auditReader = AuditReaderFactory.get(getCurrentSession());
|
||||
final AuditQuery query = auditReader.createQuery().forEntitiesAtRevision(clazz, revision);
|
||||
final List<T> resultList = query.getResultList();
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getEntitiesModifiedAtRevision(final Number revision) {
|
||||
final AuditReader auditReader = AuditReaderFactory.get(getCurrentSession());
|
||||
final AuditQuery query = auditReader.createQuery().forEntitiesModifiedAtRevision(clazz, revision);
|
||||
final List<T> resultList = query.getResultList();
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getRevisions() {
|
||||
final AuditReader auditReader = AuditReaderFactory.get(getCurrentSession());
|
||||
final AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(clazz, true, true);
|
||||
final List<T> resultList = query.getResultList();
|
||||
return resultList;
|
||||
}
|
||||
|
||||
}
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.envers.AuditReader;
|
||||
import org.hibernate.envers.AuditReaderFactory;
|
||||
import org.hibernate.envers.query.AuditQuery;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AbstractHibernateAuditableDao<T extends Serializable> extends AbstractHibernateDao<T> implements IAuditOperations<T> {
|
||||
|
||||
@Override
|
||||
public List<T> getEntitiesAtRevision(final Number revision) {
|
||||
final AuditReader auditReader = AuditReaderFactory.get(getCurrentSession());
|
||||
final AuditQuery query = auditReader.createQuery().forEntitiesAtRevision(clazz, revision);
|
||||
final List<T> resultList = query.getResultList();
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getEntitiesModifiedAtRevision(final Number revision) {
|
||||
final AuditReader auditReader = AuditReaderFactory.get(getCurrentSession());
|
||||
final AuditQuery query = auditReader.createQuery().forEntitiesModifiedAtRevision(clazz, revision);
|
||||
final List<T> resultList = query.getResultList();
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getRevisions() {
|
||||
final AuditReader auditReader = AuditReaderFactory.get(getCurrentSession());
|
||||
final AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(clazz, true, true);
|
||||
final List<T> resultList = query.getResultList();
|
||||
return resultList;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
+56
-56
@@ -1,56 +1,56 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
public class AbstractJpaDao<T extends Serializable> extends AbstractDao<T> implements IOperations<T> {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
// API
|
||||
|
||||
@Override
|
||||
public T findOne(final long id) {
|
||||
return em.find(clazz, Long.valueOf(id).intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
final CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
final CriteriaQuery<T> cq = cb.createQuery(clazz);
|
||||
final Root<T> rootEntry = cq.from(clazz);
|
||||
final CriteriaQuery<T> all = cq.select(rootEntry);
|
||||
final TypedQuery<T> allQuery = em.createQuery(all);
|
||||
return allQuery.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(final T entity) {
|
||||
em.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T update(final T entity) {
|
||||
em.merge(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(final T entity) {
|
||||
em.remove(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(final long entityId) {
|
||||
delete(findOne(entityId));
|
||||
}
|
||||
|
||||
}
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
public class AbstractJpaDao<T extends Serializable> extends AbstractDao<T> implements IOperations<T> {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
// API
|
||||
|
||||
@Override
|
||||
public T findOne(final long id) {
|
||||
return em.find(clazz, Long.valueOf(id).intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
final CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
final CriteriaQuery<T> cq = cb.createQuery(clazz);
|
||||
final Root<T> rootEntry = cq.from(clazz);
|
||||
final CriteriaQuery<T> all = cq.select(rootEntry);
|
||||
final TypedQuery<T> allQuery = em.createQuery(all);
|
||||
return allQuery.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(final T entity) {
|
||||
em.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T update(final T entity) {
|
||||
em.merge(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(final T entity) {
|
||||
em.remove(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(final long entityId) {
|
||||
delete(findOne(entityId));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
+14
-14
@@ -1,14 +1,14 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public interface IAuditOperations<T extends Serializable> {
|
||||
|
||||
List<T> getEntitiesAtRevision(Number revision);
|
||||
|
||||
List<T> getEntitiesModifiedAtRevision(Number revision);
|
||||
|
||||
List<T> getRevisions();
|
||||
|
||||
}
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public interface IAuditOperations<T extends Serializable> {
|
||||
|
||||
List<T> getEntitiesAtRevision(Number revision);
|
||||
|
||||
List<T> getEntitiesModifiedAtRevision(Number revision);
|
||||
|
||||
List<T> getRevisions();
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.dao.common;
|
||||
package com.baeldung.persistence.dao.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
+27
-27
@@ -1,28 +1,28 @@
|
||||
package org.baeldung.persistence.dao.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.persistence.dao.IBarAuditableDao;
|
||||
import org.baeldung.persistence.dao.common.AbstractHibernateAuditableDao;
|
||||
import org.baeldung.persistence.model.Bar;
|
||||
|
||||
public class BarAuditableDao extends AbstractHibernateAuditableDao<Bar> implements IBarAuditableDao {
|
||||
|
||||
public BarAuditableDao() {
|
||||
super();
|
||||
|
||||
setClazz(Bar.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
@Override
|
||||
public List<Bar> getRevisions() {
|
||||
final List<Bar> resultList = super.getRevisions();
|
||||
for (final Bar bar : resultList) {
|
||||
bar.getFooSet().size(); // force FooSet initialization
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
package com.baeldung.persistence.dao.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.persistence.dao.IBarAuditableDao;
|
||||
import com.baeldung.persistence.dao.common.AbstractHibernateAuditableDao;
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
|
||||
public class BarAuditableDao extends AbstractHibernateAuditableDao<Bar> implements IBarAuditableDao {
|
||||
|
||||
public BarAuditableDao() {
|
||||
super();
|
||||
|
||||
setClazz(Bar.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
@Override
|
||||
public List<Bar> getRevisions() {
|
||||
final List<Bar> resultList = super.getRevisions();
|
||||
for (final Bar bar : resultList) {
|
||||
bar.getFooSet().size(); // force FooSet initialization
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
}
|
||||
+19
-19
@@ -1,19 +1,19 @@
|
||||
package org.baeldung.persistence.dao.impl;
|
||||
|
||||
import org.baeldung.persistence.dao.IBarDao;
|
||||
import org.baeldung.persistence.dao.common.AbstractHibernateDao;
|
||||
import org.baeldung.persistence.model.Bar;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class BarDao extends AbstractHibernateDao<Bar> implements IBarDao {
|
||||
|
||||
public BarDao() {
|
||||
super();
|
||||
|
||||
setClazz(Bar.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
}
|
||||
package com.baeldung.persistence.dao.impl;
|
||||
|
||||
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
|
||||
import com.baeldung.persistence.dao.IBarDao;
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class BarDao extends AbstractHibernateDao<Bar> implements IBarDao {
|
||||
|
||||
public BarDao() {
|
||||
super();
|
||||
|
||||
setClazz(Bar.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
}
|
||||
+19
-19
@@ -1,19 +1,19 @@
|
||||
package org.baeldung.persistence.dao.impl;
|
||||
|
||||
import org.baeldung.persistence.dao.IBarDao;
|
||||
import org.baeldung.persistence.dao.common.AbstractJpaDao;
|
||||
import org.baeldung.persistence.model.Bar;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class BarJpaDao extends AbstractJpaDao<Bar> implements IBarDao {
|
||||
|
||||
public BarJpaDao() {
|
||||
super();
|
||||
|
||||
setClazz(Bar.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
}
|
||||
package com.baeldung.persistence.dao.impl;
|
||||
|
||||
import com.baeldung.persistence.dao.IBarDao;
|
||||
import com.baeldung.persistence.dao.common.AbstractJpaDao;
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class BarJpaDao extends AbstractJpaDao<Bar> implements IBarDao {
|
||||
|
||||
public BarJpaDao() {
|
||||
super();
|
||||
|
||||
setClazz(Bar.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.persistence.dao.impl;
|
||||
|
||||
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
|
||||
import com.baeldung.persistence.model.Child;
|
||||
import com.baeldung.persistence.dao.IChildDao;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ChildDao extends AbstractHibernateDao<Child> implements IChildDao {
|
||||
|
||||
public ChildDao() {
|
||||
super();
|
||||
|
||||
setClazz(Child.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.persistence.dao.impl;
|
||||
|
||||
import com.baeldung.persistence.dao.common.AbstractHibernateAuditableDao;
|
||||
import com.baeldung.persistence.model.Foo;
|
||||
import com.baeldung.persistence.dao.IFooAuditableDao;
|
||||
|
||||
public class FooAuditableDao extends AbstractHibernateAuditableDao<Foo> implements IFooAuditableDao {
|
||||
|
||||
public FooAuditableDao() {
|
||||
super();
|
||||
|
||||
setClazz(Foo.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package org.baeldung.persistence.dao.impl;
|
||||
package com.baeldung.persistence.dao.impl;
|
||||
|
||||
import org.baeldung.persistence.dao.IFooDao;
|
||||
import org.baeldung.persistence.dao.common.AbstractHibernateDao;
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
|
||||
import com.baeldung.persistence.dao.IFooDao;
|
||||
import com.baeldung.persistence.model.Foo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.persistence.dao.impl;
|
||||
|
||||
import com.baeldung.persistence.dao.IParentDao;
|
||||
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
|
||||
import com.baeldung.persistence.model.Parent;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ParentDao extends AbstractHibernateDao<Parent> implements IParentDao {
|
||||
|
||||
public ParentDao() {
|
||||
super();
|
||||
|
||||
setClazz(Parent.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.model;
|
||||
package com.baeldung.persistence.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.model;
|
||||
package com.baeldung.persistence.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.model;
|
||||
package com.baeldung.persistence.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.baeldung.persistence.model;
|
||||
package com.baeldung.persistence.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.service;
|
||||
|
||||
import com.baeldung.persistence.dao.common.IAuditOperations;
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
|
||||
public interface IBarAuditableService extends IBarService, IAuditOperations<Bar> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.service;
|
||||
|
||||
import com.baeldung.persistence.dao.common.IOperations;
|
||||
import com.baeldung.persistence.model.Bar;
|
||||
|
||||
public interface IBarService extends IOperations<Bar> {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.persistence.service;
|
||||
|
||||
import com.baeldung.persistence.model.Child;
|
||||
import com.baeldung.persistence.dao.common.IOperations;
|
||||
|
||||
public interface IChildService extends IOperations<Child> {
|
||||
//
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user