forked from ClouGence/hasor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # pom.xml
- Loading branch information
Showing
55 changed files
with
2,046 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#Hasor-Solon 部署 dataway的 例子 | ||
|
||
1. 部署 dataway,需要用到 solon.boot 相关的包(solon 需要jdk8+支持); | ||
2. 本例用了h2数据库,以确保此例随时可运行; | ||
3. solon 的项目,只支持jar运行。。。本例的pom.xml配置,即是生成jar包;通过mvn package可生成。 | ||
4. 本例已将编译结果放在 bin/目录下 | ||
5. 用此命令可运行:java -jar example-solon_dataway.jar | ||
|
||
|
||
**关于 solon.boot 的配置** | ||
|
||
##### 方案一:undertow | ||
```xml | ||
<dependency> | ||
<groupId>org.noear</groupId> | ||
<artifactId>solon.boot.undertow</artifactId> | ||
</dependency> | ||
``` | ||
|
||
|
||
##### 方案二:jetty (此方案会小2m左右;本例用的是此方案) | ||
```xml | ||
<dependency> | ||
<groupId>org.noear</groupId> | ||
<artifactId>solon.boot.jetty</artifactId> | ||
</dependency> | ||
|
||
<!-- solon.boot.jetty 默认只使用了 handler 接口;所以要添加 jetty-servlet 包,以支持 servlet 容器 --> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-servlet</artifactId> | ||
</dependency> | ||
``` | ||
|
||
#### 补充:如果要使用完整的 solon 功能,比如:事务,缓存,验证,模板等。可以再引入 | ||
```xml | ||
<dependency> | ||
<groupId>org.noear</groupId> | ||
<artifactId>solon-web</artifactId> | ||
<type>pom</type> | ||
</dependency> | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?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> | ||
|
||
<groupId>net.hasor</groupId> | ||
<artifactId>example-solon_dataway</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>${project.artifactId}</name> | ||
<description>java project for solon demo</description> | ||
|
||
<parent> | ||
<groupId>org.noear</groupId> | ||
<artifactId>solon-parent</artifactId> | ||
<version>1.1.1</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.noear</groupId> | ||
<artifactId>solon.boot.jetty</artifactId> | ||
</dependency> | ||
|
||
<!-- 支持 servlet 容器 --> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-servlet</artifactId> | ||
</dependency> | ||
|
||
<!-- 与 net.hasor:hasor-solon 代码相同(因 hasor-solon 未发制,本例用 solon 已发布的包) --> | ||
<dependency> | ||
<groupId>org.noear</groupId> | ||
<artifactId>hasor-solon-plugin</artifactId> | ||
</dependency> | ||
|
||
|
||
<!-- dataway --> | ||
<dependency> | ||
<groupId>net.hasor</groupId> | ||
<artifactId>hasor-dataway</artifactId> | ||
<version>4.2.0</version> | ||
</dependency> | ||
|
||
<!-- 线程池 --> | ||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP</artifactId> | ||
<version>3.3.1</version> | ||
</dependency> | ||
|
||
<!-- mysql 驱动 --> | ||
<!-- <dependency>--> | ||
<!-- <groupId>mysql</groupId>--> | ||
<!-- <artifactId>mysql-connector-java</artifactId>--> | ||
<!-- <version>5.1.49</version>--> | ||
<!-- </dependency>--> | ||
|
||
<!-- H2 驱动 --> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.21</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<finalName>${project.name}</finalName> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<compilerArgument>-parameters</compilerArgument> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<finalName>${project.name}</finalName> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<archive> | ||
<manifest> | ||
<mainClass>webapp.DatawayApp</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- 这段必须加,不然hasor.schemas会丢失掉 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>1.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> | ||
<resource>META-INF/hasor.schemas</resource> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
14 changes: 14 additions & 0 deletions
14
example/example-solon_dataway/src/main/java/webapp/DatawayApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package webapp; | ||
|
||
import net.hasor.solon.boot.EnableHasor; | ||
import net.hasor.solon.boot.EnableHasorWeb; | ||
import org.noear.solon.XApp; | ||
import webapp.dso.module.StartModule; | ||
|
||
@EnableHasor(startWith = StartModule.class) | ||
@EnableHasorWeb | ||
public class DatawayApp { | ||
public static void main(String[] args) throws Throwable { | ||
XApp.start(DatawayApp.class, args); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
example/example-solon_dataway/src/main/java/webapp/dso/DsHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package webapp.dso; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.InputStream; | ||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
public class DsHelper { | ||
public static void initData(DataSource ds) { | ||
Connection conn = null; | ||
try { | ||
conn = ds.getConnection(); | ||
String[] sqls = getSqlFromFile(); | ||
for (String sql : sqls) { | ||
runSql(conn, sql); | ||
} | ||
|
||
} catch (SQLException sqlException) { | ||
throw new RuntimeException(sqlException); | ||
} finally { | ||
try { | ||
if (conn != null) conn.close(); | ||
} catch (SQLException sqlException) { | ||
//ignore | ||
} | ||
} | ||
} | ||
|
||
private static String[] getSqlFromFile() { | ||
try { | ||
InputStream ins = DsHelper.class.getResourceAsStream("/db/schema.sql"); | ||
int len = ins.available(); | ||
byte[] bs = new byte[len]; | ||
ins.read(bs); | ||
String str = new String(bs, "UTF-8"); | ||
String[] sql = str.split(";"); | ||
return sql; | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
private static void runSql(Connection conn, String sql) throws SQLException { | ||
PreparedStatement ps = conn.prepareStatement(sql); | ||
ps.executeUpdate(); | ||
ps.close(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
example/example-solon_dataway/src/main/java/webapp/dso/module/StartModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package webapp.dso.module; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import net.hasor.core.ApiBinder; | ||
import net.hasor.db.JdbcModule; | ||
import net.hasor.db.Level; | ||
import net.hasor.web.WebApiBinder; | ||
import net.hasor.web.WebModule; | ||
import org.noear.solon.XApp; | ||
import org.noear.solon.core.Aop; | ||
import org.noear.solon.core.ExtendLoader; | ||
import webapp.dso.DsHelper; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.Properties; | ||
|
||
public class StartModule implements WebModule { | ||
@Override | ||
public void loadModule(ApiBinder apiBinder) throws Throwable { | ||
apiBinder.installModule(buildDs()); | ||
} | ||
|
||
@Override | ||
public void loadModule(WebApiBinder webApiBinder) throws Throwable { | ||
webApiBinder.installModule(buildDs()); | ||
} | ||
|
||
private JdbcModule buildDs() { | ||
//for mysql | ||
//DataSource ds = Aop.inject(new HikariDataSource(), XApp.cfg().getProp("db1")); | ||
|
||
//for h2 | ||
DataSource ds = buildH2Ds(); | ||
|
||
return new JdbcModule(Level.Full, ds); | ||
} | ||
|
||
private DataSource buildH2Ds() { | ||
//1.替换H2的持久化路径(路径要变,所以不做自动注入处理) | ||
Properties props = XApp.cfg().getProp("db1"); | ||
props.setProperty("jdbcUrl", props.getProperty("jdbcUrl").replace("~/", ExtendLoader.path())); | ||
|
||
//2.生成DataSource | ||
DataSource ds = Aop.inject(new HikariDataSource(), props); | ||
|
||
try { | ||
//3.需要初始化schame(第一次会成功;之后会失败;不用管...) | ||
DsHelper.initData(ds); | ||
} catch (Exception ex) { | ||
|
||
} | ||
|
||
return ds; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
example/example-solon_dataway/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
#for mysql | ||
#db1.schema= rock | ||
#db1.jdbcUrl= jdbc:mysql://localdb:3306/rock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true | ||
#db1.driverClassName= com.mysql.jdbc.Driver | ||
#db1.username= demo | ||
#db1.password= UL0hHlg0Ybq60xyb | ||
|
||
#for h2 //:~/会被转为solon扩展文件 | ||
db1.jdbcUrl=jdbc:h2:~/localjt;MODE=MYSQL;DB_CLOSE_DELAY=-1;AUTO_RECONNECT=TRUE;DATABASE_TO_LOWER=TRUE;IGNORECASE=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE | ||
db1.driverClassName=org.h2.Driver | ||
db1.username=sa | ||
db1.password=Ca78XJDFawZ5jaOL | ||
|
||
#solon 扩展目录配置 //:可用于存放h2文件 //::!开头,表示自动创建这个目录 | ||
solon.extend=!dataway_ext | ||
|
||
#hasor 配置 | ||
HASOR_DATAQL_DATAWAY=true | ||
HASOR_DATAQL_DATAWAY_ADMIN=true |
37 changes: 37 additions & 0 deletions
37
example/example-solon_dataway/src/main/resources/db/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CREATE TABLE interface_info ( -- Dataway 中的API | ||
api_id varchar(64) NOT NULL PRIMARY KEY COMMENT 'ID', | ||
api_method varchar(12) NOT NULL COMMENT 'HttpMethod:GET、PUT、POST', | ||
api_path varchar(512) NOT NULL COMMENT'拦截路径', | ||
api_status varchar(4) NOT NULL COMMENT'状态:-1-删除, 0-草稿,1-发布,2-有变更,3-禁用', | ||
api_comment varchar(255) NOT NULL COMMENT'注释', | ||
api_type varchar(24) NOT NULL COMMENT'脚本类型:SQL、DataQL', | ||
api_script CLOB NOT NULL COMMENT'查询脚本:xxxxxxx', | ||
api_schema CLOB NOT NULL COMMENT'接口的请求/响应数据结构', | ||
api_sample CLOB NOT NULL COMMENT'请求/响应/请求头样本数据', | ||
api_option CLOB NOT NULL COMMENT'扩展配置信息', | ||
api_create_time varchar(32) NOT NULL COMMENT'创建时间', | ||
api_gmt_time varchar(32) NOT NULL COMMENT'修改时间' | ||
); | ||
|
||
CREATE UNIQUE INDEX uk_interface_info on interface_info (api_path); | ||
|
||
|
||
|
||
CREATE TABLE interface_release ( -- Dataway API 发布历史。 | ||
pub_id varchar(64) NOT NULL PRIMARY KEY COMMENT 'Publish ID', | ||
pub_api_id varchar(64) NOT NULL COMMENT '所属API ID', | ||
pub_method varchar(12) NOT NULL COMMENT 'HttpMethod:GET、PUT、POST', | ||
pub_path varchar(512) NOT NULL COMMENT '拦截路径', | ||
pub_status varchar(4) NOT NULL COMMENT '状态:-1-删除, 0-草稿,1-发布,2-有变更,3-禁用', | ||
pub_comment varchar(255) NOT NULL COMMENT '注释', | ||
pub_type varchar(24) NOT NULL COMMENT '脚本类型:SQL、DataQL', | ||
pub_script CLOB NOT NULL COMMENT '查询脚本:xxxxxxx', | ||
pub_script_ori CLOB NOT NULL COMMENT '原始查询脚本,仅当类型为SQL时不同', | ||
pub_schema CLOB NOT NULL COMMENT '接口的请求/响应数据结构', | ||
pub_sample CLOB NOT NULL COMMENT '请求/响应/请求头样本数据', | ||
pub_option CLOB NOT NULL COMMENT '扩展配置信息', | ||
pub_release_time varchar(32) NOT NULL COMMENT '发布时间(下线不更新)' | ||
); | ||
|
||
CREATE INDEX idx_interface_release_api on interface_release (pub_api_id); | ||
CREATE INDEX idx_interface_release_path on interface_release (pub_path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 整合 Solon | ||
|
||
  Hasor-Solon 是一款让 Hasor 和 Solon 互融互通的整合工具。使之支持 Solon Boot 方式。 | ||
|
||
---------- | ||
## 特性 | ||
01. 在 Hasor 中使用 Solon。 | ||
02. 在 Solon 中使用 Hasor。 | ||
03. 支持 Solon Boot 配置。 | ||
|
||
## 样例 | ||
|
||
|
||
Solon Boot 方式: | ||
```java | ||
// 默认 | ||
@EnableHasor | ||
|
||
// 如果想在 Solon 中使用 hasor-web 那么使用下面这个注解 | ||
@EnableHasorWeb | ||
``` |
Oops, something went wrong.