Skip to content
Snippets Groups Projects
Commit 7c3f7c97 authored by felmer's avatar felmer
Browse files

LMS-1364 QueryServer introduced

SVN: 14747
parent d80592fc
No related merge requests found
/*
* 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.dbmigration.DatabaseConfigurationContext;
/**
*
*
* @author Franz-Josef Elmer
*/
public class DatabaseDefinition
{
private final String label;
private final DatabaseConfigurationContext configurationContext;
public DatabaseDefinition(String label, DatabaseConfigurationContext configurationContext)
{
this.label = label;
this.configurationContext = configurationContext;
}
public String getLabel()
{
return label;
}
public DatabaseConfigurationContext getConfigurationContext()
{
return configurationContext;
}
}
/*
* 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 java.util.Map;
import javax.annotation.Resource;
import javax.sql.DataSource;
import net.lemnik.eodsql.DataSet;
import net.lemnik.eodsql.QueryTool;
import org.springframework.stereotype.Component;
import ch.rinn.restrictions.Private;
import ch.systemsx.cisd.authentication.ISessionManager;
import ch.systemsx.cisd.common.spring.ExposablePropertyPaceholderConfigurer;
import ch.systemsx.cisd.common.utilities.BeanUtils;
import ch.systemsx.cisd.common.utilities.ExtendedProperties;
import ch.systemsx.cisd.dbmigration.DatabaseConfigurationContext;
import ch.systemsx.cisd.openbis.generic.server.AbstractServer;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.server.plugin.IDataSetTypeSlaveServerPlugin;
import ch.systemsx.cisd.openbis.generic.server.plugin.ISampleTypeSlaveServerPlugin;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
import ch.systemsx.cisd.openbis.plugin.query.shared.IQueryServer;
import ch.systemsx.cisd.openbis.plugin.query.shared.ResourceNames;
/**
*
*
* @author Franz-Josef Elmer
*/
@Component(ResourceNames.QUERY_PLUGIN_SERVER)
public class QueryServer extends AbstractServer<IQueryServer> implements
IQueryServer
{
@Resource(name = "propertyConfigurer")
private ExposablePropertyPaceholderConfigurer configurer;
private DatabaseDefinition databaseDefinition;
public QueryServer()
{
}
@Private
QueryServer(final ISessionManager<Session> sessionManager, final IDAOFactory daoFactory,
final ISampleTypeSlaveServerPlugin sampleTypeSlaveServerPlugin,
final IDataSetTypeSlaveServerPlugin dataSetTypeSlaveServerPlugin)
{
super(sessionManager, daoFactory, sampleTypeSlaveServerPlugin, dataSetTypeSlaveServerPlugin);
}
public IQueryServer createLogger(boolean invocationSuccessful, long elapsedTime)
{
return new QueryServerLogger(getSessionManager(), invocationSuccessful, elapsedTime);
}
public String tryToGetQueryDatabaseLabel()
{
DatabaseDefinition definition = tryToGetDatabaseDefinition();
return definition == null ? null : definition.getLabel();
}
public TableModel queryDatabase(String sessionToken, String sqlQuery)
{
checkSession(sessionToken);
DatabaseDefinition definition = tryToGetDatabaseDefinition();
if (definition == null)
{
throw new UnsupportedOperationException("Undefined query database");
}
DataSource dataSource = definition.getConfigurationContext().getDataSource();
DataSet<Map<String, Object>> result = QueryTool.select(dataSource, sqlQuery);
for (Map<String, Object> row : result)
{
System.out.println(row);
}
result.close();
return null;
}
private DatabaseDefinition tryToGetDatabaseDefinition()
{
if (databaseDefinition == null)
{
ExtendedProperties databaseProperties =
ExtendedProperties.getSubset(configurer.getResolvedProps(), "query-database",
true);
if (databaseProperties.isEmpty() == false)
{
DatabaseConfigurationContext configurationContext =
BeanUtils
.createBean(DatabaseConfigurationContext.class, databaseProperties);
databaseDefinition =
new DatabaseDefinition(databaseProperties.getProperty("label"),
configurationContext);
}
}
return databaseDefinition;
}
}
/*
* 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.authentication.ISessionManager;
import ch.systemsx.cisd.openbis.generic.server.AbstractServerLogger;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
import ch.systemsx.cisd.openbis.plugin.query.shared.IQueryServer;
/**
*
*
* @author Franz-Josef Elmer
*/
class QueryServerLogger extends AbstractServerLogger implements IQueryServer
{
QueryServerLogger(final ISessionManager<Session> sessionManager,
final boolean invocationSuccessful, final long elapsedTime)
{
super(sessionManager, invocationSuccessful, elapsedTime);
}
public String tryToGetQueryDatabaseLabel()
{
return null;
}
public TableModel queryDatabase(String sessionToken, String sqlQuery)
{
logAccess(sessionToken, "query_database", "SQL(%s)", sqlQuery);
return null;
}
}
/*
* 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.shared;
import org.springframework.transaction.annotation.Transactional;
import ch.systemsx.cisd.openbis.generic.shared.IServer;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
/**
*
*
* @author Franz-Josef Elmer
*/
public interface IQueryServer extends IServer
{
public String tryToGetQueryDatabaseLabel();
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.POWER_USER)
public TableModel queryDatabase(String sessionToken, String sqlQuery);
}
/*
* 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.shared;
/**
*
*
* @author Franz-Josef Elmer
*/
public class ResourceNames
{
public final static String QUERY_PLUGIN_SERVICE = "query-plugin-service";
public final static String QUERY_PLUGIN_SERVER = "query-plugin-server";
private ResourceNames()
{
}
}
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