Examples of TypedPropertyCriteria


Examples of org.jboss.solder.properties.query.TypedPropertyCriteria

        if (relationshipClass == null) {
            throw new IdentityException("Error initializing JpaIdentityStore - relationshipClass not set.");
        }

        List<Property<Object>> props = PropertyQueries.createQuery(relationshipClass)
                .addCriteria(new TypedPropertyCriteria(identityClass))
                .addCriteria(new PropertyTypeCriteria(PropertyType.RELATIONSHIP_FROM))
                .getResultList();

        if (props.size() == 1) {
            modelProperties.put(PROPERTY_RELATIONSHIP_FROM, props.get(0));
        } else if (props.size() > 1) {
            throw new IdentityException(
                    "Ambiguous relationshipFrom property in relationship class " +
                            relationshipClass.getName());
        } else {
            Property<Object> p = findNamedProperty(relationshipClass, "relationshipFrom",
                    "fromIdentityObject", "fromIdentity");
            if (p != null) {
                modelProperties.put(PROPERTY_RELATIONSHIP_FROM, p);
            } else {
                // Last resort - search for a property with a type of identityClass
                // and a "from" in its name
                props = PropertyQueries.createQuery(relationshipClass)
                        .addCriteria(new TypedPropertyCriteria(identityClass))
                        .getResultList();

                for (Property<Object> prop : props) {
                    if (prop.getName().contains("from")) {
                        modelProperties.put(PROPERTY_RELATIONSHIP_FROM, prop);
                        break;
                    }
                }
            }
        }


        props = PropertyQueries.createQuery(relationshipClass)
                .addCriteria(new TypedPropertyCriteria(identityClass))
                .addCriteria(new PropertyTypeCriteria(PropertyType.RELATIONSHIP_TO))
                .getResultList();

        if (props.size() == 1) {
            modelProperties.put(PROPERTY_RELATIONSHIP_TO, props.get(0));
        } else if (props.size() > 1) {
            throw new IdentityException(
                    "Ambiguous relationshipTo property in relationship class " +
                            relationshipClass.getName());
        } else {
            Property<Object> p = findNamedProperty(relationshipClass, "relationshipTo",
                    "toIdentityObject", "toIdentity");
            if (p != null) {
                modelProperties.put(PROPERTY_RELATIONSHIP_TO, p);
            } else {
                // Last resort - search for a property with a type of identityClass
                // and a "to" in its name
                props = PropertyQueries.createQuery(relationshipClass)
                        .addCriteria(new TypedPropertyCriteria(identityClass))
                        .getResultList();

                for (Property<Object> prop : props) {
                    if (prop.getName().contains("to")) {
                        modelProperties.put(PROPERTY_RELATIONSHIP_TO, prop);
                        break;
                    }
                }
            }
        }

        props = PropertyQueries.createQuery(relationshipClass)
                .addCriteria(new PropertyTypeCriteria(PropertyType.TYPE))
                .getResultList();
        if (props.size() == 1) {
            modelProperties.put(PROPERTY_RELATIONSHIP_TYPE, props.get(0));
        } else if (props.size() > 1) {
            throw new IdentityException(
                    "Ambiguous relationshipType property in relationship class " +
                            relationshipClass.getName());
        } else {
            Property<Object> p = findNamedProperty(relationshipClass,
                    "identityRelationshipType", "relationshipType", "type");
            if (p != null) {
                modelProperties.put(PROPERTY_RELATIONSHIP_TYPE, p);
            } else {
                props = PropertyQueries.createQuery(relationshipClass)
                        .getResultList();
                for (Property<Object> prop : props) {
                    if (prop.getName().contains("type")) {
                        modelProperties.put(PROPERTY_RELATIONSHIP_TYPE, prop);
                        break;
                    }
                }
            }
        }

        props = PropertyQueries.createQuery(relationshipClass)
                .addCriteria(new PropertyTypeCriteria(PropertyType.NAME))
                .addCriteria(new TypedPropertyCriteria(String.class))
                .getResultList();

        if (props.size() == 1) {
            modelProperties.put(PROPERTY_RELATIONSHIP_NAME, props.get(0));
        } else if (props.size() > 1) {
            throw new IdentityException(
                    "Ambiguous relationship name property in relationship class " +
                            relationshipClass.getName());
        } else {
            Property<Object> p = findNamedProperty(relationshipClass, "relationshipName", "name");
            if (p != null) {
                modelProperties.put(PROPERTY_RELATIONSHIP_NAME, p);
            }
        }

        if (modelProperties.containsKey(PROPERTY_RELATIONSHIP_NAME)) {
            namedRelationshipsSupported = true;
        }

        if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_FROM)) {
            throw new IdentityException(
                    "Error initializing JpaIdentityStore - no valid relationship from property found.");
        }

        if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_TO)) {
            throw new IdentityException(
                    "Error initializing JpaIdentityStore - no valid relationship to property found.");
        }

        if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_TYPE)) {
            throw new IdentityException(
                    "Error initializing JpaIdentityStore - no valid relationship type property found.");
        }

        if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_NAME)) {
            throw new IdentityException(
                    "Error initializing JpaIdentityStore - no valid relationship name property found.");
        }

        Class<?> typeClass = modelProperties.get(PROPERTY_RELATIONSHIP_TYPE).getJavaClass();
        if (!String.class.equals(typeClass)) {
            props = PropertyQueries.createQuery(typeClass)
                    .addCriteria(new PropertyTypeCriteria(PropertyType.NAME))
                    .addCriteria(new TypedPropertyCriteria(String.class))
                    .getResultList();

            if (props.size() == 1) {
                modelProperties.put(PROPERTY_RELATIONSHIP_TYPE_NAME, props.get(0));
            } else if (props.size() > 1) {
View Full Code Here

Examples of org.jboss.solder.properties.query.TypedPropertyCriteria

    protected void configureAttributes() throws IdentityException {
        // If an attribute class has been configured, scan it for attributes
        if (attributeClass != null) {
            List<Property<Object>> props = PropertyQueries.createQuery(attributeClass)
                    .addCriteria(new PropertyTypeCriteria(PropertyType.NAME))
                    .addCriteria(new TypedPropertyCriteria(String.class))
                    .getResultList();

            if (props.size() == 1) {
                modelProperties.put(PROPERTY_ATTRIBUTE_NAME, props.get(0));
            } else if (props.size() > 1) {
                throw new IdentityException(
                        "Ambiguous attribute name property in class " +
                                attributeClass.getName());
            } else {
                Property<Object> prop = findNamedProperty(attributeClass,
                        "attributeName", "name");
                if (prop != null) modelProperties.put(PROPERTY_ATTRIBUTE_NAME, prop);
            }

            props = PropertyQueries.createQuery(attributeClass)
                    .addCriteria(new PropertyTypeCriteria(PropertyType.VALUE))
                    .getResultList();

            if (props.size() == 1) {
                modelProperties.put(PROPERTY_ATTRIBUTE_VALUE, props.get(0));
            } else if (props.size() > 1) {
                throw new IdentityException(
                        "Ambiguous attribute value property in class " +
                                attributeClass.getName());
            } else {
                Property<Object> prop = findNamedProperty(attributeClass,
                        "attributeValue", "value");
                if (prop != null) modelProperties.put(PROPERTY_ATTRIBUTE_VALUE, prop);
            }

            props = PropertyQueries.createQuery(attributeClass)
                    .addCriteria(new TypedPropertyCriteria(identityClass))
                    .getResultList();

            if (props.size() == 1) {
                modelProperties.put(PROPERTY_ATTRIBUTE_IDENTITY, props.get(0));
            } else if (props.size() > 1) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.