Search in sources :

Example 61 with AttributeData

use of io.jans.orm.model.AttributeData in project jans by JanssenProject.

the class SqlOperationServiceImpl method getEntryDataList.

private List<EntryData> getEntryDataList(TableMapping tableMapping, ResultSet resultSet) throws EntryConvertationException, SQLException {
    List<EntryData> entryDataList = new LinkedList<>();
    List<AttributeData> attributeDataList = null;
    while (!resultSet.isLast()) {
        attributeDataList = getAttributeDataList(tableMapping, resultSet, false);
        if (attributeDataList == null) {
            break;
        }
        EntryData entryData = new EntryData(attributeDataList);
        entryDataList.add(entryData);
    }
    return entryDataList;
}
Also used : EntryData(io.jans.orm.model.EntryData) LinkedList(java.util.LinkedList) AttributeData(io.jans.orm.model.AttributeData)

Example 62 with AttributeData

use of io.jans.orm.model.AttributeData in project jans by JanssenProject.

the class SqlOperationServiceImpl method getAttributeDataList.

private List<AttributeData> getAttributeDataList(TableMapping tableMapping, ResultSet resultSet, boolean skipDn) throws EntryConvertationException {
    try {
        if ((resultSet == null)) {
            return null;
        }
        if (!resultSet.next()) {
            return null;
        }
        List<AttributeData> result = new ArrayList<AttributeData>();
        int columnsCount = resultSet.getMetaData().getColumnCount();
        for (int i = 1; i <= columnsCount; i++) {
            ResultSetMetaData metaData = resultSet.getMetaData();
            String shortAttributeName = metaData.getColumnName(i);
            String columnTypeName = metaData.getColumnTypeName(i).toLowerCase();
            boolean isNullable = metaData.isNullable(i) == ResultSetMetaData.columnNullable;
            Object attributeObject = resultSet.getObject(shortAttributeName);
            if (SqlOperationService.DOC_ID.equalsIgnoreCase(shortAttributeName) || SqlOperationService.ID.equalsIgnoreCase(shortAttributeName)) {
                // Skip internal attributes
                continue;
            }
            if (skipDn && SqlOperationService.DN.equalsIgnoreCase(shortAttributeName)) {
                // Skip DN attribute
                continue;
            }
            String attributeName = fromInternalAttribute(shortAttributeName);
            Boolean multiValued = Boolean.FALSE;
            Object[] attributeValueObjects;
            if (attributeObject == null) {
                attributeValueObjects = NO_OBJECTS;
                if (isNullable) {
                    // Ignore columns with default NULL values
                    continue;
                }
            } else {
                if (isJsonColumn(tableMapping.getTableName(), columnTypeName)) {
                    attributeValueObjects = convertDbJsonToValue(attributeObject.toString());
                    multiValued = Boolean.TRUE;
                } else if (attributeObject instanceof Integer) {
                    int columnType = resultSet.getMetaData().getColumnType(i);
                    if (columnType == java.sql.Types.SMALLINT) {
                        if (attributeObject.equals(0)) {
                            attributeObject = Boolean.FALSE;
                        } else if (attributeObject.equals(1)) {
                            attributeObject = Boolean.TRUE;
                        }
                    }
                    attributeValueObjects = new Object[] { attributeObject };
                } else if ((attributeObject instanceof Boolean) || (attributeObject instanceof Long)) {
                    attributeValueObjects = new Object[] { attributeObject };
                } else if (attributeObject instanceof String) {
                    Object value = attributeObject.toString();
                    try {
                        SimpleDateFormat jsonDateFormat = new SimpleDateFormat(SQL_DATA_FORMAT);
                        value = jsonDateFormat.parse(attributeObject.toString());
                    } catch (Exception ex) {
                    }
                    attributeValueObjects = new Object[] { value };
                } else if (attributeObject instanceof Timestamp) {
                    attributeValueObjects = new Object[] { new java.util.Date(((Timestamp) attributeObject).getTime()) };
                } else {
                    Object value = attributeObject.toString();
                    attributeValueObjects = new Object[] { value };
                }
            }
            unescapeValues(attributeValueObjects);
            AttributeData tmpAttribute = new AttributeData(attributeName, attributeValueObjects, multiValued);
            if (multiValued != null) {
                tmpAttribute.setMultiValued(multiValued);
            }
            result.add(tmpAttribute);
        }
        return result;
    } catch (SQLException ex) {
        throw new EntryConvertationException("Failed to convert entry!", ex);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) QueryException(com.querydsl.core.QueryException) DeleteException(io.jans.orm.exception.operation.DeleteException) MappingException(io.jans.orm.exception.MappingException) PersistenceException(io.jans.orm.exception.operation.PersistenceException) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SQLException(java.sql.SQLException) SearchException(io.jans.orm.exception.operation.SearchException) EntryNotFoundException(io.jans.orm.exception.operation.EntryNotFoundException) ResultSetMetaData(java.sql.ResultSetMetaData) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) SimpleDateFormat(java.text.SimpleDateFormat) AttributeData(io.jans.orm.model.AttributeData)

Aggregations

AttributeData (io.jans.orm.model.AttributeData)62 MappingException (io.jans.orm.exception.MappingException)29 ArrayList (java.util.ArrayList)23 SearchException (io.jans.orm.exception.operation.SearchException)22 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)17 AuthenticationException (io.jans.orm.exception.AuthenticationException)15 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)14 AttributeDataModification (io.jans.orm.model.AttributeDataModification)13 JsonObject (io.jans.orm.annotation.JsonObject)10 LinkedList (java.util.LinkedList)10 DateTimeParseException (java.time.format.DateTimeParseException)8 List (java.util.List)8 ParsedKey (io.jans.orm.impl.model.ParsedKey)7 JsonObject (com.couchbase.client.java.document.json.JsonObject)6 AttributeName (io.jans.orm.annotation.AttributeName)6 PersistenceException (io.jans.orm.exception.operation.PersistenceException)6 Annotation (java.lang.annotation.Annotation)6 AttributeModificationType (io.jans.orm.model.AttributeDataModification.AttributeModificationType)5 LinkedHashMap (java.util.LinkedHashMap)5