v1.4
This commit is contained in:
parent
fa51661a52
commit
3c454b0195
|
@ -9,6 +9,10 @@ public interface InsertBuilder<T extends SQLAction<?>> {
|
||||||
|
|
||||||
String getTableName();
|
String getTableName();
|
||||||
|
|
||||||
|
boolean isIgnore();
|
||||||
|
|
||||||
|
InsertBuilder setIgnore(boolean ignore);
|
||||||
|
|
||||||
T setColumnNames(List<String> columnNames);
|
T setColumnNames(List<String> columnNames);
|
||||||
|
|
||||||
default T setColumnNames(String... columnNames) {
|
default T setColumnNames(String... columnNames) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ public abstract class InsertBuilderImpl<T extends SQLAction<?>>
|
||||||
extends AbstractSQLBuilder implements InsertBuilder<T> {
|
extends AbstractSQLBuilder implements InsertBuilder<T> {
|
||||||
|
|
||||||
protected final String tableName;
|
protected final String tableName;
|
||||||
|
protected boolean ignore;
|
||||||
|
|
||||||
public InsertBuilderImpl(@NotNull SQLManagerImpl manager, String tableName) {
|
public InsertBuilderImpl(@NotNull SQLManagerImpl manager, String tableName) {
|
||||||
super(manager);
|
super(manager);
|
||||||
|
@ -23,8 +24,19 @@ public abstract class InsertBuilderImpl<T extends SQLAction<?>>
|
||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String buildSQL(String tableName, List<String> columnNames) {
|
@Override
|
||||||
return buildSQL("INSERT IGNORE INTO", tableName, columnNames);
|
public boolean isIgnore() {
|
||||||
|
return ignore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InsertBuilder setIgnore(boolean ignore) {
|
||||||
|
this.ignore = ignore;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static String buildSQL(String tableName, boolean ignore, List<String> columnNames) {
|
||||||
|
return buildSQL("INSERT "+(ignore ? "IGNORE " : "")+"INTO", tableName, columnNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String buildSQL(String sqlPrefix, String tableName, List<String> columnNames) {
|
protected static String buildSQL(String sqlPrefix, String tableName, List<String> columnNames) {
|
||||||
|
|
|
@ -204,7 +204,7 @@ public class SQLManagerImpl implements SQLManager {
|
||||||
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateBatchAction<Integer> setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateBatchAction<Integer> setColumnNames(List<String> columnNames) {
|
||||||
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), isIgnore(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ public class SQLManagerImpl implements SQLManager {
|
||||||
return new InsertBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
return new InsertBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateAction<Integer> setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateAction<Integer> setColumnNames(List<String> columnNames) {
|
||||||
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), isIgnore(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user