
br.com.objectos.schema.info.SchemaColumnMethod Maven / Gradle / Ivy
/*
* Copyright 2015 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.schema.info;
import java.util.List;
import javax.lang.model.element.Modifier;
import br.com.objectos.core.util.MoreCollectors;
import br.com.objectos.db.SortOrder;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
/**
* @author [email protected] (Marcio Endo)
*/
class SchemaColumnMethod extends ColumnMethod {
private final List referencedColumnInfoList;
public SchemaColumnMethod(ColumnInfoMethodInfo columnInfo,
ColumnName columnName,
List referencedColumnInfoList) {
super(columnInfo, columnName);
this.referencedColumnInfoList = referencedColumnInfoList;
}
@Override
public TypeSpec innerAnnotation(SchemaName schemaName, TableName tableName) {
return innerAnnotationBuilder(schemaName, tableName)
.addMethod(comparison())
.addMethod(orderBy())
.build();
}
@Override
List innerClassMethodList() {
return referencedColumnInfoList.stream()
.map(ColumnInfoAnnotationInfo::columnClassMethod)
.collect(MoreCollectors.toImmutableList());
}
private MethodSpec comparison() {
Class> comparisonOperatorClass = columnInfo().comparisonOperatorClass();
return MethodSpec.methodBuilder("comparison")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.defaultValue("$T.$L", comparisonOperatorClass, columnInfo().comparisonOperatorDefaultValue())
.returns(comparisonOperatorClass)
.build();
}
private MethodSpec orderBy() {
return MethodSpec.methodBuilder("orderBy")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.defaultValue("$T.$L", SortOrder.class, SortOrder.ASC)
.returns(SortOrder.class)
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy