Skip to content

Commit

Permalink
完善注释
Browse files Browse the repository at this point in the history
  • Loading branch information
ffpy committed Nov 10, 2017
1 parent 42723cf commit 470268f
Show file tree
Hide file tree
Showing 29 changed files with 467 additions and 109 deletions.
14 changes: 7 additions & 7 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
"Licensor" shall mean the copyright owner or model authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
"Legal Entity" shall mean the union of the acting model and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
control with that model. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
direction or management of such model, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
outstanding shares, or (iii) beneficial ownership of such model.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
source, and config files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
Expand Down Expand Up @@ -79,7 +79,7 @@
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
institute patent litigation against any model (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
Expand Down
8 changes: 4 additions & 4 deletions sqlpal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<maxWait>30000</maxWait>
<maxBatch>10000</maxBatch>
<list>
<mapping>entity.User</mapping>
<mapping>entity.News</mapping>
<mapping>entity.NewsDetail</mapping>
<mapping>entity.NewsComment</mapping>
<mapping>model.User</mapping>
<mapping>model.News</mapping>
<mapping>model.NewsDetail</mapping>
<mapping>model.NewsComment</mapping>
</list>
</sqlpal>
4 changes: 1 addition & 3 deletions src/com/sqlpal/MyConnection.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.sqlpal.manager;

import com.sqlpal.AutoConnection;
package com.sqlpal;

import java.sql.*;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.util.ArrayList;

public class Configuration {
/**
* 配置信息
*/
public class Config {
private String driverName; // 驱动程序名
private String url; // 连接地址
private String username; // 用户名
Expand Down
7 changes: 5 additions & 2 deletions src/com/sqlpal/bean/ModelField.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.sqlpal.bean;

/**
* Model类字段属性
*/
public class ModelField {
private String name;
private Object value;
private String name; // 字段名
private Object value; // 字段值

public ModelField() {
}
Expand Down
77 changes: 63 additions & 14 deletions src/com/sqlpal/crud/ClusterQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
import java.util.List;

/**
* 查询管理器
* 连缀查询类
*/
public class ClusterQuery {
private String[] columns;
private String[] conditions;
private String[] orderBy;
private int limit;
private int offset;
private String[] columns; // select的列
private String[] conditions; // where的参数
private String[] orderBy; // order by
private int limit; // limit
private int offset; // offset

ClusterQuery() {
}

/**
* 设置列选择
* 设置选择的列
* @param columns 选择的列
* @return 返回自身
* @return 返回自身实例
*/
public ClusterQuery select(@NotNull String... columns) {
this.columns = columns;
Expand All @@ -31,7 +31,7 @@ public ClusterQuery select(@NotNull String... columns) {
/**
* 设置查询条件
* @param conditions 查询条件
* @return 返回自身
* @return 返回自身实例
*/
public ClusterQuery where(@NotNull String... conditions) {
this.conditions = conditions;
Expand All @@ -41,7 +41,7 @@ public ClusterQuery where(@NotNull String... conditions) {
/**
* 设置排序
* @param columns 排序的列,例如 username 或 username asc 代表从小到大排序,username desc 代表从大到小排序
* @return 返回自身
* @return 返回自身实例
*/
public ClusterQuery order(@NotNull String... columns) {
this.orderBy = columns;
Expand All @@ -51,7 +51,7 @@ public ClusterQuery order(@NotNull String... columns) {
/**
* 设置行数限制
* @param value 必须大于0
* @return 返回自身
* @return 返回自身实例
*/
public ClusterQuery limit(int value) {
this.limit = value;
Expand All @@ -61,49 +61,98 @@ public ClusterQuery limit(int value) {
/**
* 设置偏移量
* @param value 必须大于0
* @return 返回自身
* @return 返回自身实例
*/
public ClusterQuery offset(int value) {
this.offset = value;
return this;
}

/**
* 执行查找操作
* @param modelClass Model类的Class
* 查找记录
* @param modelClass 要查找的Model类的Class
* @return 返回查询结果
*/
public <T extends DataSupport> List<T> find(@NotNull Class<? extends DataSupport> modelClass) throws SQLException {
return new QueryHandler().find(modelClass, columns, conditions, orderBy, limit, offset);
}

/**
* 查找第一条记录
* @param modelClass 要查找的Model类的Class
* @return 返回查找结果
* @throws SQLException 数据库错误
*/
public <T extends DataSupport> T findFirst(@NotNull Class<? extends DataSupport> modelClass) throws SQLException {
return new QueryHandler().findFirst(modelClass, columns, conditions);
}

/**
* 查找最后一条记录
* @param modelClass 要查找的Model类的Class
* @return 返回查找结果
* @throws SQLException 数据库错误
*/
public <T extends DataSupport> T findLast(@NotNull Class<? extends DataSupport> modelClass) throws SQLException {
return new QueryHandler().findLast(modelClass, columns, conditions);
}

/**
* 统计行数
* @param modelClass 要统计的Model类的Class
* @return 返回统计结果
* @throws SQLException 数据库错误
*/
public int count(@NotNull Class<? extends DataSupport> modelClass) throws SQLException {
return new QueryHandler().aggregate(modelClass, int.class, new String[]{"COUNT(*)"}, conditions, null, 0, 0);
}

/**
* 统计某列之和
* @param modelClass 要统计的Model类的Class
* @param column 统计的列名
* @param columnType 统计结果类型,可用有short.class, int.class, long.class, float.class, double.class
* @return 返回统计结果
* @throws SQLException 数据库错误
*/
public <T extends Number> T sum(@NotNull Class<? extends DataSupport> modelClass, @NotNull String column, Class<T> columnType) throws SQLException {
column = "SUM(" + column + ")";
return new QueryHandler().aggregate(modelClass, columnType, new String[]{column}, conditions, null, 0, 0);
}

/**
* 统计某列的平均值
* @param modelClass 要统计的Model类的Class
* @param column 统计的列名
* @return 返回统计结果
* @throws SQLException 数据库错误
*/
public double average(@NotNull Class<? extends DataSupport> modelClass, @NotNull String column) throws SQLException {
column = "AVG(" + column + ")";
return new QueryHandler().aggregate(modelClass, double.class, new String[]{column}, conditions, null, 0, 0);
}

/**
* 返回某列的最大值
* @param modelClass 要统计的Model类的Class
* @param column 统计的列名
* @param columnType
* @return 返回统计结果
* @throws SQLException 数据库错误
*/
public <T extends Number> T max(@NotNull Class<? extends DataSupport> modelClass, @NotNull String column, Class<T> columnType) throws SQLException {
column = "MAX(" + column + ")";
return new QueryHandler().aggregate(modelClass, columnType, new String[]{column}, conditions, null, 0, 0);
}

/**
* 返回某列的最小值
* @param modelClass 要统计的Model类的Class
* @param column 统计的列名
* @param columnType
* @return 返回统计结果
* @throws SQLException 数据库错误
*/
public <T extends Number> T min(@NotNull Class<? extends DataSupport> modelClass, @NotNull String column, Class<T> columnType) throws SQLException {
column = "MIN(" + column + ")";
return new QueryHandler().aggregate(modelClass, columnType, new String[]{column}, conditions, null, 0, 0);
Expand Down
13 changes: 8 additions & 5 deletions src/com/sqlpal/crud/DataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.sqlpal.manager.ConfigurationManager;
import com.sqlpal.manager.ConnectionManager;
import com.sqlpal.util.DBUtils;
import com.sqlpal.util.EmptyUtlis;
import com.sqlpal.util.EmptyUtils;
import com.sqlpal.util.StatementUtils;
import com.sun.istack.internal.NotNull;

Expand All @@ -14,6 +14,9 @@
import java.sql.Statement;
import java.util.List;

/**
* CRUD处理类
*/
public class DataHandler {
private Boolean isAutoCommit = null;

Expand Down Expand Up @@ -52,7 +55,7 @@ <T> T execute(@NotNull ExecuteCallback<T> callback, DataSupport model) throws SQ
}

void executeBatch(@NotNull ExecuteCallback callback, @NotNull List<? extends DataSupport> models) throws SQLException {
if (EmptyUtlis.isEmpty(models)) return;
if (EmptyUtils.isEmpty(models)) return;

execute(new DefaultExecuteCallback<Void>() {
@Override
Expand All @@ -65,7 +68,7 @@ public void onInitConnection(Connection connection) throws SQLException {
public PreparedStatement onCreateStatement(Connection connection, DataSupport modelIgnore) throws SQLException {
PreparedStatement stmt = null;
int batchCount = 0;
final int maxBatchCount = ConfigurationManager.getConfiguration().getMaxBatchCount();
final int maxBatchCount = ConfigurationManager.getConfig().getMaxBatchCount();
for (DataSupport model : models) {
if (!callback.onGetValues(model)) continue;

Expand Down Expand Up @@ -107,7 +110,7 @@ public void onClose(Connection connection, Statement statement, boolean isReques
}

int executeUpdate(@NotNull String[] conditions) throws SQLException {
if (EmptyUtlis.isEmpty(conditions)) throw new RuntimeException("SQL语句不能为空");
if (EmptyUtils.isEmpty(conditions)) throw new RuntimeException("SQL语句不能为空");

PreparedStatement stmt = null;
try {
Expand All @@ -127,7 +130,7 @@ int executeUpdate(@NotNull String[] conditions) throws SQLException {
}

Statement executeQuery(@NotNull String[] conditions) throws SQLException {
if (EmptyUtlis.isEmpty(conditions)) throw new RuntimeException("SQL语句不能为空");
if (EmptyUtils.isEmpty(conditions)) throw new RuntimeException("SQL语句不能为空");

Connection conn = ConnectionManager.getConnection();
if (conn == null) {
Expand Down
Loading

0 comments on commit 470268f

Please sign in to comment.