BAEL-12937

This commit is contained in:
Loredana 2019-05-18 15:34:01 +03:00
parent 47e6077a79
commit cbac5e3e76
41 changed files with 89 additions and 101 deletions

View File

@ -18,12 +18,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@ -108,12 +102,6 @@
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -156,7 +144,6 @@
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
<jta.version>1.1</jta.version>
<querydsl.version>4.2.1</querydsl.version>
<hsqldb.version>2.4.1</hsqldb.version>
<!-- util -->
<guava.version>21.0</guava.version>

View File

@ -1,11 +1,10 @@
package org.baeldung.config;
package com.baeldung.config;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.baeldung.persistence.dao.IFooDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -24,15 +23,16 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.baeldung.persistence.dao.impl.FooDao;
import com.baeldung.hibernate.dao.FooDao;
import com.baeldung.jpa.dao.IFooDao;
import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = { "com.baeldung.persistence" }, transactionManagerRef = "jpaTransactionManager")
@EnableJpaRepositories(basePackages = { "com.baeldung.hibernate.dao" }, transactionManagerRef = "jpaTransactionManager")
@EnableJpaAuditing
@PropertySource({ "classpath:persistence-mysql.properties" })
@ComponentScan({ "com.baeldung.persistence" })
@ComponentScan({ "com.baeldung.persistence", "com.baeldung.hibernate.dao" })
public class PersistenceConfig {
@Autowired

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import java.util.Properties;
@ -25,8 +25,8 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "org.baeldung.persistence" })
@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
@ComponentScan({ "com.baeldung.persistence","com.baeldung.jpa.dao" })
@EnableJpaRepositories(basePackages = "com.baeldung.jpa.dao")
public class PersistenceJPAConfig {
@Autowired
@ -42,7 +42,7 @@ public class PersistenceJPAConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);

View File

@ -1,9 +1,9 @@
package com.baeldung.persistence.dao.impl;
package com.baeldung.hibernate.dao;
import org.baeldung.persistence.dao.IFooDao;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.model.Foo;
import org.springframework.stereotype.Repository;
import com.baeldung.jpa.dao.IFooDao;
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
@Repository

View File

@ -1,4 +1,4 @@
package org.baeldung.jdbc;
package com.baeldung.jdbc;
import java.sql.SQLException;
@ -10,7 +10,7 @@ public class CustomSQLErrorCodeTranslator extends SQLErrorCodeSQLExceptionTransl
@Override
protected DataAccessException customTranslate(final String task, final String sql, final SQLException sqlException) {
if (sqlException.getErrorCode() == -104) {
if (sqlException.getErrorCode() == 23505) {
return new DuplicateKeyException("Custome Exception translator - Integrity contraint voilation.", sqlException);
}
return null;

View File

@ -1,4 +1,4 @@
package org.baeldung.jdbc;
package com.baeldung.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;

View File

@ -1,4 +1,4 @@
package org.baeldung.jdbc;
package com.baeldung.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;

View File

@ -1,4 +1,4 @@
package org.baeldung.jdbc.config;
package com.baeldung.jdbc.config;
import javax.sql.DataSource;
@ -10,12 +10,12 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
@Configuration
@ComponentScan("org.baeldung.jdbc")
@ComponentScan("com.baeldung.jdbc")
public class SpringJdbcConfig {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).addScript("classpath:jdbc/schema.sql").addScript("classpath:jdbc/test-data.sql").build();
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("classpath:jdbc/schema.sql").addScript("classpath:jdbc/test-data.sql").build();
}
// @Bean

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.dao;
package com.baeldung.jpa.dao;
import java.io.Serializable;
import java.util.List;

View File

@ -1,6 +1,6 @@
package org.baeldung.persistence.dao;
package com.baeldung.jpa.dao;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.model.Foo;
import org.springframework.stereotype.Repository;
@Repository

View File

@ -1,8 +1,8 @@
package org.baeldung.persistence.dao;
package com.baeldung.jpa.dao;
import java.util.List;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.model.Foo;
public interface IFooDao {

View File

@ -2,11 +2,12 @@ package com.baeldung.persistence.dao.common;
import java.io.Serializable;
import org.baeldung.persistence.dao.AbstractJpaDAO;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import com.baeldung.jpa.dao.AbstractJpaDAO;
@Repository
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class GenericJpaDao<T extends Serializable> extends AbstractJpaDAO<T> implements IGenericDao<T> {

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.model;
package com.baeldung.persistence.model;
import java.io.Serializable;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.model;
package com.baeldung.persistence.model;
import java.io.Serializable;

View File

@ -1,9 +1,9 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import java.util.List;
import org.baeldung.persistence.dao.IFooDao;
import org.baeldung.persistence.model.Foo;
import com.baeldung.jpa.dao.IFooDao;
import com.baeldung.persistence.model.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.config;
package com.baeldung.spring.data.persistence.config;
import java.util.Properties;
@ -24,9 +24,9 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-${envTarget:h2}.properties" })
@ComponentScan({ "org.baeldung.spring.data.persistence" })
@ComponentScan({ "com.baeldung.spring.data.persistence" })
// @ImportResource("classpath*:springDataPersistenceConfig.xml")
@EnableJpaRepositories(basePackages = "org.baeldung.spring.data.persistence.dao")
@EnableJpaRepositories(basePackages = "com.baeldung.spring.data.persistence.dao")
public class PersistenceConfig {
@Autowired
@ -40,7 +40,7 @@ public class PersistenceConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.spring.data.persistence.model" });
em.setPackagesToScan(new String[] { "com.baeldung.spring.data.persistence.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
// vendorAdapter.set

View File

@ -1,6 +1,6 @@
package org.baeldung.spring.data.persistence.dao;
package com.baeldung.spring.data.persistence.dao;
import org.baeldung.spring.data.persistence.model.Foo;
import com.baeldung.spring.data.persistence.model.Foo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

View File

@ -1,11 +1,11 @@
package org.baeldung.spring.data.persistence.dao.user;
package com.baeldung.spring.data.persistence.dao.user;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import org.baeldung.spring.data.persistence.model.User;
import com.baeldung.spring.data.persistence.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

View File

@ -1,11 +1,11 @@
package org.baeldung.spring.data.persistence.dao.user;
package com.baeldung.spring.data.persistence.dao.user;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import org.baeldung.spring.data.persistence.model.User;
import com.baeldung.spring.data.persistence.model.User;
public interface UserRepositoryCustom {
List<User> findUserByEmails(Set<String> emails);

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.dao.user;
package com.baeldung.spring.data.persistence.dao.user;
import java.util.ArrayList;
import java.util.Collection;
@ -15,7 +15,7 @@ import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.baeldung.spring.data.persistence.model.User;
import com.baeldung.spring.data.persistence.model.User;
public class UserRepositoryCustomImpl implements UserRepositoryCustom {

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.model;
package com.baeldung.spring.data.persistence.model;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.model;
package com.baeldung.spring.data.persistence.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.model;
package com.baeldung.spring.data.persistence.model;
import javax.persistence.*;

View File

@ -1,6 +1,6 @@
package org.baeldung.spring.data.persistence.service;
package com.baeldung.spring.data.persistence.service;
import org.baeldung.spring.data.persistence.model.Foo;
import com.baeldung.spring.data.persistence.model.Foo;
import com.baeldung.persistence.dao.common.IOperations;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.service.common;
package com.baeldung.spring.data.persistence.service.common;
import java.io.Serializable;
import java.util.List;

View File

@ -1,10 +1,10 @@
package org.baeldung.spring.data.persistence.service.impl;
package com.baeldung.spring.data.persistence.service.impl;
import org.baeldung.spring.data.persistence.model.Foo;
import org.baeldung.spring.data.persistence.dao.IFooDao;
import org.baeldung.spring.data.persistence.service.IFooService;
import org.baeldung.spring.data.persistence.service.common.AbstractService;
import com.baeldung.spring.data.persistence.model.Foo;
import com.baeldung.spring.data.persistence.dao.IFooDao;
import com.baeldung.spring.data.persistence.service.IFooService;
import com.baeldung.spring.data.persistence.service.common.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;

View File

@ -4,7 +4,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"
>
<bean id="employeeDao" class="org.baeldung.jdbc.EmployeeDAO">
<bean id="employeeDao" class="com.baeldung.jdbc.EmployeeDAO">
<property name="dataSource" ref="dataSource"/>
</bean>

View File

@ -11,7 +11,7 @@
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="org.baeldung.persistence.model"/>
<property name="packagesToScan" value="com.baeldung.persistence.model"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
<!-- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> <property name="generateDdl" value="${jpa.generateDdl}" /> <property name="databasePlatform"

View File

@ -7,6 +7,6 @@
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
>
<jpa:repositories base-package="org.baeldung.persistence.dao"/>
<jpa:repositories base-package="com.baeldung.persistence.dao"/>
</beans>

View File

@ -1,9 +1,9 @@
package org.baeldung.jdbc;
package com.baeldung.jdbc;
import java.util.ArrayList;
import java.util.List;
import org.baeldung.jdbc.config.SpringJdbcConfig;
import com.baeldung.jdbc.config.SpringJdbcConfig;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.hasSize;
@ -15,8 +15,8 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Foo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,9 +1,9 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Foo;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import java.util.List;
@ -10,9 +10,9 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Bar;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Bar;
import com.baeldung.persistence.model.Foo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.junit.Assert.assertNull;
@ -9,8 +9,8 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.baeldung.config.PersistenceJPAConfig;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceJPAConfig;
import com.baeldung.persistence.model.Foo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,12 +1,12 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.baeldung.config.PersistenceConfig;
import org.baeldung.persistence.model.Foo;
import com.baeldung.config.PersistenceConfig;
import com.baeldung.persistence.model.Foo;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.exception.SQLGrammarException;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.dao.user;
package com.baeldung.spring.data.persistence.dao.user;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
@ -18,8 +18,8 @@ import java.util.stream.Stream;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.baeldung.spring.data.persistence.config.PersistenceConfig;
import org.baeldung.spring.data.persistence.model.User;
import com.baeldung.spring.data.persistence.config.PersistenceConfig;
import com.baeldung.spring.data.persistence.model.User;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -1,11 +1,11 @@
package org.baeldung.spring.data.persistence.dao.user;
package com.baeldung.spring.data.persistence.dao.user;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.LocalDate;
import org.baeldung.spring.data.persistence.config.PersistenceConfig;
import org.baeldung.spring.data.persistence.model.User;
import com.baeldung.spring.data.persistence.config.PersistenceConfig;
import com.baeldung.spring.data.persistence.model.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.persistence.service;
package com.baeldung.spring.data.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.hasItem;
@ -11,8 +11,8 @@ import static org.junit.Assert.assertThat;
import java.io.Serializable;
import java.util.List;
import org.baeldung.spring.data.persistence.model.Foo;
import org.baeldung.util.IDUtil;
import com.baeldung.spring.data.persistence.model.Foo;
import com.baeldung.util.IDUtil;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;

View File

@ -1,10 +1,10 @@
package org.baeldung.spring.data.persistence.service;
package com.baeldung.spring.data.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.junit.Assert.assertNotNull;
import org.baeldung.spring.data.persistence.model.Foo;
import org.baeldung.spring.data.persistence.config.PersistenceConfig;
import com.baeldung.spring.data.persistence.model.Foo;
import com.baeldung.spring.data.persistence.config.PersistenceConfig;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;