use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method extractManyAssociationQNames.
private void extractManyAssociationQNames(EntityDescriptor entityDesc, Map<QualifiedName, QNameInfo> extractedQNames, Set<QualifiedName> newQNames, Boolean setQNameTableNameToNull) {
for (AssociationDescriptor mAssoDesc : entityDesc.state().manyAssociations()) {
QualifiedName qName = mAssoDesc.qualifiedName();
if (SQLSkeletonUtil.isQueryable(mAssoDesc.accessor())) {
if (!extractedQNames.containsKey(qName)) {
//
extractedQNames.put(//
qName, //
QNameInfo.fromManyAssociation(//
qName, setQNameTableNameToNull ? null : (QNAME_TABLE_NAME_PREFIX + extractedQNames.size()), //
mAssoDesc));
newQNames.add(qName);
}
}
}
}
use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method initConnection.
@Override
public void initConnection() throws SQLException {
this._configuration.refresh();
this.initTypes();
this.modifyPrimitiveTypes(this._primitiveTypes, this._state.javaTypes2SQLTypes().get());
String schemaName = this._configuration.get().schemaName().get();
if (schemaName == null) {
schemaName = DEFAULT_SCHEMA_NAME;
} else {
this.checkSchemaName(schemaName);
}
LOGGER.debug("Will use '{}' as schema name", schemaName);
this._state.schemaName().set(schemaName);
this._state.entityTypePKs().set(new HashMap<String, Integer>());
this._state.usedClassesPKs().set(new HashMap<CompositeDescriptor, Integer>());
this._state.entityUsedQNames().set(new HashMap<EntityDescriptor, Set<QualifiedName>>());
this._state.qNameInfos().set(new HashMap<QualifiedName, QNameInfo>());
this._state.enumPKs().set(new HashMap<String, Integer>());
Connection connection = this._dataSource.getConnection();
try {
connection.setAutoCommit(true);
connection.setReadOnly(false);
this.syncDB(connection);
} finally {
SQLUtil.closeQuietly(connection);
}
if (LOGGER.isDebugEnabled()) {
String newline = "\n";
String tab = "\t";
String colonspace = ": ";
StringBuilder report = new StringBuilder();
report.append("schemaName: ").append(_state.schemaName().get()).append(newline);
report.append("qNameInfos: ").append(newline);
for (Map.Entry<QualifiedName, QNameInfo> entry : _state.qNameInfos().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("entityUsedQNames:").append(newline);
for (Map.Entry<EntityDescriptor, Set<QualifiedName>> entry : _state.entityUsedQNames().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("usedClassesPKs:").append(newline);
for (Map.Entry<CompositeDescriptor, Integer> entry : _state.usedClassesPKs().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("javaTypes2SQLTypes:").append(newline);
for (Map.Entry<Class<?>, Integer> entry : _state.javaTypes2SQLTypes().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("entityTypePKs:").append(newline);
for (Map.Entry<String, Integer> entry : _state.entityTypePKs().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("enumPKs:").append(newline);
for (Map.Entry<String, Integer> entry : _state.enumPKs().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
LOGGER.debug("SQLDBState after initConnection:\n{}", report.toString());
}
}
use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.
the class AbstractSQLIndexing method insertAssoAndManyAssoQNames.
private void insertAssoAndManyAssoQNames(Map<QualifiedName, PreparedStatement> qNameInsertPSs, PreparedStatement insertToAllQNamesPS, EntityState state, Integer qNamePK, Long entityPK) throws SQLException {
for (AssociationDescriptor aDesc : state.entityDescriptor().state().associations()) {
if (SQLSkeletonUtil.isQueryable(aDesc.accessor())) {
QualifiedName qName = aDesc.qualifiedName();
PreparedStatement ps = qNameInsertPSs.get(qName);
EntityReference ref = state.associationValueOf(qName);
if (ref != null) {
insertToAllQNamesPS.setInt(1, qNamePK);
insertToAllQNamesPS.setLong(2, entityPK);
insertToAllQNamesPS.addBatch();
ps.setInt(1, qNamePK);
ps.setLong(2, entityPK);
ps.setString(3, ref.identity());
ps.addBatch();
++qNamePK;
}
}
}
for (AssociationDescriptor mDesc : state.entityDescriptor().state().manyAssociations()) {
if (SQLSkeletonUtil.isQueryable(mDesc.accessor())) {
QualifiedName qName = mDesc.qualifiedName();
PreparedStatement ps = qNameInsertPSs.get(qName);
Integer index = 0;
for (EntityReference ref : state.manyAssociationValueOf(qName)) {
if (ref != null) {
insertToAllQNamesPS.setInt(1, qNamePK);
insertToAllQNamesPS.setLong(2, entityPK);
insertToAllQNamesPS.addBatch();
ps.setInt(1, qNamePK);
ps.setLong(2, entityPK);
ps.setInt(3, index);
ps.setString(4, ref.identity());
ps.addBatch();
++qNamePK;
}
++index;
}
}
}
}
use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.
the class Triples method addTripleManyAssociation.
public Triple addTripleManyAssociation(final ManyAssociationFunction<?> manyAssociationReference, final boolean optional) {
AssociationFunction<?> traversedAssociation = manyAssociationReference.traversedAssociation();
String subject = "?entity";
if (traversedAssociation != null) {
subject = addTripleAssociation(traversedAssociation, false).value;
}
QualifiedName qualifiedName = QualifiedName.fromAccessor(manyAssociationReference.accessor());
String predicatePrefix = addNamespace(qualifiedName.toNamespace());
String predicate = predicatePrefix + ":" + qualifiedName.name();
Triple collectionTriple = addTriple(subject, predicate, optional);
String liSubject = collectionTriple.value;
return addTriple(liSubject, "rdf:li", false);
}
use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.
the class ValueCompositeCxfType method readObject.
@Override
public Object readObject(final MessageReader reader, final Context context) throws DatabindingException {
QName qname = getSchemaType();
final String className = (qname.getNamespaceURI() + "." + qname.getLocalPart()).substring(20);
// Read attributes
ValueDescriptor descriptor = module.valueDescriptor(className);
StateDescriptor stateDescriptor = descriptor.state();
final Map<QualifiedName, Object> values = new HashMap<>();
while (reader.hasMoreElementReaders()) {
MessageReader childReader = reader.getNextElementReader();
QName childName = childReader.getName();
QualifiedName childQualifiedName = QualifiedName.fromClass((Class) typeClass, childName.getLocalPart());
PropertyDescriptor propertyDescriptor = stateDescriptor.findPropertyModelByQualifiedName(childQualifiedName);
Type propertyType = propertyDescriptor.type();
AegisType type = getTypeMapping().getType(propertyType);
Object value = type.readObject(childReader, context);
values.put(childQualifiedName, value);
}
ValueBuilder<?> builder = module.newValueBuilderWithState((Class<?>) typeClass, new Function<PropertyDescriptor, Object>() {
@Override
public Object map(PropertyDescriptor descriptor1) {
return values.get(descriptor1.qualifiedName());
}
}, new Function<AssociationDescriptor, EntityReference>() {
@Override
public EntityReference map(AssociationDescriptor descriptor) {
Object value = values.get(descriptor.qualifiedName());
if (value == null) {
return null;
}
return EntityReference.parseEntityReference(value.toString());
}
}, new Function<AssociationDescriptor, Iterable<EntityReference>>() {
@Override
public Iterable<EntityReference> map(AssociationDescriptor descriptor) {
Object value = values.get(descriptor.qualifiedName());
if (value == null) {
return Iterables.empty();
}
String[] ids = value.toString().split(",");
List<EntityReference> references = new ArrayList<>(ids.length);
for (String id : ids) {
references.add(EntityReference.parseEntityReference(id));
}
return references;
}
}, new Function<AssociationDescriptor, Map<String, EntityReference>>() {
@Override
public Map<String, EntityReference> map(AssociationDescriptor descriptor) {
Object value = values.get(descriptor.qualifiedName());
if (value == null) {
return Collections.emptyMap();
}
String[] namedRefs = value.toString().split(",");
Map<String, EntityReference> references = new HashMap<>(namedRefs.length);
for (String namedRef : namedRefs) {
String[] splitted = namedRef.split(":");
references.put(splitted[0], EntityReference.parseEntityReference(splitted[1]));
}
return references;
}
});
return builder.newInstance();
}
Aggregations