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;
}
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);
}
}
Aggregations