Mercurial > dive4elements > gnv-client
view geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/QueryExecutorBase.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | ebeb56428409 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.geobackend.base.query; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import de.intevation.gnv.geobackend.base.DefaultResult; import de.intevation.gnv.geobackend.base.DefaultResultDescriptor; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.ResultDescriptor; /** * This is an abstract Basicimplementation of the Interface * QueryExecutor providing several Helpermethods. * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> * */ public abstract class QueryExecutorBase implements QueryExecutor { /** * Constructor */ public QueryExecutorBase() { super(); } /** * This Method puts the Filtervalues into the Querystring * @param queryString the Query which should be manipulated * @param filter the values which should be put into the Query * @return the manipulated Query */ protected String setFilterValues(String queryString, String[] filter){ String returnValue = queryString; for (int i = 0; i < filter.length; i++){ returnValue = returnValue.replaceFirst("[?]", filter[i]); } return returnValue; } /** * This Methods converts the ResultSet into an Collection of Result-objects * @param resultSet the ResultSet which should be converted * @return an Collection containing Result-Objects * @throws SQLException */ protected Collection<Result> createResultCollection(ResultSet resultSet) throws SQLException{ Collection<Result> returnValue = new ArrayList<Result>(); ResultDescriptor resultDescriptor = null; int columns = -1; List<String> columnNames = null; while (resultSet.next()){ if (resultDescriptor == null){ resultDescriptor = new DefaultResultDescriptor(); ResultSetMetaData rsmd = resultSet.getMetaData(); columns = rsmd.getColumnCount(); for (int i = 1; i <= columns; i++){ resultDescriptor.addColumn(rsmd.getColumnName(i), rsmd.getColumnClassName(i)); } } Result result = convertResult(resultSet, resultDescriptor); returnValue.add(result); } return returnValue; } /** * This Method converts one Singel ResultSetEntry into an Result-Object * @param resultSet the ResultSet where the Entry should be took from. * @param resultDescriptor the ResultsetDescriptor which describes the Entry * @return an new Result-Objects containing the Values of the ResultSet-Entry * @throws SQLException */ private Result convertResult(ResultSet resultSet, ResultDescriptor resultDescriptor) throws SQLException { Result result = new DefaultResult(resultDescriptor); for (int i = 0, N = resultDescriptor.getColumnCount(); i < N; i++) { result.addColumnValue(i, resultSet.getObject(i+1)); } return result; } public Collection<Result> cachedResults(String query) { return null; } public void cacheResults(String query, Collection<Result> result) { } public void clearCache(String[] tableNames) { } }