|
@@ -13,34 +13,34 @@ import java.lang.reflect.Field;
|
|
|
|
|
|
@SuppressWarnings("UnusedReturnValue")
|
|
|
@AllArgsConstructor
|
|
|
-public class Fields<T> {
|
|
|
+public class Select<T> {
|
|
|
|
|
|
private final Sql<T> sql;
|
|
|
|
|
|
- public <S, V> Fields<T> select(SFunction<S, V> function) {
|
|
|
+ public <S, V> Select<T> select(SFunction<S, V> function) {
|
|
|
sql.fieldList.add(sql.getSqlFieldName(function));
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> select(String alias, SFunction<S, V> function) {
|
|
|
+ public <S, V> Select<T> select(String alias, SFunction<S, V> function) {
|
|
|
sql.fieldList.add(sql.getSqlFieldName(alias, function));
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> select(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> select(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add(sql.getSqlFieldName(function) + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> select(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> select(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add(sql.getSqlFieldName(alias, function) + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
@SafeVarargs
|
|
|
- public final <S, V> Fields<T> select(SFunction<S, V>... functions) {
|
|
|
+ public final <S, V> Select<T> select(SFunction<S, V>... functions) {
|
|
|
for (SFunction<S, V> function : functions) {
|
|
|
select(function);
|
|
|
}
|
|
@@ -48,71 +48,71 @@ public class Fields<T> {
|
|
|
}
|
|
|
|
|
|
@SafeVarargs
|
|
|
- public final <S, V> Fields<T> select(String alias, SFunction<S, V>... functions) {
|
|
|
+ public final <S, V> Select<T> select(String alias, SFunction<S, V>... functions) {
|
|
|
for (SFunction<S, V> function : functions) {
|
|
|
select(alias, function);
|
|
|
}
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Fields<T> distinct() {
|
|
|
+ public Select<T> distinct() {
|
|
|
sql.distinct = true;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> max(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> max(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("MAX(" + sql.getSqlFieldName(function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> max(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> max(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("MAX(" + sql.getSqlFieldName(alias, function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> min(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> min(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("MIN(" + sql.getSqlFieldName(function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> min(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> min(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("MIN(" + sql.getSqlFieldName(alias, function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> count(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> count(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("COUNT(" + sql.getSqlFieldName(function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> count(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> count(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("COUNT(" + sql.getSqlFieldName(alias, function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> sum(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> sum(SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("SUM(" + sql.getSqlFieldName(function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public <S, V> Fields<T> sum(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
+ public <S, V> Select<T> sum(String alias, SFunction<S, V> function, SFunction<T, ?> asFunction) {
|
|
|
String as = PropertyNamer.methodToProperty(LambdaUtils.extract(asFunction).getImplMethodName());
|
|
|
sql.fieldList.add("SUM(" + sql.getSqlFieldName(alias, function) + ")" + StringPool.SPACE + as);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Fields<T> selectAll(Class<?> cls) {
|
|
|
+ public Select<T> selectAll(Class<?> cls) {
|
|
|
return selectAll(sql.getTableAlias(cls), cls);
|
|
|
}
|
|
|
|
|
|
- public Fields<T> selectAll(String alias, Class<?> cls) {
|
|
|
+ public Select<T> selectAll(String alias, Class<?> cls) {
|
|
|
Field[] fields = ReflectUtil.getFields(cls);
|
|
|
for (Field field : fields) {
|
|
|
String fieldName = ReflectUtil.getFieldName(field);
|