Skip to content

Commit 550fd94

Browse files
committed
主键类型相关代码全面使用泛型
1 parent fbcf3a5 commit 550fd94

File tree

5 files changed

+23
-41
lines changed

5 files changed

+23
-41
lines changed

src/main/java/apijson/framework/APIJSONFunctionParser.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
/**可远程调用的函数类
5454
* @author Lemon
5555
*/
56-
public class APIJSONFunctionParser extends AbstractFunctionParser {
56+
public class APIJSONFunctionParser<T extends Object> extends AbstractFunctionParser<T> {
5757
public static final String TAG = "APIJSONFunctionParser";
5858

5959
@NotNull
@@ -79,23 +79,23 @@ public APIJSONFunctionParser(RequestMethod method, String tag, int version, JSON
7979
public HttpSession getSession() {
8080
return session;
8181
}
82-
public APIJSONFunctionParser setSession(HttpSession session) {
82+
public APIJSONFunctionParser<T> setSession(HttpSession session) {
8383
this.session = session;
8484
return this;
8585
}
8686

8787
@Override
88-
public APIJSONFunctionParser setMethod(RequestMethod method) {
88+
public APIJSONFunctionParser<T> setMethod(RequestMethod method) {
8989
super.setMethod(method);
9090
return this;
9191
}
9292
@Override
93-
public APIJSONFunctionParser setTag(String tag) {
93+
public APIJSONFunctionParser<T> setTag(String tag) {
9494
super.setTag(tag);
9595
return this;
9696
}
9797
@Override
98-
public APIJSONFunctionParser setVersion(int version) {
98+
public APIJSONFunctionParser<T> setVersion(int version) {
9999
super.setVersion(version);
100100
return this;
101101
}
@@ -283,7 +283,7 @@ public static <T extends Object> JSONObject init(boolean shutdownWhenServerError
283283
if (item.get("language") != null) {
284284
String language = item.getString("language");
285285
if (SCRIPT_EXECUTOR_MAP.get(language) == null) {
286-
onServerError("找不到脚本语言 " + language + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionParser 中注册!", shutdownWhenServerError);
286+
onServerError("找不到脚本语言 " + language + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionParser<T> 中注册!", shutdownWhenServerError);
287287
}
288288
ScriptExecutor scriptExecutor = SCRIPT_EXECUTOR_MAP.get(language);
289289
scriptExecutor.load(name, scriptMap.get(name).getString("script"));
@@ -337,7 +337,7 @@ protected static void onServerError(String msg, boolean shutdown) throws ServerE
337337
public static void test() throws Exception {
338338
test(null);
339339
}
340-
public static void test(APIJSONFunctionParser function) throws Exception {
340+
public static <T extends Object> void test(APIJSONFunctionParser<T> function) throws Exception {
341341
int i0 = 1, i1 = -2;
342342
JSONObject request = new JSONObject();
343343
request.put("id", 10);
@@ -710,14 +710,6 @@ public String getMethodArguments(@NotNull JSONObject curObj, String methodArgsKe
710710
}
711711

712712

713-
/**改用 getMethodDefinition
714-
*/
715-
@Deprecated
716-
public String getMethodDefination(@NotNull JSONObject curObj) throws IllegalArgumentException {
717-
// curObj.put("arguments", removeComment(curObj.getString("methodArgs")));
718-
return getMethodDefination(curObj, "method", "arguments", "genericType", "genericExceptions", "Java");
719-
}
720-
721713
/**获取方法的定义
722714
* @param curObj
723715
* @return
@@ -729,13 +721,6 @@ public String getMethodDefinition(@NotNull JSONObject curObj) throws IllegalArgu
729721
// curObj.put("arguments", removeComment(curObj.getString("methodArgs")));
730722
return getMethodDefinition(curObj, "method", "arguments", "genericType", "genericExceptions", "Java");
731723
}
732-
/**改用 getMethodDefinition
733-
*/
734-
@Deprecated
735-
public String getMethodDefination(@NotNull JSONObject curObj, String method, String arguments
736-
, String type, String exceptions, String language) throws IllegalArgumentException {
737-
return getMethodDefinition(curObj, method, arguments, type, exceptions, language);
738-
}
739724
/**获取方法的定义
740725
* @param curObj
741726
* @param method

src/main/java/apijson/framework/APIJSONObjectParser.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,17 @@
1818

1919
import javax.servlet.http.HttpSession;
2020

21+
import apijson.orm.*;
2122
import com.alibaba.fastjson.JSONObject;
2223

2324
import apijson.NotNull;
2425
import apijson.RequestMethod;
25-
import apijson.orm.AbstractObjectParser;
26-
import apijson.orm.AbstractParser;
27-
import apijson.orm.Join;
28-
import apijson.orm.SQLConfig;
2926

3027

3128
/**简化Parser,getObject和getArray(getArrayConfig)都能用
3229
* @author Lemon
3330
*/
34-
public class APIJSONObjectParser extends AbstractObjectParser {
31+
public class APIJSONObjectParser<T extends Object> extends AbstractObjectParser<T> {
3532
public static final String TAG = "APIJSONObjectParser";
3633

3734
/**for single object
@@ -44,26 +41,26 @@ public class APIJSONObjectParser extends AbstractObjectParser {
4441
* @param isArrayMainTable
4542
* @throws Exception
4643
*/
47-
public APIJSONObjectParser(HttpSession session, @NotNull JSONObject request, String parentPath, SQLConfig arrayConfig
44+
public APIJSONObjectParser(HttpSession session, @NotNull JSONObject request, String parentPath, SQLConfig<T> arrayConfig
4845
, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
4946
super(request, parentPath, arrayConfig, isSubquery, isTable, isArrayMainTable);
5047
}
5148

5249
@Override
53-
public APIJSONObjectParser setMethod(RequestMethod method) {
50+
public APIJSONObjectParser<T> setMethod(RequestMethod method) {
5451
super.setMethod(method);
5552
return this;
5653
}
5754

5855
@Override
59-
public APIJSONObjectParser setParser(AbstractParser<?> parser) {
56+
public APIJSONObjectParser<T> setParser(Parser<T> parser) {
6057
super.setParser(parser);
6158
return this;
6259
}
6360

6461

6562
@Override
66-
public SQLConfig newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
63+
public SQLConfig<T> newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
6764
return APIJSONSQLConfig.newSQLConfig(method, table, alias, request, joinList, isProcedure);
6865
}
6966

src/main/java/apijson/framework/APIJSONParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ public Object onFunctionParse(String key, String function, String parentPath, St
145145

146146

147147
@Override
148-
public APIJSONObjectParser createObjectParser(JSONObject request, String parentPath, SQLConfig arrayConfig
148+
public APIJSONObjectParser<T> createObjectParser(JSONObject request, String parentPath, SQLConfig<T> arrayConfig
149149
, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
150150

151-
return new APIJSONObjectParser(getSession(), request, parentPath, arrayConfig, isSubquery, isTable, isArrayMainTable) {
151+
return new APIJSONObjectParser<T>(getSession(), request, parentPath, arrayConfig, isSubquery, isTable, isArrayMainTable) {
152152

153153
// @Override
154154
// protected APIJSONSQLConfig newQueryConfig() {

src/main/java/apijson/framework/APIJSONSQLConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public class APIJSONSQLConfig<T extends Object> extends AbstractSQLConfig<T> {
5959
SIMPLE_CALLBACK = new SimpleCallback<Object>() {
6060

6161
@Override
62-
public SQLConfig getSQLConfig(RequestMethod method, String database, String schema,String datasource, String table) {
63-
SQLConfig config = APIJSON_CREATOR.createSQLConfig();
62+
public SQLConfig<Object> getSQLConfig(RequestMethod method, String database, String schema,String datasource, String table) {
63+
SQLConfig<Object> config = APIJSON_CREATOR.createSQLConfig();
6464
config.setMethod(method);
6565
config.setDatabase(database);
6666
config.setDatasource(datasource);
@@ -228,14 +228,14 @@ public APIJSONSQLConfig(RequestMethod method, int count, int page) {
228228
* @return
229229
* @throws Exception
230230
*/
231-
public static SQLConfig newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
232-
return newSQLConfig(method, table, alias, request, joinList, isProcedure, SIMPLE_CALLBACK);
231+
public static <T extends Object> SQLConfig<T> newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
232+
return (SQLConfig<T>) newSQLConfig(method, table, alias, request, joinList, isProcedure, SIMPLE_CALLBACK);
233233
}
234234

235235

236236
// 支持 !key 反选字段 和 字段名映射,依赖插件 https://github.com/APIJSON/apijson-column
237237
@Override
238-
public AbstractSQLConfig setColumn(List<String> column) {
238+
public AbstractSQLConfig<T> setColumn(List<String> column) {
239239
if (ENABLE_COLUMN_CONFIG) {
240240
column = ColumnUtil.compatInputColumn(column, getTable(), getMethod(), getVersion(), ! isConfigTable());
241241
}

src/main/java/apijson/framework/APIJSONSQLExecutor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class APIJSONSQLExecutor<T extends Object> extends AbstractSQLExecutor<T>
7373

7474

7575
@Override
76-
public PreparedStatement setArgument(@NotNull SQLConfig config, @NotNull PreparedStatement statement, int index, Object value) throws SQLException {
76+
public PreparedStatement setArgument(@NotNull SQLConfig<T> config, @NotNull PreparedStatement statement, int index, Object value) throws SQLException {
7777
if (config.isPostgreSQL() && JSON.isBooleanOrNumberOrString(value) == false) {
7878
PGobject o = new PGobject();
7979
o.setType("jsonb");
@@ -87,7 +87,7 @@ public PreparedStatement setArgument(@NotNull SQLConfig config, @NotNull Prepare
8787

8888

8989
@Override
90-
protected Object getValue(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition,
90+
protected Object getValue(SQLConfig<T> config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition,
9191
JSONObject table, int columnIndex, String lable, Map<String, JSONObject> childMap) throws Exception {
9292

9393
Object value = super.getValue(config, rs, rsmd, tablePosition, table, columnIndex, lable, childMap);
@@ -97,7 +97,7 @@ protected Object getValue(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd
9797

9898
// 支持 !key 反选字段 和 字段名映射,依赖插件 https://github.com/APIJSON/apijson-column
9999
@Override
100-
protected String getKey(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition, JSONObject table,
100+
protected String getKey(SQLConfig<T> config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition, JSONObject table,
101101
int columnIndex, Map<String, JSONObject> childMap) throws Exception {
102102

103103
String key = super.getKey(config, rs, rsmd, tablePosition, table, columnIndex, childMap);

0 commit comments

Comments
 (0)