Justice-love 6 ans auparavant
Parent
commit
f8470d1ac3

+ 39 - 0
config/database/pom.xml

@ -0,0 +1,39 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
    <parent>
6
        <artifactId>config</artifactId>
7
        <groupId>org.eddy</groupId>
8
        <version>1.0-SNAPSHOT</version>
9
    </parent>
10
    <modelVersion>4.0.0</modelVersion>
11
12
    <artifactId>database</artifactId>
13
14
    <dependencies>
15
        <dependency>
16
            <groupId>org.eddy</groupId>
17
            <artifactId>share</artifactId>
18
            <version>1.0-SNAPSHOT</version>
19
        </dependency>
20
        <dependency>
21
            <groupId>com.h2database</groupId>
22
            <artifactId>h2</artifactId>
23
        </dependency>
24
        <dependency>
25
            <groupId>com.alibaba</groupId>
26
            <artifactId>druid</artifactId>
27
        </dependency>
28
        <dependency>
29
            <groupId>org.mybatis</groupId>
30
            <artifactId>mybatis</artifactId>
31
            <optional>true</optional>
32
        </dependency>
33
        <dependency>
34
            <groupId>junit</groupId>
35
            <artifactId>junit</artifactId>
36
        </dependency>
37
    </dependencies>
38
39
</project>

+ 51 - 0
config/database/src/main/java/org/eddy/database/DatabaseResourceFinder.java

@ -0,0 +1,51 @@
1
package org.eddy.database;
2
3
import org.apache.ibatis.session.SqlSession;
4
import org.apache.ibatis.session.SqlSessionFactory;
5
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
6
import org.eddy.basic.Resource;
7
import org.eddy.basic.ResourceFinder;
8
9
import java.util.Objects;
10
11
public class DatabaseResourceFinder implements ResourceFinder {
12
13
    private static SqlSessionFactory sessionFactory;
14
15
    static {
16
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
17
        sessionFactory = builder.build(DatabaseResourceFinder.class.getResourceAsStream("/configuration.xml"));
18
    }
19
20
    @Override
21
    public Resource findInitResource(String namespace) {
22
        Objects.requireNonNull(namespace);
23
24
        try (SqlSession sqlSession = sessionFactory.openSession(true)) {
25
            ResourceMapper resourceMapper = sqlSession.getMapper(ResourceMapper.class);
26
            return resourceMapper.findInitResource(namespace);
27
        }
28
    }
29
30
    @Override
31
    public Resource findDynamicResource(String namespace, String name) {
32
        Objects.requireNonNull(namespace);
33
        Objects.requireNonNull(name);
34
35
        try (SqlSession sqlSession = sessionFactory.openSession(true)) {
36
            ResourceMapper resourceMapper = sqlSession.getMapper(ResourceMapper.class);
37
            return resourceMapper.findDynamicResource(namespace, name);
38
        }
39
    }
40
41
    @Override
42
    public Resource findAutoResource(String namespace, String name) {
43
        Objects.requireNonNull(namespace);
44
        Objects.requireNonNull(name);
45
46
        try (SqlSession sqlSession = sessionFactory.openSession(true)) {
47
            ResourceMapper resourceMapper = sqlSession.getMapper(ResourceMapper.class);
48
            return resourceMapper.findAutoResource(namespace, name);
49
        }
50
    }
51
}

+ 23 - 0
config/database/src/main/java/org/eddy/database/DruidSourceFactory.java

@ -0,0 +1,23 @@
1
package org.eddy.database;
2
3
import com.alibaba.druid.pool.DruidDataSourceFactory;
4
import org.apache.ibatis.datasource.DataSourceFactory;
5
6
import javax.sql.DataSource;
7
import java.util.Properties;
8
9
public class DruidSourceFactory implements DataSourceFactory {
10
    private Properties properties;
11
12
    public void setProperties(Properties props) {
13
        this.properties = props;
14
    }
15
16
    public DataSource getDataSource() {
17
        try {
18
            return DruidDataSourceFactory.createDataSource(properties);
19
        } catch (Exception e) {
20
            throw new RuntimeException(e);
21
        }
22
    }
23
}

+ 13 - 0
config/database/src/main/java/org/eddy/database/ResourceMapper.java

@ -0,0 +1,13 @@
1
package org.eddy.database;
2
3
import org.apache.ibatis.annotations.Param;
4
import org.eddy.basic.Resource;
5
6
public interface ResourceMapper {
7
8
    Resource findInitResource(@Param("namespace") String namespace);
9
10
    Resource findDynamicResource(@Param("namespace") String namespace, @Param("name") String name);
11
12
    Resource findAutoResource(@Param("namespace") String namespace, @Param("name") String name);
13
}

+ 1 - 0
config/database/src/main/resources/META-INF/services/org.eddy.basic.ResourceFinder

@ -0,0 +1 @@
1
org.eddy.database.DatabaseResourceFinder

+ 24 - 0
config/database/src/main/resources/ResourceMapper.xml

@ -0,0 +1,24 @@
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
<mapper namespace="org.eddy.database.ResourceMapper">
4
5
    <resultMap id="resource" type="org.eddy.basic.Resource">
6
        <result column="id" property="id"/>
7
        <result column="name" property="name"/>
8
        <result column="namespace" property="namespace"/>
9
        <result column="content" property="content"/>
10
        <result column="type" property="resourceType" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
11
    </resultMap>
12
13
    <sql id="column">id, name, namespace, type, content</sql>
14
    <select id="findInitResource" resultMap="resource">
15
        select <include refid="column"/> from resource where namespace = #{namespace} and type = 'INIT'
16
    </select>
17
    <select id="findDynamicResource" resultMap="resource">
18
        select <include refid="column"/> from resource where namespace = #{namespace} and name = #{name} and type = 'DYNAMIC'
19
    </select>
20
21
    <select id="findAutoResource" resultMap="resource">
22
        select <include refid="column"/> from resource where namespace = #{namespace} and name = #{name} and type = 'AUTO'
23
    </select>
24
</mapper>

+ 45 - 0
config/database/src/main/resources/configuration.xml

@ -0,0 +1,45 @@
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3
4
       Copyright 2009-2016 the original author or authors.
5
6
       Licensed under the Apache License, Version 2.0 (the "License");
7
       you may not use this file except in compliance with the License.
8
       You may obtain a copy of the License at
9
10
          http://www.apache.org/licenses/LICENSE-2.0
11
12
       Unless required by applicable law or agreed to in writing, software
13
       distributed under the License is distributed on an "AS IS" BASIS,
14
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
       See the License for the specific language governing permissions and
16
       limitations under the License.
17
18
-->
19
<!DOCTYPE configuration
20
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
21
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
22
23
<configuration>
24
25
26
27
  <environments default="development">
28
    <environment id="development">
29
      <transactionManager type="JDBC">
30
      </transactionManager>
31
      <dataSource type="org.eddy.database.DruidSourceFactory">
32
        <property name="driver" value="org.h2.Driver" />
33
        <property name="url" value="jdbc:h2:file:~/.h2/configServer" />
34
        <property name="validationQuery" value="SELECT 1" />
35
        <property name="username" value="sa" />
36
      </dataSource>
37
    </environment>
38
  </environments>
39
40
41
  <mappers>
42
    <mapper resource="ResourceMapper.xml"/>
43
  </mappers>
44
45
</configuration>

+ 24 - 0
config/database/src/test/java/org/eddy/DatabaseTest.java

@ -0,0 +1,24 @@
1
package org.eddy;
2
3
import org.eddy.basic.ResourceFinder;
4
import org.eddy.database.DatabaseResourceFinder;
5
import org.junit.Test;
6
7
import java.util.ServiceLoader;
8
9
public class DatabaseTest {
10
11
    @Test
12
    public void test() {
13
        DatabaseResourceFinder finder = new DatabaseResourceFinder();
14
        System.out.println(finder.findInitResource("org.apache.ibatis.eddy.mapper.UserMapper"));
15
    }
16
17
    @Test
18
    public void test2() {
19
        ServiceLoader<ResourceFinder> serviceLoader = ServiceLoader.load(ResourceFinder.class);
20
        for (ResourceFinder aServiceLoader : serviceLoader) {
21
            System.out.println(aServiceLoader.findInitResource("org.apache.ibatis.eddy.mapper.UserMapper"));
22
        }
23
    }
24
}

+ 68 - 0
config/pom.xml

@ -0,0 +1,68 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
    <modelVersion>4.0.0</modelVersion>
6
7
    <groupId>org.eddy</groupId>
8
    <artifactId>config</artifactId>
9
    <packaging>pom</packaging>
10
    <version>1.0-SNAPSHOT</version>
11
    <modules>
12
        <module>share</module>
13
        <module>database</module>
14
    </modules>
15
16
17
    <dependencyManagement>
18
        <dependencies>
19
            <dependency>
20
                <groupId>org.projectlombok</groupId>
21
                <artifactId>lombok</artifactId>
22
                <version>1.16.20</version>
23
            </dependency>
24
25
            <dependency>
26
                <groupId>com.h2database</groupId>
27
                <artifactId>h2</artifactId>
28
                <version>1.4.196</version>
29
                <scope>runtime</scope>
30
            </dependency>
31
            <dependency>
32
                <groupId>com.alibaba</groupId>
33
                <artifactId>druid</artifactId>
34
                <version>1.1.10</version>
35
            </dependency>
36
            <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
37
            <dependency>
38
                <groupId>org.mybatis</groupId>
39
                <artifactId>mybatis</artifactId>
40
                <version>3.4.6</version>
41
                <optional>true</optional>
42
            </dependency>
43
            <!-- https://mvnrepository.com/artifact/junit/junit -->
44
            <dependency>
45
                <groupId>junit</groupId>
46
                <artifactId>junit</artifactId>
47
                <version>4.12</version>
48
                <scope>test</scope>
49
            </dependency>
50
51
        </dependencies>
52
    </dependencyManagement>
53
54
    <build>
55
        <plugins>
56
            <plugin>
57
                <groupId>org.apache.maven.plugins</groupId>
58
                <artifactId>maven-compiler-plugin</artifactId>
59
                <version>3.6.0</version>
60
                <configuration>
61
                    <source>1.8</source>
62
                    <target>1.8</target>
63
                </configuration>
64
            </plugin>
65
        </plugins>
66
    </build>
67
68
</project>

+ 21 - 0
config/share/pom.xml

@ -0,0 +1,21 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
    <parent>
6
        <artifactId>config</artifactId>
7
        <groupId>org.eddy</groupId>
8
        <version>1.0-SNAPSHOT</version>
9
    </parent>
10
    <modelVersion>4.0.0</modelVersion>
11
12
    <artifactId>share</artifactId>
13
14
    <dependencies>
15
        <dependency>
16
            <groupId>org.projectlombok</groupId>
17
            <artifactId>lombok</artifactId>
18
        </dependency>
19
    </dependencies>
20
21
</project>

+ 27 - 0
config/share/src/main/java/org/eddy/basic/Resource.java

@ -0,0 +1,27 @@
1
package org.eddy.basic;
2
3
import lombok.Getter;
4
import lombok.Setter;
5
import lombok.ToString;
6
7
import java.io.ByteArrayInputStream;
8
import java.io.InputStream;
9
10
@Getter @Setter
11
@ToString(exclude = "content")
12
public class Resource {
13
14
    private Long id;
15
    private String name;
16
    private String namespace;
17
    private String content;
18
    private ResourceType resourceType;
19
20
    public InputStream getInputStream() {
21
        return null == content ? null : new ByteArrayInputStream(content.getBytes());
22
    }
23
24
    public String getStatementId() {
25
        return String.join(".", namespace, name);
26
    }
27
}

+ 18 - 0
config/share/src/main/java/org/eddy/basic/ResourceFinder.java

@ -0,0 +1,18 @@
1
package org.eddy.basic;
2
3
import java.util.List;
4
5
public interface ResourceFinder {
6
7
    default Resource findInitResource(String namespace) {
8
        return null;
9
    }
10
11
    default Resource findDynamicResource(String namespace, String name) {
12
        return null;
13
    }
14
15
    default Resource findAutoResource(String namespace, String name) {
16
        return null;
17
    }
18
}

+ 6 - 0
config/share/src/main/java/org/eddy/basic/ResourceType.java

@ -0,0 +1,6 @@
1
package org.eddy.basic;
2
3
public enum  ResourceType {
4
5
    INIT, DYNAMIC, AUTO
6
}

+ 4 - 0
html-data/src/main/java/com/ai/ipu/htmldata/builder/HtmlDataBuilder.java

@ -0,0 +1,4 @@
1
package com.ai.ipu.htmldata.builder;
2
3
public class HtmlDataBuilder {
4
}

+ 4 - 0
html-data/src/main/java/com/ai/ipu/htmldata/builder/Query.java

@ -0,0 +1,4 @@
1
package com.ai.ipu.htmldata.builder;
2
3
public class Query {
4
}