Search in sources :

Example 1 with TableMapping

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;
}
Also used : Instant(java.time.Instant) TableMapping(io.jans.orm.cloud.spanner.model.TableMapping) Duration(java.time.Duration)

Example 2 with TableMapping

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;
}
Also used : Instant(java.time.Instant) SearchException(io.jans.orm.exception.operation.SearchException) TableMapping(io.jans.orm.cloud.spanner.model.TableMapping) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) Duration(java.time.Duration) AttributeData(io.jans.orm.model.AttributeData)

Example 3 with TableMapping

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;
}
Also used : SelectExpressionItem(net.sf.jsqlparser.statement.select.SelectExpressionItem) ArrayList(java.util.ArrayList) TableMapping(io.jans.orm.cloud.spanner.model.TableMapping) SearchException(io.jans.orm.exception.operation.SearchException) ValueWithStructField(io.jans.orm.cloud.spanner.model.ValueWithStructField) StructField(com.google.cloud.spanner.Type.StructField) Column(net.sf.jsqlparser.schema.Column) AllTableColumns(net.sf.jsqlparser.statement.select.AllTableColumns) SelectItem(net.sf.jsqlparser.statement.select.SelectItem) List(java.util.List) ArrayList(java.util.ArrayList) ExpressionList(net.sf.jsqlparser.expression.operators.relational.ExpressionList) LinkedList(java.util.LinkedList)

Example 4 with TableMapping

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;
}
Also used : Instant(java.time.Instant) TableMapping(io.jans.orm.cloud.spanner.model.TableMapping) Duration(java.time.Duration) AttributeData(io.jans.orm.model.AttributeData)

Example 5 with TableMapping

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;
}
Also used : TableMapping(io.jans.orm.cloud.spanner.model.TableMapping)

Aggregations

TableMapping (io.jans.orm.cloud.spanner.model.TableMapping)17 Duration (java.time.Duration)8 Instant (java.time.Instant)8 StructField (com.google.cloud.spanner.Type.StructField)5 ValueWithStructField (io.jans.orm.cloud.spanner.model.ValueWithStructField)4 AttributeData (io.jans.orm.model.AttributeData)4 SearchException (io.jans.orm.exception.operation.SearchException)3 LinkedList (java.util.LinkedList)3 Mutation (com.google.cloud.spanner.Mutation)2 WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)2 SpannerException (com.google.cloud.spanner.SpannerException)2 PersistenceException (io.jans.orm.exception.operation.PersistenceException)2 MessageDigest (java.security.MessageDigest)2 Column (net.sf.jsqlparser.schema.Column)2 KeySet (com.google.cloud.spanner.KeySet)1 Builder (com.google.cloud.spanner.Statement.Builder)1 KeyConversionException (io.jans.orm.exception.KeyConversionException)1 MappingException (io.jans.orm.exception.MappingException)1 EntryConvertationException (io.jans.orm.exception.operation.EntryConvertationException)1 AttributeDataModification (io.jans.orm.model.AttributeDataModification)1