used cached resultset for additional data in places (wip)

This commit is contained in:
John Woodlock
2012-08-28 23:16:02 +10:00
parent 47fe49da8c
commit dca9063a07
2 changed files with 50 additions and 38 deletions
@@ -37,7 +37,7 @@ public class GenericDataServiceImpl implements GenericDataService {
} }
@Override @Override
public CachedRowSetImpl getCachedResultSet(String sql, String errorMsg) { public CachedRowSetImpl getCachedResultSet(String sql, String sqlErrorMsg) {
Connection db_connection = null; Connection db_connection = null;
Statement db_statement = null; Statement db_statement = null;
@@ -51,7 +51,7 @@ public class GenericDataServiceImpl implements GenericDataService {
return crs; return crs;
} catch (SQLException e) { } catch (SQLException e) {
throw new PlatformDataIntegrityException("error.msg.sql.error", throw new PlatformDataIntegrityException("error.msg.sql.error",
e.getMessage(), errorMsg); e.getMessage(), sqlErrorMsg);
} finally { } finally {
dbClose(db_statement, db_connection); dbClose(db_statement, db_connection);
@@ -114,17 +114,14 @@ public class ReadWriteNonCoreDataServiceImpl implements
private GenericResultsetData fillExtraDataGenericResultSet( private GenericResultsetData fillExtraDataGenericResultSet(
final String type, final String set, final Long id) { final String type, final String set, final Long id) {
String sql = "select f.`name`, f.data_type, f.data_length, f.display_type, f.allowed_list_id from stretchydata_datasettype t join stretchydata_dataset d on d.datasettype_id = t.id join stretchydata_dataset_fields f on f.dataset_id = d.id where d.`name` = '" String sql = "select f.`name`, f.data_type, f.data_length, f.display_type, f.allowed_list_id from stretchydata_datasettype t join stretchydata_dataset d on d.datasettype_id = t.id join stretchydata_dataset_fields f on f.dataset_id = d.id where d.`name` = '"
+ set + "' and t.`name` = '" + type + "' order by f.id"; + set + "' and t.`name` = '" + type + "' order by f.id";
String sqlErrorMsg = "Additional Fields Type: " + type + " Set: " String sqlErrorMsg = "Additional Fields Type: " + type + " Set: "
+ set + " Id: " + id; + set + " Id: " + id;
CachedRowSetImpl rsmd = genericDataService.getCachedResultSet(sql, sqlErrorMsg); CachedRowSetImpl rsmd = genericDataService.getCachedResultSet(sql,
sqlErrorMsg);
Connection db_connection = null; Connection db_connection = null;
Statement db_statement2 = null; Statement db_statement2 = null;
@@ -179,18 +176,41 @@ public class ReadWriteNonCoreDataServiceImpl implements
columnHeaders.add(rsch); columnHeaders.add(rsch);
} while (rsmd.next()); } while (rsmd.next());
String unScopedSQL = "select " + selectFieldList + " from `" String unScopedSQL = "select " + selectFieldList + " from `"
+ type + "` t ${dataScopeCriteria} left join `" + type + "` t ${dataScopeCriteria} left join `"
+ fullDatasetName + "` s on s.id = t.id " + fullDatasetName + "` s on s.id = t.id "
+ " where t.id = " + id; + " where t.id = " + id;
sql = dataScopedSQL(unScopedSQL, type); sql = dataScopedSQL(unScopedSQL, type);
logger.info("addition fields sql: " + sql); logger.info("addition fields sql: " + sql);
//maybe can reduce parameters a bit (type and id only needed because of exception)
resultsetDataRows = getResultsetDataRows(columnHeaders, sql,
sqlErrorMsg, type, id);
CachedRowSetImpl rs = genericDataService.getCachedResultSet(sql, sqlErrorMsg); } else {
//db_statement3 = db_connection.createStatement(); throw new AdditionalFieldsNotFoundException(type, set);
//ResultSet rs = db_statement3.executeQuery(sql); }
return new GenericResultsetData(columnHeaders, resultsetDataRows);
} catch (SQLException e) {
throw new PlatformDataIntegrityException("error.msg.sql.error",
e.getMessage(), "Additional Fields Type: " + type
+ " Set: " + set + " Id: " + id);
} finally {
genericDataService.dbClose(db_statement2, db_connection);
}
}
private List<ResultsetDataRow> getResultsetDataRows(
List<ResultsetColumnHeader> columnHeaders, String sql,
String sqlErrorMsg, String type, Long id) {
List<ResultsetDataRow> resultsetDataRows = null;
CachedRowSetImpl rs = genericDataService.getCachedResultSet(sql,
sqlErrorMsg);
try {
if (rs.next()) { if (rs.next()) {
String columnName = null; String columnName = null;
String columnValue = null; String columnValue = null;
@@ -208,24 +228,16 @@ public class ReadWriteNonCoreDataServiceImpl implements
resultsetDataRow.setRow(columnValues); resultsetDataRow.setRow(columnValues);
resultsetDataRows.add(resultsetDataRow); resultsetDataRows.add(resultsetDataRow);
} while (rs.next()); } while (rs.next());
} else { return resultsetDataRows;
// could also be not found because of data scope
throw new AdditionalFieldsNotFoundException(type, id);
} }
} else {
throw new AdditionalFieldsNotFoundException(type, set);
}
return new GenericResultsetData(columnHeaders, resultsetDataRows);
} catch (SQLException e) { } catch (SQLException e) {
throw new PlatformDataIntegrityException("error.msg.sql.error", throw new PlatformDataIntegrityException("error.msg.sql.error",
e.getMessage(), "Additional Fields Type: " + type e.getMessage(), sqlErrorMsg);
+ " Set: " + set + " Id: " + id);
} finally {
genericDataService.dbClose(db_statement2, db_connection);
} }
// could also be not found because of data scope so need to split this
// up
throw new AdditionalFieldsNotFoundException(type, id);
} }
@Override @Override