Slight enhancement to Server performance.
parent
4f2d0e7738
commit
bfc62cd77c
|
@ -395,7 +395,9 @@ public class BulletinBoardSQLServer implements BulletinBoardServer{
|
||||||
|
|
||||||
BulletinBoardMessageList.Builder resultListBuilder = BulletinBoardMessageList.newBuilder();
|
BulletinBoardMessageList.Builder resultListBuilder = BulletinBoardMessageList.newBuilder();
|
||||||
|
|
||||||
String sql;
|
// SQL length is roughly 50 characters per filter + 50 for the query itself
|
||||||
|
StringBuilder sqlBuilder = new StringBuilder(50 * (filterList.getFilterCount() + 1));
|
||||||
|
|
||||||
MapSqlParameterSource namedParameters;
|
MapSqlParameterSource namedParameters;
|
||||||
int paramNum;
|
int paramNum;
|
||||||
|
|
||||||
|
@ -410,14 +412,13 @@ public class BulletinBoardSQLServer implements BulletinBoardServer{
|
||||||
|
|
||||||
// Check if Tag/Signature tables are required for filtering purposes
|
// Check if Tag/Signature tables are required for filtering purposes
|
||||||
|
|
||||||
sql = sqlQueryProvider.getSQLString(SQLQueryProvider.QueryType.GET_MESSAGES);
|
sqlBuilder.append(sqlQueryProvider.getSQLString(SQLQueryProvider.QueryType.GET_MESSAGES));
|
||||||
|
|
||||||
// Add conditions
|
// Add conditions
|
||||||
|
|
||||||
namedParameters = new MapSqlParameterSource();
|
namedParameters = new MapSqlParameterSource();
|
||||||
|
|
||||||
if (!filters.isEmpty()) {
|
if (!filters.isEmpty()) {
|
||||||
sql += " WHERE ";
|
sqlBuilder.append(" WHERE ");
|
||||||
|
|
||||||
for (paramNum = 0 ; paramNum < filters.size() ; paramNum++) {
|
for (paramNum = 0 ; paramNum < filters.size() ; paramNum++) {
|
||||||
|
|
||||||
|
@ -427,11 +428,11 @@ public class BulletinBoardSQLServer implements BulletinBoardServer{
|
||||||
if (isFirstFilter) {
|
if (isFirstFilter) {
|
||||||
isFirstFilter = false;
|
isFirstFilter = false;
|
||||||
} else {
|
} else {
|
||||||
sql += " AND ";
|
sqlBuilder.append(" AND ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += sqlQueryProvider.getCondition(filter.getType(), paramNum);
|
sqlBuilder.append(sqlQueryProvider.getCondition(filter.getType(), paramNum));
|
||||||
|
|
||||||
SQLQueryProvider.FilterTypeParam filterTypeParam = SQLQueryProvider.FilterTypeParam.getFilterTypeParamName(filter.getType());
|
SQLQueryProvider.FilterTypeParam filterTypeParam = SQLQueryProvider.FilterTypeParam.getFilterTypeParamName(filter.getType());
|
||||||
|
|
||||||
|
@ -447,13 +448,10 @@ public class BulletinBoardSQLServer implements BulletinBoardServer{
|
||||||
|
|
||||||
// Run query
|
// Run query
|
||||||
|
|
||||||
List<BulletinBoardMessage.Builder> msgBuilders = jdbcTemplate.query(sql, namedParameters, messageMapper);
|
List<BulletinBoardMessage.Builder> msgBuilders = jdbcTemplate.query(sqlBuilder.toString(), namedParameters, messageMapper);
|
||||||
|
|
||||||
|
|
||||||
// Compile list of messages
|
// Compile list of messages
|
||||||
|
|
||||||
sql = sqlQueryProvider.getSQLString(SQLQueryProvider.QueryType.GET_SIGNATURES);
|
|
||||||
|
|
||||||
for (BulletinBoardMessage.Builder msgBuilder : msgBuilders) {
|
for (BulletinBoardMessage.Builder msgBuilder : msgBuilders) {
|
||||||
|
|
||||||
// Retrieve signatures
|
// Retrieve signatures
|
||||||
|
@ -461,7 +459,10 @@ public class BulletinBoardSQLServer implements BulletinBoardServer{
|
||||||
namedParameters = new MapSqlParameterSource();
|
namedParameters = new MapSqlParameterSource();
|
||||||
namedParameters.addValue("EntryNum", msgBuilder.getEntryNum());
|
namedParameters.addValue("EntryNum", msgBuilder.getEntryNum());
|
||||||
|
|
||||||
List<Signature> signatures = jdbcTemplate.query(sql, namedParameters, signatureMapper);
|
List<Signature> signatures = jdbcTemplate.query(
|
||||||
|
sqlQueryProvider.getSQLString(SQLQueryProvider.QueryType.GET_SIGNATURES),
|
||||||
|
namedParameters,
|
||||||
|
signatureMapper);
|
||||||
|
|
||||||
// Append signatures
|
// Append signatures
|
||||||
msgBuilder.addAllSig(signatures);
|
msgBuilder.addAllSig(signatures);
|
||||||
|
|
|
@ -53,15 +53,15 @@ public class BulletinBoardWebApp implements BulletinBoardServer, ServletContextL
|
||||||
String dbType = servletContext.getInitParameter("dbType");
|
String dbType = servletContext.getInitParameter("dbType");
|
||||||
String dbName = servletContext.getInitParameter("dbName");
|
String dbName = servletContext.getInitParameter("dbName");
|
||||||
|
|
||||||
if ("SQLite".compareTo(dbType) == 0){
|
if ("SQLite".equals(dbType)){
|
||||||
|
|
||||||
bulletinBoard = new BulletinBoardSQLServer(new SQLiteQueryProvider(dbName));
|
bulletinBoard = new BulletinBoardSQLServer(new SQLiteQueryProvider(dbName));
|
||||||
|
|
||||||
} else if ("H2".compareTo(dbType) == 0) {
|
} else if ("H2".equals(dbType)) {
|
||||||
|
|
||||||
bulletinBoard = new BulletinBoardSQLServer(new H2QueryProvider(dbName));
|
bulletinBoard = new BulletinBoardSQLServer(new H2QueryProvider(dbName));
|
||||||
|
|
||||||
} else if ("MySQL".compareTo(dbType) == 0) {
|
} else if ("MySQL".equals(dbType)) {
|
||||||
|
|
||||||
String dbAddress = servletContext.getInitParameter("dbAddress");
|
String dbAddress = servletContext.getInitParameter("dbAddress");
|
||||||
int dbPort = Integer.parseInt(servletContext.getInitParameter("dbPort"));
|
int dbPort = Integer.parseInt(servletContext.getInitParameter("dbPort"));
|
||||||
|
|
Loading…
Reference in New Issue