Package org.springframework.roo.classpath.details

Examples of org.springframework.roo.classpath.details.FieldMetadata


     * @param identifier can be <code>null</code>
     * @return the identifier (never returns null)
     */
    private FieldMetadata getIdentifierField() {
        if (parent != null) {
            final FieldMetadata idField = parent.getIdentifierField();
            if (idField != null) {
                if (MemberFindingUtils.getAnnotationOfType(
                        idField.getAnnotations(), ID) != null) {
                    return idField;
                }
                else if (MemberFindingUtils.getAnnotationOfType(
                        idField.getAnnotations(), EMBEDDED_ID) != null) {
                    return idField;
                }
            }
            return parent.getIdentifierField();
        }

        // Try to locate an existing field with @javax.persistence.Id
        final List<FieldMetadata> idFields = governorTypeDetails
                .getFieldsWithAnnotation(ID);
        if (!idFields.isEmpty()) {
            return getIdentifierField(idFields, ID);
        }

        // Try to locate an existing field with @javax.persistence.EmbeddedId
        final List<FieldMetadata> embeddedIdFields = governorTypeDetails
                .getFieldsWithAnnotation(EMBEDDED_ID);
        if (!embeddedIdFields.isEmpty()) {
            return getIdentifierField(embeddedIdFields, EMBEDDED_ID);
        }

        // Ensure there isn't already a field called "id"; if so, compute a
        // unique name (it's not really a fatal situation at the end of the day)
        final JavaSymbolName idField = governorTypeDetails
                .getUniqueFieldName(getIdentifierFieldName());

        // We need to create one
        final JavaType identifierType = getIdentifierType();

        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        final boolean hasIdClass = !(identifierType.isCoreType() || identifierType
                .equals(GAE_DATASTORE_KEY));
        final JavaType annotationType = hasIdClass ? EMBEDDED_ID : ID;
        annotations.add(new AnnotationMetadataBuilder(annotationType));

        // Encode keys as strings on GAE to support entity group hierarchies
        if (isGaeEnabled && identifierType.equals(JavaType.STRING)) {
            AnnotationMetadataBuilder extensionBuilder = new AnnotationMetadataBuilder(
                    DATANUCLEUS_JPA_EXTENSION);
            extensionBuilder.addStringAttribute("vendorName", "datanucleus");
            extensionBuilder.addStringAttribute("key", "gae.encoded-pk");
            extensionBuilder.addStringAttribute("value", "true");
            annotations.add(extensionBuilder);
        }

        // Compute the column name, as required
        if (!hasIdClass) {
            if (!"".equals(annotationValues.getSequenceName())) {
                String generationType = isGaeEnabled || isDatabaseDotComEnabled ? "IDENTITY"
                        : "AUTO";

                // ROO-746: Use @GeneratedValue(strategy = GenerationType.TABLE)
                // If the root of the governor declares @Inheritance(strategy =
                // InheritanceType.TABLE_PER_CLASS)
                if ("AUTO".equals(generationType)) {
                    AnnotationMetadata inheritance = governorTypeDetails
                            .getAnnotation(INHERITANCE);
                    if (inheritance == null) {
                        inheritance = getInheritanceAnnotation();
                    }
                    if (inheritance != null) {
                        final AnnotationAttributeValue<?> value = inheritance
                                .getAttribute(new JavaSymbolName("strategy"));
                        if (value instanceof EnumAttributeValue) {
                            final EnumAttributeValue enumAttributeValue = (EnumAttributeValue) value;
                            final EnumDetails details = enumAttributeValue
                                    .getValue();
                            if (details != null
                                    && details.getType().equals(
                                            INHERITANCE_TYPE)) {
                                if ("TABLE_PER_CLASS".equals(details.getField()
                                        .getSymbolName())) {
                                    generationType = "TABLE";
                                }
                            }
                        }
                    }
                }

                final AnnotationMetadataBuilder generatedValueBuilder = new AnnotationMetadataBuilder(
                        GENERATED_VALUE);
                generatedValueBuilder.addEnumAttribute("strategy",
                        new EnumDetails(GENERATION_TYPE, new JavaSymbolName(
                                generationType)));

                if (StringUtils.isNotBlank(annotationValues.getSequenceName())
                        && !(isGaeEnabled || isDatabaseDotComEnabled)) {
                    final String sequenceKey = StringUtils
                            .uncapitalize(destination.getSimpleTypeName())
                            + "Gen";
                    generatedValueBuilder.addStringAttribute("generator",
                            sequenceKey);
                    final AnnotationMetadataBuilder sequenceGeneratorBuilder = new AnnotationMetadataBuilder(
                            SEQUENCE_GENERATOR);
                    sequenceGeneratorBuilder.addStringAttribute("name",
                            sequenceKey);
                    sequenceGeneratorBuilder.addStringAttribute("sequenceName",
                            annotationValues.getSequenceName());
                    annotations.add(sequenceGeneratorBuilder);
                }
                annotations.add(generatedValueBuilder);
            }

            final String identifierColumn = StringUtils
                    .stripToEmpty(getIdentifierColumn());
            String columnName = idField.getSymbolName();
            if (StringUtils.isNotBlank(identifierColumn)) {
                // User has specified an alternate column name
                columnName = identifierColumn;
            }

View Full Code Here


            // for it
            return null;
        }

        if (parent != null) {
            final FieldMetadata result = parent.getVersionField();
            if (result != null) {
                // It's the parent's responsibility to provide the accessor, not
                // ours
                return parent.getVersionAccessor();
            }
View Full Code Here

     *
     * @return the version field (may be null)
     */
    private FieldMetadata getVersionField() {
        if (parent != null) {
            final FieldMetadata result = parent.getVersionField();
            if (result != null) {
                return result;
            }
        }

View Full Code Here

            for (final BodyDeclaration member : members) {
                if (member instanceof FieldDeclaration) {
                    final FieldDeclaration castMember = (FieldDeclaration) member;
                    for (final VariableDeclarator var : castMember
                            .getVariables()) {
                        final FieldMetadata field = JavaParserFieldMetadataBuilder
                                .getInstance(declaredByMetadataId, castMember,
                                        var, compilationUnitServices,
                                        typeParameterNames).build();

                        final CommentStructure commentStructure = new CommentStructure();
                        JavaParserCommentMetadataBuilder.updateCommentsToRoo(
                                commentStructure, member);
                        field.setCommentStructure(commentStructure);

                        cidBuilder.addField(field);
                    }
                }
                if (member instanceof MethodDeclaration) {
View Full Code Here

    private void addOptionalIntegrationTestClassIntroductions() {
        // Add the GAE test helper field if the user did not define it on the
        // governor directly
        final JavaType helperType = GAE_LOCAL_SERVICE_TEST_HELPER;
        final FieldMetadata helperField = governorTypeDetails
                .getField(new JavaSymbolName("helper"));
        if (helperField != null) {
            Validate.isTrue(
                    helperField.getFieldType().getFullyQualifiedTypeName()
                            .equals(helperType.getFullyQualifiedTypeName()),
                    "Field 'helper' on '%s' must be of type '%s'",
                    destination.getFullyQualifiedTypeName(),
                    helperType.getFullyQualifiedTypeName());
        }
View Full Code Here

            builder.addAnnotation(transactionalBuilder);
        }

        // Add the data on demand field if the user did not define it on the
        // governor directly
        final FieldMetadata field = governorTypeDetails
                .getField(new JavaSymbolName("dod"));
        if (field != null) {
            Validate.isTrue(field.getFieldType().equals(dodGovernor),
                    "Field 'dod' on '%s' must be of type '%s'",
                    destination.getFullyQualifiedTypeName(),
                    dodGovernor.getFullyQualifiedTypeName());
            Validate.notNull(
                    MemberFindingUtils.getAnnotationOfType(
                            field.getAnnotations(), AUTOWIRED),
                    "Field 'dod' on '%s' must be annotated with @Autowired",
                    destination.getFullyQualifiedTypeName());
        }
        else {
            // Add the field via the ITD
View Full Code Here

        final List<FieldMetadata> idFields = persistenceMemberLocator
                .getIdentifierFields(entity);
        if (idFields.isEmpty()) {
            return null;
        }
        final FieldMetadata idField = idFields.get(0);
        final JavaType idType = persistenceMemberLocator
                .getIdentifierType(entity);
        if (idType == null) {
            return null;
        }
        metadataDependencyRegistry
                .registerDependency(idField.getDeclaredByMetadataId(),
                        metadataIdentificationString);

        final MethodParameter idParameter = new MethodParameter(idType,
                ID_FIELD_NAME);
        return layerService.getMemberTypeAdditions(
View Full Code Here

            for (final BodyDeclaration member : members) {
                if (member instanceof FieldDeclaration) {
                    final FieldDeclaration castMember = (FieldDeclaration) member;
                    for (final VariableDeclarator var : castMember
                            .getVariables()) {
                        final FieldMetadata field = JavaParserFieldMetadataBuilder
                                .getInstance(declaredByMetadataId, castMember,
                                        var, compilationUnitServices,
                                        typeParameterNames).build();
                        cidBuilder.addField(field);
                    }
View Full Code Here

     * {@link PersistenceMemberLocator} to return a mock repository for our test
     * entity.
     */
    private void setUpMockRepository() {
        final ClassOrInterfaceTypeDetails mockRepositoryDetails = mock(ClassOrInterfaceTypeDetails.class);
        final FieldMetadata mockFieldMetadata = mock(FieldMetadata.class);
        final JavaType mockRepositoryType = mock(JavaType.class);
        when(mockRepositoryType.getSimpleTypeName()).thenReturn("ClinicRepo");
        when(mockIdType.getFullyQualifiedTypeName()).thenReturn(
                Long.class.getName());
        when(mockRepositoryDetails.getName()).thenReturn(mockRepositoryType);
        when(mockFieldMetadata.getFieldType()).thenReturn(mockIdType);
        when(mockRepositoryLocator.getRepositories(mockTargetEntity))
                .thenReturn(Arrays.asList(mockRepositoryDetails));
    }
View Full Code Here

                if (identifier.getFieldType().equals(DATE)) {
                    setDateAnnotations(identifier.getColumnDefinition(),
                            annotations);
                }

                final FieldMetadata idField = new FieldMetadataBuilder(getId(),
                        Modifier.PRIVATE, annotations,
                        identifier.getFieldName(), identifier.getFieldType())
                        .build();

                // Only add field to ITD if not declared on governor
                if (!hasField(declaredFields, idField)) {
                    fields.add(idField);
                }
            }
        }

        fields.addAll(declaredFields);

        // Remove fields with static and transient modifiers
        for (final Iterator<FieldMetadata> iter = fields.iterator(); iter
                .hasNext();) {
            final FieldMetadata field = iter.next();
            if (Modifier.isStatic(field.getModifier())
                    || Modifier.isTransient(field.getModifier())) {
                iter.remove();
            }
        }

        // Remove fields with the @Transient annotation
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.details.FieldMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.