use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerFilterConverter method getStructField.
private StructField getStructField(TableMapping tableMapping, String attributeName) throws SearchException {
String attributeNameLower = attributeName.toLowerCase();
StructField structField = tableMapping.getColumTypes().get(attributeNameLower);
if (structField == null) {
TableMapping childTableMapping = tableMapping.getChildTableMappingForAttribute(attributeNameLower);
if (childTableMapping != null) {
structField = childTableMapping.getColumTypes().get(attributeNameLower);
}
}
if (structField == null) {
throw new SearchException(String.format("Unknown column name '%s' in table/child table '%s'", attributeName, tableMapping.getTableName()));
}
return structField;
}
use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerOperationServiceImpl method addEntryImpl.
private boolean addEntryImpl(TableMapping tableMapping, String key, Collection<AttributeData> attributes) throws PersistenceException {
try {
MessageDigest messageDigest = getMessageDigestInstance();
Map<String, StructField> columTypes = tableMapping.getColumTypes();
WriteBuilder mutationBuilder = Mutation.newInsertOrUpdateBuilder(tableMapping.getTableName());
List<Mutation> mutations = new LinkedList<>();
for (AttributeData attribute : attributes) {
String attributeName = attribute.getName();
StructField attributeType = columTypes.get(attributeName.toLowerCase());
// If column not inside table we should check if there is child table
if (attributeType == null) {
TableMapping childTableMapping = connectionProvider.getChildTableMappingByKey(key, tableMapping, attributeName);
if (childTableMapping == null) {
throw new PersistenceException(String.format("Failed to add entry. Column '%s' is undefined", attributeName));
}
Map<String, StructField> childColumTypes = childTableMapping.getColumTypes();
if (childColumTypes == null) {
throw new PersistenceException(String.format("Failed to add entry. Column '%s' is undefined", attributeName));
}
StructField childAttributeType = childColumTypes.get(attributeName.toLowerCase());
// Build Mutation for child table
for (Object value : attribute.getValues()) {
// Build Mutation for child table
String dictDocId = getStringUniqueKey(messageDigest, value);
WriteBuilder childMutationBuilder = Mutation.newInsertOrUpdateBuilder(childTableMapping.getTableName());
childMutationBuilder.set(SpannerOperationService.DOC_ID).to(key).set(SpannerOperationService.DICT_DOC_ID).to(dictDocId);
setMutationBuilderValue(childMutationBuilder, childAttributeType, value);
mutations.add(childMutationBuilder.build());
}
} else {
setMutationBuilderValue(mutationBuilder, attributeType, attribute.getValues());
}
}
mutations.add(0, mutationBuilder.build());
databaseClient.write(mutations);
return true;
} catch (SpannerException | IllegalStateException ex) {
throw new PersistenceException("Failed to add entry", ex);
}
}
use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerFilterConverter method addJoinTable.
private void addJoinTable(TableMapping tableMapping, String attributeName, Map<String, Join> joinTables) {
if (joinTables.containsKey(attributeName)) {
return;
}
TableMapping childTableMapping = tableMapping.getChildTableMappingForAttribute(attributeName.toLowerCase());
Table childTable = new Table(childTableMapping.getTableName());
childTable.setAlias(new Alias(attributeName, false));
EqualsTo onExpression = new EqualsTo().withLeftExpression(new Column().withTable(tableAlias).withColumnName(SpannerOperationService.DOC_ID)).withRightExpression(new Column().withTable(childTable).withColumnName(SpannerOperationService.DOC_ID));
Join join = new Join();
join.setRightItem(childTable);
join.setOnExpression(onExpression);
joinTables.put(attributeName, join);
}
use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerOperationServiceImpl method delete.
@Override
public boolean delete(String key, String objectClass) throws EntryNotFoundException {
Instant startTime = OperationDurationUtil.instance().now();
TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
boolean result = deleteImpl(tableMapping, key);
Duration duration = OperationDurationUtil.instance().duration(startTime);
OperationDurationUtil.instance().logDebug("SQL operation: delete, duration: {}, table: {}, key: {}", duration, tableMapping.getTableName(), key);
return result;
}
use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerOperationServiceImpl method deleteRecursively.
@Override
public boolean deleteRecursively(String key, String objectClass) throws EntryNotFoundException, SearchException {
Instant startTime = OperationDurationUtil.instance().now();
TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
boolean result = deleteRecursivelyImpl(tableMapping, key);
Duration duration = OperationDurationUtil.instance().duration(startTime);
OperationDurationUtil.instance().logDebug("SQL operation: delete_tree, duration: {}, table: {}, key: {}", duration, tableMapping.getTableName(), key);
return result;
}
Aggregations