Search in sources :

Example 1 with Composite

use of org.qi4j.api.composite.Composite in project qi4j-sdk by Qi4j.

the class ModuleInstance method newValueBuilderWithPrototype.

@Override
@SuppressWarnings("unchecked")
public <T> ValueBuilder<T> newValueBuilderWithPrototype(T prototype) {
    NullArgumentException.validateNotNull("prototype", prototype);
    ValueInstance valueInstance = ValueInstance.valueInstanceOf((ValueComposite) prototype);
    Class<Composite> valueType = (Class<Composite>) first(valueInstance.types());
    ModelModule<ValueModel> modelModule = typeLookup.lookupValueModel(valueType);
    if (modelModule == null) {
        throw new NoSuchValueException(valueType.getName(), name());
    }
    return new ValueBuilderWithPrototype<>(modelModule, this, prototype);
}
Also used : NoSuchValueException(org.qi4j.api.value.NoSuchValueException) Composite(org.qi4j.api.composite.Composite) ValueComposite(org.qi4j.api.value.ValueComposite) EntityComposite(org.qi4j.api.entity.EntityComposite) ValueModel(org.qi4j.runtime.value.ValueModel) ValueBuilderWithPrototype(org.qi4j.runtime.value.ValueBuilderWithPrototype) ValueInstance(org.qi4j.runtime.value.ValueInstance)

Example 2 with Composite

use of org.qi4j.api.composite.Composite in project qi4j-sdk by Qi4j.

the class AbstractNamedQueryTest method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    super.assemble(module);
    new EntityTestAssembler().assemble(module);
    String[] query = queryStrings();
    for (int i = 0; i < query.length; i++) {
        String queryName = String.format("script%02d", i + 1);
        if (query[i].length() != 0) {
            Specification<Composite> expression = createNamedQueryDescriptor(queryName, query[i]);
            queries.put(queryName, expression);
        }
    }
}
Also used : Composite(org.qi4j.api.composite.Composite) EntityTestAssembler(org.qi4j.test.EntityTestAssembler)

Example 3 with Composite

use of org.qi4j.api.composite.Composite in project qi4j-sdk by Qi4j.

the class EntityStateSerializer method serializeValueComposite.

private void serializeValueComposite(Resource subject, URI predicate, ValueComposite value, ValueType valueType, Graph graph, String baseUri, boolean includeNonQueryable) {
    final ValueFactory valueFactory = graph.getValueFactory();
    BNode collection = valueFactory.createBNode();
    graph.add(subject, predicate, collection);
    for (PropertyDescriptor persistentProperty : ((ValueCompositeType) valueType).properties()) {
        Object propertyValue = Qi4j.FUNCTION_COMPOSITE_INSTANCE_OF.map((Composite) value).state().propertyFor(persistentProperty.accessor()).get();
        if (propertyValue == null) {
            // Skip null values
            continue;
        }
        ValueType type = persistentProperty.valueType();
        if (type instanceof ValueCompositeType) {
            URI pred = valueFactory.createURI(baseUri, persistentProperty.qualifiedName().name());
            serializeValueComposite(collection, pred, (ValueComposite) propertyValue, type, graph, baseUri + persistentProperty.qualifiedName().name() + "/", includeNonQueryable);
        } else {
            serializeProperty(persistentProperty, propertyValue, collection, graph, includeNonQueryable);
        }
    }
}
Also used : BNode(org.openrdf.model.BNode) PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) ValueComposite(org.qi4j.api.value.ValueComposite) Composite(org.qi4j.api.composite.Composite) ValueType(org.qi4j.api.type.ValueType) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) ValueCompositeType(org.qi4j.api.type.ValueCompositeType)

Example 4 with Composite

use of org.qi4j.api.composite.Composite in project qi4j-sdk by Qi4j.

the class DebugConcern method debug.

@Override
public void debug(int priority, String message) {
    System.out.println("L:" + composite);
    if (loggingService == null) {
        return;
    }
    if (priority >= loggingService.debugLevel()) {
        Composite derefed = api.dereference(composite);
        loggingService.debug(derefed, message);
    }
}
Also used : Composite(org.qi4j.api.composite.Composite)

Example 5 with Composite

use of org.qi4j.api.composite.Composite in project qi4j-sdk by Qi4j.

the class CompositeModel method newProxy.

public Composite newProxy(InvocationHandler invocationHandler) throws ConstructionException {
    Class<?> mainType = first(types());
    if (mainType.isInterface()) {
        try {
            return Composite.class.cast(proxyConstructor.newInstance(invocationHandler));
        } catch (Exception e) {
            throw new ConstructionException(e);
        }
    } else {
        try {
            Object[] args = new Object[proxyConstructor.getParameterTypes().length];
            Composite composite = Composite.class.cast(proxyConstructor.newInstance(args));
            proxyClass.getField("_instance").set(composite, invocationHandler);
            return composite;
        } catch (Exception e) {
            throw new ConstructionException(e);
        }
    }
}
Also used : Composite(org.qi4j.api.composite.Composite) ConstructionException(org.qi4j.api.common.ConstructionException) ConstructionException(org.qi4j.api.common.ConstructionException) InvalidCompositeException(org.qi4j.api.composite.InvalidCompositeException)

Aggregations

Composite (org.qi4j.api.composite.Composite)7 EntityComposite (org.qi4j.api.entity.EntityComposite)2 ValueComposite (org.qi4j.api.value.ValueComposite)2 ArrayList (java.util.ArrayList)1 BNode (org.openrdf.model.BNode)1 URI (org.openrdf.model.URI)1 ValueFactory (org.openrdf.model.ValueFactory)1 ConstructionException (org.qi4j.api.common.ConstructionException)1 InvalidCompositeException (org.qi4j.api.composite.InvalidCompositeException)1 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)1 AndSpecification (org.qi4j.api.query.grammar.AndSpecification)1 AssociationNotNullSpecification (org.qi4j.api.query.grammar.AssociationNotNullSpecification)1 AssociationNullSpecification (org.qi4j.api.query.grammar.AssociationNullSpecification)1 ComparisonSpecification (org.qi4j.api.query.grammar.ComparisonSpecification)1 ContainsAllSpecification (org.qi4j.api.query.grammar.ContainsAllSpecification)1 ContainsSpecification (org.qi4j.api.query.grammar.ContainsSpecification)1 EqSpecification (org.qi4j.api.query.grammar.EqSpecification)1 GeSpecification (org.qi4j.api.query.grammar.GeSpecification)1 GtSpecification (org.qi4j.api.query.grammar.GtSpecification)1 LeSpecification (org.qi4j.api.query.grammar.LeSpecification)1