From: Gustavo Martin Morcuende Date: Thu, 19 Jan 2017 13:09:01 +0000 (+0100) Subject: Using utf8mb4 :) X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=670dec24626830ee27591fe68f5adcd14ad8facf;p=JavaForFun Using utf8mb4 :) It is available since MySQL 5.5.3 http://dev.mysql.com/doc/refman/5.7/en/charset-unicode-utf8mb4.html --- diff --git a/MyBatis/MyBatis-Spring-ReuseBatchExecutor/README.txt b/MyBatis/MyBatis-Spring-ReuseBatchExecutor/README.txt index 2272363..83356ce 100644 --- a/MyBatis/MyBatis-Spring-ReuseBatchExecutor/README.txt +++ b/MyBatis/MyBatis-Spring-ReuseBatchExecutor/README.txt @@ -8,11 +8,11 @@ mvn dependency:resolve -Dclassifier=javadoc # I am using the mybatis-generator maven plugin. So, I need always a database (it would be better to use the Eclipse plugin) -mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8" +mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8mb4" -mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci" +mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci" -mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id SERIAL, laguage_id BIGINT NOT NULL, ad_id BIGINT(20) UNSIGNED NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci" +mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id SERIAL, laguage_id BIGINT NOT NULL, ad_id BIGINT(20) UNSIGNED NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci" # Run mvn clean install (mybatis-generator plugin creates autogenerated code from tables) mvn clean install @@ -21,7 +21,7 @@ mvn clean install mysql -uroot -proot -A -e "drop database mybatis_example" # Liquibase requires (AFAIK) of an existing schema -mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8" +mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8mb4" # Run TestMain.java :) diff --git a/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/resources/liquibase/ddlChangelog.xml b/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/resources/liquibase/ddlChangelog.xml index 8aef71d..9835794 100644 --- a/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/resources/liquibase/ddlChangelog.xml +++ b/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/resources/liquibase/ddlChangelog.xml @@ -21,7 +21,7 @@ it is inherited from schema to tables and rows) anyhow this is just an example of what you can do. --> - + @@ -51,7 +51,7 @@ it is inherited from schema to tables and rows) anyhow this is just an example of what you can do. --> - + diff --git a/MyBatis/MyBatis-Spring/README.txt b/MyBatis/MyBatis-Spring/README.txt index 2272363..83356ce 100644 --- a/MyBatis/MyBatis-Spring/README.txt +++ b/MyBatis/MyBatis-Spring/README.txt @@ -8,11 +8,11 @@ mvn dependency:resolve -Dclassifier=javadoc # I am using the mybatis-generator maven plugin. So, I need always a database (it would be better to use the Eclipse plugin) -mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8" +mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8mb4" -mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci" +mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci" -mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id SERIAL, laguage_id BIGINT NOT NULL, ad_id BIGINT(20) UNSIGNED NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci" +mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id SERIAL, laguage_id BIGINT NOT NULL, ad_id BIGINT(20) UNSIGNED NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci" # Run mvn clean install (mybatis-generator plugin creates autogenerated code from tables) mvn clean install @@ -21,7 +21,7 @@ mvn clean install mysql -uroot -proot -A -e "drop database mybatis_example" # Liquibase requires (AFAIK) of an existing schema -mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8" +mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8mb4" # Run TestMain.java :) diff --git a/MyBatis/MyBatis-Spring/src/main/resources/liquibase/ddlChangelog.xml b/MyBatis/MyBatis-Spring/src/main/resources/liquibase/ddlChangelog.xml index 8aef71d..9835794 100644 --- a/MyBatis/MyBatis-Spring/src/main/resources/liquibase/ddlChangelog.xml +++ b/MyBatis/MyBatis-Spring/src/main/resources/liquibase/ddlChangelog.xml @@ -21,7 +21,7 @@ it is inherited from schema to tables and rows) anyhow this is just an example of what you can do. --> - + @@ -51,7 +51,7 @@ it is inherited from schema to tables and rows) anyhow this is just an example of what you can do. --> - + diff --git a/MyBatis/MyBatis/createdatabase.sh b/MyBatis/MyBatis/createdatabase.sh index ef2bb57..aad1310 100755 --- a/MyBatis/MyBatis/createdatabase.sh +++ b/MyBatis/MyBatis/createdatabase.sh @@ -1,9 +1,9 @@ #!/bin/bash -mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8" +mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8mb4" -mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci" +mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci" # Por alguna extraña razon no pude poner el id de esta tabla como serial y no tiene ahora este id autoincrement # Daba un error raro diciendo que no podia haber 2 claves con autoincrement en la misma tabla. Pero sí se puede... # debo estar haciendo algo mal... :( -mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id BIGINT(20) UNSIGNED NOT NULL, laguage_id BIGINT NOT NULL, ad_id SERIAL NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci" +mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id BIGINT(20) UNSIGNED NOT NULL, laguage_id BIGINT NOT NULL, ad_id SERIAL NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci" diff --git a/SpringJava/DeadLocksSQL/src/main/database/example.sql b/SpringJava/DeadLocksSQL/src/main/database/example.sql index 498cfb6..07119db 100644 --- a/SpringJava/DeadLocksSQL/src/main/database/example.sql +++ b/SpringJava/DeadLocksSQL/src/main/database/example.sql @@ -7,7 +7,7 @@ /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; +/*!40101 SET NAMES utf8mb4 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; @@ -21,15 +21,15 @@ DROP TABLE IF EXISTS `children`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `children` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(500) COLLATE utf8_unicode_ci NOT NULL, + `name` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL, `parent_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), CONSTRAINT `children_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parents` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -48,12 +48,12 @@ UNLOCK TABLES; DROP TABLE IF EXISTS `parents`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `parents` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(500) COLLATE utf8_unicode_ci NOT NULL, + `name` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- diff --git a/SpringJava/Gradle/spring-jpa-bom/pom.xml b/SpringJava/Gradle/spring-jpa-bom/pom.xml new file mode 100644 index 0000000..780b4d2 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-bom/pom.xml @@ -0,0 +1,654 @@ + + + 4.0.0 + + + de.spring.jpa + spring-jpa + 1.0-SNAPSHOT + + + spring-jpa-bom + pom + SPRING JPA BOM + http://gumartinm.name + + Spring JPA BOM example. + + + Gustavo Martin Morcuende + https://www.gumartinm.name + + + scm:git:https://git.gumartinm.name/JavaForFun + https://git.gumartinm.name/JavaForFun + + + + UTF-8 + UTF-8 + 4.3.0.RELEASE + 4.1.3 + 2.10.4 + 3.0.1 + + + ${project.basedir}/target/jacoco-it.exec + ${project.basedir}/target/jacoco.exec + + false + true + + + + + development + + development + Desarrollo local + + + true + + + + integration + + integration + Integration + false + + + + production + + production + Production + false + + + + + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.6.1 + + + + org.apache.logging.log4j + log4j-core + 2.6.1 + + + + org.slf4j + jcl-over-slf4j + 1.7.21 + + + + + org.springframework + spring-context + ${spring.version} + + + + commons-logging + commons-logging + + + + + + javax.inject + javax.inject + 1 + + + + cglib + cglib + 2.2.2 + + + + + junit + junit + 4.12 + test + + + org.mockito + mockito-core + 2.0.43-beta + test + + + + + + + + org.springframework + spring-webmvc + ${spring.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-oxm + ${spring.version} + + + commons-logging + commons-logging + + + + + + + + javax.servlet + javax.servlet-api + 4.0.0-b01 + provided + + + + + com.fasterxml.jackson.core + jackson-databind + 2.8.1 + + + + + + org.springframework + spring-orm + ${spring.version} + + + commons-logging + commons-logging + + + + + + org.springframework.data + spring-data-jpa + 1.10.2.RELEASE + + + org.springframework + spring-beans + + + org.springframework + spring-jdbc + + + org.springframework + spring-orm + + + org.springframework + spring-core + + + org.springframework + spring-aop + + + org.springframework + spring-context + + + commons-logging + commons-logging + + + + + + org.hibernate + hibernate-entitymanager + 5.2.1.Final + + + + + org.hibernate + hibernate-envers + 5.2.1.Final + + + org.springframework.data + spring-data-envers + 1.0.2.RELEASE + + + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.8.1 + + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + 2.8.1 + + + + + + javax.validation + validation-api + 1.1.0.Final + + + org.hibernate + hibernate-validator + 5.2.4.Final + + + + + + com.querydsl + querydsl-apt + ${querydsl.version} + + + com.querydsl + querydsl-jpa + ${querydsl.version} + + + + + org.liquibase + liquibase-core + 3.5.1 + + + + + org.springframework + spring-test + ${spring.version} + test + + + + commons-logging + commons-logging + + + + + com.h2database + h2 + 1.4.192 + test + + + + + + + + + + com.mysema.maven + apt-maven-plugin + 1.0.4 + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.11 + + + org.apache.maven.plugins + maven-site-plugin + 3.5.1 + + + org.apache.maven.wagon + wagon-ssh + 2.10 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + ${project.build.sourceEncoding} + + + + maven-site-plugin + + + attach-descriptor + + attach-descriptor + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + + + ${project.description} + ${project.version} + ${project.organization.name} + ${project.description} + ${project.version} + ${project.organization.name} + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven.javadoc.version} + + true + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + -Xdoclint:none + + + + org.apache.maven.plugins + maven-source-plugin + ${maven.source.version} + + + attach-sources + package + + jar-no-fork + + + + + + org.jacoco + jacoco-maven-plugin + 0.7.7.201606060606 + + + + pre-unit-test + + prepare-agent + + + + ${jacoco.ut.execution.data.file} + + surefireArgLine + + + + + post-unit-test + test + + report + + + + ${jacoco.ut.execution.data.file} + + ${project.reporting.outputDirectory}/jacoco-ut + + + + + pre-integration-test + pre-integration-test + + prepare-agent + + + + ${jacoco.it.execution.data.file} + + failsafeArgLine + + + + + post-integration-test + post-integration-test + + report + + + + ${jacoco.it.execution.data.file} + + ${project.reporting.outputDirectory}/jacoco-it + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.jacoco + jacoco-maven-plugin + [0.5,) + + + prepare-agent + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + + org.apache.maven.surefire + surefire-junit47 + 2.19.1 + + + + + -Dfile.encoding=${project.build.sourceEncoding} + ${surefireArgLine} + + ${skip.unit.tests} + + + **/*IT.java + **/*IntegrationTest.java + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.19.1 + + + + integration-test + verify + + + + ${failsafeArgLine} + + + ${skip.integration.tests} + + **/*IT.java + **/*IntegrationTest.java + + + + + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.9 + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven.javadoc.version} + + + html + + + API for ${project.name} ${project.version} + API for ${project.name} ${project.version} + + + javadoc + aggregate + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.19.1 + + + + report-only + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.5 + + + + + diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/V1__Initial_Setup.sql b/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/V1__Initial_Setup.sql index 97d1948..712c05a 100644 --- a/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/V1__Initial_Setup.sql +++ b/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/V1__Initial_Setup.sql @@ -20,9 +20,9 @@ CREATE TABLE AD ( AD_GPS BLOB, AD_MOBILE_IMAGE VARCHAR(255), CREATED_AT TIMESTAMP DEFAULT NOW() NOT NULL, - UPDATED_AT TIMESTAMP DEFAULT '1970-01-01 00:00:01' NOT NULL, + UPDATED_AT TIMESTAMP DEFAULT '1971-01-01 00:00:01' NOT NULL, CONSTRAINT PK_AD PRIMARY KEY (ID) - ); + ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE AD_AUDITED ( @@ -41,7 +41,7 @@ CREATE TABLE AD_AUDITED ( createdAt_MODIFIED BOOLEAN(1), UPDATED_AT TIMESTAMP, updatedAt_MODIFIED BOOLEAN(1), - adDescriptions_MODIFIED BOOLEAN(1)); + adDescriptions_MODIFIED BOOLEAN(1)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE AD_DESCRIPTION ( @@ -53,7 +53,7 @@ CREATE TABLE AD_DESCRIPTION ( AD_MOBILE_TEXT VARCHAR(500) NOT NULL, AD_LINK VARCHAR(3000) NOT NULL, CONSTRAINT PK_AD_DESCRIPTION PRIMARY KEY (ID) - ); + ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -69,7 +69,7 @@ CREATE TABLE AD_DESCRIPTION_AUDITED ( AD_NAME VARCHAR(255), LANGUAGE_ID BIGINT, AD_ID BIGINT - ); + ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -78,7 +78,7 @@ CREATE TABLE CUSTOM_REVISION ( REVISION_DATE TIMESTAMP NOT NULL, USERNAME VARCHAR(255), CONSTRAINT PK_CUSTOM_REVISION PRIMARY KEY (ID) - ); + ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -94,33 +94,33 @@ CREATE TABLE AD ( COMPANY_ID bigint(20) DEFAULT NULL, COMPANY_CATEG_ID bigint(20) DEFAULT NULL, AD_GPS blob, - AD_MOBILE_IMAGE varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + AD_MOBILE_IMAGE varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, CREATED_AT timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - UPDATED_AT timestamp NOT NULL DEFAULT '1970-01-01 00:00:01', + UPDATED_AT timestamp NOT NULL DEFAULT '1971-01-01 00:00:01', PRIMARY KEY (ID) -); +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE AD_DESCRIPTION ( ID bigint(20) NOT NULL AUTO_INCREMENT, LANGUAGE_ID bigint(20) NOT NULL, AD_ID bigint(20) DEFAULT NULL, - AD_NAME varchar(255) COLLATE utf8_unicode_ci NOT NULL, - AD_DESCRIPTION longtext COLLATE utf8_unicode_ci, - AD_MOBILE_TEXT varchar(500) COLLATE utf8_unicode_ci NOT NULL, - AD_LINK varchar(3000) COLLATE utf8_unicode_ci NOT NULL, + AD_NAME varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, + AD_DESCRIPTION longtext COLLATE utf8mb4_unicode_ci, + AD_MOBILE_TEXT varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL, + AD_LINK varchar(3000) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (ID), KEY IND_01_AD_DESCRIPTION (AD_ID), CONSTRAINT FK_01_AD_DESCRIPTION FOREIGN KEY (AD_ID) REFERENCES AD (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE CUSTOM_REVISION ( ID bigint(20) NOT NULL AUTO_INCREMENT, REVISION_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - USERNAME varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + USERNAME varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (ID) -); +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE AD_AUDITED ( @@ -129,7 +129,7 @@ CREATE TABLE AD_AUDITED ( REVISION_TYPE tinyint(3) DEFAULT NULL, REVISION_END bigint(20) DEFAULT NULL, REVISION_END_TIMESTAMP datetime DEFAULT NULL, - AD_MOBILE_IMAGE varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + AD_MOBILE_IMAGE varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, adMobileImage_MODIFIED bit(1) DEFAULT NULL, COMPANY_CATEG_ID bigint(20) DEFAULT NULL, companyCategId_MODIFIED bit(1) DEFAULT NULL, @@ -145,7 +145,7 @@ CREATE TABLE AD_AUDITED ( KEY IND_02_AD_AUDITED (REVISION_END), CONSTRAINT FK_01_AD_AUDITED FOREIGN KEY (REVISION) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_02_AD_AUDITED FOREIGN KEY (REVISION_END) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- CREATE TABLE "MYBATIS_EXAMPLE"."AD_AUDITED" ("ID" BIGINT NOT NULL, "REVISION" BIGINT NOT NULL, "REVISION_TYPE" TINYINT(3), "REVISION_END" BIGINT, "REVISION_END_TIMESTAMP" TIMESTAMP, "AD_MOBILE_IMAGE" VARCHAR(255), "adMobileImage_MODIFIED" BOOLEAN(1), "COMPANY_CATEG_ID" BIGINT, "companyCategId_MODIFIED" BOOLEAN(1), "COMPANY_ID" BIGINT, "companyId_MODIFIED" BOOLEAN(1), "CREATED_AT" TIMESTAMP, "createdAt_MODIFIED" BOOLEAN(1), "UPDATED_AT" TIMESTAMP, "updatedAt_MODIFIED" BOOLEAN(1), "adDescriptions_MODIFIED" BOOLEAN(1)) @@ -159,10 +159,10 @@ CREATE TABLE AD_DESCRIPTION_AUDITED ( REVISION_TYPE tinyint(3) DEFAULT NULL, REVISION_END bigint(20) DEFAULT NULL, REVISION_END_TIMESTAMP datetime DEFAULT NULL, - AD_DESCRIPTION varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - AD_LINK varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - AD_MOBILE_TEXT varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - AD_NAME varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + AD_DESCRIPTION varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + AD_LINK varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + AD_MOBILE_TEXT varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + AD_NAME varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, LANGUAGE_ID bigint(20) DEFAULT NULL, AD_ID bigint(20) DEFAULT NULL, PRIMARY KEY (ID,REVISION), @@ -170,7 +170,7 @@ CREATE TABLE AD_DESCRIPTION_AUDITED ( KEY IND_02_AD_DESCRIPTION_AUDITED (REVISION_END), CONSTRAINT FK_01_AD_DESCRIPTION_AUDITED FOREIGN KEY (REVISION) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_02_AD_DESCRIPTION_AUDITED FOREIGN KEY (REVISION_END) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml b/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml index 5c53eb9..dc82bf1 100644 --- a/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml +++ b/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml @@ -6,19 +6,19 @@ - CREATE TABLE VERSIONA (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci + CREATE TABLE VERSIONA (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci - CREATE TABLE VERSIONB (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci + CREATE TABLE VERSIONB (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci - CREATE TABLE VERSIONC (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci + CREATE TABLE VERSIONC (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8mb4, COLLATE=utf8mb4_unicode_ci --> @@ -40,7 +40,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -113,7 +113,7 @@ - + @@ -127,7 +127,7 @@ - + diff --git a/SpringJava/Gradle/spring-jpa-services/build.gradle b/SpringJava/Gradle/spring-jpa-services/build.gradle new file mode 100644 index 0000000..ab4ecf8 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/build.gradle @@ -0,0 +1,9 @@ +dependencies { + + compile(project(":spring-jpa-persistence")) + + testCompile('org.springframework:spring-test:4.3.0.RELEASE') { + exclude group: 'commons-logging', module: 'commons-logging' + } + +} diff --git a/SpringJava/Gradle/spring-jpa-services/pom.xml b/SpringJava/Gradle/spring-jpa-services/pom.xml new file mode 100644 index 0000000..06bbfaa --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/pom.xml @@ -0,0 +1,31 @@ + + 4.0.0 + + + de.spring.jpa + spring-jpa-bom + 1.0-SNAPSHOT + + + spring-jpa-services + SPRING JPA SERVICES + https://gumartinm.name/ + JPA Spring Framework. Services. + + + + + de.spring.jpa + spring-jpa-persistence + 1.0-SNAPSHOT + + + + + org.springframework + spring-test + test + + + diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdDescriptionRevisionService.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdDescriptionRevisionService.java new file mode 100644 index 0000000..498068c --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdDescriptionRevisionService.java @@ -0,0 +1,8 @@ +package de.spring.example.services; + +import de.spring.example.persistence.domain.AdDescription; + +public interface AdDescriptionRevisionService + extends RevisionService { + +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdDescriptionService.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdDescriptionService.java new file mode 100644 index 0000000..0a3dc1e --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdDescriptionService.java @@ -0,0 +1,22 @@ +package de.spring.example.services; + +import org.resthub.common.service.CrudService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.history.Revision; + +import de.spring.example.persistence.domain.AdDescription; + +public interface AdDescriptionService extends CrudService { + + public Page queryDslExample(Pageable pageRequest); + + /** + * Returns a {@link Page} of revisions for the entity with the given id. + * + * @param id must not be {@literal null}. + * @param pageable page request. + * @return a new {@link Page} with the content of the current one mapped by the given {@link Pageable}. + */ + Page> findRevisions(Long id, Pageable pageable); +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdService.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdService.java new file mode 100644 index 0000000..c491be8 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/AdService.java @@ -0,0 +1,12 @@ +package de.spring.example.services; + +import org.resthub.common.service.CrudService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import de.spring.example.persistence.domain.Ad; + +public interface AdService extends CrudService { + + public Page queryCriteriaExample(Pageable pageRequest); +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/RevisionService.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/RevisionService.java new file mode 100644 index 0000000..4e184fc --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/RevisionService.java @@ -0,0 +1,19 @@ +package de.spring.example.services; + +import java.io.Serializable; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.history.Revision; + +public interface RevisionService> { + + /** + * Returns a {@link Page} of revisions for the entity with the given id. + * + * @param id must not be {@literal null}. + * @param pageable page request. + * @return a new {@link Page} with the content of the current one mapped by the given {@link Pageable}. + */ + Page> findRevisions(ID id, Pageable pageable); +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdDescriptionRevisionServiceImpl.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdDescriptionRevisionServiceImpl.java new file mode 100644 index 0000000..8aec9e3 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdDescriptionRevisionServiceImpl.java @@ -0,0 +1,20 @@ +package de.spring.example.services.impl; + +import javax.inject.Inject; +import javax.inject.Named; + +import de.spring.example.persistence.domain.AdDescription; +import de.spring.example.persistence.repository.AdDescriptionRepository; +import de.spring.example.services.AdDescriptionRevisionService; + +@Named("adDescriptionRevisionService") +public class AdDescriptionRevisionServiceImpl + extends RevisionServiceImpl + implements AdDescriptionRevisionService { + + @Override + @Inject + public void setRepository(AdDescriptionRepository repository) { + this.repository = repository; + } +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdDescriptionServiceImpl.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdDescriptionServiceImpl.java new file mode 100644 index 0000000..39c1bcc --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdDescriptionServiceImpl.java @@ -0,0 +1,60 @@ +package de.spring.example.services.impl; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.resthub.common.service.CrudServiceImpl; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.history.Revision; + +import com.querydsl.core.types.dsl.BooleanExpression; + +import de.spring.example.persistence.domain.AdDescription; +import de.spring.example.persistence.domain.QAdDescription; +import de.spring.example.persistence.repository.AdDescriptionRepository; +import de.spring.example.services.AdDescriptionService; + +@Named("adDescriptionService") +public class AdDescriptionServiceImpl + extends CrudServiceImpl + implements AdDescriptionService { + + @Override + @Inject + public void setRepository(AdDescriptionRepository repository) { + this.repository = repository; + } + + // Extending CrudServiceImpl when we need some business logic. Otherwise we would be using + // the JPA repositories and nothing else :) + + // In this case there is any business logic, but this is just an example. + + + /** + * Using Querydsl. Giving some business logic to this service :) + * + * Querydsl: fluent interface done easy. There is no effort because it is already implemented. + * + * Criteria using Specifications requires some effort. + * + * See: de.spring.example.services.impl.AdServiceImpl + */ + @Override + public Page queryDslExample(Pageable pageRequest) { + final QAdDescription adDescription = QAdDescription.adDescription1; + final BooleanExpression adDescriptionHasAdLink = adDescription.adLink.contains("gumartinm"); + final BooleanExpression adDescriptionHasDescription = adDescription.adDescription.contains("babucha"); + /** + * https://github.com/spring-projects/spring-data-envers/pull/45 + * return repository.findAll(adDescriptionHasAdLink.and(adDescriptionHasDescription), pageRequest); + */ + return null; + } + + @Override + public Page> findRevisions(Long id, Pageable pageable) { + return this.repository.findRevisions(id, pageable); + } +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdServiceImpl.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdServiceImpl.java new file mode 100644 index 0000000..05c416e --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/AdServiceImpl.java @@ -0,0 +1,43 @@ +package de.spring.example.services.impl; + +import static org.springframework.data.jpa.domain.Specifications.where; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.resthub.common.service.CrudServiceImpl; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import de.spring.example.persistence.domain.Ad; +import de.spring.example.persistence.domain.specifications.AdSpectifications; +import de.spring.example.persistence.repository.AdRepository; +import de.spring.example.services.AdService; + +@Named("adService") +public class AdServiceImpl + extends CrudServiceImpl + implements AdService { + + @Override + @Inject + public void setRepository(AdRepository repository) { + this.repository = repository; + } + + /** + * Criteria using Specifications. + * + * It is more complicated than when using Querydsl because I have to implement the + * Specifications. Querydsl is doing everything for me. + * + * See: de.spring.example.services.impl.AdDescriptionServiceImpl + */ + @Override + public Page queryCriteriaExample(Pageable pageRequest) { + return repository.findAll( + where(AdSpectifications.createdToday()).and(AdSpectifications.mobileImage("picasso")), + pageRequest); + } + +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/RevisionServiceImpl.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/RevisionServiceImpl.java new file mode 100644 index 0000000..6e587c3 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/de/spring/example/services/impl/RevisionServiceImpl.java @@ -0,0 +1,38 @@ +package de.spring.example.services.impl; + +import java.io.Serializable; + +import javax.inject.Named; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.history.Revision; +import org.springframework.data.repository.history.RevisionRepository; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; + +import de.spring.example.services.RevisionService; + +@Named("revisionService") +public class RevisionServiceImpl, R extends RevisionRepository> + implements RevisionService { + + protected R repository; + + /** + * @param repository the repository to set + */ + public void setRepository(R repository) { + this.repository = repository; + } + + @Override + @Transactional + public Page> findRevisions(ID id, Pageable pageable) { + Assert.notNull(pageable, "page request can't be null"); + Assert.notNull(id, "Resource ID can't be null"); + + return this.repository.findRevisions(id, pageable); + } + +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/org/resthub/common/service/CrudService.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/org/resthub/common/service/CrudService.java new file mode 100644 index 0000000..7f482e6 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/org/resthub/common/service/CrudService.java @@ -0,0 +1,94 @@ +package org.resthub.common.service; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.io.Serializable; +import java.util.Set; + +/** + * CRUD Service interface. + * + * @param Your resource POJO to manage, maybe an entity or DTO class + * @param Resource id type, usually Long or String + */ +public interface CrudService { + + /** + * Create new resource. + * + * @param resource Resource to create + * @return new resource + */ + T create(T resource); + + /** + * Update existing resource. + * + * @param resource Resource to update + * @return resource updated + */ + T update(T resource); + + /** + * Delete existing resource. + * + * @param resource Resource to delete + */ + void delete(T resource); + + /** + * Delete existing resource. + * + * @param id Resource id + */ + void delete(ID id); + + /** + * Delete all existing resource. Do not use cascade remove (not a choice -> JPA specs) + */ + void deleteAll(); + + /** + * Delete all existing resource, including linked entities with cascade delete + */ + void deleteAllWithCascade(); + + /** + * Find resource by id. + * + * @param id Resource id + * @return resource + */ + T findById(ID id); + + /** + * Find resources by their ids. + * + * @param ids Resource ids + * @return a list of retrieved resources, empty if no resource found + */ + Iterable findByIds(Set ids); + + /** + * Find all resources. + * + * @return a list of all resources. + */ + Iterable findAll(); + + /** + * Find all resources (pageable). + * + * @param pageRequest page request. + * @return a new {@link Page} with the content of the current one mapped by the given {@link Pageable}. + */ + Page findAll(Pageable pageRequest); + + /** + * Count all resources. + * + * @return number of resources + */ + Long count(); +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/java/org/resthub/common/service/CrudServiceImpl.java b/SpringJava/Gradle/spring-jpa-services/src/main/java/org/resthub/common/service/CrudServiceImpl.java new file mode 100644 index 0000000..b623bf3 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/java/org/resthub/common/service/CrudServiceImpl.java @@ -0,0 +1,138 @@ +package org.resthub.common.service; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; + +import java.io.Serializable; +import java.util.Set; + +/** + * CRUD service that uses a {@link org.springframework.data.repository.PagingAndSortingRepository} Spring Data repository implementation + * + * You should extend it and inject your Repository bean by overriding {@link #setRepository(org.springframework.data.repository.PagingAndSortingRepository)} + * + * @param Your resource class to manage, usually an entity class + * @param Resource id type, usually Long or String + * @param The repository class + */ +@Transactional(readOnly = true) +public class CrudServiceImpl> implements + CrudService { + + protected R repository; + + /** + * @param repository the repository to set + */ + public void setRepository(R repository) { + this.repository = repository; + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public T create(T resource) { + Assert.notNull(resource, "Resource can't be null"); + return repository.save(resource); + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public T update(T resource) { + Assert.notNull(resource, "Resource can't be null"); + return repository.save(resource); + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public void delete(T resource) { + Assert.notNull(resource, "Resource can't be null"); + repository.delete(resource); + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public void delete(ID id) { + Assert.notNull(id, "Resource ID can't be null"); + repository.delete(id); + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public void deleteAll() { + repository.deleteAll(); + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public void deleteAllWithCascade() { + Iterable list = repository.findAll(); + for (T entity : list) { + repository.delete(entity); + } + } + + /** + * {@inheritDoc} + */ + @Override + public T findById(ID id) { + Assert.notNull(id, "Resource ID can't be null"); + return repository.findOne(id); + } + + /** + * {@inheritDoc} + */ + @Override + public Iterable findByIds(Set ids) { + Assert.notNull(ids, "Resource ids can't be null"); + return repository.findAll(ids); + } + + /** + * {@inheritDoc} + */ + @Override + public Iterable findAll() { + return repository.findAll(); + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public Page findAll(Pageable pageRequest) { + Assert.notNull(pageRequest, "page request can't be null"); + return repository.findAll(pageRequest); + } + + /** + * {@inheritDoc} + */ + @Override + public Long count() { + return repository.count(); + } +} diff --git a/SpringJava/Gradle/spring-jpa-services/src/main/resources/spring-configuration/configuration.xml b/SpringJava/Gradle/spring-jpa-services/src/main/resources/spring-configuration/configuration.xml new file mode 100644 index 0000000..82009fb --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/main/resources/spring-configuration/configuration.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file