Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2017 Jerónimo López Bezanilla
*
* 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 org.jfleet;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import org.jfleet.EntityFieldType.FieldTypeEnum;
import org.jfleet.inspection.EntityFieldAccesorFactory;
import org.jfleet.inspection.JFleetEntityInspector;
public class EntityInfoBuilder {
private final JFleetEntityInspector entityInspector;
private final Class> entityClass;
private final String tableName;
private final List columns = new ArrayList<>();
private final EntityFieldAccesorFactory accesorFactory = new EntityFieldAccesorFactory();
public EntityInfoBuilder(Class entityClass) {
this(entityClass, null);
}
public EntityInfoBuilder(Class entityClass, String tableName) {
this.entityInspector = new JFleetEntityInspector(entityClass);
this.entityClass = entityClass;
this.tableName = tableName;
}
// Information by fieldPath is automatically inspected by reflection finding the
// field accessed
public EntityInfoBuilder addField(String fieldPath) {
String columnName = fieldPath.toLowerCase().replaceAll("\\.", "_");
return addField(fieldPath, columnName, false);
}
public EntityInfoBuilder addFields(String... fieldPaths) {
for (String fieldPath : fieldPaths) {
addField(fieldPath);
}
return this;
}
public EntityInfoBuilder addField(String fieldPath, String columnName) {
return addField(fieldPath, columnName, false);
}
public EntityInfoBuilder addField(String fieldPath, String columnName, boolean identityId) {
EntityFieldType fieldType = entityInspector.buildFieldTypeByPath(fieldPath, Optional.empty());
return addField(fieldPath, columnName, fieldType, identityId);
}
public EntityInfoBuilder addField(String fieldPath, String columnName, FieldTypeEnum fieldTypeEnum) {
return addField(fieldPath, columnName, fieldTypeEnum, false);
}
public EntityInfoBuilder addField(String fieldPath, String columnName, FieldTypeEnum fieldTypeEnum,
boolean identityId) {
EntityFieldType fieldType = entityInspector.buildFieldTypeByPath(fieldPath, Optional.of(fieldTypeEnum));
return addField(fieldPath, columnName, fieldType, identityId);
}
public EntityInfoBuilder addField(String fieldPath, String columnName, EntityFieldType fieldType,
boolean identityId) {
EntityFieldType type = new EntityFieldType(fieldType.getFieldType(), fieldType.isPrimitive(), identityId);
return addField(new FieldInfo(fieldPath, columnName, type));
}
public EntityInfoBuilder addField(FieldInfo fieldInfo) {
validate(fieldInfo.getColumnName());
Function