
br.com.objectos.schema.info.ThisGenerationInfo 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.Optional;
import br.com.objectos.code.AnnotationInfo;
import br.com.objectos.code.MethodInfo;
import br.com.objectos.code.SimpleTypeInfo;
import br.com.objectos.schema.annotation.AutoIncrement;
import br.com.objectos.testable.Equality;
import br.com.objectos.testable.Tester;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
/**
* @author [email protected] (Marcio Endo)
*/
abstract class ThisGenerationInfo implements GenerationInfo {
public static ThisGenerationInfo of(MethodInfo methodInfo) {
Optional maybeAutoIncrement = methodInfo.annotationInfo(AutoIncrement.class);
if (maybeAutoIncrement.isPresent()) {
SimpleTypeInfo simpleTypeInfo = methodInfo.returnTypeInfo();
return ThisAutoIncrementGenerationInfo.of(methodInfo, simpleTypeInfo);
}
return ThisNoGenerationInfo.get();
}
public void generatedValue(TypeSpec.Builder innerAnnotation) {
}
public void insertValuesBody0(CodeBlock.Builder body, ClassName columnClassName, ColumnName columnName) {
body.add(" .value(new $T($L))\n", columnClassName, columnName.identifier());
}
public void insertValuesBody1(CodeBlock.Builder body, ClassName columnClassName, ColumnName columnName) {
body.add(" .value($L)\n", columnName.identifier());
}
public TypeName insertValuesParameterTypeName(TypeName valueTypeName) {
return valueTypeName;
}
@Override
public Equality isEqualTo(Object o) {
return Tester.of(ThisGenerationInfo.class).test(this, o);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy