Search in sources :

Example 6 with ValueDescriptor

use of org.qi4j.api.value.ValueDescriptor in project qi4j-sdk by Qi4j.

the class AbstractSQLStartup method constructApplicationInfo.

private ApplicationInfo constructApplicationInfo(Boolean setQNameTableNameToNull) throws SQLException {
    final ApplicationInfo appInfo = new ApplicationInfo();
    final List<CompositeDescriptorInfo> valueDescriptors = new ArrayList<CompositeDescriptorInfo>();
    final Deque<Object> currentPath = new ArrayDeque<Object>();
    _app.descriptor().accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {

        @Override
        public boolean visitEnter(Object visited) throws RuntimeException {
            if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
                currentPath.push(visited);
            }
            if (visited instanceof EntityDescriptor || visited instanceof ValueDescriptor) {
                // TODO filter non-visible descriptors away.
                if (visited instanceof EntityDescriptor) {
                    EntityDescriptor entityDescriptor = (EntityDescriptor) visited;
                    if (entityDescriptor.queryable()) {
                        _log.debug("THIS ONE WORKS: {}", entityDescriptor);
                        appInfo.entityDescriptors.put(first(entityDescriptor.types()).getName(), entityDescriptor);
                    }
                } else {
                    valueDescriptors.add(new CompositeDescriptorInfo((LayerDescriptor) Iterables.first(Iterables.skip(1, currentPath)), (ModuleDescriptor) Iterables.first(currentPath), (CompositeDescriptor) visited));
                }
                return false;
            }
            return true;
        }

        @Override
        public boolean visitLeave(Object visited) {
            if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
                currentPath.pop();
            }
            return true;
        }
    });
    for (EntityDescriptor descriptor : appInfo.entityDescriptors.values()) {
        Set<QualifiedName> newQNames = new HashSet<QualifiedName>();
        this.extractPropertyQNames(descriptor, this._state.qNameInfos().get(), newQNames, valueDescriptors, appInfo.enumValues, setQNameTableNameToNull);
        this.extractAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
        this.extractManyAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
        this._state.entityUsedQNames().get().put(descriptor, newQNames);
    }
    appInfo.usedValueComposites.addAll(valueDescriptors);
    return appInfo;
}
Also used : ValueDescriptor(org.qi4j.api.value.ValueDescriptor) QualifiedName(org.qi4j.api.common.QualifiedName) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) ModuleDescriptor(org.qi4j.api.structure.ModuleDescriptor) EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor) HashSet(java.util.HashSet)

Example 7 with ValueDescriptor

use of org.qi4j.api.value.ValueDescriptor in project qi4j-sdk by Qi4j.

the class AbstractSQLStartup method processPropertyTypeForQNames.

private void processPropertyTypeForQNames(PropertyDescriptor pType, Map<QualifiedName, QNameInfo> qNameInfos, Set<QualifiedName> newQNames, List<CompositeDescriptorInfo> vDescriptors, Set<String> enumValues, Boolean setQNameTableNameToNull) {
    QualifiedName qName = pType.qualifiedName();
    if (!newQNames.contains(qName) && !qName.name().equals(Identity.class.getName())) {
        newQNames.add(qName);
        // System.out.println("QName: " + qName + ", hc: " + qName.hashCode());
        QNameInfo info = qNameInfos.get(qName);
        if (info == null) {
            info = QNameInfo.fromProperty(// 
            qName, setQNameTableNameToNull ? null : (QNAME_TABLE_NAME_PREFIX + qNameInfos.size()), // 
            pType);
            qNameInfos.put(qName, info);
        }
        Type vType = info.getFinalType();
        while (vType instanceof ParameterizedType) {
            vType = ((ParameterizedType) vType).getRawType();
        }
        if (// 
        vType instanceof Class<?>) {
            final Class<?> vTypeClass = (Class<?>) vType;
            if (((Class<?>) vType).isInterface()) {
                for (CompositeDescriptorInfo descInfo : vDescriptors) {
                    CompositeDescriptor desc = descInfo.composite;
                    if (desc instanceof ValueDescriptor) {
                        ValueDescriptor vDesc = (ValueDescriptor) desc;
                        // other Serializable
                        if (Iterables.matchesAny(new Specification<Class<?>>() {

                            @Override
                            public boolean satisfiedBy(Class<?> item) {
                                return vTypeClass.isAssignableFrom(item);
                            }
                        }, vDesc.types())) {
                            for (PropertyDescriptor subPDesc : vDesc.state().properties()) {
                                // 
                                this.processPropertyTypeForQNames(// 
                                subPDesc, // 
                                qNameInfos, // 
                                newQNames, // 
                                vDescriptors, // 
                                enumValues, // 
                                setQNameTableNameToNull);
                            }
                        }
                    }
                }
            } else if (Enum.class.isAssignableFrom((Class<?>) vType)) {
                for (Object value : ((Class<?>) vType).getEnumConstants()) {
                    enumValues.add(QualifiedName.fromClass((Class<?>) vType, value.toString()).toString());
                }
            }
        }
    }
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) QualifiedName(org.qi4j.api.common.QualifiedName) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) ParameterizedType(java.lang.reflect.ParameterizedType) QNameType(org.qi4j.index.sql.support.common.QNameInfo.QNameType) Type(java.lang.reflect.Type) ObjectType(org.sql.generation.api.grammar.manipulation.ObjectType) SQLDataType(org.sql.generation.api.grammar.common.datatypes.SQLDataType) ParameterizedType(java.lang.reflect.ParameterizedType) CompositeDescriptor(org.qi4j.api.composite.CompositeDescriptor) QNameInfo(org.qi4j.index.sql.support.common.QNameInfo) Identity(org.qi4j.api.entity.Identity)

Example 8 with ValueDescriptor

use of org.qi4j.api.value.ValueDescriptor in project qi4j-sdk by Qi4j.

the class AbstractSQLIndexing method storePropertiesOfVC.

private // 
Integer storePropertiesOfVC(// 
Map<QualifiedName, PreparedStatement> qNameInsertPSs, // 
PreparedStatement insertAllQNamesPS, // 
Integer propertyPK, // 
Long entityPK, // 
Object property) throws SQLException {
    ValueDescriptor vDesc = this._qi4SPI.valueDescriptorFor((ValueComposite) property);
    StateHolder state = Qi4j.FUNCTION_COMPOSITE_INSTANCE_OF.map((ValueComposite) property).state();
    Integer originalPropertyPK = propertyPK;
    ++propertyPK;
    for (PropertyDescriptor pDesc : vDesc.state().properties()) {
        propertyPK = // 
        this.insertProperty(// 
        qNameInsertPSs, // 
        insertAllQNamesPS, // 
        propertyPK, // 
        entityPK, // 
        pDesc.qualifiedName(), // 
        state.propertyFor(pDesc.accessor()).get(), // 
        originalPropertyPK);
    }
    return propertyPK;
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) StateHolder(org.qi4j.api.property.StateHolder) ValueComposite(org.qi4j.api.value.ValueComposite)

Example 9 with ValueDescriptor

use of org.qi4j.api.value.ValueDescriptor in project qi4j-sdk by Qi4j.

the class AbstractSQLIndexing method storeVCClassIDUsingPS.

private void storeVCClassIDUsingPS(PreparedStatement ps, Integer nextFreeIndex, Object vc) throws SQLException {
    if (vc == null) {
        ps.setNull(nextFreeIndex, Types.INTEGER);
    } else {
        ValueDescriptor vDesc = this._qi4SPI.valueDescriptorFor(vc);
        Integer classID = this._state.usedClassesPKs().get().get(vDesc);
        ps.setInt(nextFreeIndex, classID);
    }
}
Also used : ValueDescriptor(org.qi4j.api.value.ValueDescriptor)

Example 10 with ValueDescriptor

use of org.qi4j.api.value.ValueDescriptor in project qi4j-sdk by Qi4j.

the class ValueEqualityTest method givenValuesOfDifferentTypesWhenTestingValueDescriptorEqualityExpectNotEquals.

@Test
public void givenValuesOfDifferentTypesWhenTestingValueDescriptorEqualityExpectNotEquals() {
    Some some = buildSomeValue(module);
    ValueDescriptor someDescriptor = qi4j.api().valueDescriptorFor(some);
    Other other = buildOtherValue(module);
    ValueDescriptor otherDescriptor = qi4j.api().valueDescriptorFor(other);
    assertThat("ValueDescriptors not equal", someDescriptor, not(equalTo(otherDescriptor)));
    assertThat("ValueDescriptors hashcode not equal", someDescriptor.hashCode(), not(equalTo(otherDescriptor.hashCode())));
}
Also used : AnotherSome(org.qi4j.runtime.property.PropertyEqualityTest.AnotherSome) Some(org.qi4j.runtime.property.PropertyEqualityTest.Some) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) Other(org.qi4j.runtime.property.PropertyEqualityTest.Other) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

ValueDescriptor (org.qi4j.api.value.ValueDescriptor)22 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)10 Test (org.junit.Test)6 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)6 AssociationStateHolder (org.qi4j.api.association.AssociationStateHolder)4 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)4 ValueComposite (org.qi4j.api.value.ValueComposite)4 IOException (java.io.IOException)3 Writer (java.io.Writer)3 Identity (org.qi4j.api.entity.Identity)3 ValueSerializationException (org.qi4j.api.value.ValueSerializationException)3 AnotherSome (org.qi4j.runtime.property.PropertyEqualityTest.AnotherSome)3 Some (org.qi4j.runtime.property.PropertyEqualityTest.Some)3 TemplateException (freemarker.template.TemplateException)2 HashMap (java.util.HashMap)2 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)2 AssociationStateDescriptor (org.qi4j.api.association.AssociationStateDescriptor)2 QualifiedName (org.qi4j.api.common.QualifiedName)2 CompositeDescriptor (org.qi4j.api.composite.CompositeDescriptor)2 CompositeInstance (org.qi4j.api.composite.CompositeInstance)2