diff --git a/README.md b/README.md index d8978d4b0adb01c2012de9dda02ee9c4f884e893..6ad33fd82946a6ad8771f842e29293a74b4a2d90 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ # 包组件 - Annotations **注释包** - lang **常用或未分类的工具包** +- lang.net **网络工具包** - Porcessing **处理工具包** -- Porcessing.Interface **集成处理接口** - Porcessing.Sort **排序工具包** - Porcessing.Stop **中断工具包** - Porcessing.sql **数据库工具包** diff --git a/build.gradle b/build.gradle index 03ed5f8368b4f00f096a5244bba7ec6d46f2ded6..1a757f24bd759d84a5cff0735240f197db0a36a0 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,6 @@ ext { junitVersion = '4.12' } dependencies { -// compile fileTree(dir: 'lib', includes: ['*.jar']) + compile fileTree(dir: 'lib', includes: ['*.jar']) // https://mvnrepository.com/artifact/org.jetbrains/annotations } diff --git a/jar/PDFLibrary.jar b/jar/PDFLibrary.jar index 9febb1de9a0e86e9eaa5176b6fb9bdfb16587e5a..478bc06712e26d569ff6ba30e407ed37cfcd7d25 100644 Binary files a/jar/PDFLibrary.jar and b/jar/PDFLibrary.jar differ diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/ByteDef.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/ByteDef.java index 0525986bc5b3dbf89af66967f7fec0b960876549..bac83ffd8a21665b7277353a798ed43339616ec1 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/ByteDef.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/ByteDef.java @@ -5,7 +5,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** *

指定字节常量列表.

- *

该注释表示该 变量/方法参数 应使用其中的常量

+ *

该注释指定应该使用的值

* * @author fybug * @version 0.0.2 @@ -15,5 +15,6 @@ import java.lang.annotation.Target; @Target( {ElementType.ANNOTATION_TYPE} ) public @interface ByteDef { + /**

应使用的常量.

*/ byte[] value() default {}; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/CanSynchronized.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/CanSynchronized.java index ad187f47e99dc41cc7aff8c2f9b995e10226dbd6..4d5a0b065668f911bc40c258f047d98ba3888353 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/CanSynchronized.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/CanSynchronized.java @@ -5,11 +5,12 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** *

可并发标识

- *

使用该类注解类标识 该方法该类下的方法 是否可用于并发

- *

静态方法理应单独标记

*
- * 代表标识范围的方法支持并发
+ * 使用该类注解类标识 该方法该类下的方法 是否可用于并发
+ *
+ * 静态方法理应单独标记
  * 
+ *

代表标识范围的方法支持并发

* * @author fybug * @version 0.0.2 diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/IntDef.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/IntDef.java index abff3a9cf8037752999446b73038ef7fd5af13b6..1a14ac4be4ddf20d9181273366def1447a5b3420 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/IntDef.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/IntDef.java @@ -5,7 +5,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** *

指定整数常量列表.

- *

该注释表示该 变量/方法参数 应使用其中的常量

+ *

该注释指定应该使用的值

* * @author fybug * @version 0.0.2 @@ -15,5 +15,6 @@ import java.lang.annotation.Target; @Target( {ElementType.ANNOTATION_TYPE} ) public @interface IntDef { + /**

应使用的常量.

*/ int[] value() default {}; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/NoSynchronized.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/NoSynchronized.java index a58f0da0cef4d0646fd9063a9875b2e0f000dbb8..2647f72d338273a03b0ef67a45ee6ddd7a2e824b 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/NoSynchronized.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/NoSynchronized.java @@ -5,11 +5,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** *

不可并发标识

- *

使用该类注解类标识 该方法该类下的方法 是否可用于并发

- *

静态方法理应单独标记

*
- * 代表标识范围的方法不支持并发
- * 
+ * 使用该类注解类标识 该方法该类下的方法 是否可用于并发 + * + * 静态方法理应单独标记 + *

代表标识范围的方法不支持并发

* * @author fybug * @version 0.0.2 diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/TestPackage.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/TestPackage.java new file mode 100644 index 0000000000000000000000000000000000000000..bc4382cffc2acaf3ad568b5cfb1550a0793f6c2a --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Annotations/TestPackage.java @@ -0,0 +1,19 @@ +package fybug.nulll.pdfunctionlibrary.Annotations; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +/** + *

测试包.

+ *

用于标识该包是测试版本的包

+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +@Documented +@Retention( RetentionPolicy.SOURCE ) +@Target( {ElementType.PACKAGE} ) +public +@interface TestPackage {} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java index 714cd5add33bbb214213b4ac62d252c62bb7c349..de917fadc3206c84526a7c7c2a2647521389e1d1 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java @@ -1,159 +1,152 @@ package fybug.nulll.pdfunctionlibrary.Processing; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.ref.SoftReference; +import java.util.HashMap; + +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.ANDPR; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.ANNOTATION; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.ENDMARK; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.GREATER; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.LESS; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.NAME; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.PERCENTAGE; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.ROD; +import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.STR; +import static fybug.nulll.pdfunctionlibrary.lang.net.bdpos.BDPos.CLASS; +import static fybug.nulll.pdfunctionlibrary.lang.net.bdpos.BDPos.NAMEMARK; +import static fybug.nulll.pdfunctionlibrary.lang.net.bdpos.BDPos.RN; /** *

字符过滤工具.

- *
- * 提供各种条件下的字符过滤
- * 
+ *

提供各种条件下的字符过滤

* * @author fybug - * @version 0.0.2 - * @since PDF 1.2 expander 2 + * @version 0.0.4 + * @since PDF 1.3 */ @SuppressWarnings( "all" ) public final class FuckChar { - @NotNull public final static char[] KEYTAB_TO_AT = {'@', '0', '2'}, KEYTAB_TO_AND = - {'@', '0', '1'}, KEYTAB_TO_EQUAL = {'@', '0', '0'}; - @NotNull public final static char KEYTAB_AT = '@', KEYTAB_EQUAL = '=', KEYTAB_AND = '&'; + /**

过滤表.

*/ + @NotNull private static SoftReference<@Nullable HashMap> map; - /** {@Hide} */ - @Deprecated - private - FuckChar() {} + @NotNull + private static synchronized + HashMap getMap() { + @NotNull HashMap m; + + if (map == null || (m = map.get()) == null) { + map = new SoftReference<>(m = new HashMap() {{ + put(ENDMARK, "@000"); + put(ANDPR, "@001"); + put(GREATER, "@002"); + put(LESS, "@003"); + put(STR, "@004"); + put(NAME, "@005"); + put(ANNOTATION, "@006"); + put(ROD, "@007"); + put(PERCENTAGE, "@008"); + put(CLASS, "@009"); + put(RN, "@010"); + put(NAMEMARK, "@011"); + }}); + } + + return m; + } /** - *

Fuck Keytab KeyWord.

- *
-     * {@code
-     * = -> @00
-     * & -> @01
-     * @ -> @02}
-     * 
+ *

过滤 Sql 语句.

* - * @param c 要过滤的字符集合 + * @param str 要过滤的数据 * - * @return 过滤后的字符 + * @return 过滤后的数据 */ @NotNull public static - String fuckKeytab(@NotNull final CharSequence c) { - @NotNull final StringBuilder s = new StringBuilder(c); - char firstchar; // 当前解析的字符 - @NotNull char[] adds; - - check: - for ( int mark = 0, lenght = s.length(); mark < lenght; ){ - // 检查第一个字符 - firstchar = s.charAt(mark); - - ck: - { - switch ( firstchar ) { - case KEYTAB_AT: - adds = KEYTAB_TO_AT; - break; - case KEYTAB_EQUAL: - adds = KEYTAB_TO_EQUAL; - break; - case KEYTAB_AND: - adds = KEYTAB_TO_AND; - break; - default: - break ck; - } - s.deleteCharAt(mark); - - // 检查位置 - if (mark < lenght - 1) { - s.insert(mark, adds); - mark += 3; - lenght += 2; - continue check; - } else { - /* 到达尾部 */ - s.append(adds); - break check; - } - } - - mark++; - } - - firstchar = 0; - s.trimToSize(); + String fuckSql(@NotNull final CharSequence s) { + @NotNull String str = s.toString(); + @NotNull final HashMap m = getMap(); + + str = str.replaceAll(ENDMARK, m.get(ENDMARK)); + str = str.replaceAll(ANDPR, m.get(ANDPR)); + str = str.replaceAll(GREATER, m.get(GREATER)); + str = str.replaceAll(LESS, m.get(LESS)); + str = str.replaceAll(STR, m.get(STR)); + str = str.replaceAll(NAME, m.get(NAME)); + str = str.replaceAll(ANNOTATION, m.get(ANNOTATION)); + str = str.replaceAll(ROD, m.get(ROD)); + str = str.replaceAll(PERCENTAGE, m.get(PERCENTAGE)); + + return str; + } - return s.toString(); + /** + *

恢复被过滤 Sql 语句.

+ * + * @param str 要恢复的数据 + * + * @return 恢复后的数据 + */ + @NotNull + public static + String refuckSql(@NotNull final CharSequence s) { + @NotNull String str = s.toString(); + @NotNull final HashMap m = getMap(); + + str = str.replaceAll(m.get(ENDMARK), ENDMARK); + str = str.replaceAll(m.get(ANDPR), ANDPR); + str = str.replaceAll(m.get(GREATER), GREATER); + str = str.replaceAll(m.get(LESS), LESS); + str = str.replaceAll(m.get(STR), STR); + str = str.replaceAll(m.get(NAME), NAME); + str = str.replaceAll(m.get(ANNOTATION), ANNOTATION); + str = str.replaceAll(m.get(ROD), ROD); + str = str.replaceAll(m.get(PERCENTAGE), PERCENTAGE); + + return str; } /** - *

Restore Keytab KeyWord.

- *

恢复{@link #fuckKeytab(CharSequence)} 处理过的字符

- *
-     * {@code
-     * @00 -> =
-     * @01 -> &
-     * @02 -> @}
-     * 
+ *

过滤 BDPos 标识符.

* - * @param c 要恢复的字符集合 + * @param s 要过滤的数据 * - * @return 恢复后的字符 + * @return 过滤后的数据 + */ + @NotNull + public static + String fuckBDPos(@NotNull final CharSequence s) { + @NotNull String str = s.toString(); + @NotNull final HashMap m = getMap(); + + str = str.replaceAll(ANDPR, m.get(ANDPR)); + str = str.replaceAll(CLASS, m.get(CLASS)); + str = str.replaceAll(RN, m.get(RN)); + str = str.replaceAll(NAMEMARK, m.get(NAMEMARK)); + + return str; + } + + /** + *

恢复过滤的 BDPos 标识符.

* - * @see #fuckKeytab(CharSequence) + * @param s 要恢复的数据 + * + * @return 恢复后的数据 */ @NotNull public static - String rollbackKeytab(@NotNull final CharSequence c) { - @NotNull final StringBuilder s = new StringBuilder(c); - @NotNull char[] checkNow = {'@', 0, 0}; // 标识缓存 - char firstchar; // 当前解析的字符 - - check: - for ( int mark = 0, lenght = s.length() - 2; mark < lenght; ){ - firstchar = s.charAt(mark); - - sw: - // 检查 - switch ( firstchar ) { - case KEYTAB_AT: - checkNow[1] = s.charAt(mark + 1); - checkNow[2] = s.charAt(mark + 2); - - // 检查基本标识 - switch ( checkNow[1] ) { - case '0': - break; - default: - break sw; - } - - // 检查标识 - switch ( checkNow[2] ) { - case '0': - s.setCharAt(mark, KEYTAB_EQUAL); - break; - case '1': - s.setCharAt(mark, KEYTAB_AND); - break; - case '2': - s.setCharAt(mark, KEYTAB_AT); - break; - default: - break sw; - } - s.delete(mark + 1, mark + 3); - - lenght -= 2; - } - - mark++; - } + String refuckBDPos(@NotNull final CharSequence s) { + @NotNull String str = s.toString(); + @NotNull final HashMap m = getMap(); - checkNow = null; - firstchar = 0; - s.trimToSize(); + str = str.replaceAll(m.get(ANDPR), ANDPR); + str = str.replaceAll(m.get(CLASS), CLASS); + str = str.replaceAll(m.get(RN), RN); + str = str.replaceAll(m.get(NAMEMARK), NAMEMARK); - return s.toString(); + return str; } } \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java index 4db9658d3084eb9520aae423b32a58f455dd357f..73e84ee5cfb35a7625bf08aacc1b39e184e5b513 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java @@ -39,22 +39,6 @@ class SelectionSort { private SelectionSort() {} - /** - *

对文本进行排序.

- *

使用{@link #UP}模式来排序

- * - * @param arrayList 即将进行排序的字符集合 - * @param 必须是字符集合的子类 - * - * @return 已排序的字符集合 - * - * @see SelectionSort#sortString(List, int) - */ - @NotNull - public static - List sortString(@Nullable final List arrayList) - { return sortString(arrayList, DOWN); } - /** *

对字符集合进行排序.

*

排序不会影响传入的对象.

@@ -172,21 +156,6 @@ class SelectionSort { return arrayList; } - /** - *

对文本进行排序.

- *

使用{@link #UP}模式来排序

- * - * @param s 即将进行排序的文本 - * - * @return 已排序的文本 - * - * @see SelectionSort#sortString(String[], int) - */ - @NotNull - public static - String[] sortString(@Nullable final String[] s) - { return sortString(s, DOWN); } - /** *

对文本数组进行排序.

*

排序不会影响传入的对象.

@@ -287,26 +256,6 @@ class SelectionSort { return arrayList; } - /** - *

对文件列表进行排序.

- *

采用{@link #MODE_DEFAULT}和{@link #DOWN}模式排序

- * - *
-     * 排序方式:
-     * 逐字符对比,char编码较大的在上面
-     * 
- * - * @param f 即将进行排序的文件表 - * - * @return 返回被排序好的文件列表 - * - * @see #sortFile(File[], int, int) - */ - @NotNull - public static - File[] sortFile(@Nullable final File[] f) - { return sortFile(f, MODE_DEFAULT, DOWN); } - /** *

对文件列表进行排序.

* @@ -355,7 +304,7 @@ class SelectionSort { } /* 分开文件/文件夹 */ - for ( int i = 0; i < f.length; i++ ) + for ( int i = 0, length = f.length; i < length; i++ ) separationFile(dirs, files, f[i]); /* 用选择排序对其进行排序 */ @@ -375,28 +324,6 @@ class SelectionSort { return file[0].toArray(new File[file[0].size()]); } - /** - *

对文件列表进行排序.

- *

采用{@link #MODE_DEFAULT}和{@link #DOWN}模式排序

- * - *
-     * 排序方式:
-     * 逐字符对比,char编码较大的在上面
-     * 
- * - * @param f 即将进行排序的文件表 - * - * @return 返回被排序好的文件列表 - * - * @throws NullPointerException 参数为空 - * @see #sortFile(List, int, int) - */ - @NotNull - public static - List sortFile(@Nullable final List f) { - return sortFile(f, MODE_DEFAULT, DOWN); - } - /** *

转化为数组后用{@link #sortFile(File[], int, int)}进行排序.

* @@ -459,12 +386,15 @@ class SelectionSort { return file[0]; } + /** + * 排序文件 + */ private static void sortFile(@SortMode int sort, LinkedList[] file) { LinkedList linkedList; LinkedList list; - for ( int index = 0; index < file.length; index++ ){ + for ( int index = 0, lenght = file.length; index < lenght; index++ ){ linkedList = file[index]; list = (LinkedList) Lists.toString(linkedList); @@ -474,22 +404,37 @@ class SelectionSort { list = (LinkedList) sortString(list, sort); /* 转化为文件路径并重新写入 */ - for ( @NotNull String string : list ){ + for ( String string : list ){ linkedList.add(new File(string)); + string = null; } } } /** *

检查是否所有数据都相同.

+ *
+     * 检查是否以检查到最大可检查的长度
+     * 如果是,则根据排序方式 按照数据长度 进行额外排序
+     * 
+ * + * @param sort 排序方式 + * @param index 当前标记位置 + * @param nowLeight 当前解析的长度 + * @param i1 第一个字符串的长度 + * @param i2 第二个字符串的长度 + * @param stringLenght 最大对比的长度 + * @param s 当前检查位置 * - * @return 应使用的索引 + * @return 检查后应使用的位置 */ private static int checkIndex(@SortMode final int sort, int index, final int nowLeight, final int i1, final int i2, final int stringLenght, final int s) { + // 检查是否已对比完成 if (nowLeight == stringLenght) { + // 按照排序方式进行额外排序 switch ( sort ) { case DOWN: if (i1 <= i2) diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/HowWhere.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Comparison.java similarity index 53% rename from src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/HowWhere.java rename to src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Comparison.java index 754e450292e86a28a81cc3e2413e05098195a12b..34058b5e3518a53f605563dad7fde4627e45ff80 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/HowWhere.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Comparison.java @@ -1,23 +1,34 @@ package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; - import com.sun.istack.internal.NotNull; + +import org.jetbrains.annotations.Nullable; /** - *

键值的逻辑运算符枚举.

+ *

比较运算符枚举.

* * @author fybug - * @version 0.0.1 + * @version 0.0.3 * @since PDF 1.2 */ +@SuppressWarnings( "All" ) public -enum HowWhere { +enum Comparison { + /**

等于.

*/ + EQULE(" = "), + /**

大于.

*/ MORE(" > "), + /**

小于.

*/ LESS(" < "), + /**

大于等于.

*/ MORE_AND(" >= "), + /**

小于等于.

*/ LESS_AND(" <= "), - NO(" <> "); + /**

不等于.

*/ + NO(" <> "), + /**

严格检查.

*/ + STRICT(" <=> "); @NotNull final private String s; - HowWhere(@NotNull final CharSequence s) {this.s = s.toString();} + Comparison(@NotNull final CharSequence s) {this.s = s.toString();} @Override public @@ -30,10 +41,13 @@ enum HowWhere { * * @return 转化成的枚举 */ + @Nullable public final - HowWhere getMde(@NotNull final CharSequence ss) { - @NotNull final String s = ss.toString(); + Comparison getMde(@NotNull final CharSequence ss) { + @NotNull final String s = String.valueOf(ss).trim(); switch ( s ) { + case "=": + return EQULE; case ">": return MORE; case "<": @@ -43,7 +57,10 @@ enum HowWhere { case "<=": return LESS_AND; case "<>": + case "!=": return NO; + case "<=>": + return STRICT; default: return null; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/InserMode.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/InserMode.java new file mode 100644 index 0000000000000000000000000000000000000000..01c4af536b0c295dbd4aee2ef9adf915441f8461 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/InserMode.java @@ -0,0 +1,31 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; +/** + *

插入模式.

+ *

指定了当前数据的插入方式和内容

+ * 所有键都需要包装和过滤 + * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +@SuppressWarnings( "all" ) +public +enum InserMode { + /** + *

插入 Null 值.

+ * 后面不需要值 + */ + NULL, + /**

插入一个值.

*/ + VAL, + /** + *

插入一个值.

+ * 不提供包装 + */ + OUT, + /** + *

使用赋值 sql 语句.

+ * 不过滤 + */ + SQL; +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Relation.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Logical.java similarity index 54% rename from src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Relation.java rename to src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Logical.java index 76b2989ceae415da38a7cc3d670b45546078e4c4..6a397021f4acd70aede24aaef197288588b8b8f6 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Relation.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Logical.java @@ -1,21 +1,29 @@ package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; import com.sun.istack.internal.NotNull; + +import org.jetbrains.annotations.Nullable; /** - *

条件与条件之间的关联.

+ *

逻辑运算符枚举.

* * @author fybug - * @version 0.0.1 + * @version 0.0.2 * @since PDF 1.2 */ +@SuppressWarnings( "All" ) public -enum Relation { +enum Logical { + /**

并且.

*/ AND(" AND "), - OR(" OR "); + /**

或者.

*/ + OR(" OR "), + /**

异或.

*/ + XOR(" XOR "); @NotNull final private String s; - Relation(@NotNull final CharSequence s) {this.s = s.toString();} + Logical(@NotNull final CharSequence s) {this.s = s.toString();} @Override + @NotNull public String toString() { return s; } @@ -26,14 +34,17 @@ enum Relation { * * @return 转换后的枚举 */ + @Nullable public - Relation getRelation(CharSequence ss) { - @NotNull final String s = ss.toString().toUpperCase(); + Logical getRelation(@Nullable final CharSequence ss) { + @NotNull final String s = String.valueOf(ss).trim().toUpperCase(); switch ( s ) { case "AND": return AND; case "OR": return OR; + case "XOR": + return XOR; default: return null; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/OrderByMode.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/OrderByMode.java deleted file mode 100644 index 26360cf7d407adf65cf1343d1fd3b12fd49f6267..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/OrderByMode.java +++ /dev/null @@ -1,34 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; -import org.jetbrains.annotations.NotNull; -/** - *

查询排序方式.

- * - * @author fybug - * @version 0.0.2 - * @since PDF 1.2 - */ -public -enum OrderByMode { - ASC, - DESC; - - /** - *

转化字符串为排序方式枚举.

- * - * @param ss 要转化的字符串 - * - * @return 转化后的枚举 - */ - public static - OrderByMode getOrderByMode(CharSequence ss) { - @NotNull final String s = ss.toString().toUpperCase(); - switch ( s ) { - case "ASC": - return ASC; - case "DESC": - return DESC; - default: - return null; - } - } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/UpdataMode.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/UpdataMode.java new file mode 100644 index 0000000000000000000000000000000000000000..f5d7ff52d5d0a257e8a4aef09c74635b5a3babfd --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/UpdataMode.java @@ -0,0 +1,78 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; +import org.jetbrains.annotations.NotNull; +/** + *

更新模式.

+ *

指定了当前数据的更新方式和内容

+ * 所有键都需要包装和过滤 + * + * @author fybug + * @version 0.0.2 + * @since PDF 1.3 + */ +@SuppressWarnings( "all" ) +public +enum UpdataMode { + /** + *

更新为 Null 值.

+ * 后面不需要值 + */ + NULL, + /**

更新为一个值.

*/ + VAL, + /** + *

插入一个值.

+ * 不提供包装 + */ + OUT, + /** + *

使用赋值 sql 语句.

+ * 不过滤 + */ + SQL, + /** + *

更新为自增.

+ * 参数为自增的值 + */ + UP("+"), + /** + *

更新为自减.

+ * 参数为自减的值 + */ + DOWN("-"), + /** + *

更新为自乘.

+ * 参数为自乘的值 + */ + MUL("*"), + /** + *

更新为自除.

+ * 参数为自除的值 + */ + EXCE("/"), + /** + *

更新为自取商.

+ */ + DIV(" DIV "), + /**

更新为自取模.

*/ + MOD(" MOD "), + /**

按位取或.

*/ + BITOR("|"), + /**

按位取于.

*/ + BITAND("&"), + /**

按位异或.

*/ + BITXOR("^"), + /**

位左移.

*/ + BITLEFT("<<"), + /**

位右移.

*/ + BITRIGHT(">>"); + @NotNull private String s; + + UpdataMode() { this(""); } + + UpdataMode(@NotNull final String s) { this.s = s; } + + @Override + @NotNull + public + String toString() { return s; } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/package-info.java index 00dff268e76b2e0d44e585e79924c9f501711ee2..dc52388c75386ea5ef51910a4493397507e6546c 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/package-info.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/package-info.java @@ -3,7 +3,7 @@ *

用来代表 SQL 的相关状态标识

* * @author fybug - * @version 0.0.1 + * @version 0.0.2 * @since PDF 1.2 */ package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Mysql.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Mysql.java index d398ca3d96e5126e64726835c19d67e6779eaa48..125a7da96d12bfd67166573c511b749aa7017f48 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Mysql.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Mysql.java @@ -4,18 +4,13 @@ import com.sun.istack.internal.Nullable; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Map; import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.OrderByMode; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.QureySet; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.sqlWhereBulid; -import fybug.nulll.pdfunctionlibrary.Util.DataMap; -import fybug.nulll.pdfunctionlibrary.Util.Map.MapFile; - -import static fybug.nulll.pdfunctionlibrary.Processing.sql.Util.sqlWhereBulid.getWhere; +import fybug.nulll.pdfunctionlibrary.Processing.CObject; +import fybug.nulll.pdfunctionlibrary.Processing.sql.mysql.MysqlSql; +import fybug.nulll.pdfunctionlibrary.Processing.sql.mysql.Updata; /** - *

Mysql 数据库工具类.

+ *

mysql 数据库工具类.

*
  * 使用该工具类进行 Sql 操作
  * 该工具会进行字段过滤和包装出 sql
@@ -23,15 +18,15 @@ import static fybug.nulll.pdfunctionlibrary.Processing.sql.Util.sqlWhereBulid.ge
  * 
* * @author fybug - * @version 0.0.2 + * @version 0.0.4 * @see Sql - * @since PDF 1.2 + * @since PDF 1.3 */ @SuppressWarnings( "all" ) @CanSynchronized public class Mysql extends Sql { - // Mysql 连接名 + // mysql 连接名 @NotNull private static final String URL = "jdbc:mysql://"; // JDBC 驱动名 @NotNull private static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; @@ -72,256 +67,58 @@ class Mysql extends Sql { pass)); } - // 增 - /** - *

插入数据到指定表中.

+ *

执行 Mysql 语句.

+ *
+     * 通过语句对象对查询方式进行包装
+     * 并保证安全和完整性
+     * 
* - * @param tabname 表名 - * @param field 要插入的数据,使用映射表,要按顺序 - */ - public - void insert(@NotNull String tabname, @NotNull final MapFile field) - { - int size = field.size(); // 总字段数量 - if (size == 0) - return; - @NotNull final StringBuilder sql = new StringBuilder("INSERT INTO "); - - try { - // 获取插入语句 - exe(getInsert(tabname, field, sql)); - } catch ( Exception e ) { - throw new RuntimeException(e); - } finally { - sql.setLength(0); - sql.trimToSize(); - } - } - - /** - *

插入数据到指定表中如有数据则会进行更新.

+ * @param sql 要执行的语句对象 * - * @param tabname 表名 - * @param field 要插入的数据,使用映射表,要按顺序 - * @param f 更新的字段 + * @return 是否发生异常 * - * @since PDF 1.3 + * @see MysqlSql */ + @Nullable public - void insertORupdate(@NotNull String tabname, - @NotNull final MapFile field, - @NotNull final Map f) - { - int size = field.size(); // 总字段数量 - if (size == 0) - return; - @NotNull StringBuilder sql = new StringBuilder("INSERT INTO "); - + boolean exe(@NotNull final MysqlSql sql) { + @NotNull final CObject lock = new CObject(); try { - CharSequence k, v; - int vlenght; - boolean ids = false; // 获取插入语句 - sql = new StringBuilder(getInsert(tabname, field, sql)); - sql.setCharAt(sql.length() - 1, ' '); - sql.append("ON DUPLICATE KEY UPDATE "); - - // 获取参数 - for ( Map.Entry entry : f.entrySet() ){ - // 过滤 - k = fuckSql(entry.getKey()); - v = entry.getValue(); - if (v == null) - vlenght = 0; - else { - v = fuckSql(v); - vlenght = v.length(); - } - - /* 检查是否是第一个 */ - if (ids) { - sql.ensureCapacity(sql.length() + k.length() + 7 + v.length()); - sql.append(", "); - } else { - sql.ensureCapacity(sql.length() + k.length() + 5 + v.length()); - ids = true; - } - - sql.append("`").append(k).append("`").append(" = ").append(v); - } - - String sqls = sql.append(";").toString(); - sql.setLength(0); - sql.trimToSize(); - sql = null; - - exe(sqls); - } catch ( Throwable e ) { - throw new RuntimeException(e); - } finally { - sql.setLength(0); - sql.trimToSize(); - } - } - - // 获取插入语句 - private - String getInsert(String tabname, MapFile f, StringBuilder sql) - { - // 过滤表名 - tabname = fuckSql(tabname); - sql.ensureCapacity(tabname.length() + 3 + sql.length()); - sql.append("`").append(tabname).append("`").append("("); - - @NotNull StringBuilder key = new StringBuilder(""), val = new StringBuilder( - " VALUES ("); // 键和值的缓存 - @NotNull boolean i = true; // 是否第一个 - @NotNull CharSequence keys; // 键 - @NotNull CharSequence vals; // 值 - @NotNull int valsLengh; // 值的长度 - - for ( DataMap v = f.get(); v != null; f.next(), v = f.get() ){ - if (v == null) - break; - - // 过滤 - keys = fuckSql(v.getKey()); - vals = v.getValue(); - if (vals == null) - valsLengh = 0; - else { - vals = fuckSql(vals); - valsLengh = vals.length(); - } - - /* 判断是否是第一个,并预加载 */ - if (!i) { - key.ensureCapacity(key.length() + 3 + keys.length()); - key.append(", "); - val.ensureCapacity(val.length() + 3 + valsLengh); - val.append(", "); - } else { - key.ensureCapacity(key.length() + 2 + keys.length()); - val.ensureCapacity(val.length() + 2 + valsLengh); - i = false; - } - - // 加入数据 - key.append("`").append(keys).append("`"); - if (vals != null) - val.append("'").append(vals).append("'"); - else - val.append("NULL"); - } - - keys = vals = null; - valsLengh = 0; - - // 放入语句中 - key.append(")"); - val.append(");"); - sql.ensureCapacity(sql.length() + key.length() + val.length()); - sql.append(key).append(val); - - // 释放资源 - key.setLength(0); - key.trimToSize(); - val.setLength(0); - val.trimToSize(); - - return sql.toString(); - } - - // 删 - - /** - *

删除数据表中数据.

- * - * @param talename 表名 - * @param sqlWhereBulid 删除条件 - */ - public - void dele(@NotNull String talename, @NotNull final sqlWhereBulid sqlWhereBulid) - { - talename = "`" + fuckSql(talename) + "`"; - StringBuilder sql = new StringBuilder("DELETE FROM "); - sql.append(talename); - - getWhere(sqlWhereBulid, sql); - - try { - // 获取插入语句 - exe(sql.toString()); + exe(lock, sql.toString()); + return true; } catch ( Exception e ) { - throw new RuntimeException(e); + e.printStackTrace(); + return false; } finally { - sql.setLength(0); - sql.trimToSize(); + close(lock); } } - // 改 - /** *

更新数据库内容.

*
      * 通过传入的字段映射和查询条件对数据库中的数据进行更新
      * 
* - * @param tabname 表名 - * @param f 更新的字段映射 - * @param whele 更新条件集合 + * @param updata 更新语句对象 + * + * @return 影响的行数 * - * @return 是否执行成功 + * @see Updata */ public - void updata(@NotNull String tabname, @NotNull final Map f, - @NotNull final sqlWhereBulid whele) + int updata(@NotNull final Updata updata) { - @NotNull StringBuilder sql; - @NotNull CharSequence k; // 键 - @NotNull CharSequence v; // 值 - int vlenght; // 值的长度 - boolean ids = true; - - // 过滤表名 - tabname = "`" + fuckSql(tabname) + "`"; - sql = new StringBuilder("UPDATE "); - sql.ensureCapacity(5 + tabname.length()); - sql.append(tabname).append(" SET "); - - // 获取参数 - for ( Map.Entry entry : f.entrySet() ){ - // 过滤 - k = fuckSql(entry.getKey()); - v = entry.getValue(); - if (v == null) - vlenght = 0; - else { - v = fuckSql(v); - vlenght = v.length(); - } - - /* 检查是否是第一个 */ - if (!ids) { - sql.ensureCapacity(sql.length() + k.length() + 7 + v.length()); - sql.append(", "); - } else { - sql.ensureCapacity(sql.length() + k.length() + 5 + v.length()); - ids = false; - } - - sql.append("`").append(k).append("`").append(" = ").append(v); - } - - // 获取条件 - getWhere(whele, sql); - + @NotNull final CObject lock = new CObject(); try { - exe(sql.toString()); + return updata(lock, updata.toString()); } catch ( Exception e ) { + e.printStackTrace(); throw new RuntimeException(e); + } finally { + close(lock); } } @@ -330,148 +127,28 @@ class Mysql extends Sql { /** *

查询数据库数据.

*
-     * 通过传入的字段对数据库进行查询,可指定是否排序
+     * 查询功能使用直接 sql 进行
      * 
* - * @param qureySet 查询参数集 + * @param sql 查询的 sql * * @return 查询的结果, 如果为 {@code Null} 则查询失败 */ @Nullable public - ResultSet qurey(@NotNull final QureySet qureySet) + ResultSet qurey(@NotNull final String sql) { - int size = qureySet.field.size(); // 总字段数量 - if (size == 0) - return null; - @Nullable ResultSet set; - @NotNull final StringBuilder sql = new StringBuilder( - "SELECT " + (qureySet.distinct ? "DISTINCT " : "")); + @NotNull final CObject lock = new CObject(); try { // 获取查询数据 - set = get(getQureySql(qureySet, sql)); + set = get(lock, sql); } catch ( Exception r ) { throw new RuntimeException(r); } finally { - sql.setLength(0); - sql.trimToSize(); } - return set; - } - - /** - *

查询两个数据表并集的数据.

- *
-     * 通过传入的字段对数据库进行查询
-     * 部分数据取第一个,部分数据取第二个
-     * 
- * - * @param first 查询参数集 - * @param all 是否查询全部 - * @param nexxt 查询参数集 - * - * @return 查询的结果, 如果为 {@code Null} 则查询失败 - */ - @Nullable - public - ResultSet unionQurey(@NotNull final QureySet first, final boolean all, - @NotNull final QureySet nexxt) - { - int size = first.field.size() + nexxt.field.size(); // 总字段数量 - if (size == 0) - return null; - @Nullable ResultSet set = null; - @NotNull final StringBuilder sql = new StringBuilder("SELECT ").append( - (first.distinct ? "DISTINCT " : "")); - - try { - getQureySql(new QureySet(first.tabname, first.field, first.whele, first.distinct, null, - first.limit), sql); - sql.ensureCapacity(sql.length() + 11); - sql.append(" UNION ").append(all ? "ALL " : ""); - - // 获取查询数据 - set = get(getQureySql(nexxt, sql)); - } catch ( Exception e ) { - throw new RuntimeException(e); - } finally { - sql.setLength(0); - sql.trimToSize(); - } return set; } - - // 获取查询语句 - private - String getQureySql(@NotNull final QureySet qureySet, @NotNull final StringBuilder sql) { - boolean ids = false; - String tmp; - - for ( int i = 0; i < qureySet.field.size(); i++ ){ - tmp = fuckSql(qureySet.field.get(i)); - - /* 检查位置 */ - if (ids) { - sql.ensureCapacity(sql.length() + 2 + tmp.length()); - sql.append(", "); - } else { - sql.ensureCapacity(sql.length() + tmp.length()); - ids = true; - } - - sql.append("`").append(tmp).append("`"); - } - - sql.ensureCapacity(sql.length() + 6 + qureySet.tabname.length()); - - // 查询条件 - sql.append(" FROM ").append("`").append(fuckSql(qureySet.tabname)).append("`"); - getWhere(qureySet.whele, sql); - - // 排序 - if (qureySet.orderSet != null) { - ids = false; - - @Nullable DataMap odata; - int orlenght = 0; // 排序符长度 - String ortmp = null; // 排序符缓存 - - while( (odata = qureySet.orderSet.get()) != null ){ - // 检查当前位置 - tmp = fuckSql(odata.getKey()); - - // 检查排序方式 - switch ( odata.getValue() ) { - case ASC: - orlenght = 4; - ortmp = " ASC"; - break; - case DESC: - orlenght = 5; - ortmp = " DESC"; - } - - if (ids) { - sql.ensureCapacity(sql.length() + 4 + tmp.length() + orlenght); - sql.append(", "); - } else { - sql.append(" ORDER BY "); - sql.ensureCapacity(sql.length() + 2 + tmp.length() + orlenght); - ids = true; - } - - sql.append("`").append(tmp).append("`").append(ortmp); - } - } - - // 指定头几条数据 - sql.ensureCapacity(sql.length() + 7 + (tmp = Long.toString(qureySet.limit)).length()); - if (qureySet.limit > -1) - sql.append(" LIMIT ").append(tmp); - - return sql.toString(); - } } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Sql.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Sql.java index c68b5fdb81a8ed2c9157089af59d02fa001e8624..df9662fecc23d079753ffb691f08b9d2554fd120 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Sql.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Sql.java @@ -8,8 +8,10 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.HashMap; import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.CObject; /** *

Sql 底层操作类.

*
@@ -18,7 +20,7 @@ import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized;
  * 
* * @author fybug - * @version 0.0.2 + * @version 0.0.3 * @see database * @since PDF 1.2 */ @@ -27,8 +29,8 @@ import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized; public class Sql implements AutoCloseable { @NotNull protected Sql.database database; - @NotNull private Connection con; - @NotNull private Statement statement; + @NotNull private HashMap con = new HashMap<>(); + @NotNull private HashMap statement = new HashMap<>(); public Sql(@NotNull final database d) throws SQLException { database = d; } @@ -39,6 +41,8 @@ class Sql implements AutoCloseable { Object clone() throws CloneNotSupportedException { Sql s = (Sql) super.clone(); s.database = database; + s.con = new HashMap<>(); + s.statement = new HashMap<>(); return s; } @@ -52,103 +56,161 @@ class Sql implements AutoCloseable { /** *

使用语句查询数据.

* - * @param sql 查询语句 + * @param cObject 事务标识 + * @param sql 查询语句 * - * @return 返回的查询集合 - * - * @throws SQLException 驱动丢失或者已经有链接 + * @return 返回的查询集合,如果执行失败则会返回{@code null} */ @Nullable public - ResultSet get(@NotNull final CharSequence sql) throws SQLException { + ResultSet get(@Nullable final CObject cObject, @NotNull final CharSequence sql) + throws SQLException + { @Nullable ResultSet rs = null; + @NotNull Connection c = null; + @NotNull Statement s; - synchronized ( this ){ - if (con == null) - //getConnection()方法,连接数据库!! - con = DriverManager.getConnection(database.DB_URL, database.USER, database.PASS); - if (statement != null) - try { - statement.close(); - } catch ( SQLException e ) { - // fuck - } + if (!con.containsKey(cObject)) { + // getConnection()方法,连接数据库 + con.put(cObject, + DriverManager.getConnection(database.DB_URL, database.USER, database.PASS)); + } + c = con.get(cObject); - //创建statement类对象,用来执行SQL语句!! - statement = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, - ResultSet.HOLD_CURSORS_OVER_COMMIT); - //ResultSet类,用来存放获取的结果集!! - rs = statement.executeQuery(sql.toString()); + if (!statement.containsKey(cObject)) { + statement.put(cObject, c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_READ_ONLY, + ResultSet.HOLD_CURSORS_OVER_COMMIT)); } + s = statement.get(cObject); + //ResultSet类,用来存放获取的结果集!! + rs = s.executeQuery(sql.toString()); return rs; } + /** + *

执行更新语句.

+ * + * @param cObject 事务标识 + * @param sql 要执行的更新语句 + * + * @return 受影响的行数 + */ + public + int updata(@Nullable final CObject cObject, @NotNull final CharSequence sql) throws SQLException + { + @Nullable ResultSet rs = null; + @NotNull Connection c = null; + @NotNull Statement s; + + if (!con.containsKey(cObject)) { + // getConnection()方法,连接数据库 + con.put(cObject, + DriverManager.getConnection(database.DB_URL, database.USER, database.PASS)); + } + c = con.get(cObject); + + if (!statement.containsKey(cObject)) { + statement.put(cObject, + c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + ResultSet.HOLD_CURSORS_OVER_COMMIT)); + } + s = statement.get(cObject); + + return s.executeUpdate(sql.toString()); + } + /** *

执行语句.

* - * @param sql 查询语句 + * @param cObject 事务标识 + * @param sql 查询语句 * * @return 执行是否成功 - * - * @throws SQLException 驱动丢失或者已经有链接 */ public - void exe(@NotNull final CharSequence sql) throws SQLException { - synchronized ( this ){ - if (con == null) - //getConnection()方法,连接数据库!! - con = DriverManager.getConnection(database.DB_URL, database.USER, database.PASS); - if (statement != null) - try { - statement.close(); - } catch ( SQLException e ) { - } + boolean exe(@Nullable final CObject cObject, @NotNull final CharSequence sql) + throws SQLException + { + @Nullable ResultSet rs = null; + @NotNull Connection c = null; + @NotNull Statement s; + + if (!con.containsKey(cObject)) { + // getConnection()方法,连接数据库 + con.put(cObject, + DriverManager.getConnection(database.DB_URL, database.USER, database.PASS)); + } + c = con.get(cObject); - //创建statement类对象,用来执行SQL语句!! - statement = con.createStatement(); - statement.execute(sql.toString()); + if (!statement.containsKey(cObject)) { + statement.put(cObject, + c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, + ResultSet.HOLD_CURSORS_OVER_COMMIT)); } + s = statement.get(cObject); + + try { + s.execute(sql.toString()); + } catch ( SQLException e ) { + e.printStackTrace(); + return false; + } + return true; } /** - *

过滤 Sql 语句.

- *
-     * 过滤了什么自己看源码
-     * 
+ *

关闭对应的连接.

* - * @param str 要过滤的数据 + * @param cObject 连接标识 * - * @return 过滤后的数据 + * @since PDF 1.3 */ - @NotNull - public static - String fuckSql(@NotNull CharSequence s) { - String str = s.toString(); - str = str.replaceAll(";", ""); - str = str.replaceAll("&", "&"); - str = str.replaceAll("<", "<"); - str = str.replaceAll(">", ">"); - str = str.replaceAll("'", ""); - str = str.replaceAll("--", ""); - str = str.replaceAll("/", ""); - str = str.replaceAll("%", ""); - return str; + public + void close(@Nullable final CObject cObject) { + @Nullable final Connection c = con.remove(cObject); + if (c != null) + try { + c.commit(); + c.close(); + } catch ( Throwable e ) { + } + + @Nullable final Statement s = statement.remove(cObject); + if (s != null) + try { + s.close(); + } catch ( Throwable e ) { + } } + /** + *

关闭所有连接.

+ * 并释放事务映射表 + */ @Override public void close() throws SQLException { synchronized ( this ){ - if (statement != null) + for ( Connection c : con.values() ){ try { - statement.close(); - } catch ( SQLException e ) { - // fuck + c.commit(); + c.close(); + } catch ( Throwable e ) { } + } + con.clear(); + con = null; + + for ( Statement s : statement.values() ){ + try { + s.close(); + } catch ( Throwable e ) { + } + } + statement.clear(); statement = null; - if (con != null) - con.close(); } database = null; } @@ -161,7 +223,7 @@ class Sql implements AutoCloseable { * * @author fybug * @version 0.0.1 - * @since JDK 1.8 + * @since PDF 1.2 */ public static class database implements Serializable { @@ -176,4 +238,8 @@ class Sql implements AutoCloseable { PASS = pass; } } + + /* 过滤字段 */ + public final static String ENDMARK = ";", ANDPR = "&", GREATER = "<", LESS = ">", STR = "'", + NAME = "`", ANNOTATION = "--", ROD = "/", PERCENTAGE = "%"; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/InsertVal.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/InsertVal.java new file mode 100644 index 0000000000000000000000000000000000000000..3f0f7c89f5ae944096df9a4119f20b18b16e0355 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/InsertVal.java @@ -0,0 +1,183 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.ref.SoftReference; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.InserMode; +import fybug.nulll.pdfunctionlibrary.Util.DataMap; +import fybug.nulll.pdfunctionlibrary.Util.Map.ArrayMap; + +import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; +/** + *

插入操作段语句.

+ *

用于保存插入的参数和类型,并生成 {@code (??, ??) VALUE (??, ??)} 语句

+ * + * @author fybug + * @version 0.0.1 + * @see InserMode + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "All" ) +public +class InsertVal extends ArrayMap> { + /**

插入空类型的指向缓存.

*/ + @NotNull private transient static SoftReference> nullCache = + new SoftReference<>(DataMap.getDataMap(InserMode.NULL, null)); + + /** + *

获取空类型指向的缓存.

+ * 使用软引用 + * + * @return {@link InserMode#NULL} + */ + @NotNull + protected + DataMap getNullCache() { + @Nullable DataMap d = nullCache.get(); + if (d == null) + nullCache = new SoftReference<>(d = DataMap.getDataMap(InserMode.NULL, null)); + return d; + } + + /** + *

加入空插入.

+ * + * @param name 要插入的属性名 + * + * @return this + * + * @see InserMode#NULL + */ + @NotNull + public + InsertVal addNull(@NotNull final String name) { + add(fuckSql(name).trim(), getNullCache()); + return this; + } + + /** + *

加入值插入.

+ * + * @param name 要插入的属性名 + * @param val 要插入的属性,为空则转化为空插入 + * + * @return this + * + * @see InserMode#VAL + */ + @NotNull + public + InsertVal addVal(@NotNull final String name, @Nullable final String val) { + add(fuckSql(name).trim(), + val == null ? getNullCache() : DataMap.getDataMap(InserMode.VAL, fuckSql(val).trim())); + return this; + } + + /** + *

加入值插入.

+ * 插入非字符串的值,不提供包装 + * + * @param name 要插入的属性名 + * @param val 要插入的属性,为空则转化为空插入 + * + * @return this + * + * @see InserMode#OUT + */ + @NotNull + public + InsertVal addOut(@NotNull final String name, @Nullable final Object val) { + add(fuckSql(name).trim(), + val == null ? getNullCache() : DataMap.getDataMap(InserMode.OUT, val)); + return this; + } + + /** + *

加入 sql 插入.

+ * + * @param name 要插入的属性名 + * @param sql 要插入的 sql 语句,为空则转化为空插入 + * + * @return this + * + * @see InserMode#SQL + */ + @NotNull + public + InsertVal addSql(@NotNull final String name, @Nullable final String sql) { + add(fuckSql(name).trim(), + sql == null ? getNullCache() : DataMap.getDataMap(InserMode.SQL, sql)); + return this; + } + + // 检查数据并加入 + private + void checkData(@NotNull final StringBuilder key, @NotNull final StringBuilder val, + @NotNull final DataMap> d) + { + @NotNull final String name = d.getKey(); // 键名 + @NotNull final DataMap dataMap = d.getValue(); + + // 加入键名 + key.append(name); + + /* 检查输入类型 */ + switch ( dataMap.getKey() ) { + case VAL: + dataMap.setValue("'" + dataMap.getValue() + "'"); + case OUT: + case SQL: + val.append(dataMap.getValue()); + break; + case NULL: + val.append("null"); + break; + } + } + + /** + *

转化为插入属性的语句.

+ * + * @return {@code (??) VALUE (??)} + */ + @NotNull + @Override + public + String toString() { + @NotNull final StringBuilder inst = new StringBuilder("("), val = new StringBuilder( + ") VALUE ("); + + /* tmp */ + @Nullable DataMap> d; + + final int nowmark = mark; // 记录当前标记 + + /* 取出数据并包装为 Sql */ + for ( boolean b = true; (d = get()) != null; next() ){ + /* 检查是否是第一个 */ + if (!b) { + inst.append(", "); + val.append(", "); + } else { + b = false; + } + + checkData(inst, val, d); + } + + mark = nowmark; + + // 收尾 + inst.ensureCapacity(val.length() + inst.length() + 1); + inst.append(val); + + val.setLength(0); + val.trimToSize(); + + inst.append(")"); + return inst.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/QureySet.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/QureySet.java deleted file mode 100644 index a29e75f2222547de5d0ede3be6cc7aa978999504..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/QureySet.java +++ /dev/null @@ -1,49 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; -import com.sun.istack.internal.NotNull; -import com.sun.istack.internal.Nullable; - -import java.util.List; -/** - *

查询参数集.

- *
- * 用来存放 Sql 查询参数
- * 需传入 数据表,要查询的字段,条件集,是否去重复,排序方式集,是否只取前几条数据
- * 
- * - * @author fybug - * @version 0.0.2 - * @since PDF 1.2 - */ -public final -class QureySet { - public @NotNull String tabname; - public @NotNull List field; - public @NotNull sqlWhereBulid whele; - public boolean distinct; - public @Nullable orderSet orderSet; - public long limit; - - /** - *

构造查询参数集.

- * - * @param tabname 表名 - * @param field 要查询的字段 - * @param whele 查询条件 - * @param distinct 去重复 - * @param orderSet 排序模式,为{@code null} 则不排序 - * @param limit 查询头几条数据,小于{@code -1} 则不指定 - */ - public - QureySet(@NotNull String tabname, @NotNull final List field, - @NotNull final sqlWhereBulid whele, final boolean distinct, - @Nullable final orderSet orderSet, final long limit) - { - - this.tabname = tabname; - this.field = field; - this.whele = whele; - this.distinct = distinct; - this.orderSet = orderSet; - this.limit = limit; - } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/UpDataVal.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/UpDataVal.java new file mode 100644 index 0000000000000000000000000000000000000000..ee419c2f85e024d60634f362fe676356b1cf9592 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/UpDataVal.java @@ -0,0 +1,300 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.ref.SoftReference; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.UpdataMode; +import fybug.nulll.pdfunctionlibrary.Util.DataMap; +import fybug.nulll.pdfunctionlibrary.Util.Map.ArrayMap; + +import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; +/** + *

更新操作段语句.

+ *

用于保存更新的参数和类型,并生成 {@code ??=??, ??=??} 语句

+ * + * @author fybug + * @version 0.0.1 + * @see UpdataMode + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "All" ) +public +class UpDataVal extends ArrayMap> { + /**

插入空类型的指向缓存.

*/ + @NotNull private transient static SoftReference> nullCache = + new SoftReference<>(DataMap.getDataMap(UpdataMode.NULL, null)); + + /** + *

获取空类型指向的缓存.

+ * 使用软引用 + * + * @return {@link UpdataMode#NULL} + */ + @NotNull + protected + DataMap getNullCache() { + @Nullable DataMap d = nullCache.get(); + if (d == null) + nullCache = new SoftReference<>(d = DataMap.getDataMap(UpdataMode.NULL, null)); + return d; + } + + /** + *

检查字段类型,并进行过滤.

+ * + * @param o 要检查的字段 + * + * @return 检查并进行相应处理的字段 + */ + @NotNull + private + String checkFidle(@com.sun.istack.internal.Nullable final Object o) { + if (o instanceof String) + return '\'' + fuckSql(o.toString()).trim() + '\''; + + return fuckSql(String.valueOf(o)).trim(); + } + + /** + *

更新为空值.

+ * + * @param name 要更新的属性名 + * + * @return this + * + * @see UpdataMode#NULL + */ + @NotNull + public + UpDataVal addNull(@NotNull final String name) { + add(fuckSql(name).trim(), getNullCache()); + return this; + } + + /** + *

加入值更新.

+ * + * @param name 要更新的属性名 + * @param val 要更新的属性,为空则转化为空更新 + * + * @return this + * + * @see UpdataMode#VAL + */ + @NotNull + public + UpDataVal addVal(@NotNull final String name, @Nullable final String val) { + add(fuckSql(name).trim(), val == null ? getNullCache() + : DataMap.getDataMap(UpdataMode.VAL, '\'' + fuckSql(val).trim() + '\'')); + return this; + } + + /** + *

加入值更新.

+ * 插入非字符串的值,不提供包装 + * + * @param name 要更新的属性名 + * @param val 要更新的属性,为空则转化为空更新 + * + * @return this + * + * @see UpdataMode#OUT + */ + @NotNull + public + UpDataVal addOut(@NotNull final String name, @Nullable final Object val) { + add(fuckSql(name).trim(), + val == null ? getNullCache() : DataMap.getDataMap(UpdataMode.OUT, checkFidle(val))); + return this; + } + + /** + * /** + *

加入 sql 更新.

+ * + * @param name 要更新的属性名 + * @param sql 要更新的 sql 语句,为空则转化为空更新 + * + * @return this + * + * @see UpdataMode#SQL + */ + @NotNull + public + UpDataVal addSql(@NotNull final String name, @Nullable final String sql) { + add(fuckSql(name).trim(), + sql == null ? getNullCache() : DataMap.getDataMap(UpdataMode.SQL, sql)); + return this; + } + + /** + *

加入自增.

+ * + * @param name 要更新的属性名 + * @param val 自增的量 + * + * @return this + * + * @see UpdataMode#UP + */ + @NotNull + public + UpDataVal addUp(@NotNull final String name, final Object val) { + add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.UP, checkFidle(val))); + return this; + } + + /** + *

加入自减.

+ * + * @param name 要更新的属性名 + * @param val 自减的量 + * + * @return this + * + * @see UpdataMode#DOWN + */ + @NotNull + public + UpDataVal addDown(@NotNull final String name, final Object val) { + add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.DOWN, checkFidle(val))); + return this; + } + + /** + *

加入自除.

+ * + * @param name 要更新的属性名 + * @param val 自除的量 + * + * @return this + * + * @see UpdataMode#EXCE + */ + @NotNull + public + UpDataVal addExce(@NotNull final String name, final Object val) { + add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.EXCE, checkFidle(val))); + return this; + } + + /** + *

加入取值.

+ * + * @param name 要更新的属性名 + * @param val 对应的属性 + * @param div 求商还是求模 + * + * @return this + * + * @see UpdataMode#DIV + * @see UpdataMode#MOD + */ + @NotNull + public + UpDataVal addExce(@NotNull final String name, final Object val, final boolean div) { + add(fuckSql(name).trim(), + DataMap.getDataMap(div ? UpdataMode.DIV : UpdataMode.MOD, checkFidle(val))); + return this; + } + + /** + *

加入自乘.

+ * + * @param name 要更新的属性名 + * @param val 自乘的量 + * + * @return this + * + * @see UpdataMode#MUL + */ + @NotNull + public + UpDataVal addMul(@NotNull final String name, final Object val) { + add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.MUL, checkFidle(val))); + return this; + } + + /** + *

加入位运算.

+ * + * @param name 要更新的属性名 + * @param bit 运算方式 + * @param val 量 + * + * @return this + * + * @see UpdataMode + */ + @NotNull + public + UpDataVal addBit(@NotNull final String name, @NotNull final UpdataMode bit, final Object val) { + add(fuckSql(name).trim(), DataMap.getDataMap(bit, checkFidle(val))); + return this; + } + + // 检查数据并加入 + private + void checkData(@NotNull final StringBuilder key, + @NotNull final DataMap> d) + { + @NotNull final String name = d.getKey(); // 键名 + @NotNull final DataMap dataMap = d.getValue(); + + // 加入键名 + key.ensureCapacity(key.length() + name.length() + 3); + key.append('`').append(name).append('`').append("="); + + /* 检查输入类型 */ + switch ( dataMap.getKey() ) { + case VAL: + dataMap.setValue("'" + dataMap.getValue() + "'"); + case OUT: + case SQL: + key.append(dataMap.getValue()); + break; + case NULL: + key.append("null"); + break; + default: + key.append("`" + name + "`").append(dataMap.getKey()).append(dataMap.getValue()); + break; + } + } + + /** + *

转化为更新属性的语句.

+ * + * @return {@code ??=??, ??=??} + */ + @NotNull + @Override + public + String toString() { + @NotNull final StringBuilder inst = new StringBuilder(); + + /* tmp */ + @Nullable DataMap> d; + + final int nowmark = mark; // 记录当前标记 + + /* 取出数据并包装为 Sql */ + for ( boolean b = true; (d = get()) != null; next() ){ + /* 检查是否是第一个 */ + if (!b) { + inst.append(", "); + } else { + b = false; + } + + checkData(inst, d); + } + + mark = nowmark; + + return inst.toString(); + } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/WhereSet.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/WhereSet.java new file mode 100644 index 0000000000000000000000000000000000000000..dea53ed73feb4f0c771cec4a2738b01741bf8191 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/WhereSet.java @@ -0,0 +1,440 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; +import com.sun.istack.internal.NotNull; +import com.sun.istack.internal.Nullable; + +import java.io.Serializable; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.Comparison; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.Logical; +import fybug.nulll.pdfunctionlibrary.lang.Cleanable; +import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; + +import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; +/** + *

数据库条件集.

+ *
+ * 存放 sql 查询条件的对象,使用字符串进行缓存
+ * 可使用内部指定参数进行添加,将会过滤输入的值
+ * 或直接添加 sql 语句,会接在当前语句后面,但不过滤
+ * 
+ *
插入的语句展示符号说明:
+ * ( * ) 代表着使用一个枚举对象作为这里的参数,通常是固定的语句
+ * [ * ] 代表着这个语句会根据你输入的参数决定是否出现,通常为取反语句
+ * [ * | * ] 代表这这个语句会根据你输入的参数决定使用哪个参数
+ * \(\) 代表这个不是上面的括号,和转义符一样
+ * \[\] 同上
+ * 大写代表 sql 语句
+ * 小写代表 变量
+ * 
+ * + * @author fybug + * @version 0.0.4 + * @see Logical + * @see Comparison + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "All" ) +public +class WhereSet extends ConsistentField implements Cleanable, Serializable, Cloneable { + // 语句缓存 + @NotNull private StringBuilder set = new StringBuilder(); + + @Override + protected + boolean consistent(@Nullable final Object obj) + { return obj.toString().equals(set.toString()); } + + @Override + @NotNull + public + String toString() { + @NotNull final StringBuilder sql = new StringBuilder(); + + getWhere(this, sql); + + sql.trimToSize(); + return sql.toString(); + } + + @Override + protected + void finalize() throws Throwable { + super.finalize(); + set.setLength(0); + set.trimToSize(); + set = null; + } + + @NotNull + @Override + public + Object clone() throws CloneNotSupportedException { + @NotNull final WhereSet s = (WhereSet) super.clone(); + + set.trimToSize(); + s.set = new StringBuilder(set.toString()); + s.set.trimToSize(); + + return s; + } + + /* + * 释放 + */ + + @Override + public + void clean() { + set.setLength(0); + set.trimToSize(); + } + + @Override + public + void free() { clean(); } + + @Override + public + void close() { + free(); + set = null; + } + + /* + * check + */ + + /** + *

检查字段类型,并进行过滤.

+ * + * @param o 要检查的字段 + * + * @return 检查并进行相应处理的字段 + */ + @NotNull + private + String checkFidle(@Nullable final Object o) { + if (o instanceof String) + return '\'' + fuckSql(o.toString()).trim() + '\''; + + return fuckSql(String.valueOf(o)).trim(); + } + + // 加入关系 + @NotNull + private + WhereSet addRelation(@NotNull final Logical logical) { + if (set.length() > 0) + set.append(logical); + return this; + } + + /* + * Add + */ + + /** + *

添加等值条件.

+ *
+     * 添加条件如下 {@code "( Logical ) key [ ! ]= val"}
+     * 即添加一个检查该键是否等于该值的条件
+     * 
+ * + * @param logical 与前面条件的关系 + * @param key 键 + * @param val 要等于的值,如不是字符串类型则不会包装 + * @param negation 是否取反,即使用 != + * + * @return this + */ + @NotNull + public + WhereSet addEqual(@NotNull final Logical logical, @NotNull String key, + @Nullable final Object val, final boolean negation) + { + // 过滤 + key = '`' + fuckSql(key).trim() + '`'; + @NotNull final String v = checkFidle(val); + + // 放入 sql + addRelation(logical).set.ensureCapacity(set.length() + key.length() + 4 + v.length()); + set.append(key).append(negation ? " !" : " ").append("= ").append(v); + + return this; + } + + /** + *

添加键值逻辑条件.

+ *
+     * 添加条件如下 {@code "( Logical ) key ( Comparison ) val"}
+     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
+     * 
+ * + * @param logical 与前面条件的关系 + * @param key 键 + * @param how 逻辑运算符 + * @param val 要判断的值,如不是字符串则不会进行包装 + * + * @return this + */ + @NotNull + public + WhereSet addWhere(@NotNull final Logical logical, @NotNull String key, + @NotNull final Comparison how, @NotNull final Object val) + { + key = '`' + fuckSql(key).trim() + '`'; + @NotNull final String v = checkFidle(val); + + addRelation(logical).set.ensureCapacity( + set.length() + key.length() + how.toString().length() + v.length()); + set.append(key).append(how).append(v); + + return this; + } + + /** + *

添加空检查.

+ *
+     * 添加条件如下 {@code "( Logical ) key IS [ NOT ] NULL"}
+     * 
+ * + * @param logical 与前面的条件的关系 + * @param key 要检查的键 + * @param negation 取反 + * + * @return this + */ + @NotNull + public + WhereSet addNullCheck(@NotNull final Logical logical, @NotNull String key, + final boolean negation) + { + key = fuckSql(key).trim(); + + addRelation(logical).set.ensureCapacity(set.length() + 14 + key.length()); + set.append("`") + .append(key) + .append("`") + .append(" IS") + .append(negation ? " NOT" : " ") + .append(" Null"); + + return this; + } + + /** + *

添加范围检查.

+ *
+     * 添加条件如下 {@code "( Logical ) key [ NOT ] BETWEEN val AND val"}
+     * 
+ * + * @param logical 与前面的条件的关系 + * @param key 要检查的键 + * @param num1 开始范围,如不是字符串则不会进行包装 + * @param num2 结束范围,如不是字符串则不会进行包装 + * @param negation 取反 + * + * @return this + */ + @NotNull + public + WhereSet addBetween(@NotNull final Logical logical, @NotNull String key, @NotNull Object num1, + @NotNull Object num2, final boolean negation) + { + key = '`' + fuckSql(key).trim() + '`'; + num1 = checkFidle(num1); + num2 = checkFidle(num2); + + addRelation(logical).set.ensureCapacity( + 17 + set.length() + key.length() + num1.toString().length() + + num2.toString().length()); + set.append(key).append(negation ? "NOT " : " ").append("BETWEEN ").append(num1).append( + " AND ").append(num2); + + return this; + } + + /** + *

加入列举检查.

+ *
+     * 添加条件如下 {@code "( Logical ) key [ NOT ] IN (val, val)"}
+     * 
+ * + * @param logical 与前面的条件的关系 + * @param key 要检查的键 + * @param negation 是否取反 + * @param val 列举的值,如不是字符串则不会进行包装 + * + * @return this + */ + @NotNull + public + WhereSet addIn(@NotNull final Logical logical, @NotNull String key, final boolean negation, + @NotNull final Object... val) + { + key = '`' + fuckSql(key).trim() + '`'; + + addRelation(logical).set.ensureCapacity(set.length() + 10 + key.length()); + set.append(key).append(negation ? " NOT IN " : " IN ").append("("); + + @NotNull String v; + boolean f = true; + + /* 加入列表组 */ + for ( int i = 0, lenght = val.length; i < lenght; i++ ){ + v = checkFidle(val[i]); + + if (!f) { + set.ensureCapacity(v.length() + 2 + set.length()); + set.append(", "); + } else { + set.ensureCapacity(set.length() + v.length()); + f = false; + } + + set.append(v); + } + + set.append(")"); + return this; + } + + /** + *

加入模糊查询.

+ *
+     * 添加条件如下 {@code "( Logical ) key [ NOT ] LIKE val"}
+     * 
+ * + * @param logical 与前面的条件的关系 + * @param key 要检查的键 + * @param val 条件,不支持除字符串以外的类型 + * @param negation 是否取反 + * + * @return this + */ + @NotNull + public + WhereSet addLike(@NotNull final Logical logical, @NotNull String key, @NotNull final String val, + final boolean negation) + { + key = '`' + fuckSql(key).trim() + '`'; + + addRelation(logical).set.ensureCapacity(set.length() + key.length() + val.length() + 9); + set.append(key).append(negation ? "NOT " : " ").append("LIKE '").append(val).append('\''); + + return this; + } + + /** + *

加入正则查询.

+ *
+     * 添加条件如下 {@code "( Logical ) [ NOT ( ] key REGEXP val [ ) ]"}
+     * 
+ * + * @param logical 与前面的条件的关系 + * @param key 要检查的键 + * @param val 正则,不支持除字符串以外的类型 + * @param negation 是否取反 + * + * @return this + */ + @NotNull + public + WhereSet addRegexp(@NotNull final Logical logical, @NotNull String key, + @NotNull final String val, final boolean negation) + { + key = '`' + fuckSql(key).trim() + '`'; + + addRelation(logical).set.ensureCapacity(set.length() + key.length() + val.length() + 9); + set.append(negation ? "NOT (" : "") + .append(key) + .append("REGEXP '") + .append(val) + .append('\'') + .append(negation ? ")" : ""); + + return this; + } + + /** + *

添加 Sql 语句.

+ *
+     * 添加的语句在 Where 后,请不要添加条件语句以外的语句
+     * 
+ * + * @param logical 与前面语句的关系 + * @param sql 要添加的 Sql 语句,不支持除字符串以外的类型,并且不进行过滤和包装 + * + * @return this + */ + @NotNull + public + WhereSet addSql(@NotNull final Logical logical, @NotNull final String sql) { + addRelation(logical).set.append(sql); + return this; + } + + /** + *

添加整合条件语句.

+ *
+     * 即使用 () 将语句包起来,可提高该串语句的优先度
+     * 添加条件如下 {@code "( Logical ) [ NOT ] \( ( WhereSet ) \)"}
+     * 
+ * + * @param logical 与前面语句的关系 + * @param whereSet 要插入的语句,不会进行过滤和包装 + * @param negation 是否取反 + * + * @return this + */ + @NotNull + public + WhereSet addMoreSql(@NotNull final Logical logical, @NotNull final WhereSet whereSet, + final boolean negation) + { + @Nullable final String s = whereSet.get().trim(); // 语句缓存 + if (s == null) + return this; + + addRelation(logical).set.ensureCapacity(6 + set.length() + s.length()); + set.append(negation ? "NOT " : " ").append("(").append(s).append(")"); + + return this; + } + + /** + *

获取语句.

+ * + * @return 没参数为 {@code Null} + */ + @Nullable + private + String get() { + if (set.length() == 0) + return null; + return set.toString(); + } + + /** + *

获取查询条件.

+ *
+     * 获取条件集里面的条件并添加到传入的字符缓存区
+     * 
+ * + * @param whele 要提取的条件集 + * @param sql 要添加的字符缓冲区 + */ + public static + void getWhere(@NotNull final WhereSet whele, @NotNull final StringBuilder sql) + { + // 条件语句 + @Nullable final String s = whele.get(); + if (s == null) + return; + + sql.ensureCapacity(7 + s.length() + sql.length()); + sql.append(" WHERE ").append(s); + } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/orderSet.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/orderSet.java deleted file mode 100644 index d6ddf3f26de2bf1386e1acf1b308a5ca95018720..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/orderSet.java +++ /dev/null @@ -1,58 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.OrderByMode; -import fybug.nulll.pdfunctionlibrary.Util.DataMap; -import fybug.nulll.pdfunctionlibrary.Util.Map.MapFile; -/** - *

数据库排序参数集.

- *
- * 用来存放 Sql 语句查询的排序参数集合
- * 使用键值存放,{@code 属性名 -> 排序方式}
- * 
- * - * @author fybug - * @version 0.0.3 - * @see MapFile - * @see OrderByMode - * @since PDF 1.2 - */ -@SuppressWarnings( "All" ) -public -class orderSet { - @NotNull private MapFile set = MapFile.userLink(); - - public - orderSet() {} - - @Override - public - Object clone() throws CloneNotSupportedException { - orderSet s = (orderSet) super.clone(); - s.set = (MapFile) set.clone(); - return s; - } - - /**

添加参数.

*/ - @NotNull - public - orderSet add(@NotNull final CharSequence key, @Nullable final OrderByMode how) - { - set.add(key, how); - return this; - } - - /** - *

获取参数.

- * - * @return 没参数为 {@code Null} - */ - @Nullable - public - DataMap get() { - if (set.size() == 0) - return null; - return set.poll(); - } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/package-info.java index 8c4044ac06e3cf1d4f756d8c8c564f85ac8696aa..53680b915859f342b510b519007ffead63d26709 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/package-info.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/package-info.java @@ -1,9 +1,9 @@ /** *

数据库辅助对象包.

- *
提供 Sql 执行辅助工具
+ *
提供 Sql 执行辅助对象
* * @author fybug - * @version 0.0.1 + * @version 0.0.2 * @since PDF 1.2 */ package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/sqlWhereBulid.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/sqlWhereBulid.java deleted file mode 100644 index e323d3bf8483bb55e9b99b4a735ff707cbc0d579..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/sqlWhereBulid.java +++ /dev/null @@ -1,1038 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; -import com.sun.istack.internal.NotNull; -import com.sun.istack.internal.Nullable; - -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.HowWhere; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.Relation; -import fybug.nulll.pdfunctionlibrary.lang.Cleanable; -import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; - -import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.fuckSql; -/** - *

数据库条件集.

- *
- * 用来生成 Sql 语句的条件的生成器
- * 可使用内部的便捷方式添加条件,或添加自定义 Sql
- * 
- * - * @author fybug - * @version 0.0.2 - * @see Relation - * @see HowWhere - * @since PDF 1.2 - */ -@SuppressWarnings( "All" ) -public -class sqlWhereBulid extends ConsistentField implements Cleanable { - // 语句缓存 - @NotNull private StringBuilder set = new StringBuilder(); - - @Override - public - int hashCode() - { return (super.hashCode() + get().hashCode()) << 5; } - - @Override - protected - boolean consistent(@Nullable final Object obj) - { return obj.toString().equals(set.toString()); } - - @Override - @NotNull - public - String toString() { return get(); } - - @Override - protected - void finalize() throws Throwable { - super.finalize(); - set.setLength(0); - set.trimToSize(); - set = null; - } - - @Override - public - Object clone() throws CloneNotSupportedException { - sqlWhereBulid s = (sqlWhereBulid) super.clone(); - s.set = new StringBuilder(set.toString()); - return s; - } - - @Override - public - void clean() { - set.setLength(0); - set.trimToSize(); - } - - @Override - public - void free() { clean(); } - - @Override - public - void close() { - free(); - set = null; - } - - /* - * AddEqual - */ - - /** - *

添加等值条件.

- *
-     * 添加条件如下 {@code "AND key [ ! ]= val"}
-     * 即添加一个检查该键是否等于该值的条件
-     * 
- * - * @param key 键 - * @param val 要等于的值 - * @param negation 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqual(@NotNull final String key, @NotNull final String val, - final boolean negation) - {return addEqual(Relation.AND, key, val, negation);} - - /** - *

添加等值条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) key [ ! ]= val"}
-     * 即添加一个检查该键是否等于该值的条件
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param val 要等于的值 - * @param negation 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqual(@NotNull final Relation relation, @NotNull String key, - @NotNull String val, final boolean negation) - { - key = fuckSql(key); - val = fuckSql(val); - - addRelation(relation).set.ensureCapacity(set.length() + key.length() + 8 + val.length()); - set.append("`").append(key).append("` ").append((negation ? "!" : "")).append("= ").append( - "'").append(val).append("'"); - return this; - } - - /** - *

添加等值条件.

- *
-     * 添加条件如下 {@code "AND key [ ! ]= val"}
-     * 即添加一个检查该键是否等于该值的条件
-     * 
- * - * @param key 键 - * @param val 要等于的值 - * @param negation 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqual(@NotNull final String key, @NotNull final long val, - final boolean negation) - {return addEqual(Relation.AND, key, val, negation);} - - /** - *

添加等值条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) key [ ! ]= val"}
-     * 即添加一个检查该键是否等于该值的条件
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param val 要等于的值 - * @param negation 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqual(@NotNull final Relation relation, @NotNull String key, - @NotNull final long val, final boolean negation) - { - key = fuckSql(key); - @NotNull final String s = Long.toString(val); - - addRelation(relation).set.ensureCapacity(set.length() + key.length() + 10 + s.length()); - set.append("`") - .append(key) - .append("` ") - .append(negation ? "!" : "") - .append("= '") - .append(s) - .append("'"); - return this; - } - - /** - *

添加等值条件.

- *
-     * 添加条件如下 {@code "AND key [ ! ]= val"}
-     * 即添加一个检查该键是否等于该值的条件
-     * 
- * - * @param key 键 - * @param val 要等于的值 - * @param negation 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqual(@NotNull final String key, @NotNull final float val, - final boolean negation) - {return addEqual(Relation.AND, key, val, negation);} - - /** - *

添加等值条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) key [ ! ]= val"}
-     * 即添加一个检查该键是否等于该值的条件
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param val 要等于的值 - * @param negation 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqual(@NotNull final Relation relation, @NotNull String key, - @NotNull final float val, final boolean negation) - { - key = fuckSql(key); - @NotNull final String s = Float.toString(val); - - addRelation(relation).set.ensureCapacity(set.length() + key.length() + 10 + s.length()); - set.append("`") - .append(key) - .append("` ") - .append(negation ? "!" : "") - .append("= '") - .append(s) - .append("'"); - return this; - } - - /* - * AddEqualPrioriy - */ - - /** - *

添加串联等值条件.

- *
-     * 添加条件如下 {@code " AND \( key [ ! ]= val ( AND | OR ) key [ ! ]= val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个等值条件,中间使用逻辑关系
-     * 
- * - * @param key 键 - * @param val 要判断的值 - * @param negation 是否取反,即使用 != - * @param r 与第一个条件的关系 - * @param key2 键 - * @param val2 要判断的值 - * @param negation2 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqualPrioriy(@NotNull final String key, @NotNull final String val, - final boolean negation, @NotNull final Relation r, @NotNull final String key2, - @NotNull final String val2, final boolean negation2) - {return addEqualPrioriy(Relation.AND, key, val, negation, r, key2, val2, negation2);} - - /** - *

添加串联等值条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) \( key [ ! ]= val ( AND | OR ) key [ ! ]= val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个等值条件,中间使用逻辑关系
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param val 要判断的值 - * @param negation 是否取反,即使用 != - * @param r 与第一个条件的关系 - * @param key2 键 - * @param val2 要判断的值 - * @param negation2 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqualPrioriy(@NotNull final Relation relation, @NotNull String key, - @NotNull String val, final boolean negation, @NotNull final Relation r, - @NotNull String key2, @NotNull String val2, final boolean negation2) - { - key = fuckSql(key); - val = fuckSql(val); - key2 = fuckSql(key2); - val2 = fuckSql(val2); - - // 第一个条件 - addRelation(relation).set.ensureCapacity(set.length() + 10 + key.length() + val.length()); - set.append("( `").append(key).append("` ").append(negation ? "!" : "").append("= ").append( - "'").append(val).append("'"); - - addRelation(relation).set.ensureCapacity(set.length() + 10 + key2.length() + val2.length()); - set.append("`").append(key2).append("` ").append(negation2 ? "!" : "").append("= ").append( - "'").append(val2).append("'").append(" )"); - return this; - } - - /** - *

添加串联等值条件.

- *
-     * 添加条件如下 {@code " AND \( key [ ! ]= val ( AND | OR ) key [ ! ]= val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个等值条件,中间使用逻辑关系
-     * 
- * - * @param key 键 - * @param val 要判断的值 - * @param negation 是否取反,即使用 != - * @param r 与第一个条件的关系 - * @param key2 键 - * @param val2 要判断的值 - * @param negation2 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqualPrioriy(@NotNull final String key, @NotNull final long val, - final boolean negation, @NotNull final Relation r, @NotNull final String key2, - @NotNull final long val2, final boolean negation2) - {return addEqualPrioriy(Relation.AND, key, val, negation, r, key2, val2, negation2);} - - /** - *

添加串联等值条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) \( key [ ! ]= val ( AND | OR ) key [ ! ]= val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个等值条件,中间使用逻辑关系
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param val 要判断的值 - * @param negation 是否取反,即使用 != - * @param r 与第一个条件的关系 - * @param key2 键 - * @param val2 要判断的值 - * @param negation2 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqualPrioriy(@NotNull final Relation relation, @NotNull String key, - @NotNull final long val, final boolean negation, @NotNull final Relation r, - @NotNull String key2, @NotNull final long val2, final boolean negation2) - { - key = fuckSql(key); - String s = Long.toString(val); - key2 = fuckSql(key2); - String s2 = Long.toString(val2); - - // 第一个条件 - addRelation(relation).set.ensureCapacity(set.length() + 10 + key.length() + s.length()); - set.append("( `").append(key).append("` ").append(negation ? "!" : "").append("= '").append( - s).append("'"); - - addRelation(relation).set.ensureCapacity(set.length() + 10 + key2.length() + s2.length()); - set.append("`").append(key2).append("` ").append(negation2 ? "!" : "").append("= '").append( - s2).append("' )"); - return this; - } - - /** - *

添加串联等值条件.

- *
-     * 添加条件如下 {@code " AND \( key [ ! ]= val ( AND | OR ) key [ ! ]= val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个等值条件,中间使用逻辑关系
-     * 
- * - * @param key 键 - * @param val 要判断的值 - * @param negation 是否取反,即使用 != - * @param r 与第一个条件的关系 - * @param key2 键 - * @param val2 要判断的值 - * @param negation2 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqualPrioriy(@NotNull final String key, @NotNull final float val, - final boolean negation, @NotNull final Relation r, @NotNull final String key2, - @NotNull final float val2, final boolean negation2) - {return addEqualPrioriy(Relation.AND, key, val, negation, r, key2, val2, negation2);} - - /** - *

添加串联等值条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) \( key [ ! ]= val ( AND | OR ) key [ ! ]= val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个等值条件,中间使用逻辑关系
-     * 
- * - * @param key 键 - * @param val 要判断的值 - * @param negation 是否取反,即使用 != - * @param r 与第一个条件的关系 - * @param key2 键 - * @param val2 要判断的值 - * @param negation2 是否取反,即使用 != - */ - @NotNull - public - sqlWhereBulid addEqualPrioriy(@NotNull final Relation relation, @NotNull String key, - @NotNull final float val, final boolean negation, @NotNull final Relation r, - @NotNull String key2, @NotNull final float val2, final boolean negation2) - { - key = fuckSql(key); - String s = Float.toString(val); - key2 = fuckSql(key2); - String s2 = Float.toString(val2); - - // 第一个条件 - addRelation(relation).set.ensureCapacity(set.length() + 10 + key.length() + s.length()); - set.append("( `").append(key).append("` ").append(negation ? "!" : "").append("= '").append( - s).append("'"); - - addRelation(relation).set.ensureCapacity(set.length() + 10 + key2.length() + s2.length()); - set.append("`").append(key2).append("` ").append(negation2 ? "!" : "").append("= '").append( - s2).append("' )"); - return this; - } - - /* - * AddWhere - */ - - /** - *

添加键值逻辑条件.

- *
-     * 添加条件如下 {@code "AND key ( < | > | <= | >= | <> ) val"}
-     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
-     * 
- * - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - */ - @NotNull - public - sqlWhereBulid addWhere(@NotNull final String key, @NotNull final HowWhere how, - @NotNull final String val) - {return addWhere(Relation.AND, key, how, val);} - - /** - *

添加键值逻辑条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) key ( < | > | <= | >= | <> ) val"}
-     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - */ - @NotNull - public - sqlWhereBulid addWhere(@NotNull final Relation relation, @NotNull String key, - @NotNull final HowWhere how, @NotNull String val) - { - key = fuckSql(key); - val = fuckSql(val); - - addRelation(relation).set.ensureCapacity( - set.length() + 4 + key.length() + val.length() + how.toString().length()); - set.append("`").append(key).append("`").append(how).append("'").append(val).append("'"); - return this; - } - - /** - *

添加键值逻辑条件.

- *
-     * 添加条件如下 {@code "AND key ( < | > | <= | >= | <> ) val"}
-     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
-     * 
- * - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - */ - @NotNull - public - sqlWhereBulid addWhere(@NotNull final String key, @NotNull final HowWhere how, - @NotNull final long val) - {return addWhere(Relation.AND, key, how, val);} - - /** - *

添加键值逻辑条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) key ( < | > | <= | >= | <> ) val"}
-     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - */ - @NotNull - public - sqlWhereBulid addWhere(@NotNull final Relation relation, @NotNull String key, - @NotNull final HowWhere how, @NotNull final long val) - { - key = fuckSql(key); - String s = Long.toString(val); - - addRelation(relation).set.ensureCapacity( - set.length() + key.length() + 4 + s.length() + how.toString().length()); - set.append("`").append(key).append("`").append(how).append("'").append(s).append("'"); - return this; - } - - /** - *

添加键值逻辑条件.

- *
-     * 添加条件如下 {@code "AND key ( < | > | <= | >= | <> ) val"}
-     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
-     * 
- * - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - */ - @NotNull - public - sqlWhereBulid addWhere(@NotNull final String key, @NotNull final HowWhere how, - @NotNull final float val) - {return addWhere(Relation.AND, key, how, val);} - - /** - *

添加键值逻辑条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) key ( < | > | <= | >= | <> ) val"}
-     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - */ - @NotNull - public - sqlWhereBulid addWhere(@NotNull final Relation relation, @NotNull String key, - @NotNull final HowWhere how, @NotNull final float val) - { - key = fuckSql(key); - String s = Float.toString(val); - - addRelation(relation).set.ensureCapacity( - set.length() + 4 + key.length() + s.length() + how.toString().length()); - set.append("`").append(key).append("`").append(how).append("'").append(s).append("'"); - return this; - } - - /* - * AddPriority - */ - - /** - *

添加串联键值逻辑条件.

- *
-     * 添加条件如下 {@code " AND \( key ( < | > | <= | >= | <> ) val ( AND | OR ) key ( < | > | <= | >= | <> ) val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个键值逻辑条件,中间使用逻辑关系
-     * 
- * - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - * @param r 与第一个条件的关系 - * @param key2 键 - * @param how2 逻辑运算符 - * @param val2 要判断的值 - */ - @NotNull - public - sqlWhereBulid addPriority(@NotNull final String key, @NotNull final HowWhere how, - @NotNull final String val, @NotNull final Relation r, @NotNull final String key2, - @NotNull final HowWhere how2, @NotNull final String val2) - {return addPriority(Relation.AND, key, how, val, r, key2, how2, val2);} - - /** - *

添加串联键值逻辑条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) \( key ( < | > | <= | >= | <> ) val ( AND | OR ) key ( < | > | <= | >= | <> ) val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个键值逻辑条件,中间使用逻辑关系
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - * @param r 与第一个条件的关系 - * @param key2 键 - * @param how2 逻辑运算符 - * @param val2 要判断的值 - */ - @NotNull - public - sqlWhereBulid addPriority(@NotNull final Relation relation, @NotNull String key, - @NotNull final HowWhere how, @NotNull String val, @NotNull final Relation r, - @NotNull String key2, @NotNull final HowWhere how2, @NotNull String val2) - { - key = fuckSql(key); - key2 = fuckSql(key2); - val = fuckSql(val); - val2 = fuckSql(val2); - - // 第一个条件 - addRelation(relation).set.ensureCapacity( - set.length() + 6 + key.length() + val.length() + how.toString().length()); - set.append("( `").append(key).append("`").append(how).append("'").append(val).append("'"); - - addRelation(r).set.ensureCapacity( - set.length() + 6 + key2.length() + val2.length() + how2.toString().length()); - set.append("`").append(key2).append("`").append(how2).append("'").append(val2).append( - "' )"); - return this; - } - - /** - *

添加串联键值逻辑条件.

- *
-     * 添加条件如下 {@code " AND \( key ( < | > | <= | >= | <> ) val ( AND | OR ) key ( < | > | <= | >= | <> ) val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个键值逻辑条件,中间使用逻辑关系
-     * 
- * - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - * @param r 与第一个条件的关系 - * @param key2 键 - * @param how2 逻辑运算符 - * @param val2 要判断的值 - */ - @NotNull - public - sqlWhereBulid addPriority(@NotNull final String key, @NotNull final HowWhere how, - @NotNull final long val, @NotNull final Relation r, @NotNull final String key2, - @NotNull final HowWhere how2, @NotNull final long val2) - {return addPriority(Relation.AND, key, how, val, r, key2, how2, val2);} - - /** - *

添加串联键值逻辑条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) \( key ( < | > | <= | >= | <> ) val ( AND | OR ) key ( < | > | <= | >= | <> ) val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个键值逻辑条件,中间使用逻辑关系
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - * @param r 与第一个条件的关系 - * @param key2 键 - * @param how2 逻辑运算符 - * @param val2 要判断的值 - */ - @NotNull - public - sqlWhereBulid addPriority(@NotNull final Relation relation, @NotNull String key, - @NotNull final HowWhere how, @NotNull final long val, @NotNull final Relation r, - @NotNull String key2, @NotNull final HowWhere how2, @NotNull final long val2) - { - key = fuckSql(key); - key2 = fuckSql(key2); - String s = Long.toString(val), s2 = Long.toString(val2); - - // 第一个条件 - addRelation(relation).set.ensureCapacity( - set.length() + 6 + key.length() + s.length() + how.toString().length()); - set.append("( `").append(key).append("`").append(how).append("'").append(val).append("'"); - - addRelation(r).set.ensureCapacity( - set.length() + 6 + key2.length() + s2.length() + how2.toString().length()); - set.append("`").append(key2).append("`").append(how2).append("'").append(val2).append( - "' )"); - return this; - } - - /** - *

添加串联键值逻辑条件.

- *
-     * 添加条件如下 {@code " AND \( key ( < | > | <= | >= | <> ) val ( AND | OR ) key ( < | > | <= | >= | <> ) val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个键值逻辑条件,中间使用逻辑关系
-     * 
- * - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - * @param r 与第一个条件的关系 - * @param key2 键 - * @param how2 逻辑运算符 - * @param val2 要判断的值 - */ - @NotNull - public - sqlWhereBulid addPriority(@NotNull final String key, @NotNull final HowWhere how, - @NotNull final float val, @NotNull final Relation r, @NotNull final String key2, - @NotNull final HowWhere how2, @NotNull final float val2) - {return addPriority(Relation.AND, key, how, val, r, key2, how2, val2);} - - /** - *

添加串联键值逻辑条件.

- *
-     * 添加条件如下 {@code "( AND | OR ) \( key ( < | > | <= | >= | <> ) val ( AND | OR ) key ( < | > | <= | >= | <> ) val \)"}
-     * 即添加一个检查所指定的表达式是否等于的条件
-     * 即两个键值逻辑条件,中间使用逻辑关系
-     * 
- * - * @param relation 与前面条件的关系 - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值 - * @param r 与第一个条件的关系 - * @param key2 键 - * @param how2 逻辑运算符 - * @param val2 要判断的值 - */ - @NotNull - public - sqlWhereBulid addPriority(@NotNull final Relation relation, @NotNull String key, - @NotNull final HowWhere how, @NotNull final float val, @NotNull final Relation r, - @NotNull String key2, @NotNull final HowWhere how2, @NotNull final float val2) - { - key = fuckSql(key); - key2 = fuckSql(key2); - String s = Float.toString(val), s2 = Float.toString(val2); - - // 第一个条件 - addRelation(relation).set.ensureCapacity( - set.length() + 6 + key.length() + s.length() + how.toString().length()); - set.append("( `").append(key).append("`").append(how).append("'").append(val).append("'"); - - addRelation(r).set.ensureCapacity( - set.length() + 6 + key2.length() + s2.length() + how2.toString().length()); - set.append("`").append(key2).append("`").append(how2).append("'").append(val2).append( - "' )"); - return this; - } - - /* - * NullCheck - */ - - /** - *

添加空检查.

- *
-     * 添加条件如下 {@code " AND key IS NULL"}
-     * 
- * - * @param key 要检查的键 - */ - @NotNull - public - sqlWhereBulid addNullCheck(@NotNull final String key) - { return addNullCheck(Relation.AND, key); } - - /** - *

添加空检查.

- *
-     * 添加条件如下 {@code "( AND | OR ) key IS NULL"}
-     * 
- * - * @param relation 与前面的条件的关系 - * @param key 要检查的键 - */ - @NotNull - public - sqlWhereBulid addNullCheck(@NotNull final Relation relation, @NotNull String key) { - key = fuckSql(key); - - addRelation(relation).set.ensureCapacity(set.length() + 10 + key.length()); - set.append("`").append(key).append("`").append(" IS Null"); - return this; - } - - /* - * PriorityNullCheck - */ - - /** - *

添加串联空检查.

- *
-     * 添加条件如下 {@code " AND \( key IS NULL ( AND | OR ) key IS NULL \)"}
-     * 即添加两个空检查并使用逻辑条件进行检查
-     * 
- * - * @param key 要检查的键 - * @param relation 与第一个条件的关系 - * @param key2 要检查的键 - */ - @NotNull - public - sqlWhereBulid addPriorityNullCheck(@NotNull final String key, @NotNull final Relation r, - @NotNull final String key2) - { return addPriorityNullCheck(Relation.AND, key, r, key2); } - - /** - *

添加串联空检查.

- *
-     * 添加条件如下 {@code "( AND | OR ) \( key IS NULL ( AND | OR ) key IS NULL \)"}
-     * 即添加两个空检查并使用逻辑条件进行检查
-     * 
- * - * @param relation 与前面的条件的关系 - * @param key 要检查的键 - * @param relation 与第一个条件的关系 - * @param key2 要检查的键 - */ - @NotNull - public - sqlWhereBulid addPriorityNullCheck(@NotNull final Relation relation, @NotNull String key, - @NotNull final Relation r, @NotNull String key2) - { - key = fuckSql(key); - key2 = fuckSql(key2); - - addRelation(relation).set.ensureCapacity(set.length() + 13 + key.length()); - set.append("( `").append(key).append("`").append(" IS Null"); - - addRelation(r).set.ensureCapacity(set.length() + 13 + key2.length()); - set.append("`").append(key2).append("`").append(" IS NULL").append(" )"); - return this; - } - - /** - *

添加 Sql 语句.

- *
-     * 添加的语句在 Where 后,请不要添加条件语句以外的语句
-     * 
- * - * @param relation 与前面语句的关系 - * @param sql 要添加的 Sql 语句 - */ - @NotNull - public - sqlWhereBulid addSql(@NotNull final Relation relation, @NotNull final String sql) { - addRelation(relation).set.append(" ").append(sql); - return this; - } - - /** - *

获取语句.

- * - * @return 没参数为 {@code Null} - */ - @Nullable - public - String get() { - if (set.length() == 0) - return null; - return set.toString(); - } - - // 加入关系 - private - sqlWhereBulid addRelation(Relation relation) { - if (set.length() > 0) - set.append(relation); - return this; - } - - /** - *

获取查询条件.

- *
-     * 获取条件集里面的条件并添加到传入的字符缓存区
-     * 
- * - * @param whele 要提取的条件集 - * @param sql 要添加的字符缓冲区 - */ - public static - void getWhere(@NotNull final sqlWhereBulid whele, @NotNull final StringBuilder sql) - { - // 条件语句 - @Nullable final String s = whele.get(); - if (s == null) - return; - - sql.ensureCapacity(7 + s.length() + sql.length()); - sql.append(" WHERE ").append(s); - } - - /** - *

将 post 来的数据转化成sql条件对象.

- * - * @param s 传入的数据 - * @param bulid 要添加的对象 - */ - public static - void toPost(@NotNull String s, @NotNull final sqlWhereBulid bulid) { - int mark; - @NotNull //* 操作类型 *// - final String key = s.substring(0, mark = s.indexOf("##")).trim().toUpperCase(); - s = s.substring(mark += 2); - mark = 0; - - switch ( key ) { - case "ADDEQUAL": - getWhereForPost.addEqual(s, bulid); - break; - case "ADDEQUALPRIORIY": - getWhereForPost.addEqualPrioriy(s, bulid); - break; - case "ADDWHERE": - getWhereForPost.addWhere(s, bulid); - break; - case "ADDPRIORITY": - getWhereForPost.addPriority(s, bulid); - break; - case "ADDNULLCHECK": - getWhereForPost.addNullCheck(s, bulid); - break; - case "ADDPRIORITYNULLCHECK": - getWhereForPost.addPriorityNullCheck(s, bulid); - break; - case "ADDSQL": - bulid.addSql(Relation.valueOf(s.substring(0, mark = s.indexOf("##"))), - s.substring(mark += 2)); - break; - } - } - - /** - *

条件对象转化类

- *

将字符串的交换信息转化为 sql 条件对象

- * - * @author fybug - * @version 0.0.1 - * @since JDK 1.8 - */ - public static final - class getWhereForPost { - public static - void addEqual(@NotNull final String stringBuilder, @NotNull final sqlWhereBulid bulid) - { - int mark; - @NotNull final String relation = stringBuilder.substring(0, mark = - stringBuilder.indexOf("##")).trim(); - @NotNull final String key = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String val; - final boolean ne; - - val = stringBuilder.substring(mark += 2, mark = stringBuilder.indexOf("##", mark)) - .trim(); - ne = Boolean.parseBoolean(stringBuilder.substring(mark += 2).trim()); - - bulid.addEqual(Relation.valueOf(relation), key, val, ne); - } - - public static - void addEqualPrioriy(@NotNull final String stringBuilder, - @NotNull final sqlWhereBulid bulid) - { - int mark = 0; - @NotNull final String relation = stringBuilder.substring(0, mark = - stringBuilder.indexOf("##")).trim(); - @NotNull final String key = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String val = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - final boolean ne = Boolean.valueOf( - stringBuilder.substring(mark += 2, mark = stringBuilder.indexOf("##", mark)) - .trim()); - @NotNull final String relation2 = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)); - @NotNull final String key2 = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)); - @NotNull final String val2 = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - final boolean ne2 = Boolean.valueOf(stringBuilder.substring(mark += 2).trim()); - - bulid.addEqualPrioriy(Relation.valueOf(relation), key, val, ne, - Relation.valueOf(relation2), key2, val2, ne2); - - } - - public static - void addWhere(@NotNull final String stringBuilder, @NotNull final sqlWhereBulid bulid) - { - int mark; - @NotNull final String relation = stringBuilder.substring(0, mark = - stringBuilder.indexOf("##")).trim(); - @NotNull final String key = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String how = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String val = stringBuilder.substring(mark += 2).trim(); - - bulid.addWhere(Relation.valueOf(relation), key, HowWhere.valueOf(how), val); - } - - public static - void addPriority(@NotNull final String stringBuilder, @NotNull final sqlWhereBulid bulid) - { - int mark; - @NotNull final String relation = stringBuilder.substring(0, mark = - stringBuilder.indexOf("##")).trim(); - @NotNull final String key = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String how = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String val = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String relation2 = stringBuilder.substring(0, mark = - stringBuilder.indexOf("##")).trim(); - @NotNull final String key2 = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String how2 = stringBuilder.substring(mark += 2, mark = - stringBuilder.indexOf("##", mark)).trim(); - @NotNull final String val2 = stringBuilder.substring(mark += 2).trim(); - - bulid.addPriority(Relation.valueOf(relation), key, HowWhere.valueOf(how), val, - Relation.valueOf(relation2), key2, HowWhere.valueOf(how2), val2); - } - - public static - void addNullCheck(@NotNull final String stringBuilder, @NotNull final sqlWhereBulid bulid) - { - int mark; - @NotNull final String relation = stringBuilder.substring(0, mark = - stringBuilder.indexOf("##")).trim(); - @NotNull final String key = stringBuilder.substring(mark += 2).trim(); - - bulid.addNullCheck(Relation.valueOf(relation), key); - } - - public static - void addPriorityNullCheck(@NotNull final String s, @NotNull final sqlWhereBulid bulid) { - - int mark; - @NotNull final String relation = s.substring(0, mark = s.indexOf("##")).trim(); - @NotNull final String key = s.substring(mark += 2, mark = s.indexOf("##", mark)).trim(); - @NotNull final String relation2 = s.substring(mark += 2, mark = s.indexOf("##", mark)) - .trim(); - @NotNull final String key2 = s.substring(mark += 2).trim(); - - bulid.addPriorityNullCheck(Relation.valueOf(relation), key, Relation.valueOf(relation2), - key2); - } - } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Delete.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Delete.java new file mode 100644 index 0000000000000000000000000000000000000000..1e40779ecafb3a61a72c55fa808bfd0a9641ceda --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Delete.java @@ -0,0 +1,170 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collection; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.WhereSet; +import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; + +import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; +/** + *

删除语句对象.

+ *
+ * 该对象包含一个完整的 {@code Mysql} 删除语句
+ * 需传入所需要的 条件语句 对象
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @see MysqlSql + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "All" ) +public final +class Delete extends ConsistentField implements MysqlSql { + @Nullable protected ArrayList tabname = new ArrayList<>(); + @Nullable protected WhereSet where = null; + + /**

构造一个空的删除语句对象.

*/ + public + Delete() {} + + /** + *

构造一个删除语句并初始化.

+ * + * @param tab 要删除的表 + * @param w 删除的条件 + */ + public + Delete(@NotNull final String tab, @NotNull final WhereSet w) { + setWhere(w); + addTabname(tab); + } + + /** + *

添加要操作的表名.

+ * + * @param s 要操作的表 + * + * @return this + */ + @Override + public @NotNull + Delete addTabname(@NotNull String s) { + s = fuckSql(s).trim(); + if (!s.equals("")) + this.tabname.add(s); + else + tabname = null; + return this; + } + + /** + *

获取当前要操作的表的列表.

+ * + * @return 要操作的表 + */ + @NotNull + public + Collection getTabname() { return tabname; } + + /** + *

设置操作条件.

+ * + * @param where 如果是{@code null} 则会清空条件 + * + * @return this + */ + @NotNull + public + Delete setWhere(@Nullable final WhereSet where) { + if (where == null) + this.where = null; + else + this.where = where; + return this; + } + + /** + *

获取条件对象.

+ * + * @return {@link WhereSet} + */ + @Nullable + public + WhereSet getWhere() { return where; } + + @Override + protected + boolean consistent(@NotNull final Object obj) + { return hashCode() == obj.hashCode(); } + + @Override + public + int hashCode() { + return ((super.hashCode() + (tabname == null ? -1 : tabname.hashCode())) << 5) + + ((where == null ? -1 : where.hashCode()) << 5); + } + + @Override + @NotNull + protected + Object clone() throws CloneNotSupportedException { + @NotNull final Delete d = (Delete) super.clone(); + d.tabname = tabname; + d.where = where == null ? null : (WhereSet) where.clone(); + return d; + } + + @NotNull + @Override + public + String toString() { + if (where == null || tabname == null) + throw new NullPointerException("No Field Sql!"); + + boolean f = true; + @NotNull final StringBuilder sql = new StringBuilder("DELETE FROM "); + tabname.trimToSize(); + + /* 获取插入表组 */ + for ( String key : tabname ){ + if (f) { + sql.ensureCapacity(sql.length() + 2 + key.length()); + f = false; + } else { + sql.ensureCapacity(sql.length() + key.length() + 4); + sql.append(", "); + } + sql.append('`').append(key).append('`'); + } + + WhereSet.getWhere(where, sql); + + sql.trimToSize(); + return sql.toString(); + } + + @Override + public + void clean() { + tabname.clear(); + where = null; + } + + @Override + public + void free() { clean(); } + + @Override + public + void close() { + where.close(); + free(); + tabname = null; + } +} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Insert.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Insert.java new file mode 100644 index 0000000000000000000000000000000000000000..1c73f7c642b7954bdd8ea26ef11d9447e981f713 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Insert.java @@ -0,0 +1,194 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.InsertVal; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.UpDataVal; +import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; + +import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; +/** + *

插入语句对象.

+ *
+ * 该对象包含一个完整的 {@code Mysql} 插入语句
+ * 需传入所需要的 操作段语句 对象
+ * 如果传入了 更新操作段 对象则会在 已有插入 的情况下进行更新
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @see MysqlSql + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "all" ) +public final +class Insert extends ConsistentField implements MysqlSql { + @Nullable protected String tabname = null; + @Nullable protected InsertVal In = null; + @Nullable protected UpDataVal up = null; + + /** + *

构造一个插入语句并初始化.

+ * + * @param tabname 要插入的表 + * @param insertVal 插入值的语句 + */ + public + Insert(@NotNull final String tabname, @NotNull final InsertVal insertVal) { + setInserVal(insertVal); + addTabname(tabname); + } + + /**

构造一个空的插入语句对象.

*/ + public + Insert() {} + + /** + *

设置要操作的表名.

+ * + * @param s 要操作的表 + * + * @return this + */ + @Override + public @NotNull + Insert addTabname(@NotNull String s) { + tabname = fuckSql(s).trim(); + if (!s.equals("")) + this.tabname = s; + else + tabname = null; + return this; + } + + /** + *

获取当前要操作的表名.

+ * + * @return 要操作的表的名称 + */ + @Nullable + public + String getTabname() { return tabname; } + + /** + *

设置插入值语句.

+ * + * @param bv 如果是{@code Null} 则会清空语句对象 + * + * @return this + * + * @see InsertVal + */ + @NotNull + public + Insert setInserVal(@Nullable final InsertVal bv) { + In = bv; + return this; + } + + /** + *

获取插入值语句.

+ * + * @return {@link InsertVal} + */ + @Nullable + public + InsertVal getInserVal() { return In; } + + /** + *

设置更新语句.

+ * + * @param u 如果是{@code Null} 则会清空语句对象 + * + * @return this + * + * @see UpDataVal + */ + @NotNull + public + Insert serUpDataVal(@Nullable final UpDataVal u) { + up = u; + return this; + } + + /** + *

获取更新语句.

+ * + * @return {@link UpDataVal} + */ + @Nullable + public + UpDataVal getUpDataVal() { return up; } + + @NotNull + @Override + public + String toString() { + if (In == null || In.size() == 0 || tabname == null) + throw new NullPointerException("No Field Sql!"); + + @NotNull final StringBuilder sql = new StringBuilder("INSERT INTO "); + + /* 插入语句部分 */ + sql.ensureCapacity(sql.length() + 3 + tabname.length()); + sql.append('`').append(tabname).append("`").append(In); + + /* 更新语句部分 */ + if (up != null) { + sql.append(" ON DUPLICATE KEY UPDATE ").append(up); + } + + sql.append(';'); + sql.trimToSize(); + return sql.toString(); + } + + @Override + protected + boolean consistent(@NotNull final Object obj) + { return obj.hashCode() == this.hashCode(); } + + @Override + public + int hashCode() { + return ((super.hashCode() + (tabname == null ? -1 : tabname.hashCode())) << 5) + + ((In == null ? -1 : In.hashCode()) << 5) + ((up == null ? -1 : up.hashCode()) << 5); + } + + @Override + @NotNull + public + Object clone() throws CloneNotSupportedException { + @NotNull final Insert i = (Insert) super.clone(); + i.tabname = this.tabname; + i.In = In == null ? null : (InsertVal) this.In.clone(); + i.up = up == null ? null : (UpDataVal) up.clone(); + return i; + } + + /* + * 释放 + */ + + @Override + public + void clean() { + tabname = null; + In = null; + up = null; + } + + @Override + public + void free() { clean(); } + + @Override + public + void close() { + In.clean(); + up.clean(); + free(); + } +} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/MysqlSql.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/MysqlSql.java new file mode 100644 index 0000000000000000000000000000000000000000..14b414b2dcf5e07a646528b6e4022f6b9259240e --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/MysqlSql.java @@ -0,0 +1,40 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; +import org.jetbrains.annotations.NotNull; + +import java.io.Serializable; + +import fybug.nulll.pdfunctionlibrary.Processing.sql.Mysql; +import fybug.nulll.pdfunctionlibrary.lang.Cleanable; +/** + *

Mysql 数据库操作对象.

+ *
+ * 此接口表示当前对象代表一个完整的 Mysql 操作语句
+ * 可通过 {@link #toString()} 打印该语句
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @see Mysql + * @since PDF 1.3 + */ +@SuppressWarnings( "all" ) +public +interface MysqlSql extends Serializable, Cloneable, Cleanable { + /** + *

打印当前操作的 sql 语句.

+ * + * @return 当前操作的 SQL 语句 + */ + @NotNull + String toString(); + + /** + *

添加要操作的表名.

+ * + * @param s 要操作的表 + * + * @return this + */ + @NotNull + MysqlSql addTabname(@NotNull final String s); +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Updata.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Updata.java new file mode 100644 index 0000000000000000000000000000000000000000..5d0d65674ad3f144d756182f62e88d7a6851aa9d --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Updata.java @@ -0,0 +1,177 @@ +package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.UpDataVal; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.WhereSet; +import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; + +import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; +/** + *

更新语句对象.

+ *
+ * 该对象包含一个完整的 {@code Mysql} 更新语句
+ * 需传入所需要的 条件语句 对象
+ * 以及需要的 更新语句段 对象
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @see MysqlSql + * @since PDF 1.3 + */ +@SuppressWarnings( "all" ) +@NoSynchronized +public final +class Updata extends ConsistentField implements MysqlSql { + @Nullable protected String tabname = null; + @Nullable protected WhereSet where = null; + @Nullable protected UpDataVal up = null; + + /** + *

添加要操作的表名.

+ * + * @param s 要操作的表 + * + * @return this + */ + @Override + public @NotNull + Updata addTabname(@NotNull final String s) { + tabname = fuckSql(s).trim(); + if (!s.equals("")) + this.tabname = s; + else + tabname = null; + return this; + } + + /** + *

获取当前要操作的表名.

+ * + * @return 要操作的表 + */ + @Nullable + public + String getTabname() { return tabname; } + + /** + *

设置操作条件.

+ * + * @param where 如果是{@code null} 则会清空条件 + * + * @return this + */ + @NotNull + public + Updata setWhere(@Nullable final WhereSet where) { + if (where == null) + this.where = null; + else + this.where = where; + return this; + } + + /** + *

获取条件对象.

+ * + * @return {@link WhereSet} + */ + @Nullable + public + WhereSet getWhere() { return where; } + + /** + *

设置更新语句段.

+ * + * @param updata 如果为{@code null} 则会清空对应的语句段 + * + * @return this + * + * @see UpDataVal + */ + @NotNull + public + Updata setUpdata(@Nullable final UpDataVal updata) { + if (updata == null) + up = null; + else + up = updata; + return this; + } + + /** + *

获取更新语句段.

+ * + * @return {@link UpDataVal} + */ + @Nullable + public + UpDataVal getUpData() { return up; } + + @Override + protected + boolean consistent(@NotNull final Object obj) + { return hashCode() == obj.hashCode(); } + + @Override + public + int hashCode() { + return ((super.hashCode() + (tabname == null ? -1 : tabname.hashCode())) << 5) + + ((where == null ? -1 : where.hashCode()) << 5) + + ((up == null ? -1 : up.hashCode()) << 5); + } + + @Override + @NotNull + protected + Object clone() throws CloneNotSupportedException { + @NotNull final Updata d = (Updata) super.clone(); + d.tabname = tabname; + d.where = where == null ? null : (WhereSet) where.clone(); + d.up = up == null ? null : (UpDataVal) up.clone(); + return d; + } + + @NotNull + @Override + public + String toString() { + if (up == null || up.size() == 0 || tabname == null) + throw new NullPointerException("No Field Sql!"); + + @NotNull final StringBuilder sql = new StringBuilder("UPDATE "); + @NotNull final String fs = up.toString(); + + // 过滤表名 + sql.ensureCapacity(sql.length() + tabname.length() + 6 + fs.length()); + sql.append('`').append(tabname).append('`').append(" SET ").append(fs); + + // 获取条件 + WhereSet.getWhere(where, sql); + + sql.trimToSize(); + return sql.toString(); + } + + @Override + public + void clean() { + up = null; + tabname = null; + where = null; + } + + @Override + public + void free() { clean(); } + + @Override + public + void close() { + up.close(); + where.close(); + free(); + } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..2b7bc9bdff628b40a85323d95c34b49337ec63bc --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/package-info.java @@ -0,0 +1,8 @@ +/** + *

MySQL 相关包.

+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataContainer.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataContainer.java index d2dae681bac48cf361efb2c2010624bb63ce371d..a5b0959b88e51dfb13363ef7112403eb19a8cdad 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataContainer.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataContainer.java @@ -55,6 +55,13 @@ class DataContainer extends ConsistentField implements Cloneable, CanEmpty { protected DataContainer(@Nullable final V t) { setValue(t); } + @Override + protected + void finalize() throws Throwable { + super.finalize(); + close(); + } + @NotNull @Override @NoSynchronized diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataGrid.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataGrid.java index 4a8f0ca0a29bae6b28a2eb9272d75c21d52b13a1..8b0629f47f52ab66e1fbc578d7f2f478450e3168 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataGrid.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataGrid.java @@ -35,7 +35,7 @@ import static fybug.nulll.pdfunctionlibrary.lang.CanEmpty.checkNull; @SuppressWarnings( "All" ) public abstract class DataGrid extends ConsistentField implements CanEmpty, Serializable, MaybeSynchronized { - private static final long serialVersionUID = 2897087111925657508L; + private static final long serialVersionUID = 4768456080120637380L; // V @Nullable protected V value = null; @@ -57,6 +57,13 @@ class DataGrid extends ConsistentField implements CanEmpty, Serializable, May return dataContainer; } + @Override + protected + void finalize() throws Throwable { + super.finalize(); + close(); + } + @Override @NoSynchronized protected diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataMap.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataMap.java index 110f0df1bce48fe59d699293f7bd85f31049c5f6..3b6aba1af714919edf89a3ed39e7c9dc3815263d 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataMap.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/DataMap.java @@ -8,7 +8,6 @@ import fybug.nulll.pdfunctionlibrary.lang.CanEmpty; import static fybug.nulll.pdfunctionlibrary.Processing.CheckObject.equalsFidle; import static fybug.nulll.pdfunctionlibrary.Util.DataContainer.cloneField; -import static fybug.nulll.pdfunctionlibrary.lang.CanEmpty.checkNull; /** *

数据映射.

*

提供一个存放一组键值的数据映射对象
@@ -18,7 +17,7 @@ import static fybug.nulll.pdfunctionlibrary.lang.CanEmpty.checkNull; * @param 值 * * @author fybug - * @version 0.0.6 + * @version 0.0.7 * @see DataGrid * @see Synchronized * @see DataMAP @@ -27,7 +26,7 @@ import static fybug.nulll.pdfunctionlibrary.lang.CanEmpty.checkNull; @SuppressWarnings( "all" ) public abstract class DataMap extends DataGrid { - private static final long serialVersionUID = 6898205580280203319L; + private static final long serialVersionUID = 6088419458345864876L; // K @Nullable protected K key; @@ -52,6 +51,13 @@ class DataMap extends DataGrid { return dataContainer; } + @Override + protected + void finalize() throws Throwable { + super.finalize(); + close(); + } + @Override @NoSynchronized protected @@ -74,12 +80,12 @@ class DataMap extends DataGrid { /**

清除键的数据.

*/ @NotNull public - DataMap cleanKey() { return setKey(null); } + DataMap cleanKey() {return setKey(null);} /**

获取键数据.

*/ @Nullable public final - K getKey() { return key; } + K getKey() {return key;} /** *

检查当前键是否为空.

@@ -93,7 +99,7 @@ class DataMap extends DataGrid { @NotNull final K t; t = getKey(); if (t != null) - return checkNull(t); + return CanEmpty.checkNull(t); return true; } @@ -113,7 +119,7 @@ class DataMap extends DataGrid { /**

清除值数据.

*/ @NotNull public - DataMap cleanValue() { return (DataMap) super.cleanValue();} + DataMap cleanValue() { return (DataMap) super.cleanValue(); } /* * 释放 @@ -130,12 +136,12 @@ class DataMap extends DataGrid { /**

{@link #clean()}

*/ @Override public - void free() { super.free(); } + void free() {super.free();} /**

{@link #free()}

*/ @Override public - void close() { super.close(); } + void close() {super.close();} /* * CheckObject @@ -143,11 +149,11 @@ class DataMap extends DataGrid { @Override public - boolean isNull() { return super.isNull() && getKey() == null; } + boolean isNull() {return super.isNull() && getKey() == null;} @Override public - boolean isEmpty() { return keyEmpty() && super.isEmpty(); } + boolean isEmpty() {return keyEmpty() && super.isEmpty();} /* * 转化 @@ -161,10 +167,12 @@ class DataMap extends DataGrid { * @since PDF 1.2 expander 2 */ @Override + @NotNull public DataMap toSynchronized() { if (this instanceof Synchronized) return this; + @NotNull final DataMap s = new Synchronized(); s.key = this.key; s.value = this.value; @@ -180,6 +188,7 @@ class DataMap extends DataGrid { * @since PDF 1.2 expander 2 */ @Override + @NotNull public DataMap removerSynchronized() { if (this instanceof DataMAP) @@ -204,7 +213,7 @@ class DataMap extends DataGrid { @NotNull public static DataMap getDataMap() - { return new DataMAP(); } + {return new DataMAP();} /** *

获取{@link DataMap} 的实现类.

@@ -258,7 +267,7 @@ class DataMap extends DataGrid { @CanSynchronized public static class Synchronized extends DataMap { - private static final long serialVersionUID = 7711392908093265021L; + private static final long serialVersionUID = 4902826450042293331L; // 同步锁 @NotNull private Object keyLock = new Object(); @@ -268,12 +277,6 @@ class DataMap extends DataGrid { public Synchronized(@Nullable final K ke, @Nullable final V v) { super(ke, v); } - @Override - @NoSynchronized - public - int hashCode() { return (super.hashCode() + keyLock.hashCode()) << 5; } - - @NotNull @Override @NoSynchronized public diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java index 74ed4680fc50fb9d6300826fff08bbdb4e75f083..46752bbc54e3b8b022b74ec32a053d8bf5cd8a65 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java @@ -10,7 +10,7 @@ import fybug.nulll.pdfunctionlibrary.Util.DataMap; *

使用了数组实现的映射集.

* * @author fybug - * @version 0.0.1 + * @version 0.0.2 * @see ArrayList * @see DataMap * @see MapFile @@ -22,6 +22,13 @@ public class ArrayMap extends ArrayList> implements MapFile { protected int mark = 0; + @Override + protected + void finalize() throws Throwable { + super.finalize(); + close(); + } + @Override @NotNull public @@ -43,17 +50,15 @@ class ArrayMap extends ArrayList> implements MapFile { DataMap poll() { if (size() == 0) return null; + if (mark > 0) mark--; + DataMap f = super.get(0); remove(0); return f; } - @Override - public - boolean isEmpty() { return size() == 0; } - @NotNull @Override public @@ -61,10 +66,34 @@ class ArrayMap extends ArrayList> implements MapFile { { return super.toArray(new DataMap[size()]); } @Override - public @NotNull + @NotNull + public ArrayMap next() { if (mark <= size()) mark++; return this; } + + @Override + public + boolean isEmpty() { return size() == 0; } + + @Override + public + boolean isNull() { return isEmpty(); } + + @Override + public + void clean() { + clear(); + mark = 0; + } + + @Override + public + void free() { clean(); } + + @Override + public + void close() { free(); } } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java index 29ad1cda37c182608b4f1129ac05c5e2cab6da44..149e3b942760d4c87fe55bd9bb452485451be696 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java @@ -10,7 +10,7 @@ import fybug.nulll.pdfunctionlibrary.Util.DataMap; *

使用了链表实现的映射集.

* * @author fybug - * @version 0.0.1 + * @version 0.0.2 * @see LinkedList * @see DataMap * @see MapFile @@ -22,6 +22,13 @@ public class LinkMap extends LinkedList> implements MapFile { protected int mark = 0; + @Override + protected + void finalize() throws Throwable { + super.finalize(); + close(); + } + @Override @NotNull public @@ -31,7 +38,8 @@ class LinkMap extends LinkedList> implements MapFile { } @Override - public @Nullable + @Nullable + public DataMap get() { if (mark < size()) return super.get(mark); @@ -39,20 +47,19 @@ class LinkMap extends LinkedList> implements MapFile { } @Override - public @Nullable + @Nullable + public DataMap poll() { if (size() == 0) return null; + if (mark > 0) mark--; + DataMap f = super.poll(); return f; } - @Override - public - boolean isEmpty() { return size() == 0; } - @NotNull @Override public @@ -60,10 +67,34 @@ class LinkMap extends LinkedList> implements MapFile { { return super.toArray(new DataMap[size()]); } @Override - public @NotNull + @NotNull + public LinkMap next() { if (mark <= size()) mark++; return this; } + + @Override + public + boolean isEmpty() { return size() == 0; } + + @Override + public + boolean isNull() { return isEmpty(); } + + @Override + public + void clean() { + clear(); + mark = 0; + } + + @Override + public + void free() { clean(); } + + @Override + public + void close() { free(); } } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java index 00a5bf7ddb9ea094dad3a9a13b26da9f2fd4ff34..b4459b2af5717f0727b670907f3560d23315ba8e 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java @@ -6,6 +6,7 @@ import java.util.Iterator; import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; import fybug.nulll.pdfunctionlibrary.Util.DataMap; +import fybug.nulll.pdfunctionlibrary.lang.CanEmpty; /** *

数据映射集.

*
@@ -19,7 +20,8 @@ import fybug.nulll.pdfunctionlibrary.Util.DataMap;
  * @param  值类型
  *
  * @author fybug
- * @version 0.0.1
+ * @version 0.0.2
+ * @see CanEmpty
  * @see Iterator
  * @see DataMap
  * @since PDF 1.2
@@ -27,7 +29,7 @@ import fybug.nulll.pdfunctionlibrary.Util.DataMap;
 @SuppressWarnings( "all" )
 @NoSynchronized
 public
-interface MapFile {
+interface MapFile extends CanEmpty {
     /**
      * 

添加一个映射.

* @@ -97,5 +99,6 @@ interface MapFile { LinkMap userLink() { return new LinkMap(); } + @NotNull Object clone(); } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Processing/Arrarys.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Processing/Arrarys.java index 525ed6b84133336bff38dfd782a73a84a3b7aba6..4a313dbd490bb52818e2f08d48a64bb3f462711c 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Processing/Arrarys.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Processing/Arrarys.java @@ -149,15 +149,16 @@ class Arrarys { U[] conversionArrayType(@Nullable final T[] in, @NotNull final ObjectCoupler coupler, @NotNull final Class outType) { + int length = 0; /* 检查数据 */ - if (in == null || in.length == 0) + if (in == null || (length = in.length) == 0) return (U[]) newInstance(outType, 0); int index = 0; // 当前转化位置指针 - @NotNull U[] out = (U[]) newInstance(outType, in.length); // 新的数组 + @NotNull U[] out = (U[]) newInstance(outType, length); // 新的数组 @Nullable T t; - for ( int i = 0; i < in.length; i++ ){ + for ( int i = 0; i < length; i++ ){ t = in[i]; if (t == null) continue; @@ -168,8 +169,7 @@ class Arrarys { } /* 去除空数据 */ - if (index < out.length) - out = Arrays.copyOf(out, index); + out = Arrarys.trim(out); return out; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CanEmpty.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CanEmpty.java index 9331e1f7b113aadd60c5a8a82e15d82794f01145..1af69d203f070a3fd7d682121e7e160c9a591157 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CanEmpty.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CanEmpty.java @@ -44,6 +44,6 @@ interface CanEmpty extends Cleanable { // 使用内部函数检查是否是空数据 return ((CanEmpty) t1).isNull() || ((CanEmpty) t1).isEmpty(); else - return false; + return t1 == null; } } \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CloseAll.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CloseAll.java index e01b141578b0e9c0f63a5c3070b70eea8b91eb22..8106efae7c1c66339d6db41ecbed3e81559cd66d 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CloseAll.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/CloseAll.java @@ -17,7 +17,7 @@ import fybug.nulll.pdfunctionlibrary.Util.Processing.Arrarys; *
* * @author fybug - * @version 0.0.5 + * @version 0.0.6 * @see ConsistentField * @see AutoCloseable * @see MaybeSynchronized @@ -60,6 +60,22 @@ class CloseAll extends ConsistentField implements AutoCloseable, MaybeSynchroniz public abstract CloseAll append(@Nullable final AutoCloseable... close); + /** + *

添加要关闭的对象.

+ * + * @param t 要追加的要关闭的对象 + * + * @return 追加的对象 + * + * @since PDF 1.3 + */ + @Nullable + public + T put(@Nullable final T t) { + append(t); + return t; + } + /**

关闭该类下的所有可关闭对象.

*/ public abstract void close(); @@ -208,9 +224,8 @@ class CloseAll extends ConsistentField implements AutoCloseable, MaybeSynchroniz while( true ){ // 仅锁住该部分,在进行关闭的时候可进行添加 synchronized ( this ){ - if (linkedList.size() == 0) + if ((closeable = linkedList.poll()) == null) break ch; - closeable = linkedList.poll(); } try { @@ -219,8 +234,6 @@ class CloseAll extends ConsistentField implements AutoCloseable, MaybeSynchroniz // 无视 } } - - closeable = null; } } @@ -257,9 +270,8 @@ class CloseAll extends ConsistentField implements AutoCloseable, MaybeSynchroniz @NotNull AutoCloseable closeable; while( true ){ - if (linkedList.size() == 0) + if ((closeable = linkedList.poll()) == null) break; - closeable = linkedList.poll(); try { closeable.close(); diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/BDPos.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/BDPos.java new file mode 100644 index 0000000000000000000000000000000000000000..160f8c29626873b034bbe4f5b0585dbabe2140bd --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/BDPos.java @@ -0,0 +1,256 @@ +package fybug.nulll.pdfunctionlibrary.lang.net.bdpos; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.CObject; +import fybug.nulll.pdfunctionlibrary.lang.CanEmpty; +/** + *

BDPos 数据容器.

+ *
+ * 该类存放载入的所有的 {@link PosClass} 对象,并使用对应的名称存放
+ * 需要加载 {@code post} 数据,也可单独进行放入
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "all" ) +public +class BDPos extends CObject implements CanEmpty, Serializable { + private static final long serialVersionUID = -2918982630884148383L; + @Nullable protected HashMap hashMap; + + /**

构造一个空的数据解析对象.

*/ + public + BDPos() { hashMap = new HashMap<>(); } + + /** + *

构造一个数据解析对象.

+ * + * @param post 要解析的 post 数据 + */ + public + BDPos(@Nullable final String post) { + this(); + loadPost(post); + } + + /** + *

加载 post 数据并解析.

+ * + * @param post 要解析的 post 数据 + * + * @return this + */ + @NotNull + public + BDPos loadPost(@Nullable String post) { + if (post == null || post.isEmpty()) { + return this; + } + + @NotNull final StringBuilder pos = new StringBuilder(post); + passPost(pos, " ###", (n, d) -> { + @NotNull final PosClass posClass = new PosClass(d); + posClass.name = n; + putClass(posClass); + }); + + return this; + } + + /** + *

解析数据.

+ * + * @param pos 内容缓存 + * @param markChar 标识符 + * + * @see PutData + */ + static + void passPost(@NotNull final StringBuilder pos, @NotNull final String markChar, + @NotNull final PutData po) + { + int mark = 0, // 最近一个标签位置 + end, // 结束位置 + lenght = markChar.length(); + @Nullable String posClass; + @Nullable @Nls String name = null; + + while( true ){ + mark = pos.indexOf(markChar, mark); + + if (mark == -1) { + break; + } + + pos.delete(mark, mark + lenght); + + /* 解析名称 */ + { + int namemark = pos.indexOf(":", mark); + if (namemark != -1) { + name = pos.substring(mark, namemark).trim(); + pos.delete(mark, namemark + 1); + } + } + + end = pos.indexOf(markChar, mark + 1); // 检查尾部 + + if (end == -1) { + posClass = pos.substring(mark); + pos.delete(mark, pos.length()); + } else { + posClass = pos.substring(mark, end); + pos.delete(mark, end); + } + + pos.trimToSize(); + po.put(name, posClass); + } + } + + /** + *

处理解析后的数据.

+ * + * @author fybug + * @see #passPost(StringBuilder, String, PutData) + */ + static + interface PutData { + /** + *

处理解析后的数据.

+ * + * @param name 该段的名称 + * @param data 数据 + */ + void put(@Nullable final String name, @NotNull final String data); + } + + /** + *

放入指令类.

+ * + * @param posClass 指令类 + * + * @return this + * + * @see PosClass + */ + @NotNull + public + BDPos putClass(@NotNull final PosClass posClass) { + hashMap.put(posClass.name, posClass); + return this; + } + + /** + *

获取指令类.

+ * + * @param name 要获取的指令类 + * + * @return {@link PosClass} + */ + @Nullable + public + PosClass getClass(@Nullable final String name) { return hashMap.get(name); } + + /** + *

删除类.

+ * + * @param name 要删除的类名 + * + * @return 删除的类 + */ + @Nullable + public + PosClass deleteClass(@Nullable final String name) { return hashMap.remove(name); } + + @NotNull + @Override + public + Object clone() throws CloneNotSupportedException { + @NotNull final BDPos bdPos = (BDPos) super.clone(); + + bdPos.hashMap = hashMap == null ? null : (HashMap) hashMap.clone(); + + return bdPos; + } + + /**

打印当前的数据.

*/ + @NotNull + @Override + public + String toString() { + @NotNull final StringBuilder str = new StringBuilder(); + + if (hashMap.size() > 0) { + for ( Map.Entry e : hashMap.entrySet() ){ + str.append(e.getValue()); + } + + str.trimToSize(); + return str.toString(); + } + return ""; + } + + @Override + protected + void finalize() throws Throwable { + super.finalize(); + clean(); + hashMap = null; + } + + /* + * Check + */ + + @Override + public + boolean isNull() { return hashMap == null; } + + @Override + public + boolean isEmpty() { return isNull() && hashMap.isEmpty(); } + + /* + * 释放 + */ + + @Override + public + void clean() { + if (hashMap != null) + hashMap.clear(); + } + + @Override + public + void free() { + if (hashMap != null) { + for ( PosClass posClass : hashMap.values() ){ + posClass.close(); + } + clean(); + } + } + + @Override + public + void close() { + free(); + hashMap = null; + } + + /* 过滤字段 */ + public final static String CLASS = "#", RN = "\n", NAMEMARK = ":"; +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/Instruct.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/Instruct.java new file mode 100644 index 0000000000000000000000000000000000000000..d2a9544a7c40ea2bd3d89cd40b856d0dfbc915d9 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/Instruct.java @@ -0,0 +1,185 @@ +package fybug.nulll.pdfunctionlibrary.lang.net.bdpos; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.lang.CanEmpty; +/** + *

指令数据.

+ *
+ * 该类存放载入的所有的 {@link PostField} 对象,并使用对应的名称存放
+ * 需要加载 {@code post} 数据,也可单独进行放入
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "all" ) +public +class Instruct implements CanEmpty, Serializable, Cloneable { + /**

指令名.

*/ + @Nullable public String name; + @NotNull protected HashMap hashMap; + + /**

构造一个空的指令.

*/ + public + Instruct() {hashMap = new HashMap<>();} + + /** + *

构造一个指令,并载入数据.

+ * + * @param classpost 该类的 post 形式 + */ + public + Instruct(@Nullable final String classpost) { + this(); + loading(classpost); + } + + /** + *

加载数据.

+ * + * @param post 要加载的数据 post 形式 + * + * @return this + */ + @NotNull + public + Instruct loading(@Nullable String post) { + if (post == null || post.isEmpty()) { + return this; + } + @NotNull final StringBuilder str = new StringBuilder(post); + BDPos.passPost(str, " #", (n, d) -> { + @NotNull final PostField postField = new PostField(d); + postField.name = n; + putPostField(postField); + }); + + return this; + } + + /** + *

放入属性数据.

+ * + * @param u 要放入的属性类 + * + * @return this + * + * @see PostField + */ + @NotNull + public + Instruct putPostField(@NotNull final PostField u) { + hashMap.put(u.name, u); + return this; + } + + /** + *

获取属性数据.

+ * + * @param name 要获取的属性名称 + * + * @return {@link PostField} + */ + @Nullable + public + PostField getPostField(@Nullable final String name) { return hashMap.get(name); } + + /** + *

删除属性数据.

+ * + * @param name 要删除的属性名称 + * + * @return 删除的属性 + */ + @Nullable + public + PostField deletePostField(@Nullable final String name) { return hashMap.remove(name); } + + @Override + public @NotNull + Object clone() throws CloneNotSupportedException { + @NotNull final Instruct posClass = (Instruct) super.clone(); + + posClass.hashMap = hashMap == null ? null : (HashMap) hashMap.clone(); + posClass.name = name; + + return posClass; + } + + @Override + @NotNull + public + String toString() { + @NotNull final StringBuilder str = new StringBuilder(" ## ").append( + name == null ? "" : (name + ":")); + + if (hashMap.size() > 0) { + for ( Map.Entry e : hashMap.entrySet() ){ + str.append(e.getValue()); + } + + str.trimToSize(); + return str.toString(); + } + return ""; + } + + @Override + protected + void finalize() throws Throwable { + super.finalize(); + clean(); + hashMap = null; + name = null; + } + + /* + * Check + */ + + @Override + public + boolean isNull() { return hashMap == null; } + + @Override + public + boolean isEmpty() { return isNull() && hashMap.isEmpty(); } + + /* + * 释放 + */ + + @Override + public + void clean() { + if (hashMap != null) + hashMap.clear(); + } + + @Override + public + void free() { + if (hashMap != null) { + for ( PostField posClass : hashMap.values() ){ + posClass.close(); + } + clean(); + name = null; + } + } + + @Override + public + void close() { + free(); + hashMap = null; + } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/PosClass.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/PosClass.java new file mode 100644 index 0000000000000000000000000000000000000000..60f741672ae5954973f9615d4c6eaf83b9547f58 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/PosClass.java @@ -0,0 +1,187 @@ +package fybug.nulll.pdfunctionlibrary.lang.net.bdpos; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.Processing.CObject; +import fybug.nulll.pdfunctionlibrary.lang.CanEmpty; +/** + *

BDPos 指令类.

+ *
+ * 该类存放载入的所有的 {@link Instruct} 对象,并使用对应的名称存放
+ * 需要加载 {@code post} 数据,也可单独进行放入
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +@NoSynchronized +@SuppressWarnings( "all" ) +public +class PosClass extends CObject implements CanEmpty, Serializable { + /**

类名.

*/ + @Nullable public String name; + @NotNull protected HashMap hashMap; + + /**

构造一个空的指令类.

*/ + public + PosClass() {hashMap = new HashMap<>();} + + /** + *

构造一个指令类,并载入数据.

+ * + * @param classpost 该类的 post 形式 + */ + public + PosClass(@Nullable final String classpost) { + this(); + loadClass(classpost); + } + + /** + *

加载数据.

+ * + * @param post 要加载的数据 post 形式 + * + * @return this + */ + @NotNull + public + PosClass loadClass(@Nullable String post) { + if (post == null || post.isEmpty()) { + return this; + } + + @NotNull final StringBuilder pos = new StringBuilder(post); + BDPos.passPost(pos, " ##", (n, d) -> { + @NotNull final Instruct instruct = new Instruct(d); + instruct.name = n; + putInstruct(instruct); + }); + + return this; + } + + /** + *

放入指令数据.

+ * + * @param u 要放入的指令类 + * + * @return this + * + * @see Instruct + */ + @NotNull + public + PosClass putInstruct(@NotNull final Instruct u) { + hashMap.put(u.name, u); + return this; + } + + /** + *

获取指令数据.

+ * + * @param name 要获取的指令名称 + * + * @return {@link Instruct} + */ + @Nullable + public + Instruct getInstruct(@Nullable final String name) { return hashMap.get(name); } + + /** + *

删除指令数据.

+ * + * @param name 要删除的指令名称 + * + * @return 删除的指令 + */ + @Nullable + public + Instruct deleteInstruct(@Nullable final String name) { return hashMap.remove(name); } + + @Override + public @NotNull + Object clone() throws CloneNotSupportedException { + @NotNull final PosClass posClass = (PosClass) super.clone(); + + posClass.hashMap = hashMap == null ? null : (HashMap) hashMap.clone(); + posClass.name = name; + + return posClass; + } + + @Override + @NotNull + public + String toString() { + @NotNull final StringBuilder str = new StringBuilder(" ### ").append( + name == null ? "" : (name + ":")); + + if (hashMap.size() > 0) { + for ( Map.Entry e : hashMap.entrySet() ){ + str.append(e.getValue()); + } + + str.trimToSize(); + return str.toString(); + } + return ""; + } + + @Override + protected + void finalize() throws Throwable { + super.finalize(); + clean(); + hashMap = null; + name = null; + } + + /* + * Check + */ + + @Override + public + boolean isNull() { return hashMap == null; } + + @Override + public + boolean isEmpty() { return isNull() && hashMap.isEmpty(); } + + /* + * 释放 + */ + + @Override + public + void clean() { + if (hashMap != null) + hashMap.clear(); + } + + @Override + public + void free() { + if (hashMap != null) { + for ( Instruct posClass : hashMap.values() ){ + posClass.close(); + } + clean(); + name = null; + } + } + + @Override + public + void close() { + free(); + hashMap = null; + } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/PostField.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/PostField.java new file mode 100644 index 0000000000000000000000000000000000000000..b7a98387a1f24db1fb748161a9bbb3212af7c29b --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/PostField.java @@ -0,0 +1,253 @@ +package fybug.nulll.pdfunctionlibrary.lang.net.bdpos; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.LinkedList; + +import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; +import fybug.nulll.pdfunctionlibrary.lang.CanEmpty; +/** + *

属性集.

+ * + * @author fybug + * @version 0.0.1 + * @see #data + * @since PDF 1.3 + */ +@SuppressWarnings( "All" ) +@NoSynchronized +public +class PostField implements CanEmpty, Serializable, Cloneable { + /**

属性名.

*/ + @Nullable public String name; + /** + *

存放解析出来的属性.

+ *
+     * 大小大于 {@code 1} 则为多内容
+     * 内容为 {@link String} 则为单属性
+     * 内容为 {@link String[]} 则为多属性
+     * 使用 {@link Class#isArray()} 进行判断
+     * 
+ */ + @NotNull protected LinkedList data; + + /**

构造一个空的属性.

*/ + public + PostField() { data = new LinkedList(); } + + /** + *

构造一个属性,并载入数据.

+ * + * @param classpost 该类的 post 形式 + */ + public + PostField(@Nullable final String classpost) { + this(); + loadField(classpost); + } + + /** + *

载入属性.

+ * + * @param post 要加载的数据 post 形式 + * + * @return this + */ + @NotNull + public + PostField loadField(@Nullable String post) { + if (post == null || post.isEmpty()) { + return this; + } + + @NotNull final StringBuilder str = new StringBuilder(post); + while( passPost(str) ) + ; + + return this; + } + + // 解析当前数据 + private + boolean passPost(@NotNull final StringBuilder post) { + int rnmark = post.indexOf("\n", 0); // 换行符位置 + int mark = post.lastIndexOf("&", rnmark == -1 ? post.length() : rnmark); // 分割符位置 + boolean b = true; + @NotNull String sd; // 当前解析缓存 + + // 拆解当前行数据 + if (rnmark == -1) { + sd = post.toString(); + + post.delete(0, post.length()); + b = false; + } else { + sd = post.substring(0, rnmark); + post.delete(0, rnmark + 1); + } + + // 没有更多属性 + if (mark == -1) { + data.add(sd); + } else { + @NotNull final ArrayList strings = new ArrayList<>(); + @NotNull String[] ss; + mark = 0; + + /* 拆解每个属性 */ + do { + strings.add(sd.substring(mark, (mark = sd.indexOf("&", mark)) == -1 ? sd.length() + : mark)); + mark++; + } + while( mark != 0 ); + + strings.trimToSize(); + strings.toArray(ss = new String[strings.size()]); + strings.clear(); + + data.add(ss); + } + + sd = null; + + post.trimToSize(); + return b; + } + + /** + *

放入属性.

+ * + * @param u 要放入的属性 + * + * @return this + */ + @NotNull + public + PostField putField(@NotNull final String u) { + data.add(u); + return this; + } + + /** + *

放入属性.

+ * + * @param u 要放入的属性 + * + * @return this + */ + @NotNull + public + PostField putField(@NotNull final String[] u) { + data.add(u); + return this; + } + + /** + *

获取属性.

+ * + * @return 如果只有一条记录则会返回该条记录,如果有多条记录则会返回记录数组,返回 {@code Object[0]} 则为无记录 + */ + @NotNull + public + Object getField() { + if (data.size() == 1) + return data.get(0); + else { + Object[] os = new Object[data.size()]; + data.toArray(os); + return os; + } + } + + @Override + public @NotNull + Object clone() throws CloneNotSupportedException { + @NotNull final PostField posClass = (PostField) super.clone(); + + posClass.data = data == null ? null : (LinkedList) data.clone(); + posClass.name = name; + + return posClass; + } + + @Override + @NotNull + public + String toString() { + @NotNull final StringBuilder str = new StringBuilder(" # ").append( + name == null ? "" : (name + ":")); + + if (data.size() > 0) { + @NotNull String[] ss; // 更改指向类型 + /* 遍历属性表 */ + for ( Object o : data ){ + if (!o.getClass().isArray()) { + // 单属性 + str.append(o).append('\n'); + } else { + ss = (String[]) o; + /* 遍历多属性 */ + for ( int i = 0; i < ss.length; i++ ){ + str.append(ss[i]).append("&"); + } + + str.setCharAt(str.length() - 1, '\n'); + } + } + + str.deleteCharAt(str.length() - 1); + str.trimToSize(); + return str.toString(); + } + return ""; + } + + @Override + protected + void finalize() throws Throwable { + super.finalize(); + clean(); + data = null; + name = null; + } + + /* + * Check + */ + + @Override + public + boolean isNull() { return data == null; } + + @Override + public + boolean isEmpty() { return isNull() && data.isEmpty(); } + + /* + * 释放 + */ + + @Override + public + void clean() { + if (data != null) + data.clear(); + } + + @Override + public + void free() { + clean(); + name = null; + } + + @Override + public + void close() { + free(); + data = null; + } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..52ffc35680bce38252c69b3e1be6454e2c2fdcd2 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/bdpos/package-info.java @@ -0,0 +1,29 @@ +/** + *

BDPos 工具包.

+ *
+ * BDPos 是一种网络消息传输格式
+ * 用于像服务器发送消息,服务器应按要求执行对应的函数,一般不要求响应
+ * 
+ *
格式
+ * {@code ###} 该消息域为一个类,类中需包含类名和下列标签
+ * {@code ##} 该消息域为一条指令,需包含指令属性
+ * {@code #} 该消息域为一组属性,通常包含键值
+ * {@code &} 通常用于有多组内容的属性,用于分割每个属性值,一般属性不需要
+ * {@code \n} 通常为分割当前消息域中的特殊属性,该属性有多组内容
+ *
+ * {@code
+ * // 类级
+ *  ### Delete:
+ * // 指令级
+ *  ## Info:
+ * // 属性级 **以上的换行均为方便示例,实际中不应出现换行
+ *  # name:test # url:127.0.0.1 ## mess: # where:key&val // 多属性
+ * key&val // 多内容
+ * key }
+ * 
+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +package fybug.nulll.pdfunctionlibrary.lang.net.bdpos; diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..2b1312b08ea43d2e4def45636f7c2a00a3dca26a --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/lang/net/package-info.java @@ -0,0 +1,8 @@ +/** + *

网络工具包.

+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 + */ +package fybug.nulll.pdfunctionlibrary.lang.net; \ No newline at end of file diff --git a/src/test/java/TestBDPost.java b/src/test/java/TestBDPost.java new file mode 100644 index 0000000000000000000000000000000000000000..bb370296114858e5eaa4bc1b6ad97373063890e5 --- /dev/null +++ b/src/test/java/TestBDPost.java @@ -0,0 +1,88 @@ +import org.junit.Before; +import org.junit.Test; + +import fybug.nulll.pdfunctionlibrary.lang.net.bdpos.BDPos; +public +class TestBDPost { + String da; + + @Before + public + void init() { + StringBuilder stringBuilder = new StringBuilder(" ### c1:"); + { + stringBuilder.append(" ## I1:"); + { + stringBuilder.append(" # f1:"); + { + stringBuilder.append("as"); + } + stringBuilder.append(" # f2:"); + { + stringBuilder.append("a1").append("&"); + stringBuilder.append("a2").append("&"); + stringBuilder.append("a3"); + } + } + stringBuilder.append(" ## I2:"); + { + stringBuilder.append(" # f1:"); + { + stringBuilder.append("sw"); + stringBuilder.append("ewq"); + } + { + stringBuilder.append("ewq").append("&"); + stringBuilder.append("tret"); + } + } + } + stringBuilder.append(" ### :"); + { + stringBuilder.append(" ## I1:"); + { + stringBuilder.append(" # f1:"); + { + stringBuilder.append("as"); + } + stringBuilder.append(" # f2:"); + { + stringBuilder.append("a1").append("&"); + stringBuilder.append("a2").append("&"); + stringBuilder.append("a3"); + } + } + stringBuilder.append(" ## I2:"); + { + stringBuilder.append(" # f1:"); + { + stringBuilder.append("sw"); + stringBuilder.append("ewq"); + } + { + stringBuilder.append("ewq").append("&"); + stringBuilder.append("tret"); + } + } + } + + stringBuilder.trimToSize(); + da = stringBuilder.toString(); + } + + @Test + public + void TestBDPos() { + BDPos pos = new BDPos(da); + System.out.println(pos.toString()); + } + + @Test + public + void TestDBPost() { + BDPos pos = new BDPos(da); + System.out.println(pos.getClass("").name); + System.out.println(pos.getClass("").getInstruct("I1").name); + System.out.println(pos.getClass("").getInstruct("I1").getPostField("f1").getField()); + } +} \ No newline at end of file diff --git a/src/test/java/TestMysql.java b/src/test/java/TestMysql.java new file mode 100644 index 0000000000000000000000000000000000000000..05ab1ac6e48a828f92a5e4fdf80e4f243ac4b324 --- /dev/null +++ b/src/test/java/TestMysql.java @@ -0,0 +1,79 @@ +import org.junit.Before; +import org.junit.Test; + +import java.sql.SQLException; + +import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.Logical; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Mysql; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.InsertVal; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.UpDataVal; +import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.WhereSet; +import fybug.nulll.pdfunctionlibrary.Processing.sql.mysql.Delete; +import fybug.nulll.pdfunctionlibrary.Processing.sql.mysql.Insert; +import fybug.nulll.pdfunctionlibrary.Processing.sql.mysql.Updata; +public +class TestMysql { + Mysql mysql; + + @Before + public + void init() { + try { + mysql.close(); + } catch ( Throwable ignored ) { + } + try { + mysql = Mysql.getDatabase("127.0.0.1", 3306, "pageviews", "root", "2650693483"); + } catch ( SQLException e ) { + e.printStackTrace(); + } + } + + @Test + public + void TestDelete() { + Delete delete = new Delete(); + WhereSet set = new WhereSet(); + + set.addEqual(Logical.AND, "number", 1, false); + + delete.addTabname("record"); + delete.setWhere(set); + + System.out.println(mysql.exe(delete)); + } + + @Test + public + void TestUpdate() { + Updata updata = new Updata(); + WhereSet set = new WhereSet(); + UpDataVal val = new UpDataVal(); + + set.addIn(Logical.AND, "date", false, "2018-12-05", "2018-12-06"); + + updata.addTabname("record"); + updata.setWhere(set); + + val.addMul("number", 2); + updata.setUpdata(val); + + System.out.println(mysql.updata(updata)); + } + + @Test + public + void TestInser() { + Insert insert = new Insert(); + InsertVal val = new InsertVal(); + + val.addVal("name", "Blog"); + val.addVal("date", "2018-12-09"); + val.addVal("number", "0"); + + insert.addTabname("record"); + insert.setInserVal(val); + + System.out.println(mysql.exe(insert)); + } +}