Skip to content
Snippets Groups Projects
Commit 5e98380f authored by felmer's avatar felmer
Browse files

LMS-1361 introducing IDAO

SVN: 14850
parent bb1a82ba
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,6 @@ import org.springframework.jdbc.support.JdbcUtils;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.common.utilities.Template;
import ch.systemsx.cisd.openbis.generic.shared.basic.ExpressionUtil;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DoubleTableCell;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISerializableComparable;
......@@ -48,7 +47,7 @@ import ch.systemsx.cisd.openbis.plugin.query.shared.basic.dto.QueryParameterBind
/**
* @author Franz-Josef Elmer
*/
class DAO extends SimpleJdbcDaoSupport
class DAO extends SimpleJdbcDaoSupport implements IDAO
{
private static DataTypeCode getDataTypeCode(int sqlType)
{
......@@ -88,9 +87,6 @@ class DAO extends SimpleJdbcDaoSupport
throw new UserFailureException("Sorry, only select statements are allowed.");
}
sqlQuery.replace(ExpressionUtil.START, "");
sqlQuery.replace(ExpressionUtil.END, "");
PreparedStatementCallback callback = new PreparedStatementCallback()
{
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException,
......@@ -125,14 +121,13 @@ class DAO extends SimpleJdbcDaoSupport
cells.add(new DoubleTableCell(number.doubleValue()));
} else
{
cells
.add(new StringTableCell(value == null ? "" : value
.toString()));
String string = value == null ? "" : value.toString();
cells.add(new StringTableCell(string));
}
}
}
rows.add(new TableModelRow(cells));
}
resultSet.close();
JdbcUtils.closeResultSet(resultSet);
return new TableModel(headers, rows);
}
};
......
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.plugin.query.server;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
import ch.systemsx.cisd.openbis.plugin.query.shared.basic.dto.QueryParameterBindings;
/**
*
*
* @author Franz-Josef Elmer
*/
interface IDAO
{
public abstract TableModel query(String sqlQuery, QueryParameterBindings bindingsOrNull);
}
\ No newline at end of file
......@@ -65,7 +65,7 @@ public class QueryServer extends AbstractServer<IQueryServer> implements IQueryS
/** @deprecated don't use it directly - use getter instead */
@Deprecated
private DAO dao;
private IDAO dao;
public QueryServer()
{
......@@ -73,9 +73,11 @@ public class QueryServer extends AbstractServer<IQueryServer> implements IQueryS
QueryServer(final ISessionManager<Session> sessionManager, final IDAOFactory daoFactory,
final ISampleTypeSlaveServerPlugin sampleTypeSlaveServerPlugin,
final IDataSetTypeSlaveServerPlugin dataSetTypeSlaveServerPlugin)
final IDataSetTypeSlaveServerPlugin dataSetTypeSlaveServerPlugin,
IDAO dao)
{
super(sessionManager, daoFactory, sampleTypeSlaveServerPlugin, dataSetTypeSlaveServerPlugin);
this.dao = dao;
}
public IQueryServer createLogger(boolean invocationSuccessful, long elapsedTime)
......@@ -83,25 +85,6 @@ public class QueryServer extends AbstractServer<IQueryServer> implements IQueryS
return new QueryServerLogger(getSessionManager(), invocationSuccessful, elapsedTime);
}
private DAO getDAO()
{
if (dao == null)
{
dao = createDAO();
}
return dao;
}
private DAO createDAO()
{
DatabaseDefinition definition = tryToGetDatabaseDefinition();
if (definition == null)
{
throw new UnsupportedOperationException("Undefined query database");
}
return new DAO(definition.getConfigurationContext().getDataSource());
}
public String tryToGetQueryDatabaseLabel(String sessionToken)
{
checkSession(sessionToken);
......@@ -181,26 +164,6 @@ public class QueryServer extends AbstractServer<IQueryServer> implements IQueryS
}
}
private DatabaseDefinition tryToGetDatabaseDefinition()
{
if (databaseDefinition == null)
{
ExtendedProperties databaseProperties =
ExtendedProperties.getSubset(configurer.getResolvedProps(),
DATABASE_PROPERTIES_PREFIX, true);
if (databaseProperties.isEmpty() == false)
{
DatabaseConfigurationContext configurationContext =
BeanUtils
.createBean(DatabaseConfigurationContext.class, databaseProperties);
databaseDefinition =
new DatabaseDefinition(PropertyUtils.getMandatoryProperty(
databaseProperties, LABEL_PROPERTY_KEY), configurationContext);
}
}
return databaseDefinition;
}
public TableModel queryDatabase(String sessionToken, String sqlQuery,
QueryParameterBindings bindings)
{
......@@ -233,5 +196,39 @@ public class QueryServer extends AbstractServer<IQueryServer> implements IQueryS
{
return getDAO().query(sqlQuery, bindings);
}
private IDAO getDAO()
{
if (dao == null)
{
DatabaseDefinition definition = tryToGetDatabaseDefinition();
if (definition == null)
{
throw new UnsupportedOperationException("Undefined query database");
}
dao = new DAO(definition.getConfigurationContext().getDataSource());
}
return dao;
}
private DatabaseDefinition tryToGetDatabaseDefinition()
{
if (databaseDefinition == null)
{
ExtendedProperties databaseProperties =
ExtendedProperties.getSubset(configurer.getResolvedProps(),
DATABASE_PROPERTIES_PREFIX, true);
if (databaseProperties.isEmpty() == false)
{
DatabaseConfigurationContext configurationContext =
BeanUtils
.createBean(DatabaseConfigurationContext.class, databaseProperties);
databaseDefinition =
new DatabaseDefinition(PropertyUtils.getMandatoryProperty(
databaseProperties, LABEL_PROPERTY_KEY), configurationContext);
}
}
return databaseDefinition;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment