mirror of
https://github.com/CarmJos/EasySQL.git
synced 2024-09-19 21:35:47 +00:00
[v0.3.0] 添加测试项目,并对新内容进行测试
This commit is contained in:
parent
e98a3357ab
commit
8a07759b87
41
.github/gpg_public.key
vendored
Normal file
41
.github/gpg_public.key
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
|
|
||||||
|
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
|
||||||
|
OK7d0W/LdJ3iFeselROADHgPQn14sg==
|
||||||
|
=rRA5
|
||||||
|
-----END PGP PUBLIC KEY BLOCK-----
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<version>0.3.0-SNAPSHOT</version>
|
<version>0.3.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -106,6 +106,7 @@ public interface SQLAction<T> {
|
|||||||
* 执行语句并处理返回值
|
* 执行语句并处理返回值
|
||||||
*
|
*
|
||||||
* @param function 处理方法
|
* @param function 处理方法
|
||||||
|
* @param defaultResult 默认结果,若处理后的结果为null,则返回该值
|
||||||
* @param exceptionHandler 异常处理器 默认为 {@link #defaultExceptionHandler()}
|
* @param exceptionHandler 异常处理器 默认为 {@link #defaultExceptionHandler()}
|
||||||
* @param <R> 需要返回的内容
|
* @param <R> 需要返回的内容
|
||||||
* @return 指定类型数据
|
* @return 指定类型数据
|
||||||
@ -139,8 +140,8 @@ public interface SQLAction<T> {
|
|||||||
/**
|
/**
|
||||||
* 执行语句并处理返回值
|
* 执行语句并处理返回值
|
||||||
*
|
*
|
||||||
* @param defaultResult 默认结果,若处理后的结果为null,则返回该值
|
|
||||||
* @param function 处理方法
|
* @param function 处理方法
|
||||||
|
* @param defaultResult 默认结果,若处理后的结果为null,则返回该值
|
||||||
* @param <R> 需要返回的内容
|
* @param <R> 需要返回的内容
|
||||||
* @return 指定类型数据
|
* @return 指定类型数据
|
||||||
* @throws SQLException 当SQL操作出现问题时抛出
|
* @throws SQLException 当SQL操作出现问题时抛出
|
||||||
|
@ -113,9 +113,9 @@ public interface SQLManager {
|
|||||||
* 对库中的某个表执行更改
|
* 对库中的某个表执行更改
|
||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @return {@link TableAlertBuilder}
|
* @return {@link TableAlterBuilder}
|
||||||
*/
|
*/
|
||||||
TableAlertBuilder alterTable(@NotNull String tableName);
|
TableAlterBuilder alterTable(@NotNull String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建一个查询
|
* 新建一个查询
|
||||||
|
@ -8,7 +8,7 @@ import cc.carm.lib.easysql.api.enums.NumberType;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public interface TableAlertBuilder extends SQLBuilder {
|
public interface TableAlterBuilder extends SQLBuilder {
|
||||||
|
|
||||||
SQLAction<Integer> renameTo(@NotNull String newTableName);
|
SQLAction<Integer> renameTo(@NotNull String newTableName);
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public interface TableAlertBuilder extends SQLBuilder {
|
|||||||
* 为该表移除一个索引
|
* 为该表移除一个索引
|
||||||
*
|
*
|
||||||
* @param indexName 索引名
|
* @param indexName 索引名
|
||||||
* @return @return {@link SQLUpdateAction}
|
* @return {@link SQLUpdateAction}
|
||||||
*/
|
*/
|
||||||
SQLAction<Integer> dropIndex(@NotNull String indexName);
|
SQLAction<Integer> dropIndex(@NotNull String indexName);
|
||||||
|
|
||||||
@ -31,14 +31,14 @@ public interface TableAlertBuilder extends SQLBuilder {
|
|||||||
* 为该表移除一个外键
|
* 为该表移除一个外键
|
||||||
*
|
*
|
||||||
* @param keySymbol 外键名
|
* @param keySymbol 外键名
|
||||||
* @return @return {@link SQLUpdateAction}
|
* @return {@link SQLUpdateAction}
|
||||||
*/
|
*/
|
||||||
SQLAction<Integer> dropForeignKey(@NotNull String keySymbol);
|
SQLAction<Integer> dropForeignKey(@NotNull String keySymbol);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为该表移除主键(须添加新主键)
|
* 为该表移除主键(须添加新主键)
|
||||||
*
|
*
|
||||||
* @return @return {@link SQLUpdateAction}
|
* @return {@link SQLUpdateAction}
|
||||||
*/
|
*/
|
||||||
SQLAction<Integer> dropPrimaryKey();
|
SQLAction<Integer> dropPrimaryKey();
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ public interface TableAlertBuilder extends SQLBuilder {
|
|||||||
*
|
*
|
||||||
* @param columnName 列名
|
* @param columnName 列名
|
||||||
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
||||||
* @return {@link TableAlertBuilder}
|
* @return {@link TableAlterBuilder}
|
||||||
*/
|
*/
|
||||||
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName, @NotNull NumberType numberType) {
|
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName, @NotNull NumberType numberType) {
|
||||||
return addAutoIncrementColumn(columnName, numberType, false, true);
|
return addAutoIncrementColumn(columnName, numberType, false, true);
|
||||||
@ -120,7 +120,7 @@ public interface TableAlertBuilder extends SQLBuilder {
|
|||||||
* <p> 注意:一个表只允许有一个自增列!
|
* <p> 注意:一个表只允许有一个自增列!
|
||||||
*
|
*
|
||||||
* @param columnName 列名
|
* @param columnName 列名
|
||||||
* @return {@link TableAlertBuilder}
|
* @return {@link TableAlterBuilder}
|
||||||
*/
|
*/
|
||||||
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName) {
|
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName) {
|
||||||
return addAutoIncrementColumn(columnName, NumberType.INT);
|
return addAutoIncrementColumn(columnName, NumberType.INT);
|
@ -86,43 +86,52 @@ public interface TableCreateBuilder extends SQLBuilder {
|
|||||||
*
|
*
|
||||||
* @param columnName 列名
|
* @param columnName 列名
|
||||||
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
||||||
* @param primary 是否为主键,若为false则设定为唯一键
|
* @param asPrimaryKey 是否为主键,若为false则设定为唯一键
|
||||||
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
|
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
|
||||||
* @return {@link TableCreateBuilder}
|
* @return {@link TableCreateBuilder}
|
||||||
*/
|
*/
|
||||||
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
|
TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
|
||||||
boolean primary, boolean unsigned) {
|
boolean asPrimaryKey, boolean unsigned);
|
||||||
return addColumn(columnName,
|
|
||||||
(numberType == null ? NumberType.INT : numberType).name()
|
|
||||||
+ (unsigned ? " UNSIGNED " : " ")
|
|
||||||
+ "NOT NULL AUTO_INCREMENT " + (primary ? "PRIMARY KEY" : "UNIQUE KEY")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为该表添加一个自增主键列
|
* 为该表添加一个INT类型的自增主键列
|
||||||
* <p> 自增列强制要求为数字类型,非空,且为UNIQUE。
|
* <p> 自增列强制要求为数字类型,非空,且为UNIQUE。
|
||||||
* <p> 注意:一个表只允许有一个自增列!
|
* <p> 注意:一个表只允许有一个自增列!
|
||||||
*
|
*
|
||||||
* @param columnName 列名
|
* @param columnName 列名
|
||||||
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
* @param asPrimaryKey 是否为主键,若为false则设定为唯一键
|
||||||
|
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
|
||||||
* @return {@link TableCreateBuilder}
|
* @return {@link TableCreateBuilder}
|
||||||
*/
|
*/
|
||||||
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType) {
|
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName,
|
||||||
return addAutoIncrementColumn(columnName, numberType, true, true);
|
boolean asPrimaryKey, boolean unsigned) {
|
||||||
|
return addAutoIncrementColumn(columnName, NumberType.INT, asPrimaryKey, unsigned);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为该表添加一个INT类型的自增列
|
||||||
|
* <p> 自增列强制要求为数字类型,非空,且为UNIQUE。
|
||||||
|
* <p> 注意:一个表只允许有一个自增列!
|
||||||
|
*
|
||||||
|
* @param columnName 列名
|
||||||
|
* @param asPrimaryKey 是否为主键,若为false则设定为唯一键
|
||||||
|
* @return {@link TableCreateBuilder}
|
||||||
|
*/
|
||||||
|
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, boolean asPrimaryKey) {
|
||||||
|
return addAutoIncrementColumn(columnName, asPrimaryKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为该表添加一个INT类型的自增主键列
|
* 为该表添加一个INT类型的自增主键列
|
||||||
* <p> 自增列强制要求为数字类型,非空,且为UNIQUE。
|
* <p> 自增列强制要求为数字类型,非空,且为UNIQUE。
|
||||||
* <p> 本方法采用的类型为 INT 如有其他需要请自行使用 {@link #addAutoIncrementColumn(String, NumberType)} 方法。
|
|
||||||
* <p> 注意:一个表只允许有一个自增列!
|
* <p> 注意:一个表只允许有一个自增列!
|
||||||
*
|
*
|
||||||
* @param columnName 列名
|
* @param columnName 列名
|
||||||
* @return {@link TableCreateBuilder}
|
* @return {@link TableCreateBuilder}
|
||||||
*/
|
*/
|
||||||
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName) {
|
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName) {
|
||||||
return addAutoIncrementColumn(columnName, null);
|
return addAutoIncrementColumn(columnName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,8 +145,8 @@ public interface TableCreateBuilder extends SQLBuilder {
|
|||||||
* @param columnName 索引包含的列
|
* @param columnName 索引包含的列
|
||||||
* @return {@link TableCreateBuilder}
|
* @return {@link TableCreateBuilder}
|
||||||
*/
|
*/
|
||||||
default TableCreateBuilder setIndex(@NotNull IndexType type,
|
default TableCreateBuilder setIndex(@NotNull String columnName,
|
||||||
@NotNull String columnName) {
|
@NotNull IndexType type) {
|
||||||
return setIndex(type, null, columnName);
|
return setIndex(type, null, columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.0-SNAPSHOT</version>
|
<version>0.3.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -2,14 +2,14 @@ package cc.carm.lib.easysql.builder.impl;
|
|||||||
|
|
||||||
import cc.carm.lib.easysql.action.SQLUpdateActionImpl;
|
import cc.carm.lib.easysql.action.SQLUpdateActionImpl;
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
import cc.carm.lib.easysql.api.builder.TableAlertBuilder;
|
import cc.carm.lib.easysql.api.builder.TableAlterBuilder;
|
||||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||||
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
|
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
|
||||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAlertBuilder {
|
public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAlterBuilder {
|
||||||
|
|
||||||
protected final @NotNull String tableName;
|
protected final @NotNull String tableName;
|
||||||
|
|
||||||
@ -25,28 +25,28 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> renameTo(@NotNull String newTableName) {
|
public SQLAction<Integer> renameTo(@NotNull String newTableName) {
|
||||||
return new SQLUpdateActionImpl(getManager(),
|
return new SQLUpdateActionImpl(getManager(),
|
||||||
"ALERT TABLE `" + getTableName() + "` RENAME TO `" + newTableName + "`"
|
"ALTER TABLE `" + getTableName() + "` RENAME TO `" + newTableName + "`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> changeComment(@NotNull String newTableComment) {
|
public SQLAction<Integer> changeComment(@NotNull String newTableComment) {
|
||||||
return new SQLUpdateActionImpl(getManager(),
|
return new SQLUpdateActionImpl(getManager(),
|
||||||
"ALERT TABLE `" + getTableName() + "` COMMENT '" + newTableComment + "'"
|
"ALTER TABLE `" + getTableName() + "` COMMENT '" + newTableComment + "'"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> setAutoIncrementIndex(int index) {
|
public SQLAction<Integer> setAutoIncrementIndex(int index) {
|
||||||
return new SQLUpdateActionImpl(getManager(),
|
return new SQLUpdateActionImpl(getManager(),
|
||||||
"ALERT TABLE `" + getTableName() + "` AUTO_INCREMENT=" + index
|
"ALTER TABLE `" + getTableName() + "` AUTO_INCREMENT=" + index
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> addIndex(@NotNull IndexType indexType, @NotNull String indexName, @NotNull String columnName, @NotNull String... moreColumns) {
|
public SQLAction<Integer> addIndex(@NotNull IndexType indexType, @NotNull String indexName, @NotNull String columnName, @NotNull String... moreColumns) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` ADD "
|
"ALTER TABLE `" + getTableName() + "` ADD "
|
||||||
+ TableCreateBuilderImpl.buildIndexSettings(indexType, indexName, columnName, moreColumns)
|
+ TableCreateBuilderImpl.buildIndexSettings(indexType, indexName, columnName, moreColumns)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -54,63 +54,73 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> dropIndex(@NotNull String indexName) {
|
public SQLAction<Integer> dropIndex(@NotNull String indexName) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` DROP INDEX `" + indexName + "`"
|
"ALTER TABLE `" + getTableName() + "` DROP INDEX `" + indexName + "`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> dropForeignKey(@NotNull String keySymbol) {
|
public SQLAction<Integer> dropForeignKey(@NotNull String keySymbol) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` DROP FOREIGN KEY `" + keySymbol + "`"
|
"ALTER TABLE `" + getTableName() + "` DROP FOREIGN KEY `" + keySymbol + "`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> dropPrimaryKey() {
|
public SQLAction<Integer> dropPrimaryKey() {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` DROP PRIMARY KEY"
|
"ALTER TABLE `" + getTableName() + "` DROP PRIMARY KEY"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn) {
|
public SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn) {
|
||||||
|
String orderSettings = null;
|
||||||
|
if (afterColumn != null) {
|
||||||
|
if (afterColumn.length() > 0) {
|
||||||
|
orderSettings = "AFTER `" + afterColumn + "`";
|
||||||
|
} else {
|
||||||
|
orderSettings = "FIRST";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` ADD `" + columnName + "` " + settings
|
"ALTER TABLE `" + getTableName() + "` ADD `" + columnName + "` " + settings
|
||||||
|
+ (orderSettings != null ? " " + orderSettings : "")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName) {
|
public SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` RENAME COLUMN `" + columnName + "` TO `" + newName + "`"
|
"ALTER TABLE `" + getTableName() + "` RENAME COLUMN `" + columnName + "` TO `" + newName + "`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings) {
|
public SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` MODIFY COLUMN `" + columnName + "` " + settings
|
"ALTER TABLE `" + getTableName() + "` MODIFY COLUMN `" + columnName + "` " + settings
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> removeColumn(@NotNull String columnName) {
|
public SQLAction<Integer> removeColumn(@NotNull String columnName) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` DROP `" + columnName + "`"
|
"ALTER TABLE `" + getTableName() + "` DROP `" + columnName + "`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) {
|
public SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` ALERT `" + columnName + "` SET DEFAULT " + defaultValue
|
"ALTER TABLE `" + getTableName() + "` ALTER `" + columnName + "` SET DEFAULT " + defaultValue
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> removeColumnDefault(@NotNull String columnName) {
|
public SQLAction<Integer> removeColumnDefault(@NotNull String columnName) {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALERT TABLE `" + getTableName() + "` ALERT `" + columnName + "` DROP DEFAULT"
|
"ALTER TABLE `" + getTableName() + "` ALTER `" + columnName + "` DROP DEFAULT"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import cc.carm.lib.easysql.api.action.SQLUpdateAction;
|
|||||||
import cc.carm.lib.easysql.api.builder.TableCreateBuilder;
|
import cc.carm.lib.easysql.api.builder.TableCreateBuilder;
|
||||||
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
||||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||||
|
import cc.carm.lib.easysql.api.enums.NumberType;
|
||||||
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
|
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
|
||||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -45,21 +46,15 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
|
|||||||
StringBuilder createSQL = new StringBuilder();
|
StringBuilder createSQL = new StringBuilder();
|
||||||
createSQL.append("CREATE TABLE IF NOT EXISTS `").append(tableName).append("`");
|
createSQL.append("CREATE TABLE IF NOT EXISTS `").append(tableName).append("`");
|
||||||
createSQL.append("(");
|
createSQL.append("(");
|
||||||
for (int i = 0; i < columns.size(); i++) {
|
createSQL.append(String.join(", ", columns));
|
||||||
createSQL.append(columns.get(i));
|
if (indexes.size() > 0) {
|
||||||
if (i != columns.size() - 1) createSQL.append(", ");
|
createSQL.append(", ");
|
||||||
|
createSQL.append(String.join(", ", indexes));
|
||||||
}
|
}
|
||||||
|
if (foreignKeys.size() > 0) {
|
||||||
for (int i = 0; i < indexes.size(); i++) {
|
createSQL.append(", ");
|
||||||
createSQL.append(indexes.get(i));
|
createSQL.append(String.join(", ", foreignKeys));
|
||||||
if (i != indexes.size() - 1) createSQL.append(", ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < foreignKeys.size(); i++) {
|
|
||||||
createSQL.append(foreignKeys.get(i));
|
|
||||||
if (i != foreignKeys.size() - 1) createSQL.append(", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
createSQL.append(") ").append(getTableSettings());
|
createSQL.append(") ").append(getTableSettings());
|
||||||
|
|
||||||
if (tableComment != null) {
|
if (tableComment != null) {
|
||||||
@ -75,6 +70,16 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
|
||||||
|
boolean asPrimaryKey, boolean unsigned) {
|
||||||
|
return addColumn(columnName,
|
||||||
|
(numberType == null ? NumberType.INT : numberType).name()
|
||||||
|
+ (unsigned ? " UNSIGNED " : " ")
|
||||||
|
+ "NOT NULL AUTO_INCREMENT " + (asPrimaryKey ? "PRIMARY KEY" : "UNIQUE KEY")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName,
|
public TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName,
|
||||||
@NotNull String columnName, @NotNull String... moreColumns) {
|
@NotNull String columnName, @NotNull String... moreColumns) {
|
||||||
|
@ -130,7 +130,7 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableAlertBuilder alterTable(@NotNull String tableName) {
|
public TableAlterBuilder alterTable(@NotNull String tableName) {
|
||||||
return new TableAlterBuilderImpl(this, tableName);
|
return new TableAlterBuilderImpl(this, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.0-SNAPSHOT</version>
|
<version>0.3.0</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -27,7 +27,7 @@ public class EasySQLDemo {
|
|||||||
.addColumn("phone", "VARCHAR(16)")
|
.addColumn("phone", "VARCHAR(16)")
|
||||||
.addColumn("registerTime", "DATETIME NOT NULL")
|
.addColumn("registerTime", "DATETIME NOT NULL")
|
||||||
// .addColumn("INDEX `phone`") // 原始方法添加索引
|
// .addColumn("INDEX `phone`") // 原始方法添加索引
|
||||||
.setIndex(IndexType.UNIQUE_KEY, "username") // 添加唯一索引
|
.setIndex("username", IndexType.UNIQUE_KEY) // 添加唯一索引
|
||||||
.setIndex(IndexType.INDEX, "contact", "email", "phone") //添加联合索引 (示例)
|
.setIndex(IndexType.INDEX, "contact", "email", "phone") //添加联合索引 (示例)
|
||||||
.build().execute(null /* 不处理错误 */);
|
.build().execute(null /* 不处理错误 */);
|
||||||
|
|
||||||
|
130
example/easysql-test/pom.xml
Normal file
130
example/easysql-test/pom.xml
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>easysql-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>0.3.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||||
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<artifactId>easysql-test</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easysql-hikaricp</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.25</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.29</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.17.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.17.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
|
<version>2.17.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
<!-- when downloading via Maven we can pull depends individually -->
|
||||||
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptRef>jar-with-dependencies</descriptRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>cc.carm.lib.easysql.testrunner.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>assembly</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,36 @@
|
|||||||
|
package cc.carm.lib.easysql.testrunner;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public abstract class EasySQLTest {
|
||||||
|
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
|
public abstract void onTest(SQLManager sqlManager) throws SQLException;
|
||||||
|
|
||||||
|
public boolean executeTest(int index, SQLManager sqlManager) {
|
||||||
|
String testName = getClass().getSimpleName();
|
||||||
|
|
||||||
|
print(" #%s 测试 @%s 开始", index, testName);
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
onTest(sqlManager);
|
||||||
|
print(" #%s 测试 @%s 成功,耗时 %s ms。", index, testName, (System.currentTimeMillis() - start));
|
||||||
|
return true;
|
||||||
|
} catch (Exception exception) {
|
||||||
|
print(" #%s 测试 @%s 失败,耗时 %s ms。", index, testName, (System.currentTimeMillis() - start));
|
||||||
|
exception.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void print(@NotNull String format, Object... params) {
|
||||||
|
Main.print(format, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
package cc.carm.lib.easysql.testrunner;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.EasySQL;
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.testrunner.tests.TableAlterTest;
|
||||||
|
import cc.carm.lib.easysql.testrunner.tests.TableCreateTest;
|
||||||
|
import cc.carm.lib.easysql.testrunner.tests.TableRenameTest;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
if (args.length < 4) {
|
||||||
|
print("请提供以下参数: 数据库地址 数据库用户名 数据库密码");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SQLManager sqlManager;
|
||||||
|
try {
|
||||||
|
print("初始化 SQLManager...");
|
||||||
|
print("数据库驱动 %s", args[0]);
|
||||||
|
print("数据库地址 %s", args[1]);
|
||||||
|
print("数据库用户 %s", args[2]);
|
||||||
|
print("数据库密码 %s", args[3]);
|
||||||
|
sqlManager = EasySQL.createManager(args[0], args[1], args[2], args[3]);
|
||||||
|
sqlManager.setDebugMode(args.length > 4);
|
||||||
|
print("SQLManager 初始化完成!");
|
||||||
|
} catch (Exception exception) {
|
||||||
|
print("SQLManager 初始化失败,请检查数据库配置。");
|
||||||
|
exception.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print("加载测试类...");
|
||||||
|
Set<EasySQLTest> tests = new LinkedHashSet<>();
|
||||||
|
tests.add(new TableCreateTest());
|
||||||
|
tests.add(new TableAlterTest());
|
||||||
|
tests.add(new TableRenameTest());
|
||||||
|
|
||||||
|
print("准备进行测试...");
|
||||||
|
|
||||||
|
int index = 1;
|
||||||
|
int success = 0;
|
||||||
|
|
||||||
|
Iterator<EasySQLTest> testIterator = tests.iterator();
|
||||||
|
|
||||||
|
print("准备完成,请按回车键开始执行测试。");
|
||||||
|
|
||||||
|
while (testIterator.hasNext()) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
if (scanner.nextLine() != null) {
|
||||||
|
|
||||||
|
EasySQLTest currentTest = testIterator.next();
|
||||||
|
|
||||||
|
if (currentTest.executeTest(index, sqlManager)) {
|
||||||
|
success++;
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
print(" ");
|
||||||
|
print("全部测试执行完毕,成功 %s 个,失败 %s 个。",
|
||||||
|
success, (tests.size() - success)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void print(@NotNull String format, Object... params) {
|
||||||
|
System.out.printf((format) + "%n", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable EasySQLTest cast(@NotNull Class<?> value) {
|
||||||
|
if (!EasySQLTest.class.isAssignableFrom(value)) return null;
|
||||||
|
try {
|
||||||
|
return (EasySQLTest) value.newInstance();
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package cc.carm.lib.easysql.testrunner.tests;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.api.enums.NumberType;
|
||||||
|
import cc.carm.lib.easysql.testrunner.EasySQLTest;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class TableAlterTest extends EasySQLTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
|
||||||
|
print(" 修改 test_user_table");
|
||||||
|
sqlManager.alterTable("test_user_table")
|
||||||
|
.addColumn("test", "VARCHAR(16) NOT NULL")
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
sqlManager.alterTable("test_user_table")
|
||||||
|
.addColumn("test2", "VARCHAR(16) NOT NULL", "username")
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
|
||||||
|
print(" 修改 test_user_info");
|
||||||
|
sqlManager.alterTable("test_user_info")
|
||||||
|
.addAutoIncrementColumn("num", NumberType.BIGINT, false, true)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
sqlManager.alterTable("test_user_info")
|
||||||
|
.addColumn("a", "VARCHAR(16) NOT NULL", "")
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package cc.carm.lib.easysql.testrunner.tests;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
||||||
|
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||||
|
import cc.carm.lib.easysql.testrunner.EasySQLTest;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class TableCreateTest extends EasySQLTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
|
||||||
|
print(" 创建 test_user_table");
|
||||||
|
sqlManager.createTable("test_user_table")
|
||||||
|
.addAutoIncrementColumn("id")
|
||||||
|
.addColumn("uuid", "VARCHAR(36) NOT NULL", "用户UUID")
|
||||||
|
.addColumn("username", "VARCHAR(16) NOT NULL", "用户名")
|
||||||
|
.addColumn("age", "TINYINT DEFAULT 0 NOT NULL", "年龄")
|
||||||
|
|
||||||
|
.setIndex("uuid", IndexType.UNIQUE_KEY)
|
||||||
|
.build().execute();
|
||||||
|
|
||||||
|
print(" 创建 test_user_info");
|
||||||
|
sqlManager.createTable("test_user_info")
|
||||||
|
.addColumn("uid", "INT UNSIGNED NOT NULL")
|
||||||
|
.addColumn("info", "TEXT", "相关信息")
|
||||||
|
.addForeignKey("uid", "user",
|
||||||
|
"test_user_table", "id",
|
||||||
|
ForeignKeyRule.CASCADE, ForeignKeyRule.CASCADE
|
||||||
|
)
|
||||||
|
.setIndex(IndexType.FULLTEXT_INDEX, "sign", "info")
|
||||||
|
.build().execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cc.carm.lib.easysql.testrunner.tests;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.testrunner.EasySQLTest;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class TableRenameTest extends EasySQLTest {
|
||||||
|
@Override
|
||||||
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
print(" 重命名 test_user_table");
|
||||||
|
sqlManager.alterTable("test_user_table")
|
||||||
|
.renameTo("test_user_table2")
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
}
|
7
pom.xml
7
pom.xml
@ -16,15 +16,16 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>0.3.0-SNAPSHOT</version>
|
<version>0.3.0</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>easysql-api</module>
|
<module>easysql-api</module>
|
||||||
<module>easysql-impl</module>
|
<module>easysql-impl</module>
|
||||||
|
|
||||||
<module>with-cp/easysql-beecp</module>
|
<module>with-pool/easysql-beecp</module>
|
||||||
<module>with-cp/easysql-hikaricp</module>
|
<module>with-pool/easysql-hikaricp</module>
|
||||||
<module>example/easysql-demo</module>
|
<module>example/easysql-demo</module>
|
||||||
|
<module>example/easysql-test</module>
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.0-SNAPSHOT</version>
|
<version>0.3.0</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.0-SNAPSHOT</version>
|
<version>0.3.0</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
Loading…
Reference in New Issue
Block a user