ingo@1127: /*
ingo@1127: * Copyright (c) 2010 by Intevation GmbH
ingo@1127: *
ingo@1127: * This program is free software under the LGPL (>=v2.1)
ingo@1127: * Read the file LGPL.txt coming with the software for details
ingo@1127: * or visit http://www.gnu.org/licenses/ if it does not exist.
ingo@1127: */
ingo@1127:
tim@132: package de.intevation.gnv.geobackend.base.query.container;
tim@132:
tim@132: import java.util.Properties;
tim@132:
tim@132: import org.apache.log4j.Logger;
tim@132:
tim@891: import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException;
tim@891:
tim@132: /**
sascha@893: * Factoryclass to provide a singleton-Instance of an
tim@891: * QueryContainer
-Object
sascha@887: * @author Tim Englich
tim@132: */
tim@132: public class QueryContainerFactory {
sascha@885:
tim@132: /**
tim@132: * the logger, used to log exceptions and additonaly information
tim@132: */
tim@132: private static Logger log = Logger.getLogger(QueryContainerFactory.class);
tim@132:
sascha@885:
tim@132: /**
tim@132: * The singleton Instance of this Factory.
tim@132: */
tim@132: private static QueryContainerFactory instance = null;
tim@132:
tim@132: /**
tim@132: * The ConnectionPool providing the Connections to the DatabaseBackends
tim@132: */
tim@132: private QueryContainer queryContainer = null;
tim@132:
tim@132: /**
tim@132: * Basic-Constructor of this Class
tim@132: */
tim@132: private QueryContainerFactory() {
tim@132: super();
tim@132: }
tim@132:
tim@132: /**
tim@132: * This Method provides an singleton Instance of this Class.
tim@132: * @return an singleton Instance of this Class
tim@132: */
sascha@541: public static synchronized QueryContainerFactory getInstance(){
tim@132: if (instance == null){
tim@132: instance = new QueryContainerFactory();
tim@132: }
tim@132: return instance;
tim@132: }
sascha@885:
sascha@885:
tim@132: /**
tim@132: * Getting the QueryContainer
tim@132: * @return the QueryContainer
tim@132: */
tim@132: public QueryContainer getQueryContainer(){
tim@132: return this.queryContainer;
tim@132: }
tim@132:
tim@132: /**
tim@132: * Initializes the QueryContainer.
tim@132: * Should only be called once on system startup
tim@132: * @param properties the Properties for the Individual Configuration of the QueryContainerbb
sascha@885: * @throws QueryContainerException
tim@132: */
tim@132: public synchronized void initializeQueryContainer(Properties properties) throws QueryContainerException{
tim@132: log.debug("ConnectionPoolFactory.initializeConnectionPool");
tim@132: if (this.queryContainer == null){
tim@132: this.queryContainer = new DefaultQueryContainer();
tim@132: this.queryContainer.initialize(properties);
tim@132: }else{
tim@132: log.warn("ConnectionPool already initialized");
tim@132: }
tim@132: }
tim@132:
tim@132: /**
tim@132: * Checks if the QueryContainer has already been initialized.
tim@132: * @return true if the QueryContainer is initialized.
tim@132: */
tim@132: public boolean isInitialized(){
tim@132: return this.queryContainer != null;
tim@132: }
tim@132: }