From c09ce5731d7e3a4d1f1097a8ef07d4a152e6fe6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Wed, 7 Aug 2024 13:36:53 +0800 Subject: [PATCH] 'commit' --- .../main/java/com/dsideal/ZhuQue/Start.java | 38 +- .../com/dsideal/ZhuQue/Util/CommonUtil.java | 21 + .../ZhuQue/Ylt/Controller/YltController.java | 73 ++ .../com/jfinal/plugin/activerecord/Db.java | 844 ------------------ ZhuQue/src/main/resource/fzby.txt | 17 +- 5 files changed, 117 insertions(+), 876 deletions(-) create mode 100644 ZhuQue/src/main/java/com/dsideal/ZhuQue/Ylt/Controller/YltController.java delete mode 100644 ZhuQue/src/main/java/com/jfinal/plugin/activerecord/Db.java diff --git a/ZhuQue/src/main/java/com/dsideal/ZhuQue/Start.java b/ZhuQue/src/main/java/com/dsideal/ZhuQue/Start.java index b578c68..f9dcffc 100644 --- a/ZhuQue/src/main/java/com/dsideal/ZhuQue/Start.java +++ b/ZhuQue/src/main/java/com/dsideal/ZhuQue/Start.java @@ -6,13 +6,11 @@ import com.dsideal.ZhuQue.Index.Controller.IndexController; import com.dsideal.ZhuQue.Interceptor.*; import com.dsideal.ZhuQue.Util.CommonUtil; import com.dsideal.ZhuQue.Util.LogBackLogFactory; -import com.dsideal.ZhuQue.Util.RedisKit; +import com.dsideal.ZhuQue.Ylt.Controller.YltController; import com.jfinal.config.*; import com.jfinal.kit.PropKit; import com.jfinal.kit.StrKit; import com.jfinal.plugin.activerecord.ActiveRecordPlugin; -import com.jfinal.plugin.activerecord.Record; -import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect; import com.jfinal.plugin.hikaricp.HikariCpPlugin; import com.jfinal.plugin.redis.RedisPlugin; @@ -20,7 +18,6 @@ import com.jfinal.server.undertow.UndertowServer; import com.jfinal.template.Engine; import java.io.File; -import java.util.List; public class Start extends JFinalConfig { public static void main(String[] args) { @@ -44,8 +41,6 @@ public class Start extends JFinalConfig { // 加载少量必要配置,随后可用PropKit.get(...)获取值 PropKit.use("application.properties"); - //配置统一的错误页面 - me.setError404View("/html/common/404/index.html"); } /** @@ -55,9 +50,8 @@ public class Start extends JFinalConfig { public void configRoute(Routes me) { //默认页面 me.add("/", IndexController.class); - //登录表 - //me.add("/loginPerson", LoginPersonController.class); - + //驿来特业务 + me.add("/Ylt", YltController.class); } @Override @@ -79,13 +73,13 @@ public class Start extends JFinalConfig { @Override public void configPlugin(Plugins me) { - HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), + HikariCpPlugin hpPlugin = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim(), PropKit.get("driverClassName")); - masterPlugin.setConnectionTestQuery(connectionTestQuery); - masterPlugin.setConnectionTimeout(connectionTimeoutMs); - masterPlugin.setIdleTimeout(idleTimeoutMs); - masterPlugin.setMaxLifetime(maxLifetimeMs); - masterPlugin.setMaximumPoolSize(maxPoolSize); + hpPlugin.setConnectionTestQuery(connectionTestQuery); + hpPlugin.setConnectionTimeout(connectionTimeoutMs); + hpPlugin.setIdleTimeout(idleTimeoutMs); + hpPlugin.setMaxLifetime(maxLifetimeMs); + hpPlugin.setMaximumPoolSize(maxPoolSize); String jdbcUrlSlave = PropKit.get("jdbcUrlSlave"); if (StrKit.isBlank(jdbcUrlSlave)) jdbcUrlSlave = PropKit.get("jdbcUrl"); @@ -96,14 +90,12 @@ public class Start extends JFinalConfig { slavePlugin.setIdleTimeout(idleTimeoutMs); slavePlugin.setMaxLifetime(maxLifetimeMs); slavePlugin.setMaximumPoolSize(maxPoolSize); - me.add(masterPlugin); + me.add(hpPlugin); me.add(slavePlugin); // 配置ActiveRecord插件 - ActiveRecordPlugin masterArp = new ActiveRecordPlugin("master", masterPlugin); - masterArp.setDialect(new PostgreSqlDialect()); - ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin); - slaveArp.setDialect(new PostgreSqlDialect()); + ActiveRecordPlugin arp = new ActiveRecordPlugin(hpPlugin); + arp.setDialect(new PostgreSqlDialect()); //遍历sql目录下所有的sql文件 File sqlDir; @@ -113,13 +105,11 @@ public class Start extends JFinalConfig { for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) { //只加载.sql文件 if (sqlFile.getName().indexOf(".sql") > 0) { - masterArp.addSqlTemplate("/Sql/" + sqlFile.getName()); - slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName()); + arp.addSqlTemplate("/Sql/" + sqlFile.getName()); } } //加载 - me.add(masterArp); - me.add(slaveArp); + me.add(arp); // 用于缓存模块的redis服务 RedisPlugin redis = new RedisPlugin("Redis", PropKit.get("redis_ip"), PropKit.getInt("redis_port"), 10 * 1000, PropKit.get("redis_password")); //启动redis组件 diff --git a/ZhuQue/src/main/java/com/dsideal/ZhuQue/Util/CommonUtil.java b/ZhuQue/src/main/java/com/dsideal/ZhuQue/Util/CommonUtil.java index c2edf79..46a4cc2 100644 --- a/ZhuQue/src/main/java/com/dsideal/ZhuQue/Util/CommonUtil.java +++ b/ZhuQue/src/main/java/com/dsideal/ZhuQue/Util/CommonUtil.java @@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.file.FileWriter; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.jfinal.kit.Kv; import com.jfinal.kit.PropKit; import com.jfinal.kit.StrKit; import com.jfinal.plugin.activerecord.Page; @@ -784,4 +785,24 @@ public class CommonUtil { return year + "-" + month + "-" + day; } + + /** + * 功能:通过重载,获取返回的数据标准格式 + * + * @param record + * @return + */ + public static Kv getRet(Record record, boolean success, String message) { + List dictList = new ArrayList<>(); + dictList.add(record); + return getRet(dictList, success, message); + } + + public static Kv getRet(List dictList, boolean success, String message) { + Kv kv = Kv.by("code", 1000); + kv.set("success", success); + kv.set("msg", message); + kv.set("data", dictList); + return kv; + } } diff --git a/ZhuQue/src/main/java/com/dsideal/ZhuQue/Ylt/Controller/YltController.java b/ZhuQue/src/main/java/com/dsideal/ZhuQue/Ylt/Controller/YltController.java new file mode 100644 index 0000000..e475e89 --- /dev/null +++ b/ZhuQue/src/main/java/com/dsideal/ZhuQue/Ylt/Controller/YltController.java @@ -0,0 +1,73 @@ +package com.dsideal.ZhuQue.Ylt.Controller; + +import com.dsideal.ZhuQue.Interceptor.IsLoginInterface; +import com.dsideal.ZhuQue.Util.CommonUtil; +import com.dsideal.ZhuQue.Util.SessionKit; +import com.jfinal.aop.Before; +import com.jfinal.core.Controller; +import com.jfinal.ext.interceptor.GET; +import com.jfinal.kit.Kv; +import com.jfinal.plugin.activerecord.Record; + +import java.util.ArrayList; +import java.util.List; + + +public class YltController extends Controller { + + public List getAll() { + List list = new ArrayList<>(); + + Record r1 = new Record(); + r1.set("dictKey", 1); + r1.set("dictValue", "卫生间"); + r1.set("imageUrl", "station-toilet"); + r1.set("id", null); + r1.set("parentId", null); + r1.set("code", null); + r1.set("sort", null); + r1.set("remark", null); + r1.set("isSealed", null); + r1.set("isDeleted", null); + list.add(r1); + + Record r2 = new Record(); + r2.set("dictKey", 1); + r2.set("dictValue", "卫生间"); + r2.set("imageUrl", "station-toilet"); + r2.set("id", null); + r2.set("parentId", null); + r2.set("code", null); + r2.set("sort", null); + r2.set("remark", null); + r2.set("isSealed", null); + r2.set("isDeleted", null); + list.add(r2); + return list; + } + + /** + * 功能:测试不依赖JWT的TOKEN数据的方法 + */ + @Before({GET.class}) + public void getList() { + List list = getAll(); + renderJson(CommonUtil.getRet(list, true, "获取成功!")); + } + + /** + * 功能:测试依赖JWT的TOKEN数据的方法 + */ + @Before({GET.class}) + @IsLoginInterface({}) + public void getListWithAuth() { + String userId = SessionKit.get(getRequest(), getResponse(), "userId"); + String phone = SessionKit.get(getRequest(), getResponse(), "phone"); + + System.out.println(userId); + System.out.println(phone); + + List list = getAll(); + renderJson(CommonUtil.getRet(list, true, "获取成功!")); + } +} \ No newline at end of file diff --git a/ZhuQue/src/main/java/com/jfinal/plugin/activerecord/Db.java b/ZhuQue/src/main/java/com/jfinal/plugin/activerecord/Db.java deleted file mode 100644 index b41f377..0000000 --- a/ZhuQue/src/main/java/com/jfinal/plugin/activerecord/Db.java +++ /dev/null @@ -1,844 +0,0 @@ -/** - * Copyright (c) 2011-2023, James Zhan 詹波 (jfinal@126.com). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jfinal.plugin.activerecord; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.Connection; -import java.sql.SQLException; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Future; -import java.util.function.Function; - -import com.jfinal.kit.SyncWriteMap; - -/** - * Db. Powerful database query and update tool box. - */ -@SuppressWarnings("rawtypes") -public class Db { - - private static DbPro MAIN = null; - - private static String SLAVE="slave"; - private static final Map cache = new SyncWriteMap(32, 0.25F); - - /** - * for DbKit.addConfig(configName) - */ - static void init(String configName) { - MAIN = DbKit.getConfig(configName).dbProFactory.getDbPro(configName); // new DbPro(configName); - cache.put(configName, MAIN); - } - - /** - * for DbKit.removeConfig(configName) - */ - static void removeDbProWithConfig(String configName) { - if (MAIN != null && MAIN.config.getName().equals(configName)) { - MAIN = null; - } - cache.remove(configName); - } - - public static DbPro use(String configName) { - DbPro result = cache.get(configName); - if (result == null) { - Config config = DbKit.getConfig(configName); - if (config == null) { - //System.out.println("Config not found by configName: " + configName); - return MAIN; - } - result = config.dbProFactory.getDbPro(configName); // new DbPro(configName); - cache.put(configName, result); - } - return result; - } - - public static DbPro use() { - return MAIN; - } - - static List query(Config config, Connection conn, String sql, Object... paras) throws SQLException { - return use(SLAVE).query(config, conn, sql, paras); - } - - public static List query(String sql, Object... paras) { - return use(SLAVE).query(sql, paras); - } - - /** - * @param sql an SQL statement - * @see #query(String, Object...) - */ - public static List query(String sql) { - return use(SLAVE).query(sql); - } - - /** - * Execute sql query and return the first result. I recommend add "limit 1" in your sql. - * - * @param sql an SQL statement that may contain one or more '?' IN parameter placeholders - * @param paras the parameters of sql - * @return Object[] if your sql has select more than one column, - * and it return Object if your sql has select only one column. - */ - public static T queryFirst(String sql, Object... paras) { - return use(SLAVE).queryFirst(sql, paras); - } - - /** - * @param sql an SQL statement - * @see #queryFirst(String, Object...) - */ - public static T queryFirst(String sql) { - return use(SLAVE).queryFirst(sql); - } - - // 26 queryXxx method below ----------------------------------------------- - - /** - * Execute sql query just return one column. - * - * @param the type of the column that in your sql's select statement - * @param sql an SQL statement that may contain one or more '?' IN parameter placeholders - * @param paras the parameters of sql - * @return T - */ - public static T queryColumn(String sql, Object... paras) { - return use(SLAVE).queryColumn(sql, paras); - } - - public static T queryColumn(String sql) { - return use(SLAVE).queryColumn(sql); - } - - public static String queryStr(String sql, Object... paras) { - return use(SLAVE).queryStr(sql, paras); - } - - public static String queryStr(String sql) { - return use(SLAVE).queryStr(sql); - } - - public static Integer queryInt(String sql, Object... paras) { - return use(SLAVE).queryInt(sql, paras); - } - - public static Integer queryInt(String sql) { - return use(SLAVE).queryInt(sql); - } - - public static Long queryLong(String sql, Object... paras) { - return use(SLAVE).queryLong(sql, paras); - } - - public static Long queryLong(String sql) { - return use(SLAVE).queryLong(sql); - } - - public static Double queryDouble(String sql, Object... paras) { - return use(SLAVE).queryDouble(sql, paras); - } - - public static Double queryDouble(String sql) { - return use(SLAVE).queryDouble(sql); - } - - public static Float queryFloat(String sql, Object... paras) { - return use(SLAVE).queryFloat(sql, paras); - } - - public static Float queryFloat(String sql) { - return use(SLAVE).queryFloat(sql); - } - - public static BigDecimal queryBigDecimal(String sql, Object... paras) { - return use(SLAVE).queryBigDecimal(sql, paras); - } - - public static BigDecimal queryBigDecimal(String sql) { - return use(SLAVE).queryBigDecimal(sql); - } - - public static BigInteger queryBigInteger(String sql, Object... paras) { - return use(SLAVE).queryBigInteger(sql, paras); - } - - public static BigInteger queryBigInteger(String sql) { - return use(SLAVE).queryBigInteger(sql); - } - - public static byte[] queryBytes(String sql, Object... paras) { - return use(SLAVE).queryBytes(sql, paras); - } - - public static byte[] queryBytes(String sql) { - return use(SLAVE).queryBytes(sql); - } - - public static java.util.Date queryDate(String sql, Object... paras) { - return use(SLAVE).queryDate(sql, paras); - } - - public static java.util.Date queryDate(String sql) { - return use(SLAVE).queryDate(sql); - } - - public static LocalDateTime queryLocalDateTime(String sql, Object... paras) { - return use(SLAVE).queryLocalDateTime(sql, paras); - } - - public static LocalDateTime queryLocalDateTime(String sql) { - return use(SLAVE).queryLocalDateTime(sql); - } - - public static java.sql.Time queryTime(String sql, Object... paras) { - return use(SLAVE).queryTime(sql, paras); - } - - public static java.sql.Time queryTime(String sql) { - return use(SLAVE).queryTime(sql); - } - - public static java.sql.Timestamp queryTimestamp(String sql, Object... paras) { - return use(SLAVE).queryTimestamp(sql, paras); - } - - public static java.sql.Timestamp queryTimestamp(String sql) { - return use(SLAVE).queryTimestamp(sql); - } - - public static Boolean queryBoolean(String sql, Object... paras) { - return use(SLAVE).queryBoolean(sql, paras); - } - - public static Boolean queryBoolean(String sql) { - return use(SLAVE).queryBoolean(sql); - } - - public static Short queryShort(String sql, Object... paras) { - return use(SLAVE).queryShort(sql, paras); - } - - public static Short queryShort(String sql) { - return use(SLAVE).queryShort(sql); - } - - public static Byte queryByte(String sql, Object... paras) { - return use(SLAVE).queryByte(sql, paras); - } - - public static Byte queryByte(String sql) { - return use(SLAVE).queryByte(sql); - } - - public static Number queryNumber(String sql, Object... paras) { - return use(SLAVE).queryNumber(sql, paras); - } - - public static Number queryNumber(String sql) { - return use(SLAVE).queryNumber(sql); - } - // 26 queryXxx method under ----------------------------------------------- - - /** - * Execute sql update - */ - static int update(Config config, Connection conn, String sql, Object... paras) throws SQLException { - return MAIN.update(config, conn, sql, paras); - } - - /** - * Execute update, insert or delete sql statement. - * - * @param sql an SQL statement that may contain one or more '?' IN parameter placeholders - * @param paras the parameters of sql - * @return either the row count for INSERT, UPDATE, - * or DELETE statements, or 0 for SQL statements - * that return nothing - */ - public static int update(String sql, Object... paras) { - return MAIN.update(sql, paras); - } - - /** - * @param sql an SQL statement - * @see #update(String, Object...) - */ - public static int update(String sql) { - return MAIN.update(sql); - } - - static List find(Config config, Connection conn, String sql, Object... paras) throws SQLException { - return use(SLAVE).find(config, conn, sql, paras); - } - - - public static List find(String sql, Object... paras) { - return use(SLAVE).find(sql, paras); - } - - - public static List find(String sql) { - return use(SLAVE).find(sql); - } - - public static List findAll(String tableName) { - return use(SLAVE).findAll(tableName); - } - - /** - * Find first record. I recommend add "limit 1" in your sql. - * - * @param sql an SQL statement that may contain one or more '?' IN parameter placeholders - * @param paras the parameters of sql - * @return the Record object - */ - public static Record findFirst(String sql, Object... paras) { - return use(SLAVE).findFirst(sql, paras); - } - - /** - * @param sql an SQL statement - * @see #findFirst(String, Object...) - */ - public static Record findFirst(String sql) { - return use(SLAVE).findFirst(sql); - } - - /** - * Find record by id with default primary key. - *

-     * Example:
-     * Record user = Db.findById("user", 15);
-     * 
- * - * @param tableName the table name of the table - * @param idValue the id value of the record - */ - public static Record findById(String tableName, Object idValue) { - return use(SLAVE).findById(tableName, idValue); - } - - public static Record findById(String tableName, String primaryKey, Object idValue) { - return use(SLAVE).findById(tableName, primaryKey, idValue); - } - - /** - * Find record by ids. - *
-     * Example:
-     * Record user = Db.findByIds("user", "user_id", 123);
-     * Record userRole = Db.findByIds("user_role", "user_id, role_id", 123, 456);
-     * 
- * - * @param tableName the table name of the table - * @param primaryKey the primary key of the table, composite primary key is separated by comma character: "," - * @param idValues the id value of the record, it can be composite id values - */ - public static Record findByIds(String tableName, String primaryKey, Object... idValues) { - return use(SLAVE).findByIds(tableName, primaryKey, idValues); - } - - /** - * Delete record by id with default primary key. - *
-     * Example:
-     * Db.deleteById("user", 15);
-     * 
- * - * @param tableName the table name of the table - * @param idValue the id value of the record - * @return true if delete succeed otherwise false - */ - public static boolean deleteById(String tableName, Object idValue) { - return MAIN.deleteById(tableName, idValue); - } - - public static boolean deleteById(String tableName, String primaryKey, Object idValue) { - return MAIN.deleteById(tableName, primaryKey, idValue); - } - - /** - * Delete record by ids. - *
-     * Example:
-     * Db.deleteByIds("user", "user_id", 15);
-     * Db.deleteByIds("user_role", "user_id, role_id", 123, 456);
-     * 
- * - * @param tableName the table name of the table - * @param primaryKey the primary key of the table, composite primary key is separated by comma character: "," - * @param idValues the id value of the record, it can be composite id values - * @return true if delete succeed otherwise false - */ - public static boolean deleteByIds(String tableName, String primaryKey, Object... idValues) { - return MAIN.deleteByIds(tableName, primaryKey, idValues); - } - - /** - * Delete record. - *
-     * Example:
-     * boolean succeed = Db.delete("user", "id", user);
-     * 
- * - * @param tableName the table name of the table - * @param primaryKey the primary key of the table, composite primary key is separated by comma character: "," - * @param record the record - * @return true if delete succeed otherwise false - */ - public static boolean delete(String tableName, String primaryKey, Record record) { - return MAIN.delete(tableName, primaryKey, record); - } - - /** - *
-     * Example:
-     * boolean succeed = Db.delete("user", user);
-     * 
- * - * @see #delete(String, String, Record) - */ - public static boolean delete(String tableName, Record record) { - return MAIN.delete(tableName, record); - } - - /** - * Execute delete sql statement. - * - * @param sql an SQL statement that may contain one or more '?' IN parameter placeholders - * @param paras the parameters of sql - * @return the row count for DELETE statements, or 0 for SQL statements - * that return nothing - */ - public static int delete(String sql, Object... paras) { - return MAIN.delete(sql, paras); - } - - /** - * @param sql an SQL statement - * @see #delete(String, Object...) - */ - public static int delete(String sql) { - return MAIN.delete(sql); - } - - static Page paginate(Config config, Connection conn, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras) throws SQLException { - return use(SLAVE).paginate(config, conn, pageNumber, pageSize, select, sqlExceptSelect, paras); - } - - /** - * Paginate. - * - * @param pageNumber the page number - * @param pageSize the page size - * @param select the select part of the sql statement - * @param sqlExceptSelect the sql statement excluded select part - * @param paras the parameters of sql - * @return the Page object - */ - public static Page paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras) { - return use(SLAVE).paginate(pageNumber, pageSize, select, sqlExceptSelect, paras); - } - - public static Page paginate(int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras) { - return use(SLAVE).paginate(pageNumber, pageSize, isGroupBySql, select, sqlExceptSelect, paras); - } - - - public static Page paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect) { - return use(SLAVE).paginate(pageNumber, pageSize, select, sqlExceptSelect); - } - - public static Page paginateByFullSql(int pageNumber, int pageSize, String totalRowSql, String findSql, Object... paras) { - return use(SLAVE).paginateByFullSql(pageNumber, pageSize, totalRowSql, findSql, paras); - } - - public static Page paginateByFullSql(int pageNumber, int pageSize, boolean isGroupBySql, String totalRowSql, String findSql, Object... paras) { - return use(SLAVE).paginateByFullSql(pageNumber, pageSize, isGroupBySql, totalRowSql, findSql, paras); - } - - static boolean save(Config config, Connection conn, String tableName, String primaryKey, Record record) throws SQLException { - return MAIN.save(config, conn, tableName, primaryKey, record); - } - - /** - * Save record. - *
-     * Example:
-     * Record userRole = new Record().set("user_id", 123).set("role_id", 456);
-     * Db.save("user_role", "user_id, role_id", userRole);
-     * 
- * - * @param tableName the table name of the table - * @param primaryKey the primary key of the table, composite primary key is separated by comma character: "," - * @param record the record will be saved - */ - public static boolean save(String tableName, String primaryKey, Record record) { - return MAIN.save(tableName, primaryKey, record); - } - - /** - * @see #save(String, String, Record) - */ - public static boolean save(String tableName, Record record) { - return MAIN.save(tableName, record); - } - - static boolean update(Config config, Connection conn, String tableName, String primaryKey, Record record) throws SQLException { - return MAIN.update(config, conn, tableName, primaryKey, record); - } - - /** - * Update Record. - *
-     * Example:
-     * Db.update("user_role", "user_id, role_id", record);
-     * 
- * - * @param tableName the table name of the Record save to - * @param primaryKey the primary key of the table, composite primary key is separated by comma character: "," - * @param record the Record object - */ - public static boolean update(String tableName, String primaryKey, Record record) { - return MAIN.update(tableName, primaryKey, record); - } - - /** - * Update record with default primary key. - *
-     * Example:
-     * Db.update("user", record);
-     * 
- * - * @see #update(String, String, Record) - */ - public static boolean update(String tableName, Record record) { - return MAIN.update(tableName, record); - } - - - public static Object execute(ICallback callback) { - return MAIN.execute(callback); - } - - /** - * Execute callback. It is useful when all the API can not satisfy your requirement. - * - * @param config the Config object - * @param callback the ICallback interface - */ - static Object execute(Config config, ICallback callback) { - return MAIN.execute(config, callback); - } - - /** - * Execute transaction. - * - * @param config the Config object - * @param transactionLevel the transaction level - * @param atom the atom operation - * @return true if transaction executing succeed otherwise false - */ - static boolean tx(Config config, int transactionLevel, IAtom atom) { - return MAIN.tx(config, transactionLevel, atom); - } - - /** - * Execute transaction with default transaction level. - * - * @see #tx(int, IAtom) - */ - public static boolean tx(IAtom atom) { - return MAIN.tx(atom); - } - - public static boolean tx(int transactionLevel, IAtom atom) { - return MAIN.tx(transactionLevel, atom); - } - - /** - * 主要用于嵌套事务场景 - *

- * 实例:https://jfinal.com/feedback/4008 - *

- * 默认情况下嵌套事务会被合并成为一个事务,那么内层与外层任何地方回滚事务 - * 所有嵌套层都将回滚事务,也就是说嵌套事务无法独立提交与回滚 - *

- * 使用 txInNewThread(...) 方法可以实现层之间的事务控制的独立性 - * 由于事务处理是将 Connection 绑定到线程上的,所以 txInNewThread(...) - * 通过建立新线程来实现嵌套事务的独立控制 - */ - public static Future txInNewThread(IAtom atom) { - return MAIN.txInNewThread(atom); - } - - public static Future txInNewThread(int transactionLevel, IAtom atom) { - return MAIN.txInNewThread(transactionLevel, atom); - } - - /** - * Find Record by cache. - * - * @param cacheName the cache name - * @param key the key used to get date from cache - * @return the list of Record - * @see #find(String, Object...) - */ - public static List findByCache(String cacheName, Object key, String sql, Object... paras) { - return use(SLAVE).findByCache(cacheName, key, sql, paras); - } - - /** - * @see #findByCache(String, Object, String, Object...) - */ - public static List findByCache(String cacheName, Object key, String sql) { - return use(SLAVE).findByCache(cacheName, key, sql); - } - - /** - * Find first record by cache. I recommend add "limit 1" in your sql. - * - * @param cacheName the cache name - * @param key the key used to get date from cache - * @param sql an SQL statement that may contain one or more '?' IN parameter placeholders - * @param paras the parameters of sql - * @return the Record object - * @see #findFirst(String, Object...) - */ - public static Record findFirstByCache(String cacheName, Object key, String sql, Object... paras) { - return use(SLAVE).findFirstByCache(cacheName, key, sql, paras); - } - - /** - * @see #findFirstByCache(String, Object, String, Object...) - */ - public static Record findFirstByCache(String cacheName, Object key, String sql) { - return use(SLAVE).findFirstByCache(cacheName, key, sql); - } - - /** - * Paginate by cache. - * - * @return Page - * @see #paginate(int, int, String, String, Object...) - */ - public static Page paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras) { - return use(SLAVE).paginateByCache(cacheName, key, pageNumber, pageSize, select, sqlExceptSelect, paras); - } - - public static Page paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras) { - return use(SLAVE).paginateByCache(cacheName, key, pageNumber, pageSize, isGroupBySql, select, sqlExceptSelect, paras); - } - - /** - * @see #paginateByCache(String, Object, int, int, String, String, Object...) - */ - public static Page paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect) { - return use(SLAVE).paginateByCache(cacheName, key, pageNumber, pageSize, select, sqlExceptSelect); - } - - /** - * @see DbPro#batch(String, Object[][], int) - */ - public static int[] batch(String sql, Object[][] paras, int batchSize) { - return MAIN.batch(sql, paras, batchSize); - } - - /** - * @see DbPro#batch(String, String, List, int) - */ - public static int[] batch(String sql, String columns, List modelOrRecordList, int batchSize) { - return MAIN.batch(sql, columns, modelOrRecordList, batchSize); - } - - /** - * @see DbPro#batch(List, int) - */ - public static int[] batch(List sqlList, int batchSize) { - return MAIN.batch(sqlList, batchSize); - } - - /** - * @see DbPro#batchSave(List, int) - */ - public static int[] batchSave(List modelList, int batchSize) { - return MAIN.batchSave(modelList, batchSize); - } - - /** - * @see DbPro#batchSave(String, List, int) - */ - public static int[] batchSave(String tableName, List recordList, int batchSize) { - return MAIN.batchSave(tableName, recordList, batchSize); - } - - /** - * @see DbPro#batchUpdate(List, int) - */ - public static int[] batchUpdate(List modelList, int batchSize) { - return MAIN.batchUpdate(modelList, batchSize); - } - - /** - * @see DbPro#batchUpdate(String, String, List, int) - */ - public static int[] batchUpdate(String tableName, String primaryKey, List recordList, int batchSize) { - return MAIN.batchUpdate(tableName, primaryKey, recordList, batchSize); - } - - /** - * @see DbPro#batchUpdate(String, List, int) - */ - public static int[] batchUpdate(String tableName, List recordList, int batchSize) { - return MAIN.batchUpdate(tableName, recordList, batchSize); - } - - public static String getSql(String key) { - return use(SLAVE).getSql(key); - } - - // 支持传入变量用于 sql 生成。为了避免用户将参数拼接在 sql 中引起 sql 注入风险,只在 SqlKit 中开放该功能 - // public static String getSql(String key, Map data) { - // return MAIN.getSql(key, data); - // } - - public static SqlPara getSqlPara(String key, Record record) { - return use(SLAVE).getSqlPara(key, record); - } - - public static SqlPara getSqlPara(String key, Model model) { - return use(SLAVE).getSqlPara(key, model); - } - - public static SqlPara getSqlPara(String key, Map data) { - return use(SLAVE).getSqlPara(key, data); - } - - public static SqlPara getSqlPara(String key, Object... paras) { - return use(SLAVE).getSqlPara(key, paras); - } - - public static SqlPara getSqlParaByString(String content, Map data) { - return use(SLAVE).getSqlParaByString(content, data); - } - - public static SqlPara getSqlParaByString(String content, Object... paras) { - return use(SLAVE).getSqlParaByString(content, paras); - } - - public static List find(SqlPara sqlPara) { - return use(SLAVE).find(sqlPara); - } - - public static Record findFirst(SqlPara sqlPara) { - return use(SLAVE).findFirst(sqlPara); - } - - public static int update(SqlPara sqlPara) { - return MAIN.update(sqlPara); - } - - public static Page paginate(int pageNumber, int pageSize, SqlPara sqlPara) { - return use(SLAVE).paginate(pageNumber, pageSize, sqlPara); - } - - public static Page paginate(int pageNumber, int pageSize, boolean isGroupBySql, SqlPara sqlPara) { - return use(SLAVE).paginate(pageNumber, pageSize, isGroupBySql, sqlPara); - } - - // --------- - - /** - * 迭代处理每一个查询出来的 Record 对象 - *

-     * 例子:
-     * Db.each(record -> {
-     *    // 处理 record 的代码在此
-     *
-     *    // 返回 true 继续循环处理下一条数据,返回 false 立即终止循环
-     *    return true;
-     * }, sql, paras);
-     * 
- */ - public static void each(Function func, String sql, Object... paras) { - use(SLAVE).each(func, sql, paras); - } - - // --------- - - /** - * 使用 sql 模板进行查询,可以省去 Db.getSqlPara(...) 调用 - * - *
-     * 例子:
-     * Db.template("blog.find", Kv.by("id", 123).find();
-     * 
- */ - public static DbTemplate template(String key, Map data) { - return use(SLAVE).template(key, data); - } - - /** - * 使用 sql 模板进行查询,可以省去 Db.getSqlPara(...) 调用 - * - *
-     * 例子:
-     * Db.template("blog.find", 123).find();
-     * 
- */ - public static DbTemplate template(String key, Object... paras) { - return use(SLAVE).template(key, paras); - } - - // --------- - - /** - * 使用字符串变量作为 sql 模板进行查询,可省去外部 sql 文件来使用 - * sql 模板功能 - * - *
-     * 例子:
-     * String sql = "select * from blog where id = #para(id)";
-     * Db.templateByString(sql, Kv.by("id", 123).find();
-     * 
- */ - public static DbTemplate templateByString(String content, Map data) { - return use(SLAVE).templateByString(content, data); - } - - /** - * 使用字符串变量作为 sql 模板进行查询,可省去外部 sql 文件来使用 - * sql 模板功能 - * - *
-     * 例子:
-     * String sql = "select * from blog where id = #para(0)";
-     * Db.templateByString(sql, 123).find();
-     * 
- */ - public static DbTemplate templateByString(String content, Object... paras) { - return use(SLAVE).templateByString(content, paras); - } -} - - - diff --git a/ZhuQue/src/main/resource/fzby.txt b/ZhuQue/src/main/resource/fzby.txt index 45a34e7..a1c904e 100644 --- a/ZhuQue/src/main/resource/fzby.txt +++ b/ZhuQue/src/main/resource/fzby.txt @@ -1,11 +1,12 @@ +$$$$$$$$\ $$\ $$\ $$\ $$\ $$$$$$\ $$\ $$\ $$$$$$$$\ +\____$$ |$$ | $$ |$$ | $$ |$$ __$$\ $$ | $$ |$$ _____| + $$ / $$ | $$ |$$ | $$ |$$ / $$ |$$ | $$ |$$ | + $$ / $$$$$$$$ |$$ | $$ |$$ | $$ |$$ | $$ |$$$$$\ + $$ / $$ __$$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ __| + $$ / $$ | $$ |$$ | $$ |$$ $$\$$ |$$ | $$ |$$ | +$$$$$$$$\ $$ | $$ |\$$$$$$ |\$$$$$$ / \$$$$$$ |$$$$$$$$\ +\________|\__| \__| \______/ \___$$$\ \______/ \________| + \___| -___ ___ ___ ___ ___ ________ ___ ___ _______ -|\_____ \|\ \|\ \|\ \|\ \|\ __ \|\ \|\ \|\ ___ \ - \|___/ /\ \ \\\ \ \ \\\ \ \ \|\ \ \ \\\ \ \ __/| - / / /\ \ __ \ \ \\\ \ \ \\\ \ \ \\\ \ \ \_|/__ - / /_/__\ \ \ \ \ \ \\\ \ \ \\\ \ \ \\\ \ \ \_|\ \ - |\________\ \__\ \__\ \_______\ \_____ \ \_______\ \_______\ - \|_______|\|__|\|__|\|_______|\|___| \__\|_______|\|_______| - \|__| power by http://patorjk.com/software/taag/ \ No newline at end of file