Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.sql.DataSource;

Expand All @@ -44,6 +45,7 @@ public class QueryResultTypeSpringDao extends CRCDAO implements

JdbcTemplate jdbcTemplate = null;
NamedParameterJdbcTemplate namedParameterJdbcTemplate = null;
private static final ConcurrentHashMap<Integer, QtQueryResultType> queryResultTypeCache = new ConcurrentHashMap<>();

QtResultTypeRowMapper queryResultTypeMapper = new QtResultTypeRowMapper();

Expand All @@ -55,7 +57,6 @@ public QueryResultTypeSpringDao(DataSource dataSource,
jdbcTemplate = new JdbcTemplate(dataSource);
namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
this.dataSourceLookup = dataSourceLookup;

}

/**
Expand All @@ -68,12 +69,12 @@ public QueryResultTypeSpringDao(DataSource dataSource,
@SuppressWarnings("unchecked")
public QtQueryResultType getQueryResultTypeById(int resultTypeId) {

String sql = "select * from " + getDbSchemaName()
+ "qt_query_result_type where result_type_id = ?";
QtQueryResultType queryResultType = (QtQueryResultType) jdbcTemplate
.queryForObject(sql, new Object[] { resultTypeId },
queryResultTypeMapper);
return queryResultType;
//this is a cache to avoid multiple database calls for the same status type
return queryResultTypeCache.computeIfAbsent(resultTypeId, id -> {
String sql = "select * from " + getDbSchemaName() + "qt_query_result_type where result_type_id = ?";
QtQueryResultType queryResultType = (QtQueryResultType) jdbcTemplate.queryForObject(sql, new Object[] { id }, queryResultTypeMapper);
return queryResultType;
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package edu.harvard.i2b2.crc.dao.setfinder;

import java.util.concurrent.ConcurrentHashMap;

import edu.harvard.i2b2.crc.dao.CRCDAO;
import edu.harvard.i2b2.crc.datavo.db.DataSourceLookup;
import edu.harvard.i2b2.crc.datavo.db.QtQueryMaster;
Expand All @@ -26,6 +28,7 @@
import javax.sql.DataSource;



/**
* Class to manager persistance operation of
* QtQueryMaster
Expand All @@ -38,13 +41,9 @@ public class QueryStatusTypeSpringDao extends CRCDAO implements IQueryStatusType
JdbcTemplate jdbcTemplate = null;

QtStatusTypeRowMapper queryStatusTypeMapper = new QtStatusTypeRowMapper();




private DataSourceLookup dataSourceLookup = null;

private static final ConcurrentHashMap<Integer, QtQueryStatusType> queryStatusTypeCache = new ConcurrentHashMap<>();

public QueryStatusTypeSpringDao(DataSource dataSource,DataSourceLookup dataSourceLookup) {
setDataSource(dataSource);
setDbSchemaName(dataSourceLookup.getFullSchema());
Expand All @@ -61,10 +60,13 @@ public QueryStatusTypeSpringDao(DataSource dataSource,DataSourceLookup dataSourc
@Override
@SuppressWarnings("unchecked")
public QtQueryStatusType getQueryStatusTypeById(int statusTypeId) {

String sql = "select * from " + getDbSchemaName() + "qt_query_status_type where status_type_id = ?" ;
QtQueryStatusType queryStatusType = (QtQueryStatusType)jdbcTemplate.queryForObject(sql,new Object[]{statusTypeId},queryStatusTypeMapper );
return queryStatusType;

//this is a cache to avoid multiple database calls for the same status type
return queryStatusTypeCache.computeIfAbsent(statusTypeId, id -> {
String sql = "select * from " + getDbSchemaName() + "qt_query_status_type where status_type_id = ?" ;
QtQueryStatusType queryStatusType = (QtQueryStatusType)jdbcTemplate.queryForObject(sql,new Object[]{id},queryStatusTypeMapper );
return queryStatusType;
});
}

private static class QtStatusTypeRowMapper implements RowMapper {
Expand Down