本文整理汇总了Java中lombok.experimental.Builder类的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Builder类属于lombok.experimental包,在下文中一共展示了Builder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import lombok.experimental.Builder; //导入依赖的package包/类
public void write(@NonNull Filer filer) throws IOException {
final TypeSpec.Builder classBuilder = classBuilder(className)
.addModifiers(PUBLIC_FINAL)
.superclass(ParameterizedTypeName.get(TABLE, structureElementTypeName))
.addMethod(constructor())
.addField(structureField())
.addFields(columnFields(filer))
.addMethod(aliasOverride())
.addMethod(mapper());
if (hasAnyPersistedComplexColumns && !isView) {
classBuilder.addMethod(queryPartsAddOverride(METHOD_ADD_DEEP_QUERY_PARTS));
if (isQueryPartNeededForShallowQuery) {
classBuilder.addMethod(queryPartsAddOverride(METHOD_ADD_SHALLOW_QUERY_PARTS));
}
}
if (isView) {
classBuilder.addMethod(perfectSelectionOverride());
}
writeSource(filer, classBuilder.build());
}
示例2: write
import lombok.experimental.Builder; //导入依赖的package包/类
public TypeSpec write(@NonNull Filer filer) throws IOException {
final TypeSpec.Builder classBuilder = TypeSpec.classBuilder(className)
.addModifiers(CLASS_MODIFIERS)
.addTypeVariable(parentTableType)
.addTypeVariable(nullabilityType)
.superclass(superClass)
.addMethod(constructor())
.addMethod(toSqlArg())
.addMethod(aliasOverride());
if (transformerElement != null) {
classBuilder.addMethod(cursorParserOverride(transformerElement))
.addMethod(statementParserOverride(transformerElement));
}
if (unique) {
classBuilder.addSuperinterface(ParameterizedTypeName.get(UNIQUE, nullabilityType));
}
final TypeSpec type = classBuilder.build();
writeSource(filer, type);
return type;
}
示例3: addBulkUpdateComplexColumnIgnoreConflictLoopBody
import lombok.experimental.Builder; //导入依赖的package包/类
private void addBulkUpdateComplexColumnIgnoreConflictLoopBody(MethodSpec.Builder builder) {
builder.addStatement("final $T $L = $L.newTransaction()",
TRANSACTION, TRANSACTION_VARIABLE, DB_CONNECTION_VARIABLE)
.beginControlFlow("try");
addNullableIdCheckIfNeeded(builder);
addBindToUpdateStatement(builder);
builder.beginControlFlow("if ($L.executeUpdateDelete() > 0 && $T.$L($L, $L.getDbConnection(), $L, $L))",
STATEMENT_VARIABLE,
daoClassName,
METHOD_CALL_INTERNAL_UPDATE_ON_COMPLEX_COLUMNS,
ENTITY_VARIABLE,
MANAGER_VARIABLE,
OPERATION_HELPER_VARIABLE,
OPERATION_BY_COLUMNS_VARIABLE)
.addStatement("$L.markSuccessful()", TRANSACTION_VARIABLE)
.addStatement("atLeastOneSuccess = true")
.endControlFlow()
.nextControlFlow("catch ($T e)", OPERATION_FAILED_EXCEPTION)
.addStatement("continue")
.nextControlFlow("finally")
.addStatement("$L.end()", TRANSACTION_VARIABLE)
.endControlFlow();
}
示例4: bulkPersistExecute
import lombok.experimental.Builder; //导入依赖的package包/类
private MethodSpec bulkPersistExecute() {
final MethodSpec.Builder builder = MethodSpec.methodBuilder(METHOD_EXECUTE)
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(TypeName.BOOLEAN)
.addCode(entityDbVariablesForOperationBuilder(tableElement));
addIgnoreNullValuesControlFlowStart(builder);
addBulkPersistExecuteForNullableColumns(builder);
builder.nextControlFlow("else");
addBulkPersistExecuteForFixedColumns(builder);
builder.endControlFlow();
return builder.build();
}
示例5: addBulkPersistExecuteForFixedColumns
import lombok.experimental.Builder; //导入依赖的package包/类
private void addBulkPersistExecuteForFixedColumns(MethodSpec.Builder builder) {
addBulkPersistTopBlockForFixedColumns(builder, true);
if (tableElement.hasAnyPersistedComplexColumns()) {
ModelPersistingGenerator.addTransactionEndBlock(builder,
allTableTriggers,
"return true",
"return false",
true);
builder.endControlFlow(); // .ignoreConflict
} else {
ModelPersistingGenerator.addTransactionEndBlock(builder,
allTableTriggers,
CodeBlock.builder()
.addStatement("success = atLeastOneSuccess")
.build(),
CodeBlock.builder()
.addStatement("return atLeastOneSuccess")
.build(),
"return false",
true);
}
}
示例6: addImmutableValueRecursiveColumnRetrieveForCreatorWithoutSelection
import lombok.experimental.Builder; //导入依赖的package包/类
static void addImmutableValueRecursiveColumnRetrieveForCreatorWithoutSelection(CodeBlock.Builder builder, CodeBlock.Builder preCodeBuilder, BaseColumnElement columnElement, FormatData valueSetterFormat, String offsetString, FormatData complexCall, String complexMethodName, boolean allSelection) {
final String columnElementName = columnElement.getElementName();
final TypeName referencedTableTypeName = columnElement.getReferencedTable().getTableElementTypeName();
final boolean columnElementNullable = columnElement.isNullable();
if (columnElementNullable) {
preCodeBuilder.addStatement("$T $L = null", referencedTableTypeName, columnElementName)
.beginControlFlow("if (!cursor.isNull($L))", offsetString)
.addStatement(String.format("$L = %s", complexCall.getFormat()),
complexCall.getWithOtherArgsBefore(columnElementName));
if (!allSelection) {
preCodeBuilder.nextControlFlow("else")
.add(columnOffsetCorrectionStatement(columnElement, complexMethodName));
}
preCodeBuilder.endControlFlow();
addRetrieveClause(builder, valueSetterFormat, columnElementName);
} else {
if (allSelection) {
addRetrieveClause(builder, valueSetterFormat, complexCall.getFormat(), complexCall.getArgs());
} else {
preCodeBuilder.addStatement(String.format("final $T $L = %s", complexCall.getFormat()),
complexCall.getWithOtherArgsBefore(referencedTableTypeName, columnElementName));
addRetrieveClause(builder, valueSetterFormat, columnElementName);
}
}
}
示例7: addImmutableValueNonRecursiveColumnRetrieve
import lombok.experimental.Builder; //导入依赖的package包/类
static void addImmutableValueNonRecursiveColumnRetrieve(CodeBlock.Builder builder, CodeBlock.Builder preCodeBuilder,
String parentTableName,
BaseColumnElement columnElement, FormatData valueSetterFormat,
String offsetString, boolean forBuilder,
String settableValue,
boolean fromSelection) {
final String columnElementName = columnElement.getElementName();
final TableElement referencedTable = columnElement.getReferencedTable();
final FormatData complexColumnNewInstanceCall = complexColumnNewInstanceWithOnlyIdCall(settableValue, referencedTable);
addSimpleSelectionCheck(builder, preCodeBuilder, parentTableName, columnElement, offsetString, forBuilder, fromSelection);
if (forBuilder || !columnElement.isNullable()) {
addRetrieveClause(builder, valueSetterFormat, complexColumnNewInstanceCall.getFormat(), complexColumnNewInstanceCall.getArgs());
} else {
preCodeBuilder.addStatement("$T $L = null", referencedTable.getTableElementTypeName(), columnElementName);
if (fromSelection) {
preCodeBuilder.beginControlFlow("if ($1L != null && !cursor.isNull($1L))", offsetString);
} else {
preCodeBuilder.beginControlFlow("if (!cursor.isNull($L))", offsetString);
}
preCodeBuilder.addStatement(complexColumnNewInstanceCall.formatInto("$L = %s"),
complexColumnNewInstanceCall.getWithOtherArgsBefore(columnElementName))
.endControlFlow();
addRetrieveClause(builder, valueSetterFormat, columnElementName);
}
addSimpleSelectionCheckEnd(builder, columnElement, forBuilder, fromSelection);
}
示例8: addSimpleSelectionCheck
import lombok.experimental.Builder; //导入依赖的package包/类
static void addSimpleSelectionCheck(CodeBlock.Builder builder, CodeBlock.Builder preCodeBuilder,
String parentTableName,
BaseColumnElement columnElement,
String offsetString, boolean forBuilder, boolean fromSelection) {
if (fromSelection) {
if (forBuilder) {
if (columnElement.isNullable()) {
builder.beginControlFlow("if ($1L != null && !cursor.isNull($1L))", offsetString);
} else if (columnElement.hasNullableAnnotation()) {
builder.beginControlFlow("if ($1L != null)", offsetString);
} else {
addColumnMissingFromSelectionException(builder, columnElement, offsetString, parentTableName);
}
} else {
if (!columnElement.isNullable()) {
addColumnMissingFromSelectionException(preCodeBuilder, columnElement, offsetString, parentTableName);
}
}
}
}
示例9: buildForMutableObject
import lombok.experimental.Builder; //导入依赖的package包/类
private void buildForMutableObject() {
if (tableElement == null) {
throw new IllegalStateException("Cannot build for mutable object when table element is missing");
}
forAllBuilders(addMutableTableNewInstanceVariable());
final List<ColumnElement> allColumns = tableElement.getAllColumns();
for (int i = 0, columnsCount = allColumns.size(); i < columnsCount; i++) {
final ColumnElement columnElement = allColumns.get(i);
buildForAllValuesRetrievingMutableObject(columnElement, i, columnsCount);
buildForSelectionValuesRetrievingMutableObject(columnElement);
}
forAllBuilders(new Callback<CodeBlock.Builder>() {
@Override
public void call(CodeBlock.Builder builder) {
builder.addStatement("return $L", ENTITY_VARIABLE);
}
});
}
示例10: newInstanceWithOnlyId
import lombok.experimental.Builder; //导入依赖的package包/类
private MethodSpec newInstanceWithOnlyId(TableElement tableElement) {
final ColumnElement idColumn = tableElement.getIdColumn();
final TypeName tableElementTypeName = tableElement.getTableElementTypeName();
final MethodSpec.Builder builder = MethodSpec.methodBuilder(METHOD_NEW_INSTANCE_WITH_ONLY_ID)
.addModifiers(STATIC_METHOD_MODIFIERS)
.addParameter(idColumn.getDeserializedTypeName(), "id")
.returns(tableElementTypeName);
if (tableElement.isImmutable()) {
builder.addStatement("return $L", tableElement.getValueWriter().buildOneValueSetter("id", idColumn));
} else {
final FormatData deserializedValueSetter = idColumn.deserializedValueSetter(ENTITY_VARIABLE, "id", MANAGER_VARIABLE);
builder.addStatement("final $1T $2L = new $1T()", tableElementTypeName, ENTITY_VARIABLE)
.addStatement(deserializedValueSetter.getFormat(), deserializedValueSetter.getArgs())
.addStatement("return $L", ENTITY_VARIABLE);
}
return builder.build();
}
示例11: addMutableTableComplexColumnRetrieveFromSelection
import lombok.experimental.Builder; //导入依赖的package包/类
private void addMutableTableComplexColumnRetrieveFromSelection(CodeBlock.Builder builder, String complexMethodName, String offsetString, ColumnElement columnElement, String... args) {
final FormatData settableValue = callToComplexColumnRetrieve(complexMethodName, columnElement, args);
final String tmpVariableName = columnElement.getElementName();
final TableElement referencedTable = columnElement.getReferencedTable();
builder.addStatement(settableValue.formatInto("final $T $L = %s"), settableValue
.getWithOtherArgsBefore(
referencedTable.getTableElementTypeName(),
tmpVariableName))
.beginControlFlow("if ($L != null)", tmpVariableName);
FormatData deserializedValueSetter = columnElement.deserializedValueSetter(ENTITY_VARIABLE, tmpVariableName, MANAGER_VARIABLE);
builder.addStatement(deserializedValueSetter.getFormat(), deserializedValueSetter.getArgs())
.nextControlFlow("else");
if (!referencedTable.canBeInstantiatedWithOnlyId()) {
builder.addStatement("throw new $T(\"Complex column $L cannot be instantiated with only id\")", SQL_EXCEPTION, columnElement.getElementName());
} else {
addMutableTableComplexColumnWithOnlyIdForRetrieveFromPosition(builder, columnElement, offsetString);
}
builder.endControlFlow();
builder.endControlFlow(); // ends outer if
addSelectAllFromTableNextControlFlowCheck(builder, columnElement);
addMutableTableComplexColumnRetrieve(builder, complexMethodName, columnElement, args);
}
示例12: bindToInsertStatement
import lombok.experimental.Builder; //导入依赖的package包/类
private MethodSpec bindToInsertStatement() {
MethodSpec.Builder builder = MethodSpec.methodBuilder(METHOD_BIND_TO_INSERT_STATEMENT)
.addModifiers(STATIC_METHOD_MODIFIERS)
.addParameter(SUPPORT_SQLITE_STATEMENT, "statement")
.addParameter(entityParameter(tableElementTypeName))
.addStatement("statement.clearBindings()");
addImmutableIdsParameterIfNeeded(builder, tableElement);
int colPos = 1;
int immutableIdColPos = 0;
for (ColumnElement columnElement : tableElement.getAllColumns()) {
if (columnElement.isId() && columnElement.isAutoincrementId()) {
continue;
}
if (columnElement.isHandledRecursively() && columnElement.isReferencedTableImmutable()) {
addBindColumnFromProvidedIdsBlock(builder, columnElement, colPos, immutableIdColPos);
immutableIdColPos++;
} else {
addBindColumnToStatementBlock(builder, colPos, columnElement);
}
colPos++;
}
return builder.build();
}
示例13: internalInsert
import lombok.experimental.Builder; //导入依赖的package包/类
private MethodSpec internalInsert() {
final MethodSpec.Builder builder = MethodSpec.methodBuilder(METHOD_INTERNAL_INSERT)
.addModifiers(STATIC_METHOD_MODIFIERS)
.addParameter(entityParameter(tableElementTypeName))
.addParameter(entityDbManagerParameter())
.addParameter(operationHelperParameter())
.returns(LONG);
addCallToInternalInsertOnComplexColumnsIfNeeded(entityEnvironment, builder);
addInsertLoggingStatement(builder, tableElement);
builder.addStatement("final long id")
.addCode(insertStatementVariableFromOpHelper(tableElement, STATEMENT_VARIABLE))
.beginControlFlow("synchronized ($L)", STATEMENT_VARIABLE);
addBindToInsertStatement(builder, tableElement, daoClassName, STATEMENT_VARIABLE);
builder.addStatement("id = $L.executeInsert()", STATEMENT_VARIABLE)
.endControlFlow();
addAfterInsertLoggingStatement(builder);
addCheckIdValidity(builder, FAILED_TO_INSERT_ERR_MSG);
addSetIdStatementIfNeeded(tableElement, daoClassName, builder);
return builder
.addStatement("return id")
.build();
}
示例14: insertExecute
import lombok.experimental.Builder; //导入依赖的package包/类
private MethodSpec insertExecute(MethodSpec insert) {
final MethodSpec.Builder builder = MethodSpec.methodBuilder(METHOD_EXECUTE)
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(LONG)
.addCode(entityDbVariablesForOperationBuilder(tableElement))
.addCode(opHelperVariable(INSERT));
final boolean hasAnyPersistedComplexColumns = tableElement.hasAnyPersistedComplexColumns();
addTopMethodStartBlock(builder, hasAnyPersistedComplexColumns);
builder.addStatement("final $T id = $N($L, $L, $L)",
LONG, insert, ENTITY_VARIABLE, MANAGER_VARIABLE, OPERATION_HELPER_VARIABLE);
final String returnStatement = "return id";
final String failReturnStatement = "return -1";
ModelPersistingGenerator.addTopMethodEndBlock(builder,
allTableTriggers,
hasAnyPersistedComplexColumns,
returnStatement,
failReturnStatement,
true);
return builder.build();
}
示例15: addBulkInsertComplexColumnIgnoreConflictLoopBody
import lombok.experimental.Builder; //导入依赖的package包/类
private void addBulkInsertComplexColumnIgnoreConflictLoopBody(MethodSpec.Builder builder) {
builder.addStatement("final $T $L = $L.newTransaction()",
TRANSACTION, TRANSACTION_VARIABLE, DB_CONNECTION_VARIABLE)
.beginControlFlow("try");
addCallToInternalInsertOnComplexColumnsIfNeeded(entityEnvironment, builder);
addBindToInsertStatement(builder, tableElement, daoClassName, STATEMENT_VARIABLE);
builder.addStatement("final long id = $L.executeInsert()", STATEMENT_VARIABLE);
addAfterInsertLoggingStatement(builder);
builder.beginControlFlow("if (id != -1)");
addSetIdStatementIfNeeded(tableElement, daoClassName, builder);
builder.addStatement("$L.markSuccessful()", TRANSACTION_VARIABLE)
.addStatement("atLeastOneSuccess = true")
.endControlFlow()
.nextControlFlow("catch ($T e)", OPERATION_FAILED_EXCEPTION)
.addStatement("continue")
.nextControlFlow("finally")
.addStatement("$L.end()", TRANSACTION_VARIABLE)
.endControlFlow();
}