+ fix sql
This commit is contained in:
parent
3ad414df45
commit
11d0a2aff3
@ -5,7 +5,7 @@ plugins {
|
||||
id 'com.github.johnrengelman.shadow' version '4.0.4'
|
||||
}
|
||||
group = 'me.skymc'
|
||||
version = '4.75'
|
||||
version = '4.76'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
@ -1,5 +1,8 @@
|
||||
package me.skymc.taboolib.common.serialize;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* @Author 坏黑
|
||||
* @Since 2019-03-08 17:28
|
||||
@ -20,4 +23,12 @@ public interface TSerializable {
|
||||
default String write() {
|
||||
return TSerializer.write(this);
|
||||
}
|
||||
|
||||
default Object readBase64(String value) {
|
||||
return TSerializer.read(this, new String(Base64.getDecoder().decode(value), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
default String writeBase64() {
|
||||
return Base64.getEncoder().encodeToString(TSerializer.write(this).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
@ -29,10 +29,10 @@ public class TSerializer {
|
||||
for (Map.Entry<String, JsonElement> jsonElementEntry : serializeObject.entrySet()) {
|
||||
try {
|
||||
Field declaredField = serializable.getClass().getDeclaredField(jsonElementEntry.getKey());
|
||||
declaredField.setAccessible(true);
|
||||
if (declaredField.isAnnotationPresent(DoNotSerialize.class)) {
|
||||
continue;
|
||||
}
|
||||
declaredField.setAccessible(true);
|
||||
Optional<TSerializerElementGeneral> serializer = Arrays.stream(TSerializerElementGeneral.values()).filter(serializerElements -> serializerElements.getSerializer().matches(declaredField.getType())).findFirst();
|
||||
if (serializer.isPresent()) {
|
||||
declaredField.set(serializable, serializer.get().getSerializer().read(jsonElementEntry.getValue().getAsString()));
|
||||
|
@ -1,9 +1,11 @@
|
||||
package me.skymc.taboolib.common.serialize;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author 坏黑
|
||||
@ -17,13 +19,13 @@ public class TSerializerExample {
|
||||
// 修改参数
|
||||
date.number = 100;
|
||||
// 序列化
|
||||
String value = date.write();
|
||||
String value = date.writeBase64();
|
||||
// 打印
|
||||
System.out.println(value);
|
||||
// 创建新的对象
|
||||
SimpleData dataCopy = new SimpleData();
|
||||
// 反序列化
|
||||
dataCopy.read(value);
|
||||
dataCopy.readBase64(value);
|
||||
// 打印
|
||||
System.out.println(dataCopy);
|
||||
}
|
||||
@ -43,10 +45,14 @@ public class TSerializerExample {
|
||||
|
||||
/**
|
||||
* 特殊类型需要进行手动序列化
|
||||
* 本工具提供了基本容器的序列化方法
|
||||
* 标注 @TSerializeCollection 或 @TSerializeMap 来进行自动序列化(未完成)
|
||||
*/
|
||||
// @TSerializeCollection
|
||||
private List<Double> list = Lists.newArrayList(1.0, 2.0, 3.0);
|
||||
|
||||
// @TSerializeMap
|
||||
private Map<String, String> map = ImmutableMap.of("abc", "def");
|
||||
|
||||
/**
|
||||
* 跳过序列化
|
||||
*/
|
||||
@ -59,23 +65,16 @@ public class TSerializerExample {
|
||||
*/
|
||||
@Override
|
||||
public void read(String fieldName, String value) {
|
||||
switch (fieldName) {
|
||||
case "list": {
|
||||
// List 类型可以直接通过 TSerializer 提供的预设方法进行反序列化
|
||||
TSerializer.readCollection(list, value, TSerializerElementGeneral.DOUBLE);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (fieldName.equals("list")) {
|
||||
// List 类型可以直接通过 TSerializer 提供的预设方法进行反序列化
|
||||
TSerializer.readCollection(list, value, TSerializerElementGeneral.DOUBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String write(String fieldName, Object value) {
|
||||
switch (fieldName) {
|
||||
case "list": {
|
||||
// 序列化同理
|
||||
return TSerializer.writeCollection((Collection) value, TSerializerElementGeneral.DOUBLE);
|
||||
}
|
||||
if (fieldName.equals("list")) {
|
||||
return TSerializer.writeCollection((Collection) value, TSerializerElementGeneral.DOUBLE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package me.skymc.taboolib.common.serialize.container;
|
||||
|
||||
import me.skymc.taboolib.common.serialize.TSerializerElement;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-10-05 12:11
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TSerializeCollection {
|
||||
|
||||
Class<? extends Collection> type() default ArrayList.class;
|
||||
|
||||
Class<? extends TSerializerElement> element() default TSerializerElement.class;
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package me.skymc.taboolib.common.serialize.container;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-10-05 12:11
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TSerializeMap {
|
||||
|
||||
Class<? extends Map> type() default HashMap.class;
|
||||
|
||||
}
|
@ -32,9 +32,7 @@ public class SQLColumn extends IColumn {
|
||||
|
||||
/**
|
||||
* CHAR 类型常用构造器
|
||||
*
|
||||
* @param columnType
|
||||
* @param columnName
|
||||
* new SQLColumn(SQLColumnType.CHAR, 1, "data");
|
||||
*/
|
||||
public SQLColumn(SQLColumnType columnType, int m, String columnName) {
|
||||
this(columnType, m, 0, columnName, null);
|
||||
@ -56,6 +54,10 @@ public class SQLColumn extends IColumn {
|
||||
this(columnType, 0, 0, columnName, defaultValue);
|
||||
}
|
||||
|
||||
public SQLColumn(SQLColumnType columnType, String columnName, Object defaultValue, SQLColumnOption... columnOptions) {
|
||||
this(columnType, 0, 0, columnName, defaultValue, columnOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完整构造器
|
||||
*
|
||||
|
@ -49,11 +49,11 @@ public class SQLTable {
|
||||
}
|
||||
|
||||
public String deleteQuery() {
|
||||
return Strings.replaceWithOrder("drop table if exists `{0}`" + tableName);
|
||||
return Strings.replaceWithOrder("drop table if exists `{0}`", tableName);
|
||||
}
|
||||
|
||||
public String cleanQuery() {
|
||||
return Strings.replaceWithOrder("delete from `{0}`" + tableName);
|
||||
return Strings.replaceWithOrder("delete from `{0}`", tableName);
|
||||
}
|
||||
|
||||
public String truncateQuery() {
|
||||
|
@ -19,6 +19,7 @@ public class RunnableQuery {
|
||||
private TaskStatement statement;
|
||||
private TaskResult result;
|
||||
private TaskResult resultNext;
|
||||
private TaskResult resultAutoNext;
|
||||
private Connection connection;
|
||||
private boolean autoClose;
|
||||
private String query;
|
||||
@ -47,6 +48,11 @@ public class RunnableQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RunnableQuery resultAutoNext(TaskResult result) {
|
||||
this.resultAutoNext = result;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RunnableQuery connection(Connection connection) {
|
||||
return connection(connection, false);
|
||||
}
|
||||
@ -113,6 +119,12 @@ public class RunnableQuery {
|
||||
return resultNext.execute(resultSet);
|
||||
} else if (result != null) {
|
||||
return result.execute(resultSet);
|
||||
} else if (resultAutoNext != null) {
|
||||
Object result = null;
|
||||
while (resultSet.next()) {
|
||||
result = resultAutoNext.execute(resultSet);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -30,16 +30,6 @@ public class SQLiteColumn extends IColumn {
|
||||
this(columnType, 0, 0, columnName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* CHAR 类型常用构造器
|
||||
*
|
||||
* @param columnType
|
||||
* @param columnName
|
||||
*/
|
||||
public SQLiteColumn(SQLiteColumnType columnType, int m, String columnName) {
|
||||
this(columnType, m, 0, columnName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 主键 类型常用构造器
|
||||
* new SQLColumn(SQLiteColumnType.TEXT, "username", SQLiteColumnOption.PRIMARY_KEY, SQLiteColumnOption.AUTO_INCREMENT);
|
||||
@ -56,6 +46,10 @@ public class SQLiteColumn extends IColumn {
|
||||
this(columnType, 0, 0, columnName, defaultValue);
|
||||
}
|
||||
|
||||
public SQLiteColumn(SQLiteColumnType columnType, String columnName, Object defaultValue, SQLiteColumnOption... columnOptions) {
|
||||
this(columnType, 0, 0, columnName, defaultValue, columnOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完整构造器
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user