本文整理匯總了Java中org.springframework.roo.model.DataType.TYPE屬性的典型用法代碼示例。如果您正苦於以下問題:Java DataType.TYPE屬性的具體用法?Java DataType.TYPE怎麽用?Java DataType.TYPE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.springframework.roo.model.DataType
的用法示例。
在下文中一共展示了DataType.TYPE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initializeEntityDependenDefinitions
/**
* Initialize all entity name dependent methods-names and javaTypes
*/
private void initializeEntityDependenDefinitions() {
this.findAllMethodName = new JavaSymbolName(
"findAll".concat(StringUtils.capitalize(this.entityPlural)));
this.findMethodName = new JavaSymbolName("find".concat(StringUtils
.capitalize(entityName)));
this.getRevisionsMethodName = new JavaSymbolName("get".concat(
StringUtils.capitalize(entityName)).concat("Revisions"));
this.findRevisionsByDatesMethodName = new JavaSymbolName(
"find".concat(StringUtils.capitalize(entityName).concat(
"RevisionsByDates")));
this.findRevisionsMethodName = new JavaSymbolName(
"find".concat(StringUtils.capitalize(entityName).concat(
"Revisions")));
this.revisonItemTypeName = StringUtils.capitalize(entityName).concat(
"Revision");
this.revisonItemType = new JavaType(entity.getFullyQualifiedTypeName()
.concat(".").concat(revisonItemTypeName));
this.revisonItemListType = new JavaType(
LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
Arrays.asList(revisonItemType));
}
示例2: getMethodParamTypes
/**
* Returns the list of method parameter types.
*
* @param addParamsParameter if true will define
* <code>HashMap<String, Object> params</code> parameter
* @return
*/
private List<AnnotatedJavaType> getMethodParamTypes(
boolean addParamsParameter) {
List<AnnotatedJavaType> paramTypes = new ArrayList<AnnotatedJavaType>();
JavaType dialogType = getJavaTypeForClassName("DialogType");
paramTypes.add(new AnnotatedJavaType(dialogType,
new ArrayList<AnnotationMetadata>()));
paramTypes.add(new AnnotatedJavaType(JavaType.STRING,
new ArrayList<AnnotationMetadata>()));
paramTypes.add(new AnnotatedJavaType(JavaType.STRING,
new ArrayList<AnnotationMetadata>()));
if (addParamsParameter) {
List<JavaType> typeParams = new ArrayList<JavaType>();
typeParams.add(JavaType.STRING);
typeParams.add(new JavaType("java.lang.Object"));
JavaType hashMap = new JavaType("java.util.HashMap", 0,
DataType.TYPE, null, typeParams);
paramTypes.add(new AnnotatedJavaType(hashMap,
new ArrayList<AnnotationMetadata>()));
}
paramTypes.add(new AnnotatedJavaType(new JavaType(
"javax.servlet.http.HttpServletRequest"),
new ArrayList<AnnotationMetadata>()));
return paramTypes;
}
示例3: getListInnerClass
/**
* Gets Inner class to manage elements list for batch operations
*
* @return
*/
public ClassOrInterfaceTypeDetails getListInnerClass() {
// Generate inner class name
JavaType listInnerClassJavaType = new JavaType(destination
.getSimpleTypeName().concat("List"), 0, DataType.TYPE, null,
null);
// Create class builder
ClassOrInterfaceTypeDetailsBuilder classBuilder = new ClassOrInterfaceTypeDetailsBuilder(
getId(), Modifier.STATIC | Modifier.PUBLIC,
listInnerClassJavaType, PhysicalTypeCategory.CLASS);
// Add fields
FieldMetadata listField = getListInner_field("list", destination)
.build();
FieldMetadata selectedField = getListInner_field("selected",
new JavaType("Integer")).build();
classBuilder.addField(listField);
classBuilder.addField(selectedField);
// Adds getter/setter for list field
classBuilder.addMethod(getListInner_getter(listField));
classBuilder.addMethod(getListInner_setter(listField));
// Adds getter/setter for selected field
classBuilder.addMethod(getListInner_getter(selectedField));
classBuilder.addMethod(getListInner_setter(selectedField));
// Return generated class
return classBuilder.build();
}
示例4: getInitializer
@Override
public JavaType getInitializer() {
final List<JavaType> params = new ArrayList<JavaType>();
params.add(getGenericParameterTypeName());
return new JavaType(HASH_SET.getFullyQualifiedTypeName(), 0,
DataType.TYPE, null, params);
}
示例5: buildBodyGetRevisionsInstance
/**
* {@inheritDoc}
*/
@Override
public void buildBodyGetRevisionsInstance(InvocableMemberBodyBuilder body,
List<JavaSymbolName> parameterNames) {
JavaSymbolName identifierGetter = helper
.getGetterMethodNameForField(context.getIdentifier()
.getFieldName());
JavaType arrayListRevisionItems = new JavaType(
JdkJavaType.ARRAY_LIST.getFullyQualifiedTypeName(), 0,
DataType.TYPE, null,
Arrays.asList(context.getRevisonItemType()));
// if (getId() == null) {
body.appendFormalLine(String.format("if (%s() == null) {",
identifierGetter));
body.indent();
// // No persistent visit --> No history
body.appendFormalLine("// No persistent visit --> No history");
// return Collections.unmodifiableList(new ArrayList<VisitRevision>(0));
body.appendFormalLine(String.format(
"return %s.unmodifiableList(new %s(0));",
helper.getFinalTypeName(COLLECTIONS),
helper.getFinalTypeName(arrayListRevisionItems)));
// }
body.indentRemove();
body.appendFormalLine("}");
// return getVisitRevisions(getId(), fromDate, toDate, start, limit);
body.appendFormalLine(String.format(
"return %s(%s(), fromDate, toDate, start, limit);",
context.getGetRevisionsMethodName(), identifierGetter,
parameterNames.get(0), parameterNames.get(1),
parameterNames.get(2), parameterNames.get(3),
helper.getFinalTypeName(arrayListRevisionItems)));
}
示例6: getOneToManyMappedByField
private FieldMetadataBuilder getOneToManyMappedByField(
final JavaSymbolName fieldName,
final JavaSymbolName mappedByFieldName,
final String foreignTableName, final String foreignSchemaName,
final CascadeAction onUpdate, final CascadeAction onDelete) {
final JavaType element = DbreTypeUtils.findTypeForTableName(
managedEntities, foreignTableName, foreignSchemaName);
Validate.notNull(
element,
"Attempted to create one-to-many mapped-by field '%s' in '%s' %s",
fieldName, destination.getFullyQualifiedTypeName(),
getErrorMsg(foreignTableName + "." + foreignSchemaName));
final JavaType fieldType = new JavaType(
SET.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
Arrays.asList(element));
// Add @OneToMany annotation
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
final AnnotationMetadataBuilder oneToManyBuilder = new AnnotationMetadataBuilder(
ONE_TO_MANY);
oneToManyBuilder.addStringAttribute(MAPPED_BY,
mappedByFieldName.getSymbolName());
addCascadeType(oneToManyBuilder, onUpdate, onDelete);
annotations.add(oneToManyBuilder);
return new FieldMetadataBuilder(getId(), Modifier.PRIVATE, annotations,
fieldName, fieldType);
}
示例7: createRepository
/** {@inheritDoc} */
public void createRepository(JavaType interfaceType, JavaType domainType){
// Use Roo's Assert type for null checks
Validate.notNull(interfaceType, "Interface type required");
Validate.notNull(domainType, "Domain type required");
final String interfaceIdentifier = pathResolver.getFocusedCanonicalPath(Path.SRC_MAIN_JAVA, interfaceType);
if (fileManager.exists(interfaceIdentifier)) {
return; // Type exists already - nothing to do
}
// Build interface type.
final AnnotationMetadataBuilder interfaceAnnotationMetadata = new AnnotationMetadataBuilder(
ElasticsearchJavaType.ROO_REPOSITORY_ELASTICSEARCH);
interfaceAnnotationMetadata.addAttribute(new ClassAttributeValue(
new JavaSymbolName("domainType"), domainType));
final String interfaceMdId = PhysicalTypeIdentifier.createIdentifier(
interfaceType, pathResolver.getPath(interfaceIdentifier));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
interfaceMdId, Modifier.PUBLIC, interfaceType,
PhysicalTypeCategory.INTERFACE);
cidBuilder.addAnnotation(interfaceAnnotationMetadata.build());
final JavaType listType = new JavaType(Iterable.class.getName(), 0,
DataType.TYPE, null, Arrays.asList(domainType));
cidBuilder.addMethod(new MethodMetadataBuilder(interfaceMdId, 0,
new JavaSymbolName("findAll"), listType,
new InvocableMemberBodyBuilder()));
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
開發者ID:lbroudoux,項目名稱:spring-roo-addon-layers-repository-elasticsearch,代碼行數:30,代碼來源:ElasticsearchOperationsImpl.java
示例8: buildRevisionItemCreateListMethodBody
/**
* Builds method body (implementation) of
* XXXRevision.createList(list,reader)
*
* @param body
* @param context
* @param parameterNames
*/
private void buildRevisionItemCreateListMethodBody(
InvocableMemberBodyBuilder body, List<JavaSymbolName> parameterNames) {
JavaType arrayListRevison = new JavaType(
ARRAYLIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
Arrays.asList(context.getRevisonItemType()));
// ArrayList<VisitRevision> newList = new
// ArrayList<VisitRevision>(list.size());
body.appendFormalLine(String.format("%s newList = new %s(%s.size());",
helper.getFinalTypeName(arrayListRevison),
helper.getFinalTypeName(arrayListRevison),
parameterNames.get(0)));
// for (Object[] item : list) {
body.appendFormalLine(String.format("for (%s item : %s) {",
helper.getFinalTypeName(OBJECT_ARRAY), parameterNames.get(0)));
body.indent();
// newList.add(new VisitRevision((Visit) item[0],
// (HistoryRevisionEntity) item[1], (RevisionType) item[2]));
body.appendFormalLine(String
.format("newList.add(new %s((%s) item[0], (%s) item[1], (%s) item[2]));",
helper.getFinalTypeName(context.getRevisonItemType()),
StringUtils.capitalize(context.getEntityName()), helper
.getFinalTypeName(revisionEntityMetadata
.getType()), helper
.getFinalTypeName(REVISON_TYPE)));
// }
body.indentRemove();
body.appendFormalLine("}");
// return Collections.unmodifiableList(newList);
body.appendFormalLine(String.format(
"return %s.unmodifiableList(newList);",
helper.getFinalTypeName(COLLECTIONS)));
}
示例9: WebJpaBatchMetadata
public WebJpaBatchMetadata(String identifier, JavaType aspectName,
PhysicalTypeMetadata governorPhysicalTypeMetadata,
WebJpaBatchAnnotationValues annotationValues,
JpaBatchMetadata jpaBatchMetadata,
WebScaffoldAnnotationValues webScaffoldMetadataValue) {
super(identifier, aspectName, governorPhysicalTypeMetadata);
Validate.isTrue(isValid(identifier), "Metadata identification string '"
+ identifier + "' does not appear to be a valid");
this.helper = new WebItdBuilderHelper(this,
governorPhysicalTypeMetadata,
builder.getImportRegistrationResolver());
this.annotationValues = annotationValues;
this.service = annotationValues.getService();
Validate.notNull(service, String.format(
"Missing service value required for %s in %s",
WebJpaBatchAnnotationValues.WEB_JPA_BATCH_ANNOTATION
.getFullyQualifiedTypeName(),
governorPhysicalTypeMetadata.getType()
.getFullyQualifiedTypeName()));
this.jpaBatchMetadata = jpaBatchMetadata;
listOfIdentifiersType = jpaBatchMetadata.getListOfIdentifiersType();
listOfEntityType = jpaBatchMetadata.getListOfEntitiesType();
this.entity = jpaBatchMetadata.getEntity();
this.entityName = JavaSymbolName.getReservedWordSafeName(entity)
.getSymbolName();
this.entityIdentifier = jpaBatchMetadata.getEntityIdentifier();
listOfEntityName = new JavaSymbolName(
StringUtils.uncapitalize(jpaBatchMetadata.getEntityPlural()));
jsonResponseList = new JavaType(
JSON_RESPONSE.getFullyQualifiedTypeName(), 0, DataType.TYPE,
null, Arrays.asList(listOfEntityType));
Validate.notNull(this.entity, String.format(
"Missing entity value for %s in %s",
GvNIXJpaBatch.class.getCanonicalName(),
service.getFullyQualifiedTypeName()));
Validate.isTrue(
this.entity.equals(webScaffoldMetadataValue
.getFormBackingObject()),
String.format(
"Service batch entity and Controller formBackingObject no match in %s",
governorPhysicalTypeMetadata.getType()
.getFullyQualifiedTypeName()));
// Adding field definition
builder.addField(getConversionServiceField());
builder.addField(getLoggerField());
// Adding methods
builder.addField(getServiceField());
builder.addMethod(getDeleteMethod());
builder.addMethod(getUpdateMethod());
builder.addMethod(getCreateMethod());
builder.addMethod(getGetOIDListMethod());
builder.addMethod(getGetRequestPropertyValuesMethod());
// Check if deleteBatch, createBatch or updateBatch are duplicated with
// different name.
checkIfExistsCUDMethods(governorTypeDetails);
// Create a representation of the desired output ITD
itdTypeDetails = builder.build();
}
示例10: getRenderItemsMethod
/**
* Gets <code>renderXXX</code> method. <br>
* This method renders the required jspx for item an store it in a List of
* Map(String,String)
*
* @return
*/
private MethodMetadata getRenderItemsMethod() {
JavaType entitySearchResult = new JavaType(
SEARCH_RESULTS.getFullyQualifiedTypeName(), 0, DataType.TYPE,
null, Arrays.asList(entity));
// Define method parameter types
List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType
.convertFromJavaTypes(entitySearchResult, HTTP_SERVLET_REQUEST,
HTTP_SERVLET_RESPONSE);
// Check if a method with the same signature already exists in the
// target type
final MethodMetadata method = methodExists(renderItemsMethodName,
parameterTypes);
if (method != null) {
// If it already exists, just return the method and omit its
// generation via the ITD
return method;
}
// Define method annotations
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
// Define method throws types (none in this case)
List<JavaType> throwsTypes = new ArrayList<JavaType>();
throwsTypes.add(SERVLET_EXCEPTION);
throwsTypes.add(IO_EXCEPTION);
// Define method parameter names
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName("searchResult"));
parameterNames.add(REQUEST_PARAM_NAME);
parameterNames.add(RESPONSE_PARAM_NAME);
// Create the method body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
buildRenderItemsMethodBody(bodyBuilder);
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
getId(), Modifier.PUBLIC, renderItemsMethodName,
LIST_MAP_STRING_STRING, parameterTypes, parameterNames,
bodyBuilder);
methodBuilder.setAnnotations(annotations);
methodBuilder.setThrowsTypes(throwsTypes);
return methodBuilder.build(); // Build and return a MethodMetadata
// instance
}
示例11: getListJsonMethod
private MethodMetadataBuilder getListJsonMethod(
final MemberTypeAdditions findAllMethod) {
if (StringUtils.isBlank(annotationValues.getListJsonMethod())
|| findAllMethod == null) {
return null;
}
final JavaSymbolName methodName = new JavaSymbolName(
annotationValues.getListJsonMethod());
if (governorHasMethodWithSameName(methodName)) {
return null;
}
final JavaSymbolName toJsonArrayMethodName = jsonMetadata
.getToJsonArrayMethodName();
final List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>();
requestMappingAttributes.add(new StringAttributeValue(
new JavaSymbolName("headers"), "Accept=application/json"));
final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
REQUEST_MAPPING, requestMappingAttributes);
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(requestMapping);
annotations.add(new AnnotationMetadataBuilder(RESPONSE_BODY));
final String httpHeadersShortName = getShortName(HTTP_HEADERS);
final String responseEntityShortName = getShortName(RESPONSE_ENTITY);
final String httpStatusShortName = getShortName(HTTP_STATUS);
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine(httpHeadersShortName + " headers = new "
+ httpHeadersShortName + "();");
bodyBuilder.appendFormalLine("headers.add(\"Content-Type\", \""
+ CONTENT_TYPE + "; charset=utf-8\");");
openTry(bodyBuilder);
final JavaType list = new JavaType(List.class.getName(), 0,
DataType.TYPE, null, Arrays.asList(jsonEnabledType));
bodyBuilder.appendFormalLine(getShortName(list) + " result = "
+ findAllMethod.getMethodCall() + ";");
bodyBuilder.appendFormalLine("return new " + responseEntityShortName
+ "<String>(" + jsonEnabledTypeShortName + "."
+ toJsonArrayMethodName.getSymbolName() + "(result), headers, "
+ httpStatusShortName + ".OK);");
closeTry(bodyBuilder, responseEntityShortName, httpStatusShortName);
if (introduceLayerComponents) {
findAllMethod.copyAdditionsTo(builder, governorTypeDetails);
}
final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
getId(), PUBLIC, methodName, RESPONSE_ENTITY_STRING,
bodyBuilder);
methodBuilder.setAnnotations(annotations);
return methodBuilder;
}
示例12: file
@CliCommand(value = "field set", help = "Adds a private Set field to an existing Java source file (eg the 'one' side of a many-to-one)")
public void addFieldSetJpa(
@CliOption(key = { "", "fieldName" }, mandatory = true, help = "The name of the field to add") final JavaSymbolName fieldName,
@CliOption(key = "type", mandatory = true, help = "The entity which will be contained within the Set") final JavaType fieldType,
@CliOption(key = "class", mandatory = false, unspecifiedDefaultValue = "*", optionContext = UPDATE_PROJECT, help = "The name of the class to receive this field") final JavaType typeName,
@CliOption(key = "mappedBy", mandatory = false, help = "The field name on the referenced type which owns the relationship") final JavaSymbolName mappedBy,
@CliOption(key = "notNull", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether this value cannot be null") final boolean notNull,
@CliOption(key = "nullRequired", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether this value must be null") final boolean nullRequired,
@CliOption(key = "sizeMin", mandatory = false, help = "The minimum number of elements in the collection") final Integer sizeMin,
@CliOption(key = "sizeMax", mandatory = false, help = "The maximum number of elements in the collection") final Integer sizeMax,
@CliOption(key = "cardinality", mandatory = false, unspecifiedDefaultValue = "MANY_TO_MANY", specifiedDefaultValue = "MANY_TO_MANY", help = "The relationship cardinality at a JPA level") Cardinality cardinality,
@CliOption(key = "fetch", mandatory = false, help = "The fetch semantics at a JPA level") final Fetch fetch,
@CliOption(key = "comment", mandatory = false, help = "An optional comment for JavaDocs") final String comment,
@CliOption(key = "transient", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to mark the field as transient") final boolean transientModifier,
@CliOption(key = "permitReservedWords", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates whether reserved words are ignored by Roo") final boolean permitReservedWords) {
final ClassOrInterfaceTypeDetails cid = typeLocationService
.getTypeDetails(fieldType);
Validate.notNull(
cid,
"The specified target '--type' does not exist or can not be found. Please create this type first.");
// Check if the requested entity is a JPA @Entity
final MemberDetails memberDetails = memberDetailsScanner
.getMemberDetails(this.getClass().getName(), cid);
final AnnotationMetadata entityAnnotation = memberDetails
.getAnnotation(ENTITY);
final AnnotationMetadata persistentAnnotation = memberDetails
.getAnnotation(PERSISTENT);
if (entityAnnotation != null) {
Validate.isTrue(cardinality == Cardinality.ONE_TO_MANY
|| cardinality == Cardinality.MANY_TO_MANY,
"Cardinality must be ONE_TO_MANY or MANY_TO_MANY for the field set command");
}
else if (cid.getPhysicalTypeCategory() == PhysicalTypeCategory.ENUMERATION) {
cardinality = null;
}
else if (persistentAnnotation != null) {
// Yes, we can deal with that
}
else {
throw new IllegalStateException(
"The field set command is only applicable to enum, JPA @Entity or Spring Data @Persistence elements");
}
final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService
.getTypeDetails(typeName);
Validate.notNull(javaTypeDetails,
"The type specified, '%s', doesn't exist", typeName);
final String physicalTypeIdentifier = javaTypeDetails
.getDeclaredByMetadataId();
final SetField fieldDetails = new SetField(physicalTypeIdentifier,
new JavaType(SET.getFullyQualifiedTypeName(), 0, DataType.TYPE,
null, Arrays.asList(fieldType)), fieldName, fieldType,
cardinality);
fieldDetails.setNotNull(notNull);
fieldDetails.setNullRequired(nullRequired);
if (sizeMin != null) {
fieldDetails.setSizeMin(sizeMin);
}
if (sizeMax != null) {
fieldDetails.setSizeMax(sizeMax);
}
if (mappedBy != null) {
fieldDetails.setMappedBy(mappedBy);
}
if (fetch != null) {
fieldDetails.setFetch(fetch);
}
if (comment != null) {
fieldDetails.setComment(comment);
}
insertField(fieldDetails, permitReservedWords, transientModifier);
}
示例13: getListPagedMethod
private MethodMetadata getListPagedMethod() {
JavaSymbolName methodName = new JavaSymbolName("listPaged");
MethodMetadata method = methodExists(methodName);
if (method != null) {
return method;
}
List<JavaType> typeParams = new ArrayList<JavaType>();
typeParams.add(this.entity);
JavaType returnType = new JavaType("java.util.List", 0, DataType.TYPE,
null, typeParams);
List<AnnotatedJavaType> paramTypes = new ArrayList<AnnotatedJavaType>();
paramTypes.add(new AnnotatedJavaType(new JavaType("Integer"),
new ArrayList<AnnotationMetadata>()));
paramTypes.add(new AnnotatedJavaType(new JavaType("Integer"),
new ArrayList<AnnotationMetadata>()));
List<JavaSymbolName> paramNames = new ArrayList<JavaSymbolName>();
paramNames.add(new JavaSymbolName("page"));
paramNames.add(new JavaSymbolName("size"));
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("if (page != null || size != null) {");
bodyBuilder.indent();
bodyBuilder
.appendFormalLine("int sizeNo = size == null ? 10 : size.intValue();");
bodyBuilder
.appendFormalLine("return "
+ this.entity.getNameIncludingTypeParameters(false,
this.builder.getImportRegistrationResolver())
+ "."
+ new JpaCrudAnnotationValues(this.entityMetadata)
.getFindEntriesMethod()
.concat(this.entityMetadata.getEntityName())
.concat("Entries")
+ "(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo);");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("} else {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("return list();");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
returnType, paramTypes, paramNames, bodyBuilder).build();
}
示例14: testSimpleClass3AddField
@Test
public void testSimpleClass3AddField() throws Exception {
// Set up
final File file = getResource(SIMPLE_CLASS3_FILE_PATH);
final String fileContents = getResourceContents(file);
final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
.getTypeFromString(fileContents, SIMPLE_CLASS3_DECLARED_BY_MID,
SIMPLE_CLASS3_TYPE);
final SetField fieldDetails = new SetField(
SIMPLE_CLASS3_DECLARED_BY_MID, new JavaType(
SET.getFullyQualifiedTypeName(), 0, DataType.TYPE,
null, Arrays.asList(SIMPLE_CLASS3_TYPE)),
new JavaSymbolName("children"), SIMPLE_CLASS3_TYPE,
Cardinality.ONE_TO_MANY);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(
fieldDetails.getPhysicalTypeIdentifier(), Modifier.PRIVATE,
new ArrayList<AnnotationMetadataBuilder>(),
fieldDetails.getFieldName(), fieldDetails.getFieldType());
fieldBuilder.setFieldInitializer("new HashSet<SimpleClass3>()");
final ClassOrInterfaceTypeDetails newClassDetails = addField(
simpleInterfaceDetails, fieldBuilder.build());
// Invoke
final String result = typeParsingService
.getCompilationUnitContents(newClassDetails);
saveResult(file, result, "-addField");
checkSimple3Class(result);
assertTrue(result
.contains("private Set<SimpleClass3> children = new HashSet<SimpleClass3>();"));
// Add another
final ClassOrInterfaceTypeDetails simpleInterfaceDetails2 = typeParsingService
.getTypeFromString(result, SIMPLE_CLASS3_DECLARED_BY_MID,
SIMPLE_CLASS3_TYPE);
final ReferenceField fieldDetails2 = new ReferenceField(
SIMPLE_CLASS3_DECLARED_BY_MID, SIMPLE_CLASS2_TYPE,
new JavaSymbolName("referenceField"), Cardinality.MANY_TO_ONE);
final FieldMetadataBuilder fieldBuilder2 = new FieldMetadataBuilder(
fieldDetails2.getPhysicalTypeIdentifier(), Modifier.PRIVATE,
new ArrayList<AnnotationMetadataBuilder>(),
fieldDetails2.getFieldName(), fieldDetails2.getFieldType());
final ClassOrInterfaceTypeDetails newClassDetails2 = addField(
simpleInterfaceDetails2, fieldBuilder2.build());
// Invoke
final String result2 = typeParsingService
.getCompilationUnitContents(newClassDetails2);
// Save to file for debug
saveResult(file, result2, "-addField2");
checkSimple3Class(result2);
assertTrue(result
.contains("private Set<SimpleClass3> children = new HashSet<SimpleClass3>();"));
assertTrue(result2.contains("private SimpleClass2 referenceField;"));
}
示例15: getFindAllMethod
/**
* @return the find all method (may return null)
*/
private MethodMetadata getFindAllMethod() {
if ("".equals(crudAnnotationValues.getFindAllMethod())) {
return null;
}
// Method definition to find or build
final JavaSymbolName methodName = new JavaSymbolName(
crudAnnotationValues.getFindAllMethod() + plural);
final JavaType[] parameterTypes = {};
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
final JavaType returnType = new JavaType(
LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
Arrays.asList(destination));
// Locate user-defined method
final MethodMetadata userMethod = getGovernorMethod(methodName,
parameterTypes);
if (userMethod != null) {
Validate.isTrue(userMethod.getReturnType().equals(returnType),
"Method '%s' on '%s' must return '%s'", methodName,
destination, returnType.getNameIncludingTypeParameters());
return userMethod;
}
// Create method
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
if (isGaeEnabled) {
addTransactionalAnnotation(annotations);
}
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return " + ENTITY_MANAGER_METHOD_NAME
+ "().createQuery(\"SELECT o FROM " + entityName + " o\", "
+ destination.getSimpleTypeName() + ".class).getResultList();");
final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
getId(), Modifier.PUBLIC | Modifier.STATIC, methodName,
returnType,
AnnotatedJavaType.convertFromJavaTypes(parameterTypes),
parameterNames, bodyBuilder);
methodBuilder.setAnnotations(annotations);
return methodBuilder.build();
}