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;
}
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());
}
}
}
}
}
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;
}
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);
}
}
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())));
}
Aggregations