Package org.springframework.roo.classpath.details.annotations

Examples of org.springframework.roo.classpath.details.annotations.AnnotationMetadata


            }
            else {
                int maxLength = Integer.MAX_VALUE;

                // Check for @Size
                final AnnotationMetadata sizeAnnotation = MemberFindingUtils
                        .getAnnotationOfType(field.getAnnotations(), SIZE);
                if (sizeAnnotation != null) {
                    final AnnotationAttributeValue<?> maxValue = sizeAnnotation
                            .getAttribute(MAX_SYMBOL);
                    if (maxValue != null) {
                        validateNumericAnnotationAttribute(fieldName, "@Size",
                                "max", maxValue.getValue());
                        maxLength = ((Integer) maxValue.getValue()).intValue();
                    }
                    final AnnotationAttributeValue<?> minValue = sizeAnnotation
                            .getAttribute(MIN_SYMBOL);
                    if (minValue != null) {
                        validateNumericAnnotationAttribute(fieldName, "@Size",
                                "min", minValue.getValue());
                        final int minLength = ((Integer) minValue.getValue())
View Full Code Here


                + collaboratingMetadata.getRandomPersistentEntityMethod()
                        .getMethodName().getSymbolName() + "()";
    }

    private boolean isNullableJoinColumn(final FieldMetadata field) {
        final AnnotationMetadata joinColumnAnnotation = field
                .getAnnotation(JOIN_COLUMN);
        if (joinColumnAnnotation == null) {
            return true;
        }
        final AnnotationAttributeValue<?> nullableAttr = joinColumnAnnotation
                .getAttribute(new JavaSymbolName("nullable"));
        return nullableAttr == null || (Boolean) nullableAttr.getValue();
    }
View Full Code Here

            if (!isUnique && values != null && values.containsKey("unique")) {
                isUnique = (Boolean) values.get("unique");
            }

            // Check for @Size or @Column with length attribute
            final AnnotationMetadata sizeAnnotation = MemberFindingUtils
                    .getAnnotationOfType(field.getAnnotations(), SIZE);
            if (sizeAnnotation != null
                    && sizeAnnotation.getAttribute(MAX_SYMBOL) != null) {
                final Integer maxValue = (Integer) sizeAnnotation.getAttribute(
                        MAX_SYMBOL).getValue();
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".length() > " + maxValue + ") {");
                bodyBuilder.indent();
                if (isUnique) {
                    bodyBuilder.appendFormalLine(fieldName
                            + " = new Random().nextInt(10) + " + fieldName
                            + ".substring(1, " + maxValue + ");");
                }
                else {
                    bodyBuilder.appendFormalLine(fieldName + " = " + fieldName
                            + ".substring(0, " + maxValue + ");");
                }
                bodyBuilder.indentRemove();
                bodyBuilder.appendFormalLine("}");
            }
            else if (sizeAnnotation == null && values != null) {
                if (values.containsKey("length")) {
                    final Integer lengthValue = (Integer) values.get("length");
                    bodyBuilder.appendFormalLine("if (" + fieldName
                            + ".length() > " + lengthValue + ") {");
                    bodyBuilder.indent();
                    if (isUnique) {
                        bodyBuilder.appendFormalLine(fieldName
                                + " = new Random().nextInt(10) + " + fieldName
                                + ".substring(1, " + lengthValue + ");");
                    }
                    else {
                        bodyBuilder.appendFormalLine(fieldName + " = "
                                + fieldName + ".substring(0, " + lengthValue
                                + ");");
                    }
                    bodyBuilder.indentRemove();
                    bodyBuilder.appendFormalLine("}");
                }
            }
        }
        else if (JdkJavaType.isDecimalType(fieldType)) {
            // Check for @Digits, @DecimalMax, @DecimalMin
            final AnnotationMetadata digitsAnnotation = MemberFindingUtils
                    .getAnnotationOfType(field.getAnnotations(), DIGITS);
            final AnnotationMetadata decimalMinAnnotation = MemberFindingUtils
                    .getAnnotationOfType(field.getAnnotations(), DECIMAL_MIN);
            final AnnotationMetadata decimalMaxAnnotation = MemberFindingUtils
                    .getAnnotationOfType(field.getAnnotations(), DECIMAL_MAX);

            if (digitsAnnotation != null) {
                bodyBuilder.append(getDigitsBody(field, digitsAnnotation,
                        suffix));
View Full Code Here

        final String fieldName = field.getFieldName().getSymbolName();
        final JavaType fieldType = field.getFieldType();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

        final AnnotationMetadata minAnnotation = MemberFindingUtils
                .getAnnotationOfType(field.getAnnotations(), MIN);
        final AnnotationMetadata maxAnnotation = MemberFindingUtils
                .getAnnotationOfType(field.getAnnotations(), MAX);
        if (minAnnotation != null && maxAnnotation == null) {
            final Number minValue = (Number) minAnnotation.getAttribute(VALUE)
                    .getValue();

            if (fieldType.equals(BIG_INTEGER)) {
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".compareTo(new " + BIG_INTEGER.getSimpleTypeName()
                        + "(\"" + minValue + "\")) == -1) {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = new "
                        + BIG_INTEGER.getSimpleTypeName() + "(\"" + minValue
                        + "\");");
            }
            else {
                bodyBuilder.appendFormalLine("if (" + fieldName + " < "
                        + minValue + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + minValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }
        else if (minAnnotation == null && maxAnnotation != null) {
            final Number maxValue = (Number) maxAnnotation.getAttribute(VALUE)
                    .getValue();

            if (fieldType.equals(BIG_INTEGER)) {
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".compareTo(new " + BIG_INTEGER.getSimpleTypeName()
                        + "(\"" + maxValue + "\")) == 1) {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = new "
                        + BIG_INTEGER.getSimpleTypeName() + "(\"" + maxValue
                        + "\");");
            }
            else {
                bodyBuilder.appendFormalLine("if (" + fieldName + " > "
                        + maxValue + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + maxValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }
        else if (minAnnotation != null && maxAnnotation != null) {
            final Number minValue = (Number) minAnnotation.getAttribute(VALUE)
                    .getValue();
            final Number maxValue = (Number) maxAnnotation.getAttribute(VALUE)
                    .getValue();
            Validate.isTrue(
                    maxValue.longValue() >= minValue.longValue(),
                    "The value of @Max must be greater or equal to the value of @Min for field %s",
                    fieldName);
View Full Code Here

    private JavaType getIdentifierType(final JavaType entity) {
        final PhysicalTypeMetadata governorPhysicalTypeMetadata = getPhysicalTypeMetadata(entity);
        if (governorPhysicalTypeMetadata != null) {
            final ClassOrInterfaceTypeDetails governorTypeDetails = governorPhysicalTypeMetadata
                    .getMemberHoldingTypeDetails();
            final AnnotationMetadata jpaAnnotation = getJpaAnnotation(governorTypeDetails);
            if (jpaAnnotation != null) {
                final AnnotationAttributeValue<?> identifierTypeAttribute = jpaAnnotation
                        .getAttribute(new JavaSymbolName(IDENTIFIER_TYPE));
                if (identifierTypeAttribute != null) {
                    // The identifierType attribute exists, so get its value
                    final JavaType identifierType = (JavaType) identifierTypeAttribute
                            .getValue();
View Full Code Here

     * @return <code>null</code> if there isn't one
     */
    private AnnotationMetadata getJpaAnnotation(
            final ClassOrInterfaceTypeDetails managedEntity) {
        // The @RooJpaEntity annotation takes precedence if present
        final AnnotationMetadata rooJpaEntity = managedEntity
                .getAnnotation(ROO_JPA_ENTITY);
        if (rooJpaEntity != null) {
            return rooJpaEntity;
        }
        return managedEntity.getAnnotation(ROO_JPA_ACTIVE_RECORD);
View Full Code Here

        final Set<ClassOrInterfaceTypeDetails> managedIdentifierTypes = new LinkedHashSet<ClassOrInterfaceTypeDetails>();

        final Set<ClassOrInterfaceTypeDetails> identifierTypes = typeLocationService
                .findClassesOrInterfaceDetailsWithAnnotation(ROO_IDENTIFIER);
        for (final ClassOrInterfaceTypeDetails managedIdentifierType : identifierTypes) {
            final AnnotationMetadata identifierAnnotation = managedIdentifierType
                    .getTypeAnnotation(ROO_IDENTIFIER);
            final AnnotationAttributeValue<?> attrValue = identifierAnnotation
                    .getAttribute(DB_MANAGED);
            if (attrValue != null && (Boolean) attrValue.getValue()) {
                managedIdentifierTypes.add(managedIdentifierType);
            }
        }
View Full Code Here

    private Table updateOrDeleteManagedEntity(
            final ClassOrInterfaceTypeDetails managedEntity,
            final Database database) {
        // Update the attributes of the existing JPA-related annotation
        final AnnotationMetadata jpaAnnotation = getJpaAnnotation(managedEntity);
        Validate.validState(jpaAnnotation != null,
                "Neither @%s nor @%s found on existing DBRE-managed entity %s",
                ROO_JPA_ACTIVE_RECORD.getSimpleTypeName(), ROO_JPA_ENTITY
                        .getSimpleTypeName(), managedEntity.getName()
                        .getFullyQualifiedTypeName());

        // Find table in database using 'table' and 'schema' attributes from the
        // JPA annotation
        final AnnotationAttributeValue<?> tableAttribute = jpaAnnotation
                .getAttribute(new JavaSymbolName("table"));
        final String errMsg = "Unable to maintain database-managed entity "
                + managedEntity.getName().getFullyQualifiedTypeName()
                + " because its associated table could not be found";
        Validate.notNull(tableAttribute, errMsg);
        final String tableName = (String) tableAttribute.getValue();
        Validate.notBlank(tableName, errMsg);

        final AnnotationAttributeValue<?> schemaAttribute = jpaAnnotation
                .getAttribute(new JavaSymbolName("schema"));
        final String schemaName = schemaAttribute != null ? (String) schemaAttribute
                .getValue() : null;

        final Table table = database.getTable(tableName, schemaName);
        if (table == null) {
            // Table is missing and probably has been dropped so delete managed
            // type and its identifier if applicable
            deleteManagedType(managedEntity, "no database table called '"
                    + tableName + "'");
            return null;
        }

        table.setIncludeNonPortableAttributes(database
                .isIncludeNonPortableAttributes());
        table.setDisableVersionFields(database.isDisableVersionFields());
        table.setDisableGeneratedIdentifiers(database
                .isDisableGeneratedIdentifiers());

        // Update the @RooJpaEntity/@RooJpaActiveRecord attributes
        final AnnotationMetadataBuilder jpaAnnotationBuilder = new AnnotationMetadataBuilder(
                jpaAnnotation);
        final Set<JavaSymbolName> attributesToDeleteIfPresent = new LinkedHashSet<JavaSymbolName>();
        manageIdentifier(managedEntity.getName(), jpaAnnotationBuilder,
                attributesToDeleteIfPresent, table);

        // Manage versionField attribute
        final AnnotationAttributeValue<?> versionFieldAttribute = jpaAnnotation
                .getAttribute(new JavaSymbolName(VERSION_FIELD));
        if (versionFieldAttribute == null) {
            if (hasVersionField(table)) {
                attributesToDeleteIfPresent.add(new JavaSymbolName(
                        VERSION_FIELD));
            }
            else {
                jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
            }
        }
        else {
            final String versionFieldValue = (String) versionFieldAttribute
                    .getValue();
            if (hasVersionField(table)
                    && (StringUtils.isBlank(versionFieldValue) || VERSION
                            .equals(versionFieldValue))) {
                attributesToDeleteIfPresent.add(new JavaSymbolName(
                        VERSION_FIELD));
            }
        }

        final AnnotationAttributeValue<?> sequenceNameFieldAttribute = jpaAnnotation
                .getAttribute(new JavaSymbolName(SEQUENCE_NAME_FIELD));
        if (sequenceNameFieldAttribute == null) {
            if (!table.isDisableGeneratedIdentifiers()) {
                attributesToDeleteIfPresent.add(new JavaSymbolName(
                        SEQUENCE_NAME_FIELD));
View Full Code Here

        // Check if the requested entity is a JPA @Entity
        final MemberDetails memberDetails = memberDetailsScanner
                .getMemberDetails(DataOnDemandOperationsImpl.class.getName(),
                        cid);
        final AnnotationMetadata entityAnnotation = memberDetails
                .getAnnotation(ENTITY);
        final AnnotationMetadata persistentAnnotation = memberDetails
                .getAnnotation(PERSISTENT);
        Validate.isTrue(entityAnnotation != null
                || persistentAnnotation != null,
                "Type %s must be a persistent type",
                entity.getFullyQualifiedTypeName());
View Full Code Here

            return cache.get(symbolName);
        }

        // We need to build the plural
        String thePlural = "";
        final AnnotationMetadata annotation = MemberFindingUtils
                .getAnnotationOfType(field.getAnnotations(), ROO_PLURAL);
        if (annotation != null) {
            // Use the plural the user defined via the annotation
            final AnnotationAttributeValue<?> attribute = annotation
                    .getAttribute(new JavaSymbolName("value"));
            if (attribute != null) {
                thePlural = attribute.getValue().toString();
            }
        }
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.details.annotations.AnnotationMetadata

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.