Merge branch 'v0.0.2'
This commit is contained in:
commit
4c6f1e0b84
551
pom.xml
551
pom.xml
@ -12,24 +12,11 @@
|
||||
<name>Tigon</name>
|
||||
<description>Tigon</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>0.0.2-RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<spring.version>4.3.8.RELEASE</spring.version>
|
||||
<spring-boot.version>1.5.10.RELEASE</spring-boot.version>
|
||||
<slf4j.version>1.7.23</slf4j.version>
|
||||
<log4j.version>2.7</log4j.version>
|
||||
<shiro.version>1.3.2</shiro.version>
|
||||
<aspectj.version>1.8.10</aspectj.version>
|
||||
<main.class>Main</main.class>
|
||||
<maven.tomcat.port>8080</maven.tomcat.port>
|
||||
<maven.tomcat.path>/</maven.tomcat.path>
|
||||
<spring.version>5.0.7.RELEASE</spring.version>
|
||||
<spring-boot.version>2.0.3.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
@ -48,36 +35,24 @@
|
||||
</developers>
|
||||
|
||||
<modules>
|
||||
<!--<module>tigon-lombok</module>-->
|
||||
<module>tigon-model</module>
|
||||
<module>tigon-mybatis</module>
|
||||
<module>tigon-sequence</module>
|
||||
<module>tigon-redis</module>
|
||||
<module>tigon-mybatis-cache-redis</module>
|
||||
<module>tigon-shiro-cache</module>
|
||||
<module>tigon-shiro-cache-redis</module>
|
||||
<module>tigon-webmvc-core</module>
|
||||
<module>tigon-webmvc-spring-boot</module>
|
||||
<module>tigon-webmvc-war</module>
|
||||
<module>tigon-shiro-core</module>
|
||||
<module>tigon-shiro-spring-boot</module>
|
||||
<module>tigon-shiro-war</module>
|
||||
<module>tigon-shiro-cas</module>
|
||||
<module>tigon-shiro</module>
|
||||
<module>tigon-web</module>
|
||||
<module>tigon-service-api</module>
|
||||
<module>tigon-service-support</module>
|
||||
<module>tigon-props-config</module>
|
||||
<module>tigon-extjs</module>
|
||||
<module>tigon-freemarker-support</module>
|
||||
<module>tigon-jsp-support</module>
|
||||
<module>tigon-codegen</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-lombok</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-model</artifactId>
|
||||
@ -95,22 +70,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-webmvc-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-webmvc-spring-boot</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-webmvc-war</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-redis</artifactId>
|
||||
<artifactId>tigon-web</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -120,12 +80,12 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache-redis</artifactId>
|
||||
<artifactId>tigon-shiro-cache</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache</artifactId>
|
||||
<artifactId>tigon-shiro-cache-redis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -135,12 +95,12 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-spring-boot</artifactId>
|
||||
<artifactId>tigon-shiro</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-war</artifactId>
|
||||
<artifactId>tigon-shiro-cas</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -158,112 +118,31 @@
|
||||
<artifactId>tigon-extjs</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-freemarker-support</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-jsp-support</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-codegen</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-props-config</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>5.4.0.Final</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.3</version>
|
||||
</dependency>
|
||||
<!-- mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<!-- /mybatis -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.0.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>bson</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-core -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-web</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib</artifactId>
|
||||
<version>3.2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
<version>1.18.0</version>
|
||||
</dependency>
|
||||
<!-- Spring Boot -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-releasetrain</artifactId>
|
||||
<version>Kay-SR2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
@ -272,366 +151,33 @@
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib</artifactId>
|
||||
<version>3.2.4</version>
|
||||
</dependency>
|
||||
<!-- / Spring Boot -->
|
||||
<dependency>
|
||||
<groupId>org.jdom</groupId>
|
||||
<artifactId>jdom</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.31</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.23</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<!-- test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- java web -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp.jstl</groupId>
|
||||
<artifactId>jstl-api</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.coderplus.maven.plugins</groupId>
|
||||
<artifactId>copy-rename-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.10</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>
|
||||
target/lib
|
||||
</outputDirectory>
|
||||
<excludeScope>provided</excludeScope>
|
||||
<includeScope>runtime</includeScope>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Built-By>Shaun Chyxion</Built-By>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>${main.class}</mainClass>
|
||||
</transformer>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/spring.handlers</resource>
|
||||
</transformer>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/spring.schemas</resource>
|
||||
</transformer>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/spring.tooling</resource>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>2.6.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>remove-config-file</id>
|
||||
<goals><goal>clean</goal></goals>
|
||||
<phase>compile</phase>
|
||||
<configuration>
|
||||
<excludeDefaultDirectories>true</excludeDefaultDirectories>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>src/main/resources/spring</directory>
|
||||
<includes>
|
||||
<include>config.properties</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
<fileset>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>application.properties</include>
|
||||
<include>application.yaml</include>
|
||||
<include>log4j2.xml</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.coderplus.maven.plugins</groupId>
|
||||
<artifactId>copy-rename-maven-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-config-props-file</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceFile>src/main/resources/config_${project.activeProfiles[0].id}.properties</sourceFile>
|
||||
<destinationFile>src/main/resources/spring/config.properties</destinationFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-application-props-file</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceFile>src/main/resources/application_${project.activeProfiles[0].id}.properties</sourceFile>
|
||||
<destinationFile>src/main/resources/application.properties</destinationFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-application-yaml-file</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceFile>src/main/resources/application_${project.activeProfiles[0].id}.yaml</sourceFile>
|
||||
<destinationFile>src/main/resources/application.yaml</destinationFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-log4j2-xml-file</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceFile>src/main/resources/log4j2_${project.activeProfiles[0].id}.xml</sourceFile>
|
||||
<destinationFile>src/main/resources/log4j2.xml</destinationFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<version>3.0</version>
|
||||
<webResources>
|
||||
<resource>
|
||||
<directory>src/main/webapp</directory>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.tomcat.maven</groupId>
|
||||
<artifactId>tomcat7-maven-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<port>${maven.tomcat.port}</port>
|
||||
<path>${maven.tomcat.path}</path>
|
||||
<charset>utf-8</charset>
|
||||
<uriEncoding>utf-8</uriEncoding>
|
||||
<contextReloadable>false</contextReloadable>
|
||||
<systemProperties>
|
||||
<http.port>${maven.tomcat.port}</http.port>
|
||||
<project.basedir>${project.basedir}</project.basedir>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<configuration>
|
||||
<addResources>true</addResources>
|
||||
<mainClass>${start-class}</mainClass>
|
||||
<layout>ZIP</layout>
|
||||
<jvmArguments>
|
||||
-Xdebug
|
||||
-Dproject.basedir=${project.basedir}
|
||||
</jvmArguments>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
@ -641,37 +187,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-help-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<versionRange>
|
||||
[2.6.1,)
|
||||
</versionRange>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit a7c690619e09fae1d48584794d68d1b8ee78c197
|
@ -1 +0,0 @@
|
||||
Subproject commit a7c690619e09fae1d48584794d68d1b8ee78c197
|
@ -17,10 +17,19 @@
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<spring-boot.run.main-class>me.chyxion.tigon.codegen.TigonCodeGen</spring-boot.run.main-class>
|
||||
<mainClass>me.chyxion.tigon.codegen.TigonCodeGen</mainClass>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-freemarker-support</artifactId>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
@ -28,29 +37,32 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-webmvc-core</artifactId>
|
||||
<artifactId>tigon-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-service-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<!-- mybatis -->
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-mybatis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
@ -58,14 +70,23 @@
|
||||
</dependency>
|
||||
<!-- /mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>codegen</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
<fork>true</fork>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -0,0 +1,23 @@
|
||||
package me.chyxion.tigon.codegen;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 24, 2018 20:43:36
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class TigonCodeGen {
|
||||
|
||||
/**
|
||||
* @param args start args
|
||||
*/
|
||||
public static void main(final String[] args) {
|
||||
log.info("Startup args [{}].", args);
|
||||
SpringApplication.run(TigonCodeGen.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package me.chyxion.tigon.codegen;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 24, 2018 20:58:08
|
||||
*/
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/assets/**")
|
||||
.addResourceLocations("/assets/", "classpath:webapp/assets/");
|
||||
}
|
||||
}
|
@ -9,9 +9,11 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenService;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenBaseTool;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@ -35,11 +37,16 @@ public class CodeGenController {
|
||||
private CodeGenService service;
|
||||
@Autowired
|
||||
private CodeGenBaseTool tool;
|
||||
@Value("${codegen.components:}")
|
||||
private String genComponents;
|
||||
|
||||
@RequestMapping(method = GET)
|
||||
public ModelAndView index() {
|
||||
return new ModelAndView("webapp/views/codegen")
|
||||
.addObject("pkg", tool.getPkg());
|
||||
.addObject("pkg", tool.getPkg())
|
||||
.addObject("components",
|
||||
StringUtils.isNotBlank(genComponents) ?
|
||||
JSON.toJSONString(genComponents.split("\\s*[,;]\\s*")) : "[]");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/tables")
|
||||
|
@ -1,8 +1,7 @@
|
||||
package me.chyxion.tigon.freemarker;
|
||||
package me.chyxion.tigon.codegen.freemarker;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
|
||||
@ -13,9 +12,8 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
* chyxion@163.com <br>
|
||||
* Dec 5, 2014 2:31:39 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(FreeMarkerViewResolverExt.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -23,7 +21,7 @@ public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
|
||||
@Override
|
||||
public View resolveViewName(String viewName, Locale locale)
|
||||
throws Exception {
|
||||
log.debug("Try To Resolve View Name [{}], Locale [{}] As FreeMarker View.", viewName, locale);
|
||||
return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl\\:)|(\\.ftl\\s*$)", ""), locale);
|
||||
log.debug("Try to resolve view name [{}], locale [{}] as freemarker view.", viewName, locale);
|
||||
return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl:)|(\\.ftl\\s*$)", ""), locale);
|
||||
}
|
||||
}
|
@ -1,41 +1,25 @@
|
||||
package me.chyxion.tigon.codegen.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import org.slf4j.Logger;
|
||||
import java.util.TreeSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.*;
|
||||
import java.io.FileWriter;
|
||||
import java.sql.ResultSet;
|
||||
import org.w3c.dom.Element;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
import java.util.LinkedList;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
import java.io.FileInputStream;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import java.io.InputStreamReader;
|
||||
import me.chyxion.tigon.model.M1;
|
||||
import freemarker.template.Template;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import me.chyxion.tigon.util.WordUtils;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.CharEncoding;
|
||||
import me.chyxion.tigon.codegen.utils.DbTool;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import me.chyxion.tigon.codegen.util.DbTool;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@ -46,7 +30,6 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
|
||||
import static org.springframework.context.ConfigurableApplicationContext.*;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
|
||||
/**
|
||||
@ -56,92 +39,21 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
* chyxion@163.com <br>
|
||||
* Dec 3, 2014 11:25:17 AM
|
||||
*/
|
||||
@Slf4j
|
||||
public class CodeGenBaseTool {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(CodeGenBaseTool.class);
|
||||
|
||||
@Autowired
|
||||
private FreeMarkerConfigurer fmCfg;
|
||||
@Autowired(required = false)
|
||||
private DataSource dataSource;
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTpl;
|
||||
@Value("#{systemProperties['project.basedir']}")
|
||||
@Value("${project.base-dir}")
|
||||
private String projDir;
|
||||
private String groupId;
|
||||
@Value("${project.base-package}")
|
||||
private String pkg;
|
||||
private Properties config = new Properties();
|
||||
private Set<String> baseCols = new HashSet<String>();
|
||||
@Value("${codegen.table-prefix:}")
|
||||
private String tablePrefix;
|
||||
|
||||
/**
|
||||
* @param col
|
||||
* @return true if col is base col
|
||||
*/
|
||||
public boolean isBaseCol(String col) {
|
||||
return baseCols.contains(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public String getConfig(String key) {
|
||||
return config.getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public String getConfig(String key, String defaultValue) {
|
||||
return config.getProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* get config
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public boolean getConfig(String key, boolean defaultValue) {
|
||||
return Boolean.valueOf(getConfig(key, String.valueOf(defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public int getConfig(String key, int defaultValue) {
|
||||
return Integer.valueOf(getConfig(key, String.valueOf(defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public long getConfig(String key, long defaultValue) {
|
||||
return Long.valueOf(getConfig(key, String.valueOf(defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public double getConfig(String key, double defaultValue) {
|
||||
return Double.valueOf(getConfig(key, String.valueOf(defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public float getConfig(String key, float defaultValue) {
|
||||
return Float.valueOf(getConfig(key, String.valueOf(defaultValue)));
|
||||
}
|
||||
private Set<String> baseCols = new HashSet<>();
|
||||
|
||||
/**
|
||||
* @return the projDir
|
||||
@ -150,13 +62,6 @@ public class CodeGenBaseTool {
|
||||
return projDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the groupId
|
||||
*/
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the groupId
|
||||
*/
|
||||
@ -193,63 +98,6 @@ public class CodeGenBaseTool {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* init config
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
// disable cache
|
||||
log.info("Disable FreeMarker Cache In Dev Mode.");
|
||||
fmCfg.getConfiguration().setTemplateUpdateDelayMilliseconds(0);
|
||||
if (dataSource != null) {
|
||||
jdbcTpl = new JdbcTemplate(dataSource, true);
|
||||
}
|
||||
|
||||
try {
|
||||
log.info("Parse Group ID From [{}/pom.xml].", projDir);
|
||||
Element root = DocumentBuilderFactory.newInstance()
|
||||
.newDocumentBuilder()
|
||||
.parse(new File(projDir, "pom.xml"))
|
||||
.getDocumentElement();
|
||||
root.normalize();
|
||||
groupId = root.getElementsByTagName("groupId").item(0).getTextContent().trim();
|
||||
log.info("Group ID [{}] Found.", groupId);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Parse [groupId] From Maven POM File [" + projDir + "/pom.xml] Error Caused", e);
|
||||
}
|
||||
|
||||
InputStream cfgIns = CodeGenBaseTool.class
|
||||
.getResourceAsStream("/codegen/config.properties");
|
||||
if (cfgIns != null) {
|
||||
try {
|
||||
config.load(cfgIns);
|
||||
log.info("Code Gen Config [{}] Found.", config);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Load Code Gen Config Error Caused", e);
|
||||
}
|
||||
finally {
|
||||
IOUtils.closeQuietly(cfgIns);
|
||||
}
|
||||
}
|
||||
|
||||
baseCols.add("id");
|
||||
String baseColsProp = config.getProperty("base.cols");
|
||||
if (StringUtils.isNotBlank(baseColsProp)) {
|
||||
log.info("Code Gen Base Cols [{}] Found.", baseColsProp);
|
||||
baseCols.addAll(Arrays.asList(
|
||||
org.springframework.util.StringUtils
|
||||
.tokenizeToStringArray(
|
||||
baseColsProp, CONFIG_LOCATION_DELIMITERS, true, true)));
|
||||
}
|
||||
log.info("Code Gen Base Cols [{}] Result.", baseCols);
|
||||
pkg = config.getProperty("base.package", groupId);
|
||||
log.info("Code Gen Package [{}].", pkg);
|
||||
}
|
||||
|
||||
/**
|
||||
* list all model generated
|
||||
* @return
|
||||
@ -270,7 +118,7 @@ public class CodeGenBaseTool {
|
||||
FileInputStream fin = null;
|
||||
try {
|
||||
fin = new FileInputStream(file);
|
||||
mapData = JSON.parseObject(IOUtils.toString(fin, CharEncoding.UTF_8));
|
||||
mapData = JSON.parseObject(IOUtils.toString(fin, StandardCharsets.UTF_8));
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.info("Parse JSON File [{}] ERROR Caused.", file.getName());
|
||||
@ -284,7 +132,7 @@ public class CodeGenBaseTool {
|
||||
// backup data file
|
||||
IOUtils.copy(fin,
|
||||
new FileWriter(new File(projDir, backupFileName)),
|
||||
CharEncoding.UTF_8);
|
||||
StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
catch (IOException e1) {
|
||||
@ -296,8 +144,8 @@ public class CodeGenBaseTool {
|
||||
}
|
||||
}
|
||||
if (mapData == null) {
|
||||
mapData = new HashMap<String, Object>();
|
||||
mapData.put("items", new LinkedList<Object>());
|
||||
mapData = new HashMap<>();
|
||||
mapData.put("items", new LinkedList<>());
|
||||
}
|
||||
return mapData;
|
||||
}
|
||||
@ -309,7 +157,7 @@ public class CodeGenBaseTool {
|
||||
FileUtils.write(file, JSON.toJSONStringWithDateFormat(storeData,
|
||||
"yyyy-MM-dd HH:mm:ss",
|
||||
SerializerFeature.PrettyFormat),
|
||||
CharEncoding.UTF_8);
|
||||
StandardCharsets.UTF_8);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException("Write Data To File [" + file.getAbsolutePath() + "] ERROR Caused.", e);
|
||||
@ -371,7 +219,7 @@ public class CodeGenBaseTool {
|
||||
execSQL("drop table " + item.get("table"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.info("Drop Table Error Caused.", e);
|
||||
log.info("Drop table error caused.", e);
|
||||
}
|
||||
}
|
||||
it.remove();
|
||||
@ -392,7 +240,7 @@ public class CodeGenBaseTool {
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(
|
||||
new Template(ftl, new InputStreamReader(
|
||||
CodeGenBaseTool.class.getResourceAsStream(ftl),
|
||||
CharEncoding.UTF_8), fmCfg.getConfiguration()), model);
|
||||
StandardCharsets.UTF_8), fmCfg.getConfiguration()), model);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Code Generate Render ERROR, [" + e.getMessage() + "].", e);
|
||||
@ -410,9 +258,6 @@ public class CodeGenBaseTool {
|
||||
try {
|
||||
DatabaseMetaData md = conn.getMetaData();
|
||||
rs = md.getTables(null, null, "%", new String[] {"TABLE"});
|
||||
String tablePrefix =
|
||||
config.getProperty("table.prefix", "")
|
||||
.toLowerCase();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> mapTable = new HashMap<String, Object>();
|
||||
String table = rs.getString(3).toLowerCase();
|
||||
@ -422,7 +267,7 @@ public class CodeGenBaseTool {
|
||||
String[] tableNameParts = null;
|
||||
if (StringUtils.isNotBlank(tablePrefix) &&
|
||||
table.startsWith(tablePrefix + "_")) {
|
||||
log.info("Table Prefix [{}] Found, Trim.", tablePrefix);
|
||||
log.info("Table prefix [{}] found, trim.", tablePrefix);
|
||||
tableNameParts =
|
||||
table.substring(tablePrefix.length() + 1)
|
||||
.split("_");
|
||||
@ -451,7 +296,7 @@ public class CodeGenBaseTool {
|
||||
}
|
||||
});
|
||||
}
|
||||
return new LinkedList<Map<String, Object>>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// --
|
||||
@ -468,9 +313,7 @@ public class CodeGenBaseTool {
|
||||
col.put("isKey", keys.contains(colName));
|
||||
col.put("isIndex", indexes.contains(colName));
|
||||
col.put("col", colName);
|
||||
col.put("name",
|
||||
StringUtils.uncapitalize(
|
||||
WordUtils.convertToCamelCase(colName, "_")));
|
||||
col.put("name", WordUtils.toCamel(colName));
|
||||
int size = rs.getInt("COLUMN_SIZE");
|
||||
col.put("size", size);
|
||||
String type = rs.getString("TYPE_NAME").toLowerCase();
|
||||
|
@ -1,10 +1,10 @@
|
||||
package me.chyxion.tigon.codegen.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.CharEncoding;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import me.chyxion.tigon.codegen.CodeGenCustomizer;
|
||||
import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -57,7 +57,7 @@ public abstract class CodeGenerator {
|
||||
// write result
|
||||
FileUtils.write(new File(baseTool.getProjDir(), args.getFile()),
|
||||
baseTool.renderFtl(args.getFtl(), args.getModel()),
|
||||
CharEncoding.UTF_8);
|
||||
StandardCharsets.UTF_8);
|
||||
return args.getFile();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -1,38 +1,42 @@
|
||||
package me.chyxion.tigon.codegen.service.support;
|
||||
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
import me.chyxion.tigon.service.BaseCrudService;
|
||||
import me.chyxion.tigon.service.BaseService;
|
||||
import me.chyxion.tigon.service.support.BaseCrudServiceSupport;
|
||||
import me.chyxion.tigon.util.WordUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import me.chyxion.tigon.codegen.controller.CodeGenController.GenForm;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenBaseTool;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenService;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import java.text.DateFormat;
|
||||
import me.chyxion.tigon.model.M0;
|
||||
import me.chyxion.tigon.model.M1;
|
||||
import me.chyxion.tigon.model.M2;
|
||||
import me.chyxion.tigon.model.M3;
|
||||
import me.chyxion.tigon.webmvc.test.ControllerTestTool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.lang.reflect.Modifier;
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
import me.chyxion.tigon.util.WordUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import me.chyxion.tigon.service.BaseService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import me.chyxion.tigon.service.BaseCrudService;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
import me.chyxion.tigon.webmvc.test.ControllerTestTool;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenService;
|
||||
import me.chyxion.tigon.codegen.service.CodeGenBaseTool;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import me.chyxion.tigon.service.support.BaseCrudServiceSupport;
|
||||
import me.chyxion.tigon.codegen.controller.CodeGenController.GenForm;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
@ -41,8 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* chyxion@163.com <br>
|
||||
* Oct 6, 2014 1:10:02 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public class CodeGenServiceSupport implements CodeGenService {
|
||||
private static final Logger log = LoggerFactory.getLogger(CodeGenServiceSupport.class);
|
||||
private static final Map<String, String> TYPE_PACKAGES = new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
@ -54,6 +58,15 @@ public class CodeGenServiceSupport implements CodeGenService {
|
||||
private CodeGenBaseTool baseTool;
|
||||
@Autowired
|
||||
private List<CodeGenerator> codeGen;
|
||||
@Value("${codegen.mapper.cache-enabled:false}")
|
||||
private boolean cacheEnabled;
|
||||
|
||||
@Value("${codegen.model.super-class.name:}")
|
||||
private String modelSuperClassName;
|
||||
@Value("${codegen.model.super-class.import-name:}")
|
||||
private String modelSuperClassImportName;
|
||||
@Value("${codegen.model.super-class.import-required:true}")
|
||||
private boolean modelSuperClassImportRequired;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -88,79 +101,101 @@ public class CodeGenServiceSupport implements CodeGenService {
|
||||
fmDataModel.put("table", table.toLowerCase());
|
||||
fmDataModel.put("notNull", false);
|
||||
fmDataModel.put("notBlank", false);
|
||||
fmDataModel.put("cacheEnabled", baseTool.getConfig("cache.enabled", false));
|
||||
fmDataModel.put("cacheEnabled", cacheEnabled);
|
||||
fmDataModel.put("useGeneratedKeys", false);
|
||||
|
||||
// collect col names
|
||||
String idType = null;
|
||||
List<String> colNames = new ArrayList<String>(columns.size());
|
||||
for (Map<String, Object> col : (List<Map<String, Object>>) columns) {
|
||||
final List<String> colNames = new ArrayList<String>(columns.size());
|
||||
for (final Map<String, Object> col : (List<Map<String, Object>>) columns) {
|
||||
String colName = ((String) col.get("col")).toLowerCase();
|
||||
colNames.add(colName);
|
||||
if (M0.ID.equals(colName)) {
|
||||
String javaType = (String) col.get("javaType");
|
||||
if (ArrayUtils.contains(
|
||||
new String[] {"int", "long", "boolean", "double", "byte"},
|
||||
javaType)) {
|
||||
javaType = StringUtils.capitalize(javaType);
|
||||
}
|
||||
idType = javaType;
|
||||
String javaType = (String) col.get("javaType");
|
||||
if (ArrayUtils.contains(
|
||||
new String[] {"int", "long", "boolean", "double", "byte"},
|
||||
javaType)) {
|
||||
javaType = "int".equals(javaType) ?
|
||||
Integer.class.getSimpleName() :
|
||||
StringUtils.capitalize(javaType);
|
||||
}
|
||||
idType = javaType;
|
||||
}
|
||||
}
|
||||
String baseModelName = null;
|
||||
String baseModelFullName = null;
|
||||
Collection<String> baseCols = null;
|
||||
if (colNames.containsAll(new M3<String, String>().cols())) {
|
||||
|
||||
final String baseModelName;
|
||||
final String baseModelFullName;
|
||||
final Collection<String> baseCols;
|
||||
|
||||
// custom super class
|
||||
if (StringUtils.isNotBlank(modelSuperClassName)) {
|
||||
Assert.state(StringUtils.isNotBlank(modelSuperClassImportName),
|
||||
"config 'codegen.model.super-class.import-name' required");
|
||||
baseModelName = modelSuperClassName;
|
||||
baseModelFullName = modelSuperClassImportRequired ?
|
||||
modelSuperClassImportName : null;
|
||||
|
||||
try {
|
||||
baseCols = new HashSet<>();
|
||||
ReflectionUtils.doWithFields(ClassUtils.getClass(modelSuperClassImportName), field -> {
|
||||
log.info("Super model field [{}] found.", field);
|
||||
final int modifiers = field.getModifiers();
|
||||
if (!Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers)) {
|
||||
final String fieldName = field.getName();
|
||||
log.info("Add super model filed [{}] to base cols.", fieldName);
|
||||
baseCols.add(WordUtils.convertCamelCase(fieldName, "_").toLowerCase());
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (final ClassNotFoundException e) {
|
||||
throw new IllegalStateException(
|
||||
"No model super class [" + modelSuperClassImportName + "] found", e);
|
||||
}
|
||||
log.info("Base cols [{}] extracted.", baseCols);
|
||||
}
|
||||
else if (colNames.containsAll(new M3<String, String>().cols())) {
|
||||
baseModelName = M3.class.getSimpleName() +
|
||||
"<" + idType + ", " + idType + ">";
|
||||
baseModelFullName = M3.class.getName();
|
||||
baseCols = new M3<String, String>().cols();
|
||||
log.info("Base cols [{}] read from M3.", baseCols);
|
||||
}
|
||||
else if (colNames.containsAll(new M2<String>().cols())) {
|
||||
baseModelName = M2.class.getSimpleName() + "<" + idType + ">";
|
||||
baseModelFullName = M2.class.getName();
|
||||
baseCols = new M2<String>().cols();
|
||||
log.info("Base cols [{}] read from M2.", baseCols);
|
||||
}
|
||||
else if (colNames.containsAll(new M1<String>().cols())) {
|
||||
baseModelName = M1.class.getSimpleName() + "<" + idType + ">";
|
||||
baseModelFullName = M1.class.getName();
|
||||
baseCols = new M1<String>().cols();
|
||||
log.info("Base cols [{}] read from M1.", baseCols);
|
||||
}
|
||||
else {
|
||||
baseModelName = M0.class.getSimpleName();
|
||||
baseModelFullName = M0.class.getName();
|
||||
baseCols = new M0<String>().cols();
|
||||
}
|
||||
// custom config
|
||||
String cfgBaseModelName = baseTool.getConfig("super.base.model.name");
|
||||
if (StringUtils.isNotBlank(cfgBaseModelName)) {
|
||||
baseCols = baseTool.getBaseCols();
|
||||
log.info("Base cols [{}] read from M0.", baseCols);
|
||||
}
|
||||
|
||||
String cfgBaseModelFullName =
|
||||
baseTool.getConfig("super.base.model.full.name");
|
||||
|
||||
fmDataModel.put("baseModelName",
|
||||
baseTool.getConfig("super.base.model.name", baseModelName));
|
||||
|
||||
fmDataModel.put("baseModelFullName",
|
||||
"NONE".equalsIgnoreCase(cfgBaseModelFullName) ? null :
|
||||
StringUtils.isNotBlank(cfgBaseModelFullName) ?
|
||||
cfgBaseModelFullName : baseModelFullName);
|
||||
fmDataModel.put("baseModelFullName", baseModelFullName);
|
||||
fmDataModel.put("baseModelName", baseModelName);
|
||||
|
||||
fmDataModel.put("tableAnnotationClassName", Table.class.getName());
|
||||
fmDataModel.put("tableAnnotationName", Table.class.getSimpleName());
|
||||
|
||||
Set<String> imports = new HashSet<String>();
|
||||
List<Map<String, Object>> colsWithoutBase =
|
||||
final Set<String> imports = new HashSet<>();
|
||||
final List<Map<String, Object>> colsWithoutBase =
|
||||
(List<Map<String, Object>>) columns;
|
||||
Iterator<Map<String, Object>> colIt =
|
||||
final Iterator<Map<String, Object>> colIt =
|
||||
colsWithoutBase.iterator();
|
||||
|
||||
while (colIt.hasNext()) {
|
||||
Map<String, Object> col = colIt.next();
|
||||
// col name
|
||||
String colName = ((String) col.get("col")).toLowerCase();
|
||||
final String colName = ((String) col.get("col")).toLowerCase();
|
||||
log.info("Process model col [{}].", colName);
|
||||
if (!baseCols.contains(colName)) {
|
||||
// prop name
|
||||
String propName = (String) col.get("name");
|
||||
@ -175,13 +210,14 @@ public class CodeGenServiceSupport implements CodeGenService {
|
||||
}
|
||||
}
|
||||
// imports
|
||||
String p = TYPE_PACKAGES.get(col.get("javaType"));
|
||||
if (StringUtils.isNotBlank(p)) {
|
||||
imports.add(p);
|
||||
final String imp = TYPE_PACKAGES.get(col.get("javaType"));
|
||||
if (StringUtils.isNotBlank(imp)) {
|
||||
imports.add(imp);
|
||||
}
|
||||
}
|
||||
// remove base col
|
||||
else {
|
||||
log.info("Remove base col [{}].", colName);
|
||||
colIt.remove();
|
||||
}
|
||||
}
|
||||
@ -210,17 +246,10 @@ public class CodeGenServiceSupport implements CodeGenService {
|
||||
fmDataModel.put("baseServiceSupportName", BaseCrudServiceSupport.class.getSimpleName());
|
||||
fmDataModel.put("baseServiceSupportFullName", BaseCrudServiceSupport.class.getName());
|
||||
|
||||
// model
|
||||
//
|
||||
// mapper
|
||||
fmDataModel.put("baseMapperName", BaseMapper.class.getSimpleName());
|
||||
fmDataModel.put("baseMapperFullName", BaseMapper.class.getName());
|
||||
|
||||
// fmDataModel.put("mockMapperName", MockMapper.class.getSimpleName());
|
||||
// fmDataModel.put("mockMapperFullName", MockMapper.class.getName());
|
||||
// fmDataModel.put("mockName", Mock.class.getSimpleName());
|
||||
// fmDataModel.put("mockFullName", Mock.class.getName());
|
||||
|
||||
fmDataModel.put("ctrlrTestToolName", ControllerTestTool.class.getSimpleName());
|
||||
fmDataModel.put("ctrlrTestToolFullName", ControllerTestTool.class.getName());
|
||||
// Object Doc
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.chyxion.tigon.codegen.service.support;
|
||||
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||
|
||||
/**
|
||||
@ -19,17 +18,11 @@ public class MapperXmlCodeGen extends MapperCodeGen {
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel,
|
||||
String module, String model) {
|
||||
StringBuilder sbFilePath = new StringBuilder(resourcesDir)
|
||||
.append("mybatis/mappers/");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
sbFilePath.append(module).append("/");
|
||||
}
|
||||
sbFilePath.append(dataModel.get("minusJoinedModelName")).append("-mapper.xml");
|
||||
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MAPPER_XML,
|
||||
"/codegen/mapper-xml.ftl",
|
||||
dataModel,
|
||||
sbFilePath.toString()));
|
||||
CodeGenArgs.TARGET_MAPPER_XML,
|
||||
"/codegen/mapper-xml.ftl",
|
||||
dataModel,
|
||||
codeDir + dataModel.get("pkgDir") +
|
||||
"/mapper/" + model + "Mapper.xml"));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import java.io.File;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||
@ -17,7 +16,7 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
* chyxion@163.com <br>
|
||||
* Oct 7, 2014 12:23:13 PM
|
||||
*/
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
@Order
|
||||
public class TableCodeGen extends CodeGenerator {
|
||||
private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class);
|
||||
|
||||
@ -35,7 +34,7 @@ public class TableCodeGen extends CodeGenerator {
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
String table = (String) dataModel.get("table");
|
||||
log.info("Process Generate Table [{}] SQL File.", table);
|
||||
log.info("Process generate table [{}] SQL file.", table);
|
||||
StringBuilder filePath = new StringBuilder(resourcesDir)
|
||||
.append("db/");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
@ -51,21 +50,21 @@ public class TableCodeGen extends CodeGenerator {
|
||||
if (!Boolean.FALSE.equals(dataModel.get("createTable"))) {
|
||||
// ignore drop table error
|
||||
try {
|
||||
log.info("Execute Drop Table [{}].", table);
|
||||
log.info("Execute drop table [{}].", table);
|
||||
baseTool.execSQL("drop table " + table);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.info("Drop Table Failed, Error Message [{}], Ingore.",
|
||||
log.info("Drop table failed, error message [{}], ignore.",
|
||||
e.getMessage());
|
||||
}
|
||||
// ignore execute sql error
|
||||
try {
|
||||
log.info("Execut Create Table SQL File [{}].", filePath);
|
||||
log.info("Execute create table SQL file [{}].", filePath);
|
||||
baseTool.execSQL(new File(baseTool.getProjDir(), filePath
|
||||
.toString()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Database Create Table Error, Ingore.", e);
|
||||
log.warn("Database create table error, ignore.", e);
|
||||
}
|
||||
}
|
||||
return filePath.toString();
|
||||
|
@ -1,4 +1,4 @@
|
||||
package me.chyxion.tigon.codegen.utils;
|
||||
package me.chyxion.tigon.codegen.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
@ -3,6 +3,7 @@ package ${pkg}.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
import ${tableAnnotationClassName};
|
||||
<#if baseModelFullName?has_content>
|
||||
import ${baseModelFullName};
|
||||
@ -15,15 +16,16 @@ ${objDoc}
|
||||
@Getter
|
||||
@Setter
|
||||
@${tableAnnotationName}("${table}")
|
||||
@FieldNameConstants(prefix = "")
|
||||
public class ${ModelName} extends ${baseModelName} {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#--
|
||||
// Column Names
|
||||
<#list cols as prop>
|
||||
public static final String ${prop.col?upper_case} = "${prop.col}";
|
||||
</#list>
|
||||
-->
|
||||
|
||||
// Properties
|
||||
<#list cols as prop>
|
||||
private ${prop.javaType} ${prop.name};
|
||||
</#list>
|
||||
|
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<!-- Scan Code Gen -->
|
||||
<context:component-scan base-package="me.chyxion.tigon.codegen.controller" />
|
||||
</beans>
|
@ -1,13 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<context:component-scan base-package="me.chyxion.tigon.codegen.controller" />
|
||||
<!-- Tool -->
|
||||
<bean class="me.chyxion.tigon.codegen.service.CodeGenBaseTool" />
|
||||
|
||||
@ -23,4 +20,40 @@
|
||||
<bean class="me.chyxion.tigon.codegen.service.support.TableCodeGen" />
|
||||
<bean class="me.chyxion.tigon.codegen.service.support.ViewCodeGen" />
|
||||
|
||||
<!-- FreeMarker Config -->
|
||||
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"
|
||||
p:templateLoaderPaths="/WEB-INF/views/, classpath:/, classpath:/webapp/views/"
|
||||
p:defaultEncoding="utf-8"
|
||||
p:preferFileSystemAccess="false">
|
||||
<property name="freemarkerSettings">
|
||||
<props>
|
||||
<prop key="template_update_delay">${tigon.codegen.freemarker.cache.expire:36000}</prop>
|
||||
<prop key="output_encoding">utf-8</prop>
|
||||
<prop key="locale">en_US</prop>
|
||||
<prop key="date_format">yyyy-MM-dd</prop>
|
||||
<prop key="time_format">HH:mm:ss</prop>
|
||||
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
|
||||
<!-- avoid 000.00 -->
|
||||
<prop key="number_format">#</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
<bean class="me.chyxion.tigon.codegen.freemarker.FreeMarkerViewResolverExt"
|
||||
p:suffix=".ftl"
|
||||
p:contentType="text/html; charset=utf-8"
|
||||
p:exposeRequestAttributes="true"
|
||||
p:order="16"
|
||||
/>
|
||||
|
||||
<bean class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg>
|
||||
<bean class="com.alibaba.druid.pool.DruidDataSource"
|
||||
init-method="init"
|
||||
destroy-method="close"
|
||||
p:url="jdbc:mysql://${datasource.host}:${datasource.port}/${datasource.database-name}?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull"
|
||||
p:username="${datasource.username}"
|
||||
p:password="${datasource.password}"
|
||||
/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</beans>
|
||||
|
@ -86,13 +86,6 @@ Ext.define ('Tigon.views.CodeGen', {
|
||||
form = rc.down('form');
|
||||
form.getForm().setValues(rec.getData());
|
||||
form.down('grid').getStore().loadData(rec.get('cols'));
|
||||
// show demo grid
|
||||
// var dg = rc.down('container[name=demo_grid]');
|
||||
// dg.removeAll();
|
||||
// load view
|
||||
// dg.add(Ext.create('App.views.' +
|
||||
// (rec.get('module') ? rec.get('module') + '.' : '') +
|
||||
// rec.get('model') + '.List'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,13 +114,6 @@ Ext.define ('Tigon.views.CodeGen', {
|
||||
createTable: false
|
||||
}));
|
||||
form.down('grid').getStore().loadData(rec.get('cols'));
|
||||
// show demo grid
|
||||
// var dg = rc.down('container[name=demo_grid]');
|
||||
// dg.removeAll();
|
||||
// load view
|
||||
// dg.add(Ext.create('App.views.' +
|
||||
// (rec.get('module') ? rec.get('module') + '.' : '') +
|
||||
// rec.get('model') + '.List'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,34 +201,30 @@ Ext.define ('Tigon.views.CodeGen', {
|
||||
fieldLabel: 'Options',
|
||||
xtype: 'checkboxgroup',
|
||||
defaults: {
|
||||
checked: true,
|
||||
checked: false,
|
||||
xtype: 'checkbox',
|
||||
inputValue: true
|
||||
},
|
||||
columns: 3,
|
||||
items: [{
|
||||
boxLabel: 'Gen controller',
|
||||
checked: components.indexOf('controller') > -1,
|
||||
name: 'genController'
|
||||
}, {
|
||||
boxLabel: 'Gen service',
|
||||
name: 'genService'
|
||||
}, {
|
||||
boxLabel: 'Gen mapper',
|
||||
checked: components.indexOf('mapper') > -1,
|
||||
name: 'genMapper'
|
||||
}, {
|
||||
boxLabel: 'Gen model',
|
||||
checked: components.indexOf('model') > -1,
|
||||
name: 'genModel'
|
||||
}, {
|
||||
boxLabel: 'Gen table',
|
||||
name: 'genTable'
|
||||
}, {
|
||||
boxLabel: 'Gen form',
|
||||
checked: false,
|
||||
checked: components.indexOf('form') > -1,
|
||||
name: 'genView'
|
||||
}, {
|
||||
boxLabel: 'Create table',
|
||||
checked: false,
|
||||
name: 'createTable'
|
||||
}]
|
||||
}, {
|
||||
xtype: 'fieldcontainer',
|
||||
|
@ -16,7 +16,7 @@
|
||||
items: [{
|
||||
xtype: 'box',
|
||||
region: 'north',
|
||||
html: '<h1>Super Super Code!</h1>'
|
||||
html: '<h1>Tigon Code Gen!</h1>'
|
||||
},
|
||||
Ext.create('Tigon.views.CodeGen', {
|
||||
region: 'center'
|
||||
@ -26,6 +26,7 @@
|
||||
Ext.create('Tigon.views.ThemesBar').show();
|
||||
});
|
||||
var pkg = '${pkg}';
|
||||
var components = ${components};
|
||||
</script>
|
||||
<title>Auto Code</title>
|
||||
</head>
|
||||
|
@ -1 +0,0 @@
|
||||
# tigon-freemarker-support
|
@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<artifactId>tigon-freemarker-support</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon FreeMarker Support</name>
|
||||
<description>Tigon FreeMarker Support</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<!-- FreeMarker Config -->
|
||||
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"
|
||||
p:templateLoaderPaths="/WEB-INF/views/, classpath:/, classpath:/webapp/views/"
|
||||
p:defaultEncoding="utf-8"
|
||||
p:preferFileSystemAccess="false">
|
||||
<property name="freemarkerSettings">
|
||||
<props>
|
||||
<prop key="template_update_delay">${freemarker.cache.expire:36000}</prop>
|
||||
<prop key="output_encoding">utf-8</prop>
|
||||
<prop key="locale">en_US</prop>
|
||||
<prop key="date_format">yyyy-MM-dd</prop>
|
||||
<prop key="time_format">HH:mm:ss</prop>
|
||||
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
|
||||
<!-- avoid 000.00 -->
|
||||
<prop key="number_format">#</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
<bean class="me.chyxion.tigon.freemarker.FreeMarkerViewResolverExt"
|
||||
p:suffix=".ftl"
|
||||
p:contentType="text/html; charset=utf-8"
|
||||
p:exposeRequestAttributes="true"
|
||||
p:order="16"
|
||||
/>
|
||||
</beans>
|
@ -1,20 +0,0 @@
|
||||
package me.chyxion.tigon.freemarker.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jan 27, 2015 3:27:08 PM
|
||||
*/
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:spring/controller-test.xml")
|
||||
public class SiteControllerTest {
|
||||
|
||||
}
|
@ -1 +0,0 @@
|
||||
# Config Dev
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!-- Scan Mock -->
|
||||
<context:component-scan base-package="me.chyxion.tigon.freemarker.test"
|
||||
use-default-filters="false">
|
||||
<context:include-filter type="annotation"
|
||||
expression="me.chyxion.tigon.webmvc.stereotype.Mock" />
|
||||
<context:include-filter type="annotation"
|
||||
expression="org.springframework.stereotype.Controller" />
|
||||
<context:include-filter type="annotation"
|
||||
expression="org.springframework.stereotype.Service" />
|
||||
</context:component-scan>
|
||||
</beans>
|
@ -1 +0,0 @@
|
||||
# tigon-jsp-support
|
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<artifactId>tigon-jsp-support</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon JSP Support</name>
|
||||
<description>Tigon JSP Support</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,59 +0,0 @@
|
||||
package me.chyxion.tigon.jsp;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javax.servlet.ServletContext;
|
||||
import java.net.MalformedURLException;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Dec 5, 2014 2:33:18 PM
|
||||
*/
|
||||
public class InternalResourceViewResolverExt
|
||||
extends InternalResourceViewResolver {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(InternalResourceViewResolverExt.class);
|
||||
|
||||
@Autowired
|
||||
private ServletContext sc;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public View resolveViewName(String viewName, Locale locale)
|
||||
throws Exception {
|
||||
return super.resolveViewName(viewName(viewName), locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean canHandle(String viewName, Locale locale) {
|
||||
try {
|
||||
// avoid 404
|
||||
return sc.getResource(getPrefix() + viewName(viewName) + getSuffix()) != null;
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
log.warn("InternalResourceViewResolverExt#canHandle Eorror Caused.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process View Name
|
||||
* @param name raw name
|
||||
* @return jsp file name
|
||||
*/
|
||||
private String viewName(String name) {
|
||||
return name.replaceAll("(?i)(^\\s*jsp\\:)|(\\.jsp\\s*$)", "");
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<!-- JSP View Resolver -->
|
||||
<bean class="me.chyxion.tigon.jsp.InternalResourceViewResolverExt"
|
||||
p:prefix="/WEB-INF/views/"
|
||||
p:suffix=".jsp"
|
||||
p:contentType="text/html; charset=utf-8"
|
||||
p:order="32"
|
||||
/>
|
||||
</beans>
|
@ -1,20 +0,0 @@
|
||||
package me.chyxion.tigon.webmvc.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
// import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jan 27, 2015 3:27:08 PM
|
||||
*/
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
// @ContextConfiguration("classpath:spring/controller-test.xml")
|
||||
public class SiteControllerTest {
|
||||
|
||||
}
|
@ -21,10 +21,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.47</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@ -39,6 +41,13 @@
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.3</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@ -46,7 +55,7 @@
|
||||
</dependency>
|
||||
<!-- For Form Validate -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -33,14 +33,14 @@ public class BaseForm implements BaseFormApi {
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(Class<T> clazz, boolean convert) {
|
||||
log.debug("Copy Form [{}] To Class [{}].", this, clazz);
|
||||
log.debug("Copy form [{}] to class [{}].", this, clazz);
|
||||
T obj = null;
|
||||
try {
|
||||
obj = clazz.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Create [" + clazz + "] Object Error Caused", e);
|
||||
"Create [" + clazz + "] object error caused", e);
|
||||
}
|
||||
return copy(obj, convert);
|
||||
}
|
||||
@ -65,18 +65,18 @@ public class BaseForm implements BaseFormApi {
|
||||
public <T> T copy(T obj, boolean convert) {
|
||||
try {
|
||||
if (convert) {
|
||||
log.debug("Copy Form [{}] To [{}] With Type Converting.", this, obj);
|
||||
log.debug("Copy form [{}] to [{}] with type converting.", this, obj);
|
||||
org.apache.commons.beanutils.BeanUtils.copyProperties(obj, this);
|
||||
}
|
||||
else {
|
||||
log.debug("Copy Form [{}] To [{}].", this, obj);
|
||||
log.debug("Copy form [{}] to [{}].", this, obj);
|
||||
BeanUtils.copyProperties(this, obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Copy [" + this + "] Error Caused", e);
|
||||
"Copy [" + this + "] error caused", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,11 +10,11 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
* chyxion@163.com <br>
|
||||
* Oct 8, 2016 6:26:19 PM
|
||||
*/
|
||||
@Getter
|
||||
public class FC2<CreatorId> extends FC1 {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private transient boolean __lock = true;
|
||||
|
||||
@Getter
|
||||
@NotNullOrBlank
|
||||
protected CreatorId createdBy;
|
||||
|
||||
|
@ -2,7 +2,6 @@ package me.chyxion.tigon.form;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import me.chyxion.tigon.format.annotation.EmptyToNull;
|
||||
|
||||
/**
|
||||
@ -18,8 +17,7 @@ public class FU1<Id>
|
||||
extends FU0<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
protected Boolean enabled;
|
||||
protected boolean enabled = true;
|
||||
@EmptyToNull
|
||||
protected String note;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.chyxion.tigon.form;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
|
||||
/**
|
||||
@ -11,12 +10,12 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
* chyxion@163.com <br>
|
||||
* Oct 8, 2016 6:26:36 PM
|
||||
*/
|
||||
@Getter
|
||||
public class FU2<EditorId, Id>
|
||||
extends FU1<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private transient boolean __lock = true;
|
||||
|
||||
@Getter
|
||||
@NotNullOrBlank
|
||||
private EditorId updatedBy;
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
package me.chyxion.tigon.form;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import me.chyxion.tigon.format.annotation.Trim;
|
||||
import me.chyxion.tigon.format.annotation.EmptyToNull;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 25, 2018 22:56:52
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ListForm extends BaseForm {
|
||||
@Min(0)
|
||||
private int start;
|
||||
@Min(1)
|
||||
@Max(2048)
|
||||
private int limit = 16;
|
||||
private String search;
|
||||
@Trim
|
||||
@EmptyToNull
|
||||
private String criteria;
|
||||
@Trim
|
||||
@EmptyToNull
|
||||
private String filters;
|
||||
@Trim
|
||||
@EmptyToNull
|
||||
private String orders;
|
||||
}
|
@ -198,7 +198,37 @@ public class Search implements Serializable {
|
||||
* @return this
|
||||
*/
|
||||
public Search like(String col, String value, boolean wrapValue) {
|
||||
return like(col, wrapValue ? "%" + value + "%" : value);
|
||||
return wrapValue ? contains(col, value) : like(col, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* col contains value
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search contains(final String col, final String value) {
|
||||
return like(col, "%" + value + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
* col starts with value
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search startsWith(final String col, final String value) {
|
||||
return like(col, value + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
* col ends with value
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search endsWith(final String col, final String value) {
|
||||
return like(col, "%" + value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ import lombok.Setter;
|
||||
import lombok.NonNull;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chyxion.tigon.util.WordUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
@ -25,18 +26,23 @@ public class SearchProcessArgs {
|
||||
@Setter
|
||||
private boolean hasPrevOrCol;
|
||||
|
||||
public SearchProcessArgs append(String sqlFragment) {
|
||||
public SearchProcessArgs append(final String sqlFragment) {
|
||||
result.add(new SqlFragment(sqlFragment));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SearchProcessArgs addValue(Object value) {
|
||||
public SearchProcessArgs addValue(final Object value) {
|
||||
result.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCol() {
|
||||
String col = criterion.getCol();
|
||||
if (col.matches("^\\w+$")) {
|
||||
col = WordUtils.convertCamelCase(
|
||||
col, "_").toLowerCase();
|
||||
}
|
||||
|
||||
return StringUtils.isNotBlank(table)
|
||||
&& !col.contains(".") ?
|
||||
table + "." + col : col;
|
||||
|
@ -32,18 +32,12 @@ public class WordUtils {
|
||||
public static String[] splitToWords(String str) {
|
||||
return StringUtils.isNotBlank(str) ?
|
||||
// JSONObject - JSON Object
|
||||
str.split(new StringBuilder("(?<=[A-Z])(?=[A-Z][a-z])")
|
||||
// 99Rose - 99 Rose
|
||||
str.split(new StringBuilder("(?<=[0-9A-Z])(?=[A-Z][a-z])")
|
||||
// MySQL - My SQL
|
||||
.append("|(?<=[a-z])(?=[A-Z])")
|
||||
// 99Roses -> 99 Roses
|
||||
.append("|(?<=[^a-zA-Z])(?=[A-Z])")
|
||||
// .append("|(?<=[^A-Z])(?=[A-Z])")
|
||||
// 5s - 5 s
|
||||
// .append("|(?<=[^a-zA-Z])(?=[a-z])")
|
||||
// A3 - A 3 | a3 - a 3
|
||||
// .append("|(?<=[A-Za-z])(?=[^A-Za-z])")
|
||||
.toString()) :
|
||||
new String[]{};
|
||||
.toString()) :
|
||||
new String[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,4 +90,13 @@ public class WordUtils {
|
||||
}
|
||||
return strRtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert underline word to
|
||||
* @param word
|
||||
* @return
|
||||
*/
|
||||
public static String toCamel(final String word) {
|
||||
return StringUtils.uncapitalize(convertToCamelCase(word.toLowerCase(), "_"));
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,11 @@ public class WordUtilsTest {
|
||||
System.err.println(WordUtils.convertCamelCase("log4j", "_"));
|
||||
System.err.println(WordUtils.convertCamelCase("log4J", "_"));
|
||||
System.err.println(WordUtils.convertCamelCase("JSONObject", "_"));
|
||||
System.err.println(WordUtils.convertCamelCase("JSONObject", "_"));
|
||||
System.err.println(WordUtils.convertCamelCase("99Rose", "_"));
|
||||
System.err.println(WordUtils.convertCamelCase("AAA99Rose", "_"));
|
||||
System.err.println(WordUtils.convertCamelCase("99rose", "_"));
|
||||
System.err.println(WordUtils.convertCamelCase("Foo.JSONObject", "_"));
|
||||
|
||||
System.err.println("JSONObject".matches("^\\w+$"));
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,17 @@
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
|
@ -1,11 +1,12 @@
|
||||
package me.chyxion.tigon.mybatis.cache;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.cache.Cache;
|
||||
import org.springframework.util.Assert;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
@ -14,34 +15,30 @@ import org.springframework.data.redis.core.ValueOperations;
|
||||
* chyxion@163.com <br>
|
||||
* Feb 23, 2016 6:03:39 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public final class RedisCache implements Cache {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(RedisCache.class);
|
||||
|
||||
private String id;
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
private ValueOperations<String, Object> valueOp;
|
||||
private RedisCacheConfig config;
|
||||
private final String id;
|
||||
private final RedisTemplate<Object, Object> redisTpl;
|
||||
private final HashOperations<Object, String, Object> hashOp;
|
||||
private final RedisCacheConfig config;
|
||||
|
||||
/**
|
||||
* construct cache
|
||||
* @param id cache id
|
||||
*/
|
||||
public RedisCache(String id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cache Instance ID Could Not Be Null");
|
||||
}
|
||||
log.info("Create Redis Cache [{}].", id);
|
||||
public RedisCache(final String id) {
|
||||
Assert.hasText(id, "Redis cache instance id could not be null");
|
||||
log.info("Create redis cache [{}].", id);
|
||||
this.id = id;
|
||||
config = RedisCacheConfig.getInstance();
|
||||
redisTpl = config.getRedisTpl();
|
||||
valueOp = redisTpl.opsForValue();
|
||||
hashOp = redisTpl.opsForHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -49,43 +46,48 @@ public final class RedisCache implements Cache {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getSize() {
|
||||
log.debug("Get Cache [{}] Size.", id);
|
||||
return redisTpl.keys(prefixedKey("*")).size();
|
||||
final Long size = hashOp.size(id);
|
||||
log.info("Get redis cache [{}] size [{}].", id, size);
|
||||
return size.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void putObject(final Object key, final Object value) {
|
||||
log.debug("Put Object Key [{}], Value [{}].", key, value);
|
||||
valueOp.set(prefixedKey(key), value);
|
||||
log.debug("Put redis cache [{}] object key [{}], value [{}].", id, key, value);
|
||||
hashOp.put(id, keyMd5(key), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object getObject(final Object key) {
|
||||
Object value = valueOp.get(prefixedKey(key));
|
||||
log.debug("Get Object Key [{}], Value [{}].", key, value);
|
||||
final Object value = hashOp.get(id, keyMd5(key));
|
||||
log.debug("Get redis cache object key [{}], value [{}].", key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object removeObject(final Object key) {
|
||||
log.debug("Remove Object Key [{}].", key);
|
||||
redisTpl.delete(prefixedKey(key));
|
||||
return 1;
|
||||
log.info("Remove redis cache [{}] object key [{}].", id, key);
|
||||
return hashOp.delete(id, keyMd5(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
log.debug("Clear Cache Key [{}].", id);
|
||||
redisTpl.delete(redisTpl.keys(prefixedKey("*")));
|
||||
log.info("Clear redis cache [{}].", id);
|
||||
redisTpl.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +103,7 @@ public final class RedisCache implements Cache {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Redis Cache [" + id + "]";
|
||||
return "Redis cache [" + id + "]";
|
||||
}
|
||||
|
||||
// --
|
||||
@ -112,14 +114,9 @@ public final class RedisCache implements Cache {
|
||||
* @param key cache key
|
||||
* @return prefixed key
|
||||
*/
|
||||
String prefixedKey(Object key) {
|
||||
return prefix() + String.valueOf(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return cache prefix
|
||||
*/
|
||||
String prefix() {
|
||||
return id + ":";
|
||||
private String keyMd5(final Object key) {
|
||||
final String md5Hex = DigestUtils.md5Hex(key instanceof String ? (String) key : String.valueOf(key));
|
||||
log.debug("Get redis cache [{}] key [{}] md5 hex [{}].", id, key, md5Hex);
|
||||
return md5Hex;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package me.chyxion.tigon.mybatis.cache;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
@ -13,7 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
*/
|
||||
public class RedisCacheConfig {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
@Qualifier("redisTemplate")
|
||||
private RedisTemplate<Object, Object> redisTpl;
|
||||
private static RedisCacheConfig instance;
|
||||
|
||||
@PostConstruct
|
||||
@ -31,14 +33,7 @@ public class RedisCacheConfig {
|
||||
/**
|
||||
* @return the redisTpl
|
||||
*/
|
||||
public RedisTemplate<String, Object> getRedisTpl() {
|
||||
public RedisTemplate<Object, Object> getRedisTpl() {
|
||||
return redisTpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTpl the redisTpl to set
|
||||
*/
|
||||
public void setRedisTpl(RedisTemplate<String, Object> redisTpl) {
|
||||
this.redisTpl = redisTpl;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.chyxion.tigon.mybatis.cache.support;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.cache.Cache;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
@ -16,9 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* chyxion@163.com <br>
|
||||
* Aug 26, 2015 10:58:58 AM
|
||||
*/
|
||||
@Slf4j
|
||||
public class CacheToolSupport implements CacheTool {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(CacheToolSupport.class);
|
||||
|
||||
@Autowired
|
||||
private SqlSessionFactory ssf;
|
||||
@ -29,13 +27,13 @@ public class CacheToolSupport implements CacheTool {
|
||||
*/
|
||||
@Override
|
||||
public void clearCache(Class<?> mapper) {
|
||||
log.info("Clear Cache [{}].", mapper);
|
||||
Cache cache = getCache(mapper);
|
||||
log.info("Clear mybatis cache [{}].", mapper);
|
||||
final Cache cache = getCache(mapper);
|
||||
if (cache != null) {
|
||||
cache.clear();
|
||||
}
|
||||
else {
|
||||
log.warn("No Cache [{}] Found.", mapper);
|
||||
log.warn("No mybatis cache [{}] found.", mapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,12 @@
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@ -60,11 +62,13 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.0.28</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -85,6 +89,7 @@
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,8 +6,8 @@ import java.util.Collection;
|
||||
import me.chyxion.tigon.model.BaseModel;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
@ -140,6 +140,13 @@ public interface BaseMapper<PrimaryKey, Model extends BaseModel<PrimaryKey>> {
|
||||
*/
|
||||
int delete(@NotNull @Param(PARAM_SEARCH_KEY) PrimaryKey primaryKey);
|
||||
|
||||
/**
|
||||
* find one by search
|
||||
* @param search search
|
||||
* @return true if exists rows
|
||||
*/
|
||||
boolean exists(@Param(PARAM_SEARCH_KEY) Search search);
|
||||
|
||||
/**
|
||||
* find one by search
|
||||
* @param search search
|
||||
|
@ -0,0 +1,29 @@
|
||||
package me.chyxion.tigon.mybatis;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* 14/10/2017 10:43 PM
|
||||
*/
|
||||
public class ExistsXmlProcessor extends AbstractOnMissingCreateProcessor {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String missingXPathExpression() {
|
||||
return "/mapper/select[@id='exists']";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Element elementToAppend(Class<BaseMapper<?, ?>> mapperClass, Document doc) {
|
||||
return appendIncludeEl(doc,
|
||||
createSelectEl(doc, "exists", "boolean"), "Tigon.exists");
|
||||
}
|
||||
}
|
@ -85,13 +85,13 @@ class KeyGenInterceptor implements Interceptor {
|
||||
Object paramObj = boundSql.getParameterObject();
|
||||
if (paramObj instanceof MapperMethod.ParamMap) {
|
||||
@SuppressWarnings("unchecked")
|
||||
MapperMethod.ParamMap<Object> paramMap =
|
||||
(MapperMethod.ParamMap<Object>) paramObj;
|
||||
MapperMethod.ParamMap<Object> paramMap =
|
||||
(MapperMethod.ParamMap<Object>) paramObj;
|
||||
if (paramMap.containsKey(BaseMapper.PARAM_MODEL_KEY) ||
|
||||
paramMap.containsKey(BaseMapper.PARAM_MODELS_KEY)) {
|
||||
KeyGenerator keygen = mappedStatement.getKeyGenerator();
|
||||
if (keygen.getClass().equals(Jdbc3KeyGenerator.class)) {
|
||||
log.debug("Replace JDBC3 Key Generator.");
|
||||
log.info("Replace JDBC3 key generator.");
|
||||
SystemMetaObject.forObject(mappedStatement)
|
||||
.setValue("keyGenerator",
|
||||
new Jdbc3KeyGen(keygen));
|
||||
|
@ -46,6 +46,7 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean {
|
||||
MAPPER_XML_PROCESSORS.add(new PrimaryKeyXmlProcessor());
|
||||
MAPPER_XML_PROCESSORS.add(new ColsXmlProcessor());
|
||||
MAPPER_XML_PROCESSORS.add(new InsertXmlProcessor());
|
||||
MAPPER_XML_PROCESSORS.add(new ExistsXmlProcessor());
|
||||
MAPPER_XML_PROCESSORS.add(new FindXmlProcessor());
|
||||
MAPPER_XML_PROCESSORS.add(new ListXmlProcessor());
|
||||
MAPPER_XML_PROCESSORS.add(new CountXmlProcessor());
|
||||
@ -126,7 +127,7 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<BaseMapper<?, ?>> getMapperClass(String name) {
|
||||
private Class<BaseMapper<?, ?>> getMapperClass(String name) {
|
||||
Class<BaseMapper<?, ?>> mapperClassRtn = null;
|
||||
try {
|
||||
Class<?> classFound = ClassUtils.forName(name,
|
||||
|
@ -183,6 +183,18 @@
|
||||
</sql>
|
||||
<!--/ Delete -->
|
||||
|
||||
<!-- Exists -->
|
||||
<sql id="exists">
|
||||
select
|
||||
<![CDATA[
|
||||
if (count(*) > 0, 1, 0)
|
||||
]]>
|
||||
from
|
||||
<include refid="table" />
|
||||
<include refid="Tigon.searchForCount" />
|
||||
</sql>
|
||||
<!--/ Exists -->
|
||||
|
||||
<!-- Find One -->
|
||||
<sql id="find">
|
||||
select
|
||||
|
@ -1 +0,0 @@
|
||||
# tigon-props-config
|
@ -1,50 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<artifactId>tigon-props-config</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Props Config</name>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,120 +0,0 @@
|
||||
package me.chyxion.tigon.propsconfig;
|
||||
|
||||
import java.io.File;
|
||||
import org.slf4j.Logger;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.io.FileInputStream;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Oct 13, 2015 11:25:55 AM
|
||||
*/
|
||||
public class PropsConfig {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(PropsConfig.class);
|
||||
public static final Properties CONFIG_PROPS =
|
||||
new Properties();
|
||||
static { load(); }
|
||||
|
||||
/**
|
||||
* get app (container/tomcat) dir
|
||||
* @return app dir
|
||||
*/
|
||||
public static File getAppDir() {
|
||||
File file = new File(
|
||||
// classes
|
||||
PropsConfig.class.getResource("/").getFile())
|
||||
// WEB-INF
|
||||
.getParentFile()
|
||||
// WebApp
|
||||
.getParentFile()
|
||||
// WebApps
|
||||
.getParentFile()
|
||||
// App
|
||||
.getParentFile();
|
||||
log.info("Get App Dir [{}].", file.getAbsolutePath());
|
||||
return file;
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
|
||||
/**
|
||||
* load system config
|
||||
*/
|
||||
static void load() {
|
||||
InputStream configIn = null;
|
||||
String configPath = "/spring/config.properties";
|
||||
try {
|
||||
log.info("Load Classpath Config [{}].", configPath);
|
||||
configIn = PropsConfig.class
|
||||
.getResourceAsStream(configPath);
|
||||
if (configIn != null) {
|
||||
log.info("Classpath Config [{}] Found.", configPath);
|
||||
CONFIG_PROPS.load(configIn);
|
||||
}
|
||||
else {
|
||||
log.warn("No Classpath Config [{}] Found.", configPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Load Classpath Config [{}] Error Caused.", configPath, e);
|
||||
}
|
||||
finally {
|
||||
if (configIn != null) {
|
||||
try {
|
||||
configIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Config Input Stream Close Eroror Caused.");
|
||||
}
|
||||
}
|
||||
}
|
||||
File appDir = getAppDir();
|
||||
// load global config
|
||||
load(appDir.getParentFile());
|
||||
// load app config
|
||||
load(appDir);
|
||||
log.debug("Config Props [{}] Loaded.", CONFIG_PROPS);
|
||||
}
|
||||
|
||||
static void load(File dir) {
|
||||
// load from custom file
|
||||
File configFile = new File(dir, "config/config.properties");
|
||||
String configPath = configFile.getAbsolutePath();
|
||||
log.info("Load Config From Path [{}].", configPath);
|
||||
if (configFile.exists()) {
|
||||
log.info("Config File [{}] Exists.", configPath);
|
||||
InputStream configIn = null;
|
||||
try {
|
||||
configIn = new FileInputStream(configFile);
|
||||
Properties props = new Properties();
|
||||
props.load(configIn);
|
||||
log.debug("Config Props [{}] Found.", props);
|
||||
CONFIG_PROPS.putAll(props);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Load Config [{}] Error Caused.", configPath, e);
|
||||
}
|
||||
finally {
|
||||
if (configIn != null) {
|
||||
try {
|
||||
configIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Config Input Stream Close Error Caused.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.info("Config File [{}] Does Not Exist, Ignore.", configPath);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<context:property-placeholder properties-ref="configProps" />
|
||||
</beans>
|
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util
|
||||
http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<util:constant id="configProps"
|
||||
static-field="me.chyxion.tigon.propsconfig.PropsConfig.CONFIG_PROPS" />
|
||||
<context:property-placeholder properties-ref="configProps" />
|
||||
</beans>
|
@ -1,12 +0,0 @@
|
||||
package me.chyxion.tigon.propsconfig;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Dec 1, 2016 2:42:36 PM
|
||||
*/
|
||||
public class TestDriver {
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="encoding" value="utf-8" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="org.apache.log4j.RollingFileAppender">
|
||||
<param name="encoding" value="utf-8" />
|
||||
<param name="MaxFileSize" value="64MB" />
|
||||
<param name="MaxBackupIndex" value="16" />
|
||||
<param name="File" value="E:\\Workspaces\\Eclipse\\FlagInfoEChat\\Commons\\echat-db/.log/echat-db-test.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="org.apache">
|
||||
<level value="warn" />
|
||||
<appender-ref ref="file" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework">
|
||||
<level value="warn" />
|
||||
<appender-ref ref="file" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="debug" />
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="file" />
|
||||
</root>
|
||||
</log4j:configuration>
|
@ -1,50 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||
<import resource="classpath:spring/spring-echat-redis.xml" />
|
||||
<bean class="cn.com.flaginfo.web.cache.RedisCacheConfig" />
|
||||
<aop:aspectj-autoproxy proxy-target-class="true" />
|
||||
<bean id="dataSource"
|
||||
class="com.alibaba.druid.pool.DruidDataSource"
|
||||
init-method="init"
|
||||
destroy-method="close"
|
||||
p:url="${db.url}"
|
||||
p:username="${db.user}"
|
||||
p:password="${db.password}"
|
||||
/>
|
||||
<!-- Transaction Manager -->
|
||||
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
|
||||
p:dataSource-ref="dataSource" />
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
<!-- MyBatis SqlSessionFactory -->
|
||||
<bean id="sqlSessionFactory" class="me.chyxion.tigon.dao.mybatis.SqlSessionFactoryBeanExt"
|
||||
p:dataSource-ref="dataSource"
|
||||
p:configLocation="classpath:mybatis/mybatis-config.xml"
|
||||
p:typeAliasesPackage="${project.groupId}.**.models"
|
||||
p:mapperLocations="classpath*:mybatis/mappers/**/*-mapper.xml">
|
||||
<property name="plugins">
|
||||
<list>
|
||||
<bean class="me.chyxion.tigon.dao.mybatis.pagination.PaginationIntercepter"
|
||||
p:dataSource-ref="dataSource" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- MyBatis Mapper Auto Scan -->
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
|
||||
p:basePackage="${project.groupId}.**.mappers"
|
||||
p:sqlSessionFactoryBeanName="sqlSessionFactory"
|
||||
/>
|
||||
</beans>
|
@ -1 +0,0 @@
|
||||
# tigon-redis
|
@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<artifactId>tigon-redis</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Redis</name>
|
||||
<description>Tigon Redis</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,25 +0,0 @@
|
||||
package me.chyxion.tigon.redis.pub;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Nov 7, 2015 5:32:36 PM
|
||||
*/
|
||||
public interface PubProducer {
|
||||
String PUB_QUEUE_SUFFIX = "_QUEUE";
|
||||
String MESSAGE_CHANEL = "__PUBLICATION__";
|
||||
|
||||
/**
|
||||
* @param topic topic
|
||||
* @param message message
|
||||
*/
|
||||
void publish(String topic, Object message);
|
||||
|
||||
/**
|
||||
* @param topic topic
|
||||
* @param message message
|
||||
*/
|
||||
void publish(String topic, String message);
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package me.chyxion.tigon.redis.pub.support;
|
||||
|
||||
import me.chyxion.tigon.redis.pub.PubProducer;
|
||||
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Nov 7, 2015 5:07:50 PM
|
||||
*/
|
||||
public class PubProducerSupport
|
||||
implements PubProducer {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
@Autowired
|
||||
private StringRedisTemplate strRedisTpl;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(String topic, Object message) {
|
||||
publish(redisTpl, topic, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(String topic, String message) {
|
||||
publish(strRedisTpl, topic, message);
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
|
||||
private <T> void publish(
|
||||
RedisTemplate<String, T> redisTpl, String topic, T message) {
|
||||
redisTpl.opsForList().rightPush(topic + PUB_QUEUE_SUFFIX, message);
|
||||
strRedisTpl.convertAndSend(MESSAGE_CHANEL, topic);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<description>Tigon Redis</description>
|
||||
|
||||
<!-- Redis Config -->
|
||||
<bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
||||
p:host-name="${redis.host:localhost}"
|
||||
p:port="${redis.port:6379}"
|
||||
p:password="${redis.password:}"
|
||||
p:database="${redis.database:0}" />
|
||||
<!-- String tpl -->
|
||||
<bean class="org.springframework.data.redis.core.StringRedisTemplate">
|
||||
<constructor-arg ref="redisConnectionFactory" />
|
||||
</bean>
|
||||
<!-- Object tpl -->
|
||||
<bean class="org.springframework.data.redis.core.RedisTemplate">
|
||||
<property name="connectionFactory" ref="redisConnectionFactory" />
|
||||
<property name="keySerializer">
|
||||
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
|
||||
</property>
|
||||
<property name="hashKeySerializer">
|
||||
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
|
||||
</property>
|
||||
<property name="valueSerializer">
|
||||
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
|
||||
</property>
|
||||
<property name="hashValueSerializer">
|
||||
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
|
||||
</property>
|
||||
</bean>
|
||||
<!-- Pub Producer -->
|
||||
<bean class="me.chyxion.tigon.redis.pub.support.PubProducerSupport" />
|
||||
</beans>
|
@ -1,18 +0,0 @@
|
||||
package cn.com.flaginfo.echat.redis;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Mar 14, 2015 3:03:57 PM
|
||||
*/
|
||||
public class TestDriver {
|
||||
|
||||
@Test
|
||||
public void testHash() {
|
||||
// System.err.println(new AuthConfig().hashPassword("123", "456"));
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package cn.com.flaginfo.echat.redis.test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import me.chyxion.tigon.redis.pub.PubProducer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Nov 9, 2015 9:08:17 AM
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({
|
||||
"classpath:spring/spring-echat-redis.xml",
|
||||
"classpath:spring/spring-redis-test.xml",
|
||||
})
|
||||
public class TestPub {
|
||||
@Autowired
|
||||
private PubProducer pp;
|
||||
|
||||
@Test
|
||||
public void testRun() {
|
||||
pp.publish("MESSAGE", "Hello, Redis Pub!" + new Date());
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package cn.com.flaginfo.echat.redis.test;
|
||||
|
||||
import org.junit.Test;
|
||||
import java.util.Scanner;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Nov 9, 2015 9:27:19 AM
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({
|
||||
"classpath:spring/spring-echat-redis.xml",
|
||||
"classpath:spring/spring-redis-test.xml",
|
||||
"classpath:spring/spring-redis-sub-test.xml",
|
||||
})
|
||||
public class TestSub {
|
||||
|
||||
@Test
|
||||
public void testRun() {
|
||||
new Scanner(System.in).next();
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
log4j.rootLogger=debug, console
|
||||
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.console.Encoding=utf-8
|
||||
log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
@ -1,11 +0,0 @@
|
||||
# Config Dev
|
||||
|
||||
# Redis
|
||||
redis.host=127.0.0.1
|
||||
#redis.port=6379
|
||||
#redis.password=0211
|
||||
redis.port=6380
|
||||
redis.password=6ca2b1bf0fe311e5:Y24kfEiNJxQFc17D
|
||||
|
||||
#redis.port=6382
|
||||
#redis.password=e1605352ed8511e4:F92dd46acd0fe11e4
|
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<bean class="cn.com.flaginfo.echat.redis.test.MessageSubConsumer" />
|
||||
</beans>
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||
|
||||
</beans>
|
@ -21,6 +21,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>bson</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
|
@ -21,7 +21,7 @@ public interface BaseCrudByFormService
|
||||
FormForUpdate extends BaseFormForUpdateApi<PrimaryKey>>
|
||||
extends BaseCrudService<PrimaryKey, Model>,
|
||||
BaseQueryService<PrimaryKey, Model>,
|
||||
BaseDeleteService<PrimaryKey> {
|
||||
BaseDeleteService<PrimaryKey, Model> {
|
||||
|
||||
/**
|
||||
* @param form form
|
||||
|
@ -6,9 +6,8 @@ import me.chyxion.tigon.mybatis.Search;
|
||||
import me.chyxion.tigon.model.BaseModel;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
@ -20,7 +19,7 @@ import org.hibernate.validator.constraints.NotEmpty;
|
||||
public interface BaseCrudService
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>>
|
||||
extends BaseQueryService<PrimaryKey, Model>,
|
||||
BaseDeleteService<PrimaryKey> {
|
||||
BaseDeleteService<PrimaryKey, Model> {
|
||||
|
||||
/**
|
||||
* @param model form
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.chyxion.tigon.service;
|
||||
|
||||
import java.util.List;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -13,17 +14,19 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
* Nov 7, 2016 4:20:42 PM
|
||||
*/
|
||||
@Validated
|
||||
public interface BaseDeleteService<PrimaryKey> {
|
||||
public interface BaseDeleteService<PrimaryKey, Model> {
|
||||
|
||||
/**
|
||||
* delete by search
|
||||
* @param search search
|
||||
* @return models deleted
|
||||
*/
|
||||
int delete(@NotNull Search search);
|
||||
List<Model> delete(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* delete by primaryKey
|
||||
* @param primaryKey primaryKey
|
||||
* @return model deleted
|
||||
*/
|
||||
int delete(@NotNullOrBlank PrimaryKey primaryKey);
|
||||
Model delete(@NotNullOrBlank PrimaryKey primaryKey);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.util.List;
|
||||
import me.chyxion.tigon.model.BaseModel;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
|
@ -52,11 +52,13 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.0.28</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -77,6 +79,7 @@
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -30,9 +30,11 @@ public class BaseCrudByFormServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> create(FormForCreate form) {
|
||||
log.debug("Create Form [{}].", form);
|
||||
log.debug("Create form [{}].", form);
|
||||
validate(form);
|
||||
return create(form.copy(modelType));
|
||||
final Model model = form.copy(modelType);
|
||||
beforeCreate(form, model);
|
||||
return create(model);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,13 +42,15 @@ public class BaseCrudByFormServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> update(FormForUpdate form) {
|
||||
log.debug("Update form [{}].", form);
|
||||
validate(form);
|
||||
PrimaryKey primaryKey = form.getId();
|
||||
Model model = find(primaryKey);
|
||||
Assert.state(model != null, "No Model [" + primaryKey + "] Found");
|
||||
return update(form.copy(model));
|
||||
Assert.state(model != null, "No model [" + primaryKey + "] found");
|
||||
form.copy(model);
|
||||
beforeUpdate(form, model);
|
||||
return update(model);
|
||||
}
|
||||
|
||||
|
||||
// --
|
||||
// private methods
|
||||
@ -66,4 +70,12 @@ public class BaseCrudByFormServiceSupport
|
||||
protected void validate(FormForUpdate form) {
|
||||
// For Override
|
||||
}
|
||||
|
||||
protected void beforeCreate(FormForCreate form, Model model) {
|
||||
|
||||
}
|
||||
|
||||
protected void beforeUpdate(FormForUpdate form, Model model) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,13 @@
|
||||
package me.chyxion.tigon.service.support;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chyxion.tigon.model.BaseModel;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import me.chyxion.tigon.model.BaseModel;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import me.chyxion.tigon.service.BaseCrudService;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
@ -35,27 +29,21 @@ public class BaseCrudServiceSupport
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int delete(Search search) {
|
||||
return mapper.delete(search);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int delete(PrimaryKey primaryKey) {
|
||||
return mapper.delete(primaryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> create(Model model) {
|
||||
beforeInsert(model);
|
||||
mapper.insert(model);
|
||||
afterInsert(model);
|
||||
return toViewModel(model);
|
||||
public List<Model> delete(final Search search) {
|
||||
log.info("Delete model by search [{}].", search);
|
||||
final List<Model> models = mapper.list(search);
|
||||
if (models != null && !models.isEmpty()) {
|
||||
for (Model model : models) {
|
||||
log.info("Delete model [{}].", model);
|
||||
beforeDelete(model);
|
||||
mapper.delete(model.primaryKeyValue());
|
||||
afterDelete(model);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.warn("No model found by search [{}] to delete.", search);
|
||||
}
|
||||
return models;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,10 +51,45 @@ public class BaseCrudServiceSupport
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ViewModel<Model>> create(@NotEmpty Collection<Model> models) {
|
||||
List<ViewModel<Model>> viewModels = new ArrayList<ViewModel<Model>>(models.size());
|
||||
public Model delete(final PrimaryKey primaryKey) {
|
||||
log.info("Delete model by PK [{}].", primaryKey);
|
||||
final Model model = mapper.find(primaryKey);
|
||||
if (model != null) {
|
||||
log.info("Delete model [{}].", model);
|
||||
beforeDelete(model);
|
||||
mapper.delete(primaryKey);
|
||||
afterDelete(model);
|
||||
}
|
||||
else {
|
||||
log.warn("No model found by PK [{}] to delete.", primaryKey);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> create(Model model) {
|
||||
return create(Arrays.asList(model)).iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ViewModel<Model>> create(Collection<Model> models) {
|
||||
for (final Model model : models) {
|
||||
model.beforeInsert();
|
||||
beforeInsert(model);
|
||||
}
|
||||
mapper.insert(models);
|
||||
final List<ViewModel<Model>> viewModels =
|
||||
new ArrayList<>(models.size());
|
||||
for (Model model : models) {
|
||||
viewModels.add(create(model));
|
||||
afterInsert(model);
|
||||
viewModels.add(toViewModel(model));
|
||||
}
|
||||
return viewModels;
|
||||
}
|
||||
@ -87,7 +110,7 @@ public class BaseCrudServiceSupport
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int update(@NotNull Model model, @NotNull Search search) {
|
||||
public int update(Model model, Search search) {
|
||||
return mapper.update(model, search);
|
||||
}
|
||||
|
||||
@ -95,7 +118,7 @@ public class BaseCrudServiceSupport
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int update(@NotEmpty Map<String, ?> model, @NotNullOrBlank PrimaryKey primaryKey) {
|
||||
public int update(Map<String, ?> model, PrimaryKey primaryKey) {
|
||||
return mapper.update(model, primaryKey);
|
||||
}
|
||||
|
||||
@ -104,7 +127,7 @@ public class BaseCrudServiceSupport
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int update(@NotEmpty Map<String, ?> model, @NotNull Search search) {
|
||||
public int update(Map<String, ?> model, Search search) {
|
||||
return mapper.update(model, search);
|
||||
}
|
||||
|
||||
@ -133,4 +156,12 @@ public class BaseCrudServiceSupport
|
||||
protected void afterUpdate(Model model) {
|
||||
// Hook
|
||||
}
|
||||
|
||||
protected void beforeDelete(Model model) {
|
||||
// Hook
|
||||
}
|
||||
|
||||
protected void afterDelete(Model model) {
|
||||
// Hook
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class BaseQueryServiceSupport
|
||||
extends BaseServiceSupport<PrimaryKey, Model, Mapper>
|
||||
implements BaseQueryService<PrimaryKey, Model> {
|
||||
|
||||
@Value("${default.query.batch.size:32}")
|
||||
@Value("${tigon.query.batch.size:32}")
|
||||
private int scanBatchSize;
|
||||
|
||||
/**
|
||||
@ -33,7 +33,7 @@ public class BaseQueryServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public Model find(PrimaryKey primaryKey) {
|
||||
log.debug("Find Model By PrimaryKey [{}].", primaryKey);
|
||||
log.debug("Find model by primary key [{}].", primaryKey);
|
||||
return mapper.find(primaryKey);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class BaseQueryServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public Model find(Search search) {
|
||||
log.debug("Find Model By Search [{}].", search);
|
||||
log.debug("Find model by search [{}].", search);
|
||||
return mapper.find(search);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ public class BaseQueryServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public List<Model> list(Search search) {
|
||||
log.debug("List Models By Search [{}].", search);
|
||||
log.debug("List models by search [{}].", search);
|
||||
return mapper.list(search);
|
||||
}
|
||||
|
||||
@ -60,8 +60,8 @@ public class BaseQueryServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public ListResult<Model> listPage(Search search) {
|
||||
log.debug("List Models Page By Search [{}].", search);
|
||||
return new ListResult<Model>(list(search), count(search));
|
||||
log.debug("List models page by search [{}].", search);
|
||||
return new ListResult<>(list(search), count(search));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +88,7 @@ public class BaseQueryServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public int count(Search search) {
|
||||
log.debug("Count Model By Search [{}].", search);
|
||||
log.debug("Count model by search [{}].", search);
|
||||
return mapper.count(search);
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ public class BaseQueryServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public List<ViewModel<Model>> listViewModels(Search search) {
|
||||
log.debug("List View Models By Search [{}].", search);
|
||||
log.debug("List view models by search [{}].", search);
|
||||
return toViewModel(list(search));
|
||||
}
|
||||
|
||||
@ -107,8 +107,8 @@ public class BaseQueryServiceSupport
|
||||
@Override
|
||||
public ListResult<ViewModel<Model>> listViewModelsPage(
|
||||
Search search) {
|
||||
log.debug("List View Models Page By Search [{}].", search);
|
||||
return new ListResult<ViewModel<Model>>(
|
||||
log.debug("List view models page by search [{}].", search);
|
||||
return new ListResult<>(
|
||||
listViewModels(search),
|
||||
count(search));
|
||||
}
|
||||
@ -174,6 +174,7 @@ public class BaseQueryServiceSupport
|
||||
/**
|
||||
* @return the mapper
|
||||
*/
|
||||
@Override
|
||||
public Mapper getMapper() {
|
||||
return mapper;
|
||||
}
|
||||
@ -181,6 +182,7 @@ public class BaseQueryServiceSupport
|
||||
/**
|
||||
* @param mapper the mapper to set
|
||||
*/
|
||||
@Override
|
||||
public void setMapper(Mapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
@ -56,9 +56,8 @@ public class BaseServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> toViewModel(Model model) {
|
||||
ViewModel<Model> viewModel =
|
||||
new ViewModel<Model>(model);
|
||||
log.debug("Model [{}] To View Model.", model);
|
||||
final ViewModel<Model> viewModel = new ViewModel<>(model);
|
||||
log.debug("Model [{}] to view model.", model);
|
||||
processViewModel(viewModel, model);
|
||||
return viewModel;
|
||||
}
|
||||
@ -68,9 +67,9 @@ public class BaseServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public List<ViewModel<Model>> toViewModel(List<Model> models) {
|
||||
List<ViewModel<Model>> viewModels = null;
|
||||
final List<ViewModel<Model>> viewModels;
|
||||
if (models != null && !models.isEmpty()) {
|
||||
viewModels = new ArrayList<ViewModel<Model>>(models.size());
|
||||
viewModels = new ArrayList<>(models.size());
|
||||
for (Model model : models) {
|
||||
viewModels.add(toViewModel(model));
|
||||
}
|
||||
@ -82,14 +81,23 @@ public class BaseServiceSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* url cache clear
|
||||
* @param model model
|
||||
* @param url url
|
||||
* @return url
|
||||
*/
|
||||
protected String urlCacheClear(M1<PrimaryKey> model, String url) {
|
||||
Date dateUpdated = model.getDateUpdated();
|
||||
return dateUpdated != null ?
|
||||
url + "?_d=" + dateUpdated.getTime() : url;
|
||||
return urlCacheClear(url, model.getDateUpdated());
|
||||
}
|
||||
|
||||
/**
|
||||
* url cache clear
|
||||
* @param url url
|
||||
* @param date date
|
||||
* @return url
|
||||
*/
|
||||
protected String urlCacheClear(final String url, final Date date) {
|
||||
return date != null ? url + "?_d=" + date.getTime() : url;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,27 +20,15 @@
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<!-- shiro -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
|
@ -14,6 +14,7 @@ import org.apache.shiro.cache.CacheException;
|
||||
import me.chyxion.tigon.shiro.model.AuthUser;
|
||||
import me.chyxion.tigon.shiro.cache.SessionCache;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
@ -28,8 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
|
||||
@Autowired
|
||||
protected RedisTemplate<Serializable, Serializable> redisTpl;
|
||||
@Value("${shiro.session.redis.prefix:AUTH_SESSION}")
|
||||
@Qualifier("redisTemplate")
|
||||
protected RedisTemplate<Object, Object> redisTpl;
|
||||
@Value("${tigon.shiro.session.redis.prefix:AUTH_SESSION}")
|
||||
protected String prefix;
|
||||
protected String userIdSessionPrefix;
|
||||
|
||||
@ -65,9 +67,9 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
*/
|
||||
@Override
|
||||
public Session put(Serializable sessionId, Session session) {
|
||||
log.info("Redis Session Cache Put [{}:{}:{}].", prefix, sessionId, session);
|
||||
log.info("Redis session cache put [{}:{}:{}].", prefix, sessionId, session);
|
||||
valueOp().set(prefix + ":" + sessionId,
|
||||
(Serializable) session,
|
||||
session,
|
||||
session.getTimeout(),
|
||||
TimeUnit.MILLISECONDS);
|
||||
return session;
|
||||
@ -78,10 +80,10 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
*/
|
||||
@Override
|
||||
public Session remove(Serializable sessionId) {
|
||||
log.info("Redis Session Cache Remove [{}].", sessionId);
|
||||
log.info("Redis session cache remove [{}].", sessionId);
|
||||
Session session = get(sessionId);
|
||||
if (session != null) {
|
||||
log.info("Redis Session Cache Remove [{}].", session);
|
||||
log.info("Redis session cache remove [{}].", session);
|
||||
redisTpl.delete(prefix + ":" + sessionId);
|
||||
}
|
||||
return session;
|
||||
@ -92,7 +94,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
*/
|
||||
@Override
|
||||
public void clear() throws CacheException {
|
||||
log.warn("Redis Session Cache #clear Not Supported");
|
||||
log.warn("Redis session cache #clear not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +111,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
*/
|
||||
@Override
|
||||
public Set<Serializable> keys() {
|
||||
log.warn("Redis Session Cache #keys Not Supported");
|
||||
log.warn("Redis session cache #keys not supported");
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@ -118,7 +120,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
*/
|
||||
@Override
|
||||
public Collection<Session> values() {
|
||||
log.warn("Redis Session Cache #values Not Supported");
|
||||
log.warn("Redis session cache #values not supported");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@ -127,15 +129,15 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
*/
|
||||
@Override
|
||||
public Session findByUserId(final Serializable userId) {
|
||||
log.debug("Find Session By User Id [{}].", userId);
|
||||
log.debug("Find session by user id [{}].", userId);
|
||||
Serializable sessionId = hashOp().get(userIdSessionPrefix, userId);
|
||||
Session session = null;
|
||||
if (sessionId != null) {
|
||||
log.debug("User [{}] Session Id [{}] Found.", userId, sessionId);
|
||||
log.debug("User [{}] session id [{}] found.", userId, sessionId);
|
||||
session = get(sessionId);
|
||||
log.info("User [{}] Session [{}] Found.", userId, session);
|
||||
log.info("User [{}] session [{}] found.", userId, session);
|
||||
if (session == null) {
|
||||
log.info("No User [{}] Session Found, Remove.");
|
||||
log.info("No user [{}] session found, remove.");
|
||||
hashOp().delete(userIdSessionPrefix, userId);
|
||||
}
|
||||
}
|
||||
@ -147,23 +149,23 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||
*/
|
||||
@Override
|
||||
public Session putUserSession(Session session) {
|
||||
log.info("Put User Session [{}].", session);
|
||||
log.info("Put user session [{}].", session);
|
||||
AuthUser<?> authUser = AuthUser.get(session);
|
||||
Assert.state(authUser != null, "Auth User Not Found In Session");
|
||||
Assert.state(authUser != null, "Auth user not found in session");
|
||||
final Serializable userId = authUser.getUserId();
|
||||
Assert.state(userId != null, "Session Auth User Id Could Not Be Null");
|
||||
log.info("Put User [{}] Session [{}].", userId, session);
|
||||
Assert.state(userId != null, "Session auth user id could not be null");
|
||||
log.info("Put user [{}] session [{}].", userId, session);
|
||||
hashOp().put(userIdSessionPrefix, userId, session.getId());
|
||||
return session;
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
protected HashOperations<Serializable, Serializable, Serializable> hashOp() {
|
||||
protected HashOperations<Object, Serializable, Serializable> hashOp() {
|
||||
return redisTpl.<Serializable, Serializable>opsForHash();
|
||||
}
|
||||
|
||||
protected ValueOperations<Serializable, Serializable> valueOp() {
|
||||
protected ValueOperations<Object, Object> valueOp() {
|
||||
return redisTpl.opsForValue();
|
||||
}
|
||||
}
|
||||
|
@ -23,23 +23,17 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<!-- shiro -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
|
@ -4,7 +4,7 @@ import java.io.Serializable;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.session.Session;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
|
@ -3,9 +3,9 @@ package me.chyxion.tigon.shiro.model;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.Map;
|
||||
import lombok.ToString;
|
||||
import java.util.HashMap;
|
||||
import java.io.Serializable;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.apache.shiro.session.Session;
|
||||
@ -19,6 +19,7 @@ import org.apache.shiro.session.Session;
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class AuthUser<U> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -71,21 +72,13 @@ public class AuthUser<U> implements Serializable {
|
||||
* @param authUser auth user
|
||||
*/
|
||||
public static void save(Session session, AuthUser<?> authUser) {
|
||||
Assert.notNull(session);
|
||||
Assert.notNull(authUser);
|
||||
Assert.state(authUser.getUserId() != null, "User Id Is Null");
|
||||
Assert.notNull(session, "Session could not be null");
|
||||
Assert.notNull(authUser, "Auth user could not be null");
|
||||
Assert.state(authUser.getUserId() != null, "Auth user id could not be null");
|
||||
session.setAttribute(SESSION_AUTH_USER_KEY, authUser);
|
||||
session.touch();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name attr name
|
||||
* @param value attr value
|
||||
@ -93,7 +86,7 @@ public class AuthUser<U> implements Serializable {
|
||||
*/
|
||||
public AuthUser<U> setAttr(String name, Serializable value) {
|
||||
if (attrs == null) {
|
||||
attrs = new HashMap<String, Serializable>();
|
||||
attrs = new HashMap<>();
|
||||
}
|
||||
attrs.put(name, value);
|
||||
return this;
|
||||
|
9
tigon-shiro-cas/.gitignore
vendored
Normal file
9
tigon-shiro-cas/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
.*
|
||||
!.gitignore
|
||||
!.gitkeep
|
||||
*.iml
|
||||
**/src/main/resources/application.properties
|
||||
**/src/main/resources/log4j2.xml
|
||||
**/src/main/resources/logback.xml
|
||||
target/
|
||||
bin/
|
1
tigon-shiro-cas/README.md
Normal file
1
tigon-shiro-cas/README.md
Normal file
@ -0,0 +1 @@
|
||||
# CAS Client Shiro
|
@ -4,9 +4,10 @@
|
||||
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>
|
||||
<artifactId>tigon-shiro-war</artifactId>
|
||||
<name>Tigon Shiro WAR</name>
|
||||
<artifactId>tigon-shiro-cas</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>CAS Client Shiro</name>
|
||||
<description>CAS Client Shiro</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
@ -21,19 +22,28 @@
|
||||
<artifactId>tigon-shiro-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.pac4j</groupId>
|
||||
<artifactId>pac4j-cas</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.buji</groupId>
|
||||
<artifactId>buji-pac4j</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
@ -0,0 +1,57 @@
|
||||
package me.chyxion.tigon.shiro.cas;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.util.function.Consumer;
|
||||
import org.pac4j.core.context.WebContext;
|
||||
import org.pac4j.core.profile.CommonProfile;
|
||||
import org.pac4j.core.credentials.TokenCredentials;
|
||||
import org.pac4j.core.profile.creator.ProfileCreator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 23, 2018 16:17:53
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultProfileCreator implements ProfileCreator<TokenCredentials, CommonProfile> {
|
||||
|
||||
@Autowired(required = false)
|
||||
private UserProfileProvider userProfileProvider;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CommonProfile create(final TokenCredentials credentials, final WebContext context) {
|
||||
log.debug("Create user profile from credentials [{}].", credentials);
|
||||
|
||||
final CommonProfile userProfile = credentials.getUserProfile();
|
||||
if (userProfileProvider != null) {
|
||||
log.debug("User profile provider [{}] found.", userProfileProvider);
|
||||
final UserProfileProvider.UserProfile userProfileResult =
|
||||
userProfileProvider.getUserProfile(userProfile.getId());
|
||||
if (userProfileResult != null) {
|
||||
applyIfNotEmpty(userProfileResult.getRoles(), userProfile::addRoles);
|
||||
applyIfNotEmpty(userProfileResult.getPermissions(), userProfile::addPermissions);
|
||||
applyIfNotEmpty(userProfileResult.getAttrs(), userProfile::addAttributes);
|
||||
applyIfNotEmpty(userProfileResult.getAuthAttrs(), userProfile::addAuthenticationAttributes);
|
||||
}
|
||||
}
|
||||
return userProfile;
|
||||
}
|
||||
|
||||
private <T> void applyIfNotEmpty(final Collection<T> data, final Consumer<Collection<T>> consumer) {
|
||||
if (data != null && !data.isEmpty()) {
|
||||
consumer.accept(data);
|
||||
}
|
||||
}
|
||||
|
||||
private <K, V> void applyIfNotEmpty(final Map<K, V> data, final Consumer<Map<K, V>> consumer) {
|
||||
if (data != null && !data.isEmpty()) {
|
||||
consumer.accept(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package me.chyxion.tigon.shiro.cas;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 26, 2018 21:57:43
|
||||
*/
|
||||
@Validated
|
||||
public interface UserProfileProvider {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
class UserProfile {
|
||||
private Set<String> roles;
|
||||
private Set<String> permissions;
|
||||
private Map<String, Object> attrs;
|
||||
private Map<String, Object> authAttrs;
|
||||
}
|
||||
|
||||
UserProfile getUserProfile(@NotBlank String account);
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<description>Shiro CAS Configuration</description>
|
||||
|
||||
<bean id="securityManager" parent="securityManagerParent">
|
||||
<property name="subjectFactory">
|
||||
<bean class="io.buji.pac4j.subject.Pac4jSubjectFactory" />
|
||||
</property>
|
||||
<property name="realm">
|
||||
<bean class="io.buji.pac4j.realm.Pac4jRealm" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="casConfig" class="org.pac4j.core.config.Config">
|
||||
<constructor-arg>
|
||||
<bean class="org.pac4j.cas.client.CasClient">
|
||||
<constructor-arg>
|
||||
<bean class="org.pac4j.cas.config.CasConfiguration">
|
||||
<constructor-arg value="${tigon.shiro.cas.login-url:${tigon.shiro.cas.server.addr}/login}" />
|
||||
<property name="protocol" value="${tigon.shiro.cas.protocol:CAS20}" />
|
||||
<property name="acceptAnyProxy" value="true" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<property name="name" value="${spring.application.name}" />
|
||||
<property name="callbackUrl" value="${tigon.shiro.cas.login-callback-url:${tigon.shiro.cas.client.addr}${tigon.shiro.cas.login-callback-path:/cas/login}?client_name=${spring.application.name}}" />
|
||||
<property name="profileCreator">
|
||||
<bean class="me.chyxion.tigon.shiro.cas.DefaultProfileCreator" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="shiroFilter" parent="shiroFilterParent">
|
||||
<property name="securityManager" ref="securityManager" />
|
||||
<property name="loginUrl" value="${tigon.shiro.login-url:${tigon.shiro.cas.server.login-url:${tigon.shiro.cas.server.addr}/login}}?service=${tigon.shiro.cas.client.addr}${tigon.shiro.cas.client.login.path:/cas/login}?client_name=${spring.application.name}}" />
|
||||
|
||||
<property name="filters">
|
||||
<map>
|
||||
<entry key="${tigon.shiro.cas.login-callback-filter-name:cas}">
|
||||
<bean class="io.buji.pac4j.filter.CallbackFilter">
|
||||
<property name="config" ref="casConfig" />
|
||||
<property name="defaultUrl" value="${tigon.shiro.login-success-url:/}" />
|
||||
</bean>
|
||||
</entry>
|
||||
<entry key="${tigon.shiro.cas.security-filter-name:user}">
|
||||
<bean class="io.buji.pac4j.filter.SecurityFilter">
|
||||
<property name="config" ref="casConfig" />
|
||||
<property name="clients" value="${spring.application.name}" />
|
||||
</bean>
|
||||
</entry>
|
||||
<entry key="${tigon.shiro.cas.logout-filter-name:logout}">
|
||||
<bean class="io.buji.pac4j.filter.LogoutFilter">
|
||||
<property name="config" ref="casConfig" />
|
||||
<property name="localLogout" value="${tigon.shiro.cas.local-logout:true}" />
|
||||
<property name="centralLogout" value="${tigon.shiro.cas.central-logout:true}" />
|
||||
<property name="logoutUrlPattern" value="${tigon.shiro.logout-path:/logout}" />
|
||||
<property name="defaultUrl" value="${tigon.shiro.logout-success-url:/}" />
|
||||
</bean>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
|
||||
<property name="filterChainDefinitionMap">
|
||||
<bean class="me.chyxion.tigon.shiro.FilterChainDefinitionMap">
|
||||
<constructor-arg value="${tigon.shiro.filter-chain-definition.config-location:classpath:shiro/auth.properties}" />
|
||||
<constructor-arg>
|
||||
<map>
|
||||
<entry key="${tigon.shiro.cas.login-callback-path:/cas/login}" value="${tigon.shiro.cas.login-callback-filter-name:cas}" />
|
||||
<entry key="${tigon.shiro.cas.logout-path:/logout}" value="${tigon.shiro.cas.logout-filter-name:logout}" />
|
||||
<entry key="${tigon.shiro.cas.logout-success-url:/}" value="anon" />
|
||||
</map>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
@ -0,0 +1,20 @@
|
||||
package me.chyxion.tigon.shiro.cas;
|
||||
|
||||
import org.junit.Test;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Donghuang <br />
|
||||
* donghuang@wacai.com <br />
|
||||
* Sep 1, 2015 2:34:08 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public class TestDriver {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
}
|
||||
}
|
@ -4,5 +4,4 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<!-- Scan Controllers -->
|
||||
<bean class="me.chyxion.tigon.webmvc.test.ControllerTestTool" />
|
||||
</beans>
|
@ -17,6 +17,14 @@
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-sequence</artifactId>
|
||||
@ -24,15 +32,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-webmvc-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -1,115 +0,0 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import javax.servlet.Filter;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import javax.annotation.PostConstruct;
|
||||
import me.chyxion.tigon.webmvc.JSONViewConfig;
|
||||
import me.chyxion.tigon.webmvc.util.ResponseTool;
|
||||
import me.chyxion.tigon.webmvc.exception.ExceptionMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Apr 7, 2015 4:44:04 PM
|
||||
*/
|
||||
public class AuthConfigFactory {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(AuthConfigFactory.class);
|
||||
@Autowired(required = false)
|
||||
private AuthConfig authConfig;
|
||||
@Autowired
|
||||
private ResponseTool responseTool;
|
||||
@Autowired
|
||||
private JSONViewConfig viewConfig;
|
||||
@Autowired(required = false)
|
||||
private ExceptionMessage exceptionMessage;
|
||||
|
||||
private UserFilterExt userFilter;
|
||||
|
||||
/**
|
||||
* @return filters
|
||||
*/
|
||||
public Map<String, Filter> filters() {
|
||||
Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
|
||||
filters.put(AuthConfig.FILTER_USER, userFilter);
|
||||
if (authConfig != null) {
|
||||
authConfig.customizeFilters(filters);
|
||||
}
|
||||
log.info("Auth Filters [{}].", filters);
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return filter routings
|
||||
*/
|
||||
public Map<String, String> filterRoutings() {
|
||||
Map<String, String> routings = new LinkedHashMap<String, String>();
|
||||
routings.put("/assets/**", AuthConfig.FILTER_ANON);
|
||||
InputStream authIn = AuthConfigFactory.class
|
||||
.getResourceAsStream("/shiro/auth.properties");
|
||||
if (authIn != null) {
|
||||
Properties props = new OrderedProperties();
|
||||
try {
|
||||
props.load(authIn);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Load Auth Config Error Caused", e);
|
||||
}
|
||||
finally {
|
||||
if (authIn != null) {
|
||||
try {
|
||||
authIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String name : props.stringPropertyNames()) {
|
||||
routings.put(name, props.getProperty(name));
|
||||
}
|
||||
}
|
||||
log.info("Auth Filter Routings [{}].", routings);
|
||||
return routings;
|
||||
}
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
userFilter = new UserFilterExt(
|
||||
responseTool, viewConfig, exceptionMessage);
|
||||
}
|
||||
|
||||
static class OrderedProperties extends Properties {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final Set<String> keys = new LinkedHashSet<String>();
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
keys.add((String) key);
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Set keySet() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public Set<String> stringPropertyNames() {
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import java.util.*;
|
||||
import lombok.Getter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* @author Donghuang <br>
|
||||
* donghuang@wacai.com <br>
|
||||
* Jun 27, 2018 10:42
|
||||
*/
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class FilterChainDefinitionMap extends LinkedHashMap<String, String> {
|
||||
private final Resource configLocation;
|
||||
|
||||
public FilterChainDefinitionMap(final Resource configLocation) {
|
||||
this.configLocation = configLocation;
|
||||
}
|
||||
|
||||
public FilterChainDefinitionMap(final Resource configLocation, final Map<String, String> map) {
|
||||
super(map);
|
||||
this.configLocation = configLocation;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void init() throws IOException {
|
||||
log.info("Load shiro filter chain definition from config location [{}].", configLocation);
|
||||
|
||||
if (configLocation != null && configLocation.exists()) {
|
||||
final InputStream authIn = configLocation.getInputStream();
|
||||
if (authIn != null) {
|
||||
final Properties props = new OrderedProperties();
|
||||
try {
|
||||
props.load(authIn);
|
||||
}
|
||||
catch (final IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Load shiro filter chain definition config error caused", e);
|
||||
}
|
||||
finally {
|
||||
if (authIn != null) {
|
||||
try {
|
||||
authIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final String path : props.stringPropertyNames()) {
|
||||
final String auth = props.getProperty(path);
|
||||
log.info("Shiro filter chain definition [{}] -> [{}] added.", path, auth);
|
||||
put(path, auth);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.info("No input stream load from shiro filter chain definition config location [{}], ignore.", configLocation);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.info("Shiro filter chain definition config location [{}] does not exist, ignore.", configLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@Slf4j
|
||||
static class OrderedProperties extends Properties {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final Set<String> keys = new LinkedHashSet<>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object put(Object key, Object value) {
|
||||
log.debug("Load shiro filter chain [{}] -> [{}].", key, value);
|
||||
keys.add((String) key);
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Set keySet() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<String> stringPropertyNames() {
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.SessionListener;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* May 14, 2016 2:09:26 PM
|
||||
*/
|
||||
public interface SessionListenerExt extends SessionListener {
|
||||
|
||||
/**
|
||||
* on session validation
|
||||
* @param session session
|
||||
* @return returns true if session has been changed
|
||||
*/
|
||||
boolean onValidation(Session session);
|
||||
}
|
@ -23,7 +23,7 @@ import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO;
|
||||
* Sep 8, 2014 7:43:05 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public class SessionDAOSupport extends EnterpriseCacheSessionDAO {
|
||||
public class TigonSessionDAO extends EnterpriseCacheSessionDAO {
|
||||
@Autowired(required = false)
|
||||
private Cache<Serializable, Session> sessionCache;
|
||||
@Autowired
|
||||
@ -36,9 +36,9 @@ public class SessionDAOSupport extends EnterpriseCacheSessionDAO {
|
||||
void init() {
|
||||
if (sessionCache == null) {
|
||||
log.info("No Custom Session Store Found, Use Map Cache.");
|
||||
sessionCache = new MapCache<Serializable, Session>(
|
||||
sessionCache = new MapCache<>(
|
||||
CachingSessionDAO.ACTIVE_SESSION_CACHE_NAME,
|
||||
new ConcurrentHashMap<Serializable, Session>());
|
||||
new ConcurrentHashMap<>(512));
|
||||
}
|
||||
else {
|
||||
log.info("Use Custom Session Cache [{}].", sessionCache);
|
@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* chyxion@163.com <br>
|
||||
* Mar 12, 2015 1:18:00 PM
|
||||
*/
|
||||
public class DefaultWebSecurityManagerExt extends DefaultWebSecurityManager {
|
||||
public class TigonWebSecurityManager extends DefaultWebSecurityManager {
|
||||
@Autowired(required = false)
|
||||
private AuthCallback authCallback;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user