Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept mutliple rows/records in Jdbc Source #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/main/java/org/lsc/service/AbstractJdbcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,42 @@ public IBean getBean(String id, LscDatasets attributes, boolean fromSameService)
srcBean = beanClass.newInstance();
List<?> records = sqlMapper.queryForList(getRequestNameForObjectOrClean(fromSameService), getAttributesMap(attributes));
if(records.size() > 1) {
// this is useful for multivalued entries, for groups.
// To use with caution when few column are used because there will be many duplicated content.
// TODO : name of multivalued column should be configured, then only this one is returned as multiple values.
// TODO : if no multivalued column is set then throws an exception
/*
throw new LscServiceException("Only a single record can be returned from a getObject request ! " +
"For id=" + id + ", there are " + records.size() + " records !");
*/
for ( Object recordObject : records ) {
Map<String, Object> record = (Map<String, Object>) recordObject;
for (Entry<String, Object> entry : record.entrySet()) {
if (entry.getValue() != null) {
Set<Object> previousValues = srcBean.getDatasetById(entry.getKey());
if ( previousValues != null ) {
previousValues.add(entry.getValue());
srcBean.setDataset(entry.getKey(), previousValues);
}
else {
srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey(), entry.getValue())));
}
} else {
srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey())));
}
}
}
} else if (records.size() == 0) {
return null;
}
Map<String, Object> record = (Map<String, Object>) records.get(0);
for(Entry<String, Object> entry: record.entrySet()) {
if(entry.getValue() != null) {
srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey(), entry.getValue())));
} else {
srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey())));
else {
Map<String, Object> record = (Map<String, Object>) records.get(0);
for (Entry<String, Object> entry : record.entrySet()) {
if (entry.getValue() != null) {
srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey(), entry.getValue())));
} else {
srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey())));
}
}
}
srcBean.setMainIdentifier(id);
Expand Down