PAN-7 Initial setup of the persistence with Spring Data JPA
This commit is contained in:
@@ -41,7 +41,7 @@ allprojects {
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'org.unbroken-dome.test-sets'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
// apply plugin: 'io.spring.dependency-management'
|
||||
}
|
||||
|
||||
subprojects {
|
||||
@@ -55,12 +55,13 @@ subprojects {
|
||||
compile 'org.slf4j:slf4j-api:1.7.21'
|
||||
compile "joda-time:joda-time:2.2"
|
||||
compile('org.springframework:spring-context:5.0.9.RELEASE')
|
||||
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.4'
|
||||
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.4'
|
||||
}
|
||||
|
||||
test {
|
||||
@@ -96,9 +97,8 @@ dependencies {
|
||||
// The production code uses the SLF4J logging API at compile time
|
||||
compile 'org.slf4j:slf4j-api:1.7.21'
|
||||
compile "joda-time:joda-time:2.2"
|
||||
compile("org.springframework.boot:spring-boot-starter-web")
|
||||
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.2.RELEASE'
|
||||
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||
|
||||
@@ -13,17 +13,24 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.1.2.RELEASE'
|
||||
// compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch', version: '2.1.2.RELEASE'
|
||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.2.RELEASE'
|
||||
compile 'javax:javaee-api:7.0'
|
||||
|
||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
||||
|
||||
|
||||
compile 'com.mchange:c3p0:0.9.5.2'
|
||||
compile 'mysql:mysql-connector-java:5.1.35'
|
||||
compile 'org.hibernate:hibernate-validator:5.3.4.Final'
|
||||
compile 'javax.validation:validation-api:1.1.0.Final'
|
||||
compile('com.googlecode.log4jdbc:log4jdbc:1.2') {
|
||||
exclude(group: 'org.slf4j')
|
||||
}
|
||||
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
|
||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.2.RELEASE'
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile 'javax.el:javax.el-api:3.0.0'
|
||||
}
|
||||
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package edu.msudenver.tsp.persistence;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.JpaVendorAdapter;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import java.util.Properties;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJpaRepositories
|
||||
public class PersistenceApi {
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(PersistenceApi.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||
final LocalContainerEntityManagerFactoryBean em
|
||||
= new LocalContainerEntityManagerFactoryBean();
|
||||
em.setDataSource(dataSource());
|
||||
em.setPackagesToScan(new String[] { "edu.msudenver.tsp.persistence" });
|
||||
|
||||
final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||
em.setJpaVendorAdapter(vendorAdapter);
|
||||
em.setJpaProperties(additionalProperties());
|
||||
|
||||
return em;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DriverManagerDataSource dataSource(){
|
||||
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
dataSource.setUrl("jdbc:mysql://localhost:3306/pandamonium");
|
||||
dataSource.setUsername( "panda" );
|
||||
dataSource.setPassword( "secret" );
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager(
|
||||
final EntityManagerFactory emf){
|
||||
final JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||
transactionManager.setEntityManagerFactory(emf);
|
||||
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
|
||||
return new PersistenceExceptionTranslationPostProcessor();
|
||||
}
|
||||
|
||||
Properties additionalProperties() {
|
||||
final Properties properties = new Properties();
|
||||
properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
|
||||
properties.setProperty(
|
||||
"hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
|
||||
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
public class PersistenceConfig {
|
||||
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dao;
|
||||
|
||||
class BaseDao {
|
||||
|
||||
// <T> T findById(final int id) {
|
||||
// //TODO insert DB calls for finding objects by their ID's
|
||||
// }
|
||||
|
||||
// <T> List<T> queryForList(final String query) {
|
||||
// //TODO insert DB calls for querying for lists based on the specified query
|
||||
// }
|
||||
|
||||
// <T> T save(final T t) {
|
||||
// //TODO insert DB calls here for insert and update
|
||||
// }
|
||||
|
||||
<T> void delete(final T t) {
|
||||
//TODO insert DB calls here to delete
|
||||
}
|
||||
|
||||
// private <T> T insert(final T object) {
|
||||
// // TODO insert DB calls to insert records
|
||||
// }
|
||||
//
|
||||
// private <T> T update(final T object) {
|
||||
// //TODO insert DB calls to update records
|
||||
// }
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dao;
|
||||
|
||||
public class DefinitionDao extends BaseDao {
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dao;
|
||||
|
||||
public class NotationDao extends BaseDao {
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dao;
|
||||
|
||||
public class ProofDao extends BaseDao {
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dao;
|
||||
|
||||
public class TheoremDao extends BaseDao {
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
class BaseDto {
|
||||
private String id;
|
||||
private int version;
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
public class DefinitionDto extends BaseDto {
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
public class NotationDto extends BaseDto {
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
public class ProofDto extends BaseDto {
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
public class TheoremDto extends BaseDto {
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package edu.msudenver.tsp.persistence.entity;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class BaseEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
Integer id;
|
||||
@Version
|
||||
int version;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Definition implements Serializable {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package edu.msudenver.tsp.persistence.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Entity(name = "definitions")
|
||||
@Data
|
||||
public class DefinitionEntity extends BaseEntity {
|
||||
@Size(min = 1, max = 200, message = "Must be between 1 and 200 characters") String name;
|
||||
Definition definition;
|
||||
Notation notation;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Notation implements Serializable {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package edu.msudenver.tsp.persistence.entity;
|
||||
|
||||
public class NotationEntity extends BaseEntity {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package edu.msudenver.tsp.persistence.entity;
|
||||
|
||||
public class ProofEntity extends BaseEntity {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package edu.msudenver.tsp.persistence.entity;
|
||||
|
||||
public class TheoremEntity extends BaseEntity {
|
||||
}
|
||||
+14
-4
@@ -1,11 +1,21 @@
|
||||
package edu.msudenver.tsp.persistence.manager;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dao.DefinitionDao;
|
||||
import edu.msudenver.tsp.persistence.entity.DefinitionEntity;
|
||||
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Component
|
||||
@Controller
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(path = "/definitions/")
|
||||
public class DefinitionManager {
|
||||
final private DefinitionDao definitionDao;
|
||||
private final DefinitionRepository definitionRepository;
|
||||
|
||||
@GetMapping("/all")
|
||||
public @ResponseBody Iterable<DefinitionEntity> getAllDefinitions() {
|
||||
return definitionRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package edu.msudenver.tsp.persistence.manager;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
public class ManagerConfig {
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package edu.msudenver.tsp.persistence.manager;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dao.NotationDao;
|
||||
import edu.msudenver.tsp.persistence.repository.NotationRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class NotationManager {
|
||||
final private NotationDao notationDao;
|
||||
final private NotationRepository notationRepository;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package edu.msudenver.tsp.persistence.manager;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dao.ProofDao;
|
||||
import edu.msudenver.tsp.persistence.repository.ProofRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ProofManager {
|
||||
final private ProofDao proofDao;
|
||||
final private ProofRepository proofRepository;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package edu.msudenver.tsp.persistence.manager;
|
||||
|
||||
import edu.msudenver.tsp.persistence.dao.TheoremDao;
|
||||
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class TheoremManager {
|
||||
final private TheoremDao theoremDao;
|
||||
final private TheoremRepository theoremRepository;
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
|
||||
import edu.msudenver.tsp.persistence.entity.Definition;
|
||||
import edu.msudenver.tsp.persistence.entity.DefinitionEntity;
|
||||
import edu.msudenver.tsp.persistence.entity.Notation;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DefinitionRepository extends CrudRepository<DefinitionEntity, Integer> {
|
||||
|
||||
DefinitionEntity findByName(final String name);
|
||||
|
||||
DefinitionEntity findByDefinition(final Definition definition);
|
||||
|
||||
DefinitionEntity findByNotation(final Notation notation);
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
import edu.msudenver.tsp.persistence.entity.BaseEntity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface NotationRepository extends CrudRepository<BaseEntity, Long> {
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
import edu.msudenver.tsp.persistence.entity.BaseEntity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface ProofRepository extends CrudRepository<BaseEntity, Long> {
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package edu.msudenver.tsp.persistence.repository;
|
||||
|
||||
import edu.msudenver.tsp.persistence.entity.BaseEntity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface TheoremRepository extends CrudRepository<BaseEntity, Long> {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
spring.jpa.hibernate.ddl-auto=create
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/pandamonium
|
||||
spring.datasource.username=panda
|
||||
spring.datasource.password=secret
|
||||
Reference in New Issue
Block a user