use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerOperationServiceImpl method delete.
@Override
public long delete(String key, String objectClass, ConvertedExpression expression, int count) throws DeleteException {
Instant startTime = OperationDurationUtil.instance().now();
TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
long result = deleteImpl(tableMapping, expression, count);
Duration duration = OperationDurationUtil.instance().duration(startTime);
OperationDurationUtil.instance().logDebug("SQL operation: delete_search, duration: {}, table: {}, key: {}, expression: {}, count: {}", duration, tableMapping.getTableName(), key, expression, count);
return result;
}
use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerOperationServiceImpl method authenticateImpl.
private boolean authenticateImpl(String key, String password, String objectClass) throws SearchException {
Instant startTime = OperationDurationUtil.instance().now();
boolean result = false;
if (password != null) {
try {
List<AttributeData> attributes = lookup(key, objectClass, USER_PASSWORD);
Object userPasswordObj = null;
for (AttributeData attribute : attributes) {
if (StringHelper.equalsIgnoreCase(attribute.getName(), USER_PASSWORD)) {
userPasswordObj = attribute.getValue();
}
}
String userPassword = null;
if (userPasswordObj instanceof String) {
userPassword = (String) userPasswordObj;
}
if (userPassword != null) {
if (persistenceExtension == null) {
result = PasswordEncryptionHelper.compareCredentials(password, userPassword);
} else {
result = persistenceExtension.compareHashedPasswords(password, userPassword);
}
}
} catch (EntryConvertationException ex) {
throw new SearchException(String.format("Failed to get '%s' attribute", USER_PASSWORD), ex);
}
}
Duration duration = OperationDurationUtil.instance().duration(startTime);
TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
OperationDurationUtil.instance().logDebug("Spanner operation: bind, 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 buildSelectAttributes.
private List<SelectItem> buildSelectAttributes(TableMapping tableMapping, String key, String... attributes) throws SearchException {
String tableName = tableMapping.getTableName();
Map<String, StructField> columTypes = tableMapping.getColumTypes();
// Table alias for columns
// Column dn
Column selectDnColumn = new Column(tableAlias, DN);
SelectExpressionItem selectDnItem = new SelectExpressionItem(selectDnColumn);
// Column doc_id
Column selectDocIdColumn = new Column(tableAlias, DOC_ID);
SelectExpressionItem selectDocIdItem = new SelectExpressionItem(selectDocIdColumn);
if (ArrayHelper.isEmpty(attributes)) {
// Select all columns
AllTableColumns allColumns = new AllTableColumns(tableAlias);
List<SelectItem> selectColumns = new ArrayList<SelectItem>();
selectColumns.add(allColumns);
// Add columns from child tables
List<SelectExpressionItem> selectChildColumns = buildSelectAttributeFromChildTables(tableName);
selectColumns.addAll(selectChildColumns);
return selectColumns;
} else if ((attributes.length == 1) && StringHelper.isEmpty(attributes[0])) {
// Compatibility with base persistence layer when application pass attributes new String[] { "" }
List<SelectItem> selectColumns = Arrays.asList(selectDnItem, selectDocIdItem);
// Add columns from child tables
List<SelectExpressionItem> selectChildColumns = buildSelectAttributeFromChildTables(tableName);
selectColumns.addAll(selectChildColumns);
return selectColumns;
}
List<SelectItem> expresisons = new ArrayList<SelectItem>(attributes.length + 2);
boolean hasDn = false;
for (String attributeName : attributes) {
StructField attributeType = columTypes.get(attributeName.toLowerCase());
SelectExpressionItem selectExpressionItem;
// 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 SearchException(String.format("Failed to build select attributes. Column '%s' is undefined", attributeName));
}
// Add columns from child table
selectExpressionItem = buildSelectAttributeFromChildTable(tableName, attributeName);
} else {
Column selectColumn = new Column(tableAlias, attributeName);
selectExpressionItem = new SelectExpressionItem(selectColumn);
}
expresisons.add(selectExpressionItem);
hasDn |= StringHelper.equals(attributeName, DN);
}
if (!hasDn) {
expresisons.add(selectDnItem);
}
expresisons.add(selectDocIdItem);
return expresisons;
}
use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerOperationServiceImpl method lookup.
@Override
public List<AttributeData> lookup(String key, String objectClass, String... attributes) throws SearchException, EntryConvertationException {
Instant startTime = OperationDurationUtil.instance().now();
TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
List<AttributeData> result = lookupImpl(tableMapping, key, attributes);
Duration duration = OperationDurationUtil.instance().duration(startTime);
OperationDurationUtil.instance().logDebug("SQL operation: lookup, duration: {}, table: {}, key: {}, attributes: {}", duration, tableMapping.getTableName(), key, attributes);
return result;
}
use of io.jans.orm.cloud.spanner.model.TableMapping in project jans by JanssenProject.
the class SpannerOperationServiceImpl method getTabeMapping.
@Override
public TableMapping getTabeMapping(String key, String objectClass) {
TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
Map<String, TableMapping> childTableMapping = connectionProvider.getChildTablesMapping(key, tableMapping);
tableMapping.setChildTableMapping(childTableMapping);
return tableMapping;
}
Aggregations