Skip to content

Commit 3f2e656

Browse files
committed
2.1-SNAPSHOT
1 parent 45e625b commit 3f2e656

File tree

87 files changed

+921
-1890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+921
-1890
lines changed

hsweb-web-bean/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## 实体类模块,通用bean,po,和自定义验证器
2+
3+
### 目录结构
4+
5+
```bash
6+
--------src/main/java
7+
---------------------org.hsweb.web.bean
8+
----------------------------common # 通用bean,如增删改查通用参数
9+
------------------------------po # 各个功能的po实体
10+
----------------------------validator # 自定义hibernate-validator
11+
-----------------resources/system
12+
---------------------------------install.sql #首次启动时执行的sql
13+
```
14+
15+
### 说明
16+
po对象都应该继承[GenericPo](src/main/java/org/hsweb/web/bean/po/GenericPo.java)
17+
GenericPo 的泛型为主键的类型,hsweb建议使用String类型,通过createUID()方法手动生成id

hsweb-web-bean/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hsweb-framework</artifactId>
77
<groupId>org.hsweb</groupId>
8-
<version>2.0-SNAPSHOT</version>
8+
<version>2.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>hsweb-web-bean</artifactId>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright 2015-2016 http://hsweb.me
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.hsweb.web.bean.po.system;
18+
19+
public class SystemVersion implements Comparable<SystemVersion> {
20+
public String name;
21+
public String comment;
22+
public String website;
23+
public int majorVersion = 1;
24+
public int minorVersion = 0;
25+
public int revisionVersion = 0;
26+
public boolean snapshot;
27+
28+
public String getName() {
29+
return name;
30+
}
31+
32+
public void setName(String name) {
33+
this.name = name;
34+
}
35+
36+
public String getComment() {
37+
return comment;
38+
}
39+
40+
public void setComment(String comment) {
41+
this.comment = comment;
42+
}
43+
44+
public String getWebsite() {
45+
return website;
46+
}
47+
48+
public void setWebsite(String website) {
49+
this.website = website;
50+
}
51+
52+
public int getMajorVersion() {
53+
return majorVersion;
54+
}
55+
56+
public void setMajorVersion(int majorVersion) {
57+
this.majorVersion = majorVersion;
58+
}
59+
60+
public int getMinorVersion() {
61+
return minorVersion;
62+
}
63+
64+
public void setMinorVersion(int minorVersion) {
65+
this.minorVersion = minorVersion;
66+
}
67+
68+
public int getRevisionVersion() {
69+
return revisionVersion;
70+
}
71+
72+
public void setRevisionVersion(int revisionVersion) {
73+
this.revisionVersion = revisionVersion;
74+
}
75+
76+
public boolean isSnapshot() {
77+
return snapshot;
78+
}
79+
80+
public void setSnapshot(boolean snapshot) {
81+
this.snapshot = snapshot;
82+
}
83+
84+
@Override
85+
public int compareTo(SystemVersion o) {
86+
if (null == o) return -1;
87+
if (o.getMajorVersion() > this.getMajorVersion()) return -1;
88+
if (o.getMajorVersion() == this.getMajorVersion()) {
89+
if (o.getMinorVersion() > this.getMinorVersion()) return -1;
90+
if (o.getMinorVersion() == this.getMinorVersion()) {
91+
if (o.getRevisionVersion() > this.getRevisionVersion()) return -1;
92+
if (o.getRevisionVersion() == this.getRevisionVersion()) return 0;
93+
return 1;
94+
} else {
95+
return 1;
96+
}
97+
} else {
98+
return 1;
99+
}
100+
}
101+
102+
public static void main(String[] args) {
103+
SystemVersion systemVersion = new SystemVersion();
104+
systemVersion.setMajorVersion(2);
105+
systemVersion.setMinorVersion(2);
106+
systemVersion.setRevisionVersion(1);
107+
108+
SystemVersion systemVersion2 = new SystemVersion();
109+
systemVersion2.setMajorVersion(3);
110+
systemVersion2.setMinorVersion(2);
111+
systemVersion2.setRevisionVersion(1);
112+
113+
System.out.println(systemVersion.compareTo(systemVersion2));
114+
}
115+
}

hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/template/Template.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
import java.util.List;
66

7-
/**
8-
* Created by zhouhao on 16-5-19.
9-
*/
107
public class Template extends GenericPo<String> {
118

129
private String name;

hsweb-web-concurrent/hsweb-web-concurrent-cache/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hsweb-web-concurrent</artifactId>
77
<groupId>org.hsweb</groupId>
8-
<version>2.0-SNAPSHOT</version>
8+
<version>2.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>hsweb-web-concurrent-cache</artifactId>

hsweb-web-concurrent/hsweb-web-concurrent-lock/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hsweb-web-concurrent</artifactId>
77
<groupId>org.hsweb</groupId>
8-
<version>2.0-SNAPSHOT</version>
8+
<version>2.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>hsweb-web-concurrent-lock</artifactId>

hsweb-web-concurrent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hsweb-framework</artifactId>
77
<groupId>org.hsweb</groupId>
8-
<version>2.0-SNAPSHOT</version>
8+
<version>2.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<packaging>pom</packaging>

hsweb-web-controller/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hsweb-framework</artifactId>
77
<groupId>org.hsweb</groupId>
8-
<version>2.0-SNAPSHOT</version>
8+
<version>2.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>hsweb-web-controller</artifactId>

hsweb-web-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hsweb-framework</artifactId>
77
<groupId>org.hsweb</groupId>
8-
<version>2.0-SNAPSHOT</version>
8+
<version>2.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>hsweb-web-core</artifactId>

hsweb-web-core/src/main/java/org/hsweb/web/core/Install.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
import org.springframework.util.Assert;
2020

2121
import javax.annotation.PostConstruct;
22+
import javax.sql.DataSource;
2223
import java.io.*;
2324
import java.util.ArrayList;
2425
import java.util.List;
2526

26-
/**
27-
* Created by zhouhao on 16-4-23.
28-
*/
2927
@Configuration
3028
@EnableConfigurationProperties({DataSourceProperties.class})
3129
@AutoConfigureAfter({DataSourceAutoConfiguration.class})
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2015-2016 http://hsweb.me
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.hsweb.web.core.datasource;
18+
19+
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.stereotype.Component;
22+
23+
import javax.annotation.PostConstruct;
24+
import javax.sql.DataSource;
25+
import java.sql.Connection;
26+
import java.sql.SQLException;
27+
28+
@Component
29+
public class DataSourceHolder {
30+
31+
private static DynamicDataSource dynamicDataSource;
32+
33+
private static DataSource defaultDataSource;
34+
35+
private static DatabaseType defaultDatabaseType;
36+
37+
@Autowired(required = false)
38+
private DataSource dataSource;
39+
40+
@PostConstruct
41+
public void init() throws SQLException {
42+
if (null != dataSource) {
43+
Connection connection = null;
44+
try {
45+
connection = dataSource.getConnection();
46+
install(dataSource, DatabaseType.fromJdbcUrl(connection.getMetaData().getURL()));
47+
dataSource = null;
48+
} finally {
49+
if (null != connection)
50+
connection.close();
51+
}
52+
}
53+
}
54+
55+
public static DataSource getActiveSource() {
56+
if (dynamicDataSource != null) {
57+
return dynamicDataSource.getActiveDataSource();
58+
}
59+
return defaultDataSource;
60+
}
61+
62+
public static DatabaseType getActiveDatabaseType() {
63+
if (dynamicDataSource != null) {
64+
return dynamicDataSource.getActiveDataBaseType();
65+
}
66+
return defaultDatabaseType;
67+
}
68+
69+
public static DataSource getDefaultDataSource() {
70+
return defaultDataSource;
71+
}
72+
73+
public static DatabaseType getDefaultDatabaseType() {
74+
return defaultDatabaseType;
75+
}
76+
77+
public static void install(DynamicDataSource dynamicDataSource) {
78+
if (DataSourceHolder.dynamicDataSource != null) {
79+
throw new UnsupportedOperationException();
80+
}
81+
DataSourceHolder.dynamicDataSource = dynamicDataSource;
82+
}
83+
84+
public static void install(DataSource dataSource, DatabaseType databaseType) {
85+
if (DataSourceHolder.defaultDataSource != null) {
86+
throw new UnsupportedOperationException();
87+
}
88+
DataSourceHolder.defaultDataSource = dataSource;
89+
DataSourceHolder.defaultDatabaseType = databaseType;
90+
}
91+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2015-2016 http://hsweb.me
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.hsweb.web.core.datasource;
18+
19+
import org.springframework.util.Assert;
20+
import org.springframework.util.StringUtils;
21+
22+
public enum DatabaseType {
23+
unknown(null, null, null),
24+
mysql("com.mysql.jdbc.Driver", "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource", "select 1"),
25+
h2("org.h2.Driver", "org.h2.jdbcx.JdbcDataSource", "select 1"),
26+
oracle("oracle.jdbc.driver.OracleDriver", "oracle.jdbc.xa.client.OracleXADataSource", "select 1 from dual");
27+
28+
DatabaseType(String driverClassName, String xaDataSourceClassName, String testQuery) {
29+
this.driverClassName = driverClassName;
30+
this.testQuery = testQuery;
31+
this.xaDataSourceClassName = xaDataSourceClassName;
32+
}
33+
34+
private final String testQuery;
35+
36+
private final String driverClassName;
37+
38+
private final String xaDataSourceClassName;
39+
40+
public String getDriverClassName() {
41+
return driverClassName;
42+
}
43+
44+
public String getXaDataSourceClassName() {
45+
return xaDataSourceClassName;
46+
}
47+
48+
public String getTestQuery() {
49+
return testQuery;
50+
}
51+
52+
public static DatabaseType fromJdbcUrl(String url) {
53+
if (StringUtils.hasLength(url)) {
54+
Assert.isTrue(url.startsWith("jdbc"), "URL must start with 'jdbc'");
55+
String urlWithoutPrefix = url.substring("jdbc".length()).toLowerCase();
56+
for (DatabaseType driver : values()) {
57+
String prefix = ":" + driver.name().toLowerCase() + ":";
58+
if (driver != unknown && urlWithoutPrefix.startsWith(prefix)) {
59+
return driver;
60+
}
61+
}
62+
}
63+
return unknown;
64+
}
65+
}

hsweb-web-core/src/main/java/org/hsweb/web/core/datasource/DynamicDataSource.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
import javax.sql.CommonDataSource;
2424
import javax.sql.DataSource;
2525

26-
/**
27-
* @author zhouhao
28-
*/
2926
public interface DynamicDataSource extends DataSource {
3027
String DATA_SOURCE_FLAG = "data-source-id";
3128

3229
String DATA_SOURCE_FLAG_LAST = "data-source-id-last";
3330

34-
3531
static void useLast() {
3632
use(ThreadLocalUtils.get(DATA_SOURCE_FLAG_LAST));
3733
}
@@ -55,4 +51,6 @@ static void useDefault() {
5551
}
5652

5753
DataSource getActiveDataSource();
54+
55+
DatabaseType getActiveDataBaseType();
5856
}

0 commit comments

Comments
 (0)