use of ru.curs.celesta.score.ColumnMeta in project celesta by CourseOrchestra.
the class CursorGenerator method buildCurrentValues.
private MethodSpec buildCurrentValues(Map<String, ? extends ColumnMeta<?>> columns) {
ArrayTypeName resultType = ArrayTypeName.of(Object.class);
MethodSpec.Builder builder = MethodSpec.methodBuilder("_currentValues").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(resultType);
String spec = "return new Object[] {" + columns.values().stream().map(c -> "$N").collect(Collectors.joining(", ")) + "}";
builder.addStatement(spec, columns.values().stream().map(ColumnMeta::getName).map(this::camelize).toArray());
return builder.build();
}
use of ru.curs.celesta.score.ColumnMeta in project celesta by CourseOrchestra.
the class CursorGenerator method buildClearBuffer.
private MethodSpec buildClearBuffer(Map<String, ? extends ColumnMeta<?>> columns, Set<Column<?>> pk) {
ParameterSpec param = ParameterSpec.builder(boolean.class, "withKeys").build();
MethodSpec.Builder builder = MethodSpec.methodBuilder("_clearBuffer").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(param);
if (!pk.isEmpty()) {
builder.beginControlFlow("if ($N)", param.name);
pk.stream().forEach(c -> builder.addStatement("this.$N = null", camelize(c.getName())));
builder.endControlFlow();
}
columns.entrySet().stream().filter(e -> !pk.contains(e.getValue())).forEach(e -> builder.addStatement("this.$N = null", camelize(e.getKey())));
return builder.build();
}
use of ru.curs.celesta.score.ColumnMeta in project celesta by CourseOrchestra.
the class CursorGenerator method buildSetAutoIncrement.
private MethodSpec buildSetAutoIncrement(Map<String, ? extends ColumnMeta<?>> columns) {
MethodSpec.Builder builder = MethodSpec.methodBuilder("_setAutoIncrement").addModifiers(Modifier.PROTECTED).addAnnotation(Override.class);
ParameterSpec param = ParameterSpec.builder(int.class, "val").build();
builder.addParameter(param);
columns.entrySet().stream().filter(e -> e.getValue() instanceof IntegerColumn).filter(e -> ((IntegerColumn) e.getValue()).getSequence() != null).findAny().ifPresent(e -> builder.addStatement("this.$N = $N", camelize(e.getKey()), param.name));
return builder.build();
}
use of ru.curs.celesta.score.ColumnMeta in project celesta by CourseOrchestra.
the class BasicCursor method orderBy.
/**
* Sets sorting.
*
* @param names array of fields for sorting
*/
@Deprecated
public final void orderBy(String... names) {
ColumnMeta<?>[] columns = new ColumnMeta<?>[names.length];
for (int i = 0; i < names.length; i++) {
final String name = names[i];
Matcher m = COLUMN_NAME.matcher(name);
if (!m.matches()) {
throw new CelestaException("orderby() argument '%s' should match pattern <column name> [ASC|DESC]", name);
}
final String colName = m.group(1);
final String colOrdering = Optional.ofNullable(m.group(2)).map(String::trim).orElse(null);
ColumnMeta<?> column = validateColumnName(colName);
if ("asc".equalsIgnoreCase(colOrdering)) {
column = column.asc();
} else if ("desc".equalsIgnoreCase(colOrdering)) {
column = column.desc();
}
columns[i] = column;
}
orderBy(columns);
}
use of ru.curs.celesta.score.ColumnMeta in project celesta by CourseOrchestra.
the class NavigationQueriesMakerTest method test6.
@Test
public void test6() {
Params p = new Params(a("A"), a(false), a(true));
p.setNullsFirst(false);
WhereTermsMaker c = new WhereTermsMaker(p);
assertEquals("((\"A\" > ?) or (\"A\" is null))", c.getWhereTerm('>').getWhere());
Map<String, AbstractFilter> filters = new HashMap<>();
filters.put("A", new SingleValue(4));
p.setFilters(filters);
// Range filter must makes the system treat field as not nullable!
assertEquals("((\"A\" = ?) and (\"A\" > ?))", c.getWhereTerm('>').getWhere());
filters.put("A", new Range(4, 5));
assertEquals("((\"A\" between ? and ?) and (\"A\" > ?))", c.getWhereTerm('>').getWhere());
filters.put("A", new Filter("null|'foo'", new ColumnMeta<Void>() {
@Override
public String getName() {
return null;
}
@Override
public String jdbcGetterName() {
return null;
}
@Override
public String getCelestaType() {
return StringColumn.VARCHAR;
}
@Override
public Class<?> getJavaClass() {
return String.class;
}
@Override
public boolean isNullable() {
return true;
}
@Override
public String getCelestaDoc() {
return "";
}
}));
filters.put("B", new SingleValue(1));
assertEquals("((\"B\" = ?) and (\"A\" is null or \"A\" = 'foo') and ((\"A\" > ?) or (\"A\" is null)))", c.getWhereTerm('>').getWhere());
}
Aggregations