used cached resultset for additional data in places (wip)
This commit is contained in:
+2
-2
@@ -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);
|
||||||
|
|
||||||
|
|||||||
+48
-36
@@ -114,21 +114,18 @@ 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;
|
||||||
//Statement db_statement3 = null;
|
// Statement db_statement3 = null;
|
||||||
try {
|
try {
|
||||||
db_connection = dataSource.getConnection();
|
db_connection = dataSource.getConnection();
|
||||||
|
|
||||||
@@ -160,10 +157,10 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
|||||||
rsch.setColumnType(rsmd.getString("data_type"));
|
rsch.setColumnType(rsmd.getString("data_type"));
|
||||||
if (rsmd.getInt("data_length") > 0)
|
if (rsmd.getInt("data_length") > 0)
|
||||||
rsch.setColumnLength(rsmd.getInt("data_length"));
|
rsch.setColumnLength(rsmd.getInt("data_length"));
|
||||||
|
|
||||||
rsch.setColumnDisplayType(rsmd.getString("display_type"));
|
rsch.setColumnDisplayType(rsmd.getString("display_type"));
|
||||||
allowedListId = rsmd.getInt("allowed_list_id");
|
allowedListId = rsmd.getInt("allowed_list_id");
|
||||||
|
|
||||||
if (allowedListId > 0) {
|
if (allowedListId > 0) {
|
||||||
|
|
||||||
// logger.info("allowedListId != null: Column: " +
|
// logger.info("allowedListId != null: Column: " +
|
||||||
@@ -179,39 +176,16 @@ 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);
|
|
||||||
//db_statement3 = db_connection.createStatement();
|
|
||||||
//ResultSet rs = db_statement3.executeQuery(sql);
|
|
||||||
|
|
||||||
if (rs.next()) {
|
|
||||||
String columnName = null;
|
|
||||||
String columnValue = null;
|
|
||||||
resultsetDataRows = new ArrayList<ResultsetDataRow>();
|
|
||||||
ResultsetDataRow resultsetDataRow;
|
|
||||||
do {
|
|
||||||
resultsetDataRow = new ResultsetDataRow();
|
|
||||||
List<String> columnValues = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (int i = 0; i < columnHeaders.size(); i++) {
|
|
||||||
columnName = columnHeaders.get(i).getColumnName();
|
|
||||||
columnValue = rs.getString(columnName);
|
|
||||||
columnValues.add(columnValue);
|
|
||||||
}
|
|
||||||
resultsetDataRow.setRow(columnValues);
|
|
||||||
resultsetDataRows.add(resultsetDataRow);
|
|
||||||
} while (rs.next());
|
|
||||||
} else {
|
|
||||||
// could also be not found because of data scope
|
|
||||||
throw new AdditionalFieldsNotFoundException(type, id);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new AdditionalFieldsNotFoundException(type, set);
|
throw new AdditionalFieldsNotFoundException(type, set);
|
||||||
}
|
}
|
||||||
@@ -228,6 +202,44 @@ public class ReadWriteNonCoreDataServiceImpl implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
String columnName = null;
|
||||||
|
String columnValue = null;
|
||||||
|
resultsetDataRows = new ArrayList<ResultsetDataRow>();
|
||||||
|
ResultsetDataRow resultsetDataRow;
|
||||||
|
do {
|
||||||
|
resultsetDataRow = new ResultsetDataRow();
|
||||||
|
List<String> columnValues = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (int i = 0; i < columnHeaders.size(); i++) {
|
||||||
|
columnName = columnHeaders.get(i).getColumnName();
|
||||||
|
columnValue = rs.getString(columnName);
|
||||||
|
columnValues.add(columnValue);
|
||||||
|
}
|
||||||
|
resultsetDataRow.setRow(columnValues);
|
||||||
|
resultsetDataRows.add(resultsetDataRow);
|
||||||
|
} while (rs.next());
|
||||||
|
return resultsetDataRows;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.sql.error",
|
||||||
|
e.getMessage(), sqlErrorMsg);
|
||||||
|
}
|
||||||
|
// could also be not found because of data scope so need to split this
|
||||||
|
// up
|
||||||
|
throw new AdditionalFieldsNotFoundException(type, id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateExtraData(String type, String set, Long id,
|
public void updateExtraData(String type, String set, Long id,
|
||||||
Map<String, String> queryParams) {
|
Map<String, String> queryParams) {
|
||||||
|
|||||||
Reference in New Issue
Block a user