Skip to content

Commit

Permalink
Java: 所有 Demo 升级 APIJSON 6.2, apijson-framework 6.2, apijson-column 1…
Browse files Browse the repository at this point in the history
….7;解决 泛型 及 配置问题
  • Loading branch information
TommyLemon committed Sep 2, 2023
1 parent c503a2c commit 23b5c20
Show file tree
Hide file tree
Showing 58 changed files with 220 additions and 219 deletions.
12 changes: 6 additions & 6 deletions APIJSON-Java-Server/APIJSONBoot-BigData/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>apijson.boot</groupId>
<artifactId>apijson-boot</artifactId>
<version>6.0.0</version>
<version>6.2.0</version>
<packaging>jar</packaging>

<name>APIJSONBoot-BigData</name>
Expand Down Expand Up @@ -36,12 +36,12 @@
<dependency>
<groupId>com.github.TommyLemon</groupId>
<artifactId>unitauto-java</artifactId>
<version>2.7.2</version>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.github.TommyLemon</groupId>
<artifactId>unitauto-jar</artifactId>
<version>2.7.2</version>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
Expand All @@ -55,17 +55,17 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>6.0.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>6.0.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-column</artifactId>
<version>1.5.0</version>
<version>1.7.0</version>
</dependency>
<!-- 可使用 libs 目录的 apijson-orm.jar, apijson-framework.jar, apijson-column.jar 来替代,两种方式二选一 >>>>>>>>>> -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
* @author Lemon
*/
public class DemoSQLConfig extends APIJSONSQLConfig {
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {

public DemoSQLConfig() {
super();
Expand Down Expand Up @@ -119,7 +119,7 @@ public String getUserIdKey(String database, String schema, String datasource, St
tableColumnMap.put("User", Arrays.asList(StringUtil.split("id,sex,name,tag,head,contactIdList,pictureList,date")));
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputColumn(column, getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
tableColumnMap.put("MYSQL-sys-Privacy", Arrays.asList(StringUtil.split("id,certified,phone,balance,_password,_payPassword")));
ColumnUtil.VERSIONED_TABLE_COLUMN_MAP.put(null, tableColumnMap);
ColumnUtil.VERSIONED_TABLE_COLUMN_MAP.put(0, tableColumnMap); // SortedMap 不允许 key = null

// 字段名映射配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Map<String, Map<String, String>> tableKeyColumnMap = new HashMap<>();
Expand All @@ -134,7 +134,7 @@ public String getUserIdKey(String database, String schema, String datasource, St
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputKey(super.getKey(key), getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
tableKeyColumnMap.put("MYSQL-sys-Privacy", privacyKeyColumnMap);

ColumnUtil.VERSIONED_KEY_COLUMN_MAP.put(null, tableKeyColumnMap);
ColumnUtil.VERSIONED_KEY_COLUMN_MAP.put(0, tableKeyColumnMap); // SortedMap 不允许 key = null
// 字段名映射配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ColumnUtil.init();
Expand Down Expand Up @@ -302,10 +302,12 @@ public String getDBPassword() {
protected void onGetCrossJoinString(Join j) throws UnsupportedOperationException {
// 开启 CROSS JOIN 笛卡尔积联表 super.onGetCrossJoinString(j);
}

@Override
protected void onJoinNotRelation(String sql, String quote, Join j, String jt, List<On> onList, On on) {
// 开启 JOIN ON t1.c1 != t2.c2 等不等式关联 super.onJoinNotRelation(sql, quote, j, jt, onList, on);
protected void onJoinNotRelation(String sql, String quote, Join join, String table, List<On> onList, On on) {
// 开启 JOIN ON t1.c1 != t2.c2 等不等式关联 super.onJoinNotRelation(sql, quote, join, table, onList, on);
}

@Override
protected void onJoinComplextRelation(String sql, String quote, Join j, String jt, List<On> onList, On on) {
// 开启 JOIN ON t1.c1 LIKE concat('%', t2.c2, '%') 等复杂关联 super.onJoinComplextRelation(sql, quote, j, jt, onList, on);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import apijson.Log;
import apijson.boot.DemoApplication;
import apijson.framework.APIJSONSQLExecutor;
import apijson.orm.SQLConfig;
import apijson.orm.SQLConfig;


/**SQL 执行器,支持连接池及多数据源
* 具体见 https://github.com/Tencent/APIJSON/issues/151
* @author Lemon
*/
public class DemoSQLExecutor extends APIJSONSQLExecutor {
public class DemoSQLExecutor extends APIJSONSQLExecutor<Long> {
public static final String TAG = "DemoSQLExecutor";

// 可重写以下方法,支持 Redis 等单机全局缓存或分布式缓存
Expand All @@ -45,27 +45,27 @@ public class DemoSQLExecutor extends APIJSONSQLExecutor {
// super.removeCache(sql, type);
// }

// 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword
@Override
// 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword
@Override
public Connection getConnection(SQLConfig config) throws Exception {
Log.d(TAG, "getConnection config.getDatasource() = " + config.getDatasource());

Connection c = connectionMap.get(config.getDatabase());
if (c == null || c.isClosed()) {
try {
DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class);
// 另一种方式是 DruidConfig 初始化获取到 Datasource 后给静态变量 DATA_SOURCE 赋值: ds = DruidConfig.DATA_SOURCE.getConnection();
connectionMap.put(config.getDatabase(), ds == null ? null : ds.getConnection());
} catch (Exception e) {
Log.e(TAG, "getConnection try { "
+ "DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class); .."
+ "} catch (Exception e) = " + e.getMessage());
}
}

// 必须最后执行 super 方法,因为里面还有事务相关处理。
// 如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表
return super.getConnection(config);

Connection c = connectionMap.get(config.getDatabase());
if (c == null || c.isClosed()) {
try {
DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class);
// 另一种方式是 DruidConfig 初始化获取到 Datasource 后给静态变量 DATA_SOURCE 赋值: ds = DruidConfig.DATA_SOURCE.getConnection();
connectionMap.put(config.getDatabase(), ds == null ? null : ds.getConnection());
} catch (Exception e) {
Log.e(TAG, "getConnection try { "
+ "DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class); .."
+ "} catch (Exception e) = " + e.getMessage());
}
}

// 必须最后执行 super 方法,因为里面还有事务相关处理。
// 如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表
return super.getConnection(config);
}


Expand All @@ -81,6 +81,6 @@ public Connection getConnection(SQLConfig config) throws Exception {
// protected boolean isHideColumn(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition,
// JSONObject table, int columnIndex, Map<String, JSONObject> childMap) throws SQLException {
// return false;
// }

// }

}
10 changes: 3 additions & 7 deletions APIJSON-Java-Server/APIJSONDemo-ClickHouse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>apijson.demo</groupId>
<artifactId>apijson-demo</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>

<name>APIJSONDemo-ClickHouse</name>
<description>Demo project for testing APIJSON server based on SpringBoot</description>
Expand Down Expand Up @@ -45,12 +45,12 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>

<!-- Oracle, SQLServer 等其它数据库的 JDBC 驱动,可以在这里加上 Maven 依赖或 libs 目录放 Jar 包并依赖 -->
Expand All @@ -69,10 +69,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>apijson.demo.DemoApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
* @author Lemon
*/
public class DemoSQLConfig extends APIJSONSQLConfig {
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {

static {
DEFAULT_DATABASE = DATABASE_CLICKHOUSE; // TODO 默认数据库类型,改成你自己的
Expand Down
10 changes: 3 additions & 7 deletions APIJSON-Java-Server/APIJSONDemo-Druid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>apijson.demo</groupId>
<artifactId>apijson-demo-druid</artifactId>
<packaging>jar</packaging>
<version>6.1.0</version>
<version>6.2.0</version>

<name>APIJSONDemo-Druid</name>
<description>Demo project for Testing APIJSON Server based on SpringBoot</description>
Expand All @@ -22,12 +22,12 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>

<!-- 需要用的数据库 JDBC 驱动 -->
Expand Down Expand Up @@ -64,10 +64,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>apijson.demo.DemoApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
* @author Lemon
*/
public class DemoSQLConfig extends APIJSONSQLConfig {
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {

static {
DEFAULT_DATABASE = DATABASE_MYSQL; // TODO 默认数据库类型,改成你自己的
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* 具体见 https://github.com/Tencent/APIJSON/issues/151
* @author Lemon
*/
public class DemoSQLExecutor extends APIJSONSQLExecutor {
public class DemoSQLExecutor extends APIJSONSQLExecutor<Long> {
public static final String TAG = "DemoSQLExecutor";

// 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword
Expand Down
10 changes: 3 additions & 7 deletions APIJSON-Java-Server/APIJSONDemo-Elasticsearch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>apijson.demo</groupId>
<artifactId>apijson-demo</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>

<name>APIJSONDemo-Elasticsearch</name>
<description>Demo project for testing APIJSON server based on SpringBoot</description>
Expand All @@ -21,12 +21,12 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>

<!-- 需要用的数据库 JDBC 驱动 -->
Expand All @@ -52,10 +52,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>apijson.demo.DemoApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
* @author Lemon
*/
public class DemoSQLConfig extends APIJSONSQLConfig {
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {

static {
DEFAULT_DATABASE = DATABASE_ELASTICSEARCH; // TODO 默认数据库类型,改成你自己的
Expand Down
10 changes: 3 additions & 7 deletions APIJSON-Java-Server/APIJSONDemo-Hadoop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>apijson.demo</groupId>
<artifactId>apijson-demo</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>

<name>APIJSONDemo-Hadoop</name>
<description>Demo project for testing APIJSON server based on SpringBoot</description>
Expand All @@ -21,12 +21,12 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>

<!-- 需要用的数据库 JDBC 驱动 -->
Expand Down Expand Up @@ -123,10 +123,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>apijson.demo.DemoApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
* @author Lemon
*/
public class DemoSQLConfig extends APIJSONSQLConfig {
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {

static {
DEFAULT_DATABASE = DATABASE_MYSQL; // TODO 默认数据库类型,改成你自己的
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**SQL 执行
* @author Lemon
*/
public class DemoSQLExecutor extends APIJSONSQLExecutor {
public class DemoSQLExecutor extends APIJSONSQLExecutor<Long> {
public static final String TAG = "DemoSQLExecutor";

@Override
Expand Down
10 changes: 3 additions & 7 deletions APIJSON-Java-Server/APIJSONDemo-HikariCP/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>apijson.demo</groupId>
<artifactId>apijson-demo-hikaricp</artifactId>
<packaging>jar</packaging>
<version>6.1.0</version>
<version>6.2.0</version>

<name>APIJSONDemo</name>
<description>Demo project for Testing APIJSON Server based on SpringBoot</description>
Expand All @@ -22,12 +22,12 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>6.1.0</version>
<version>6.2.0</version>
</dependency>

<!-- 需要用的数据库 JDBC 驱动 -->
Expand Down Expand Up @@ -64,10 +64,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>apijson.demo.DemoApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
* @author Lemon
*/
public class DemoSQLConfig extends APIJSONSQLConfig {
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {

static {
DEFAULT_DATABASE = DATABASE_MYSQL; // TODO 默认数据库类型,改成你自己的
Expand Down
Loading

0 comments on commit 23b5c20

Please sign in to comment.