8000 Server:新增PostgreSQL的表;Config和Executor针对PostgreSQL优化URI和tablePath · coder-caicai/APIJSON@e46b792 · GitHub
[go: up one dir, main page]

Skip to content

Commit e46b792

Browse files
committed
Server:新增PostgreSQL的表;Config和Executor针对PostgreSQL优化URI和tablePath
1 parent 44852d1 commit e46b792

File tree

3 files changed

+84
-6
lines changed

3 files changed

+84
-6
lines changed

APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/server/DemoSQLConfig.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.List;
1818

1919
import com.alibaba.fastjson.JSONObject;
20-
import com.alibaba.fastjson.annotation.JSONField;
2120

2221
import apijson.demo.server.model.Privacy;
2322
import apijson.demo.server.model.User;
@@ -45,7 +44,7 @@ public class DemoSQLConfig extends AbstractSQLConfig {
4544
@Override
4645
public String getDBUri() {
4746
//TODO 改成你自己的
48-
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? "jdbc:postgresql://localhost:5432" : "jdbc:mysql://localhost:3306";
47+
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? "jdbc:postgresql://localhost:5432/postgres" : "jdbc:mysql://localhost:3306";
4948
}
5049
@Override
5150
public String getDBAccount() {
@@ -61,10 +60,9 @@ public String getSchema() {
6160
return StringUtil.isEmpty(s, true) ? "sys" : s; //TODO 改成你自己的
6261
}
6362

64-
@JSONField(serialize = false)
6563
@Override
66-
public String getTablePath() { //PostgreSQL 不允许 cross-database
67-
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? getSQLTable() : super.getTablePath();
64+
public String getAlias() { //getTable 不能小写,因为Verifier用大小写敏感的名称判断权限
65+
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? super.getAlias().toLowerCase() : super.getAlias();
6866
}
6967

7068

APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/server/DemoSQLExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private PreparedStatement getStatement(@NotNull SQLConfig config) throws Excepti
8282
Log.i(TAG, "select connection " + (connection == null ? " = null" : ("isClosed = " + connection.isClosed()))) ;
8383

8484
if (DemoSQLConfig.DATABASE_POSTGRESQL.equalsIgnoreCase(config.getDatabase())) { //PostgreSQL 不允许 cross-database
85-
connection = DriverManager.getConnection(config.getDBUri() + "/" + config.getSchema(), config.getDBAccount(), config.getDBPassword());
85+
connection = DriverManager.getConnection(config.getDBUri(), config.getDBAccount(), config.getDBPassword());
8686
}
8787
else {
8888
connection = DriverManager.getConnection(config.getDBUri() + "?useUnicode=true&characterEncoding=UTF-8&user="

PostgreSQL/sys.sql

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Navicat PostgreSQL Data Transfer
3+
4+
Source Server : localhost
5+
Source Server Type : PostgreSQL
6+
Source Server Version : 100005
7+
Source Host : localhost:5432
8+
Source Catalog : postgres
9+
Source Schema : sys
10+
11+
Target Server Type : PostgreSQL
12+
Target Server Version : 100005
13+
File Encoding : 65001
14+
15+
Date: 26/08/2018 18:50:42
16+
*/
17+
18+
19+
-- ----------------------------
20+
-- Table structure for apijson_user
21+
-- ----------------------------
22+
DROP TABLE IF EXISTS "sys"."apijson_user";
23+
CREATE TABLE "sys"."apijson_user" (
24+
"id" int8 NOT NULL,
25+
"name" varchar(30) COLLATE "pg_catalog"."default" NOT NULL,
26+
"sex" int2 NOT NULL DEFAULT 0,
27+
"date" timestamp(6),
28+
"head" varchar(255) COLLATE "pg_catalog"."default" NOT NULL DEFAULT 'http://my.oschina.net/img/portrait.gif?t=1451961935000'::character varying,
29+
"contactidlist" json NOT NULL DEFAULT '[]'::json,
30+
"picturelist" json NOT NULL DEFAULT '[]'::json,
31+
"tag" varchar(50) COLLATE "pg_catalog"."default"
32+
)
33+
;
34+
ALTER TABLE "sys"."apijson_user" OWNER TO "postgres";
35+
36+
-- ----------------------------
37+
-- Records of apijson_user
38+
-- ----------------------------
39+
BEGIN;
40+
INSERT INTO "sys"."apijson_user" VALUES (38710, 'TommyLemon', 0, '2017-02-01 19:21:50', 'http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000', '[82003, 82005, 90814, 82004, 82009, 82002, 82044, 93793, 70793]', '["http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "http://common.cnblogs.com/images/icon_weibo_24.png"]', 'Android&Java');
41+
INSERT INTO "sys"."apijson_user" VALUES (82002, 'Happy~', 1, '2017-02-01 19:21:50', 'http://static.oschina.net/uploads/user/1174/2348263_50.png?t=1439773471000', '[82005, 82001, 38710]', '[]', 'iOS');
42+
INSERT INTO "sys"."apijson_user" VALUES (82001, 'Test', 0, '2017-02-01 19:21:50', 'https://static.oschina.net/uploads/user/19/39085_50.jpg', '[82030, 82025, 82003, 93793, 82006, 1520242280259, 82005, 82024, 1531969715979]', '["http://common.cnblogs.com/images/icon_weibo_24.png"]', 'APIJSON User');
43+
INSERT INTO "sys"."apijson_user" VALUES (70793, 'Strong', 0, '2017-02-01 19:21:50', 'http://static.oschina.net/uploads/user/585/1170143_50.jpg?t=1390226446000', '[38710, 82002]', '["http://static.oschina.net/uploads/img/201604/22172508_eGDi.jpg", "http://static.oschina.net/uploads/img/201604/22172507_rrZ5.jpg", "https://camo.githubusercontent.com/788c0a7e11a", "https://camo.githubusercontent.com/f513f67"]', 'djdj');
44+
COMMIT;
45+
46+
-- ----------------------------
47+
-- Table structure for moment
48+
-- ----------------------------
49+
DROP TABLE IF EXISTS "sys"."moment";
50+
CREATE TABLE "sys"."moment" (
51+
"id" int8 NOT NULL,
52+
"content" varchar(1000) COLLATE "pg_catalog"."default",
53+
"userid" int8 NOT NULL DEFAULT 0,
54+
"praiseuseridlist" json NOT NULL DEFAULT '[]'::json,
55+
"picturelist" json NOT NULL DEFAULT '[]'::json,
56+
"date" timestamp(6)
57+
)
58+
;
59+
ALTER TABLE "sys"."moment" OWNER TO "postgres";
60+
61+
-- ----------------------------
62+
-- Records of moment
63+
-- ----------------------------
64+
BEGIN;
65+
INSERT INTO "sys"."moment" VALUES (12, '1111534034', 70793, '[70793, 93793, 82044, 82040, 82055, 90814, 38710, 82002, 82006, 1508072105320, 82001]', '["http://static.oschina.net/uploads/img/201604/22172508_eGDi.jpg", "http://static.oschina.net/uploads/img/201604/22172507_rrZ5.jpg", "https://camo.githubusercontent.com/788c0a7e11a4f5aadef3c886f028c79b4808613a/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343932353935372d313732303737333630382e6a7067", "http://static.oschina.net/uploads/img/201604/22172507_Pz9Y.png", "https://camo.githubusercontent.com/c98b1c86af136745cc4626c6ece830f76de9ee83/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343930383036362d313837323233393236352e6a7067", "https://camo.githubusercontent.com/f513fa631bd780dc0ec3cf2663777e356dc3664f/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343733323232332d3337333933303233322e6a7067", "https://camo.githubusercontent.com/c98b1c86af136745cc4626c6ece830f76de9ee83/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343930383036362d313837323233393236352e6a7067", "https://camo.githubusercontent.com/f513fa631bd780dc0ec3cf2663777e356dc3664f/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343733323232332d3337333933303233322e6a7067"]', '2017-02-08 08:06:11');
66+
INSERT INTO "sys"."moment" VALUES (15, 'APIJSON is a JSON Transmission Structure Protocol…', 70793, '[82055, 82002, 38710]', '["http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "http://common.cnblogs.com/images/icon_weibo_24.png"]', '2017-02-08 08:06:11');
67+
INSERT INTO "sys"."moment" VALUES (32, NULL, 82002, '[38710, 82002, 82001]', '["https://camo.githubusercontent.com/f513fa631bd780dc0ec3cf2663777e356dc3664f/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343733323232332d3337333933303233322e6a7067", "https://camo.githubusercontent.com/5f5c4e0c4dc539c34e8eae8ac0cbc6dccdfee5d3/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343533333831362d323032373434343231382e6a7067", "http://static.oschina.net/uploads/img/201604/22172508_mpwj.jpg"]', '2017-02-08 08:06:11');
68+
INSERT INTO "sys"."moment" VALUES (1531969364022, 'APIJSON, let interfaces go to hell!', 82001, '[82001, 1532188114543, 1534926301956]', '["http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "http://common.cnblogs.com/images/icon_weibo_24.png"]', '2018-07-19 11:02:44');
69+
INSERT INTO "sys"."moment" VALUES (1512314438990, 'APIJSON iOS-Swift版发布,自动生成请求代码,欢迎使用^_^ https://github.com/TommyLemon/APIJSON', 38710, '[82001, 82002, 70793, 1512531601485]', '["https://images2018.cnblogs.com/blog/660067/201712/660067-20171203231829476-1202860128.jpg"]', '2017-12-03 23:20:38');
70+
COMMIT;
71+
72+
-- ----------------------------
73+
-- Primary Key structure for table apijson_user
74+
-- ----------------------------
75+
ALTER TABLE "sys"."apijson_user" ADD CONSTRAINT "apijson_user_pkey" PRIMARY KEY ("id");
76+
77+
-- ----------------------------
78+
-- Primary Key structure for table moment
79+
-- ----------------------------
80+
ALTER TABLE "sys"."moment" ADD CONSTRAINT "moment_pkey" PRIMARY KEY ("id");

0 commit comments

Comments
 (0)
0