You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jm...@apache.org on 2004/08/27 05:22:25 UTC

cvs commit: jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl MessageResources.xml HibernateBasicMessage.hbm.xml TorqueResourcesTestCase.java HibernateResourcesTestCase.java IBatisResourcesTestCase.java

jmitchell    2004/08/26 20:22:25

  Added:       resources/contrib/src/java/org/apache/commons/resources/impl
                        IBatisResources.java HibernateResourcesFactory.java
                        HibernateResources.java TorqueResources.java
                        IBatisResourcesFactory.java
                        TorqueResourcesFactory.java
                        HibernateBasicMessage.java
               resources/contrib/src/test SqlMapConfig.properties
                        SqlMapConfig.xml iBatis-init.sql Torque.properties
                        hibernate.cfg.xml hibernate.properties
               resources/contrib/src/test/org/apache/commons/resources/impl
                        MessageResources.xml HibernateBasicMessage.hbm.xml
                        TorqueResourcesTestCase.java
                        HibernateResourcesTestCase.java
                        IBatisResourcesTestCase.java
  Log:
  Move to contrib due to lgpl license restrictions
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/IBatisResources.java
  
  Index: IBatisResources.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/IBatisResources.java,v 1.1 2004/08/27 03:22:24 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:24 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import java.io.Reader;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  import java.util.Properties;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.resources.ResourcesException;
  
  import com.ibatis.common.resources.Resources;
  import com.ibatis.db.sqlmap.SqlMap;
  import com.ibatis.db.sqlmap.XmlSqlMapBuilder;
  
  /**
   * <p>Concrete implementation of 
   * {@link org.apache.commons.resources.Resources} that 
   * retrieves values from a database via the iBatis framework for the given 
   * <code>Locale</code> and have name suffixes reflecting the 
   * <code>Locale</code> for which the document's messages apply.
   * For this specific implementation, resources are looked up in 
   * a hierarchy of database values in a manner identical to that 
   * performed by <code>java.util.ResourceBundle.getBundle().</code>.
   * </p>
   *
   * <p>The base URL passed to our constructor must contain the base name
   * of a the hibernate configuration file.</p>
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $ $Date: 2004/08/27 03:22:24 $
   */
  public class IBatisResources extends CollectionResourcesBase {
  
      /**
       * <p>The <code>Log</code> instance for this class.</p>
       */
      private static final Log log = LogFactory.getLog(HibernateResources.class);
      protected static SqlMap sqlMap;
      // ----------------------------------------------------------- Constructors
  
      /**
       * <p>Create a new 
       * {@link org.apache.commons.resources.Resources} instance with the specified
       * logical name and base resource URL.</p>
       *
       * @param name Logical name of the new instance
       * @param base Base URL of the Hibernate configuration file.
       */
      public IBatisResources(String name, String base) {
          super(name, base);
      }
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * <p>Return a <code>Map</code> containing the name-value mappings for
       * the specified base URL and requested <code>Locale</code>, if there
       * are any.  If there are no defined mappings for the specified
       * <code>Locale</code>, return an empty <code>Map</code> instead.</p>
       *
       * <p>Concrete subclasses must override this method to perform the
       * appropriate lookup.  A typical implementation will construct an
       * absolute URL based on the specified base URL and <code>Locale</code>,
       * retrieve the specified resource file (if any), and parse it into
       * a <code>Map</code> structure.</p>
       *
       * <p>Caching of previously retrieved <code>Map</code>s (if any) should
       * be performed by callers of this method.  Therefore, this method should
       * always attempt to retrieve the specified resource and load it
       * appropriately.</p>
       *
       * @param baseUrl Base URL of the resource files for this 
       * {@link org.apache.commons.resources.Resources} instance
       * @param locale <code>Locale</code> for which name-value mappings
       *  are requested
       */
      protected Map getLocaleMap(String baseUrl, Locale locale) {
  
          if (log.isDebugEnabled()) {
              log.debug("Loading database configuration '" + locale + "' resources from base '" +
                      baseUrl + "'");
          }
          
          Properties props = new Properties();
          
          String category = locale.toString();
          try {
          	if (sqlMap == null)
          		initSqlMap(baseUrl);
          	
          	// TODO change this to NOT be hard coded
  			List msgs = sqlMap.executeQueryForList("getBundleByLocale", category);
      		for (Iterator iter = msgs.iterator(); iter.hasNext();) {
      	          DatabaseBasicMessage msg = (DatabaseBasicMessage) iter.next();
      	          props.put(msg.getKey(), msg.getValue());
      	    }
  			
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  
          return props;
  
          
  
      }
      protected void initSqlMap(String configFile) throws Exception {
          Reader reader = Resources.getResourceAsReader(configFile);
          sqlMap = XmlSqlMapBuilder.buildSqlMap(reader);
          reader.close();
        }
  
      public void init() throws ResourcesException {
          super.init();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/HibernateResourcesFactory.java
  
  Index: HibernateResourcesFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/HibernateResourcesFactory.java,v 1.1 2004/08/27 03:22:24 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:24 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import org.apache.commons.resources.Resources;
  import org.apache.commons.resources.ResourcesException;
  
  /**
   * <p>Concrete implementation of 
   * {@link org.apache.commons.resources.ResourcesFactory} that creates
   * {@link org.apache.commons.resources.Resources} instances that wraps 
   * a Hibernate session and retrieves values for the given 
   * <code>Locale</code> and have name suffixes reflecting the 
   * <code>Locale</code> for which the document's messages apply.
   * For this specific implementation, resources are looked up in 
   * a hierarchy of database values in a manner identical to that 
   * performed by <code>java.util.ResourceBundle.getBundle().</code>.
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $
   */
  public class HibernateResourcesFactory extends ResourcesFactoryBase {
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * <p>Create and return a new {@link org.apache.commons.resources.Resources} 
       * instance with the specified logical name, after calling its <code>init()</code>
       * method and delegating the relevant properties.</p>
       *
       * @param name Logical name of the {@link org.apache.commons.resources.Resources} 
       * instance to create
       * 
       * @param config Configuration string for this resource (if any)
       *
       * @exception ResourcesException if a {@link org.apache.commons.resources.Resources} 
       * instance of the specified logical name cannot be created.
       */
      protected Resources createResources(String name, String config)
          throws ResourcesException {
  
          Resources res = new HibernateResources(name, config);
          res.setReturnNull(isReturnNull());
          res.init();
          return (res);
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/HibernateResources.java
  
  Index: HibernateResources.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/HibernateResources.java,v 1.1 2004/08/27 03:22:24 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:24 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  import java.util.Properties;
  
  import net.sf.hibernate.HibernateException;
  import net.sf.hibernate.Query;
  import net.sf.hibernate.Session;
  import net.sf.hibernate.SessionFactory;
  import net.sf.hibernate.cfg.Configuration;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.resources.ResourcesException;
  
  /**
   * <p>Concrete implementation of 
   * {@link org.apache.commons.resources.Resources} that wraps a 
   * Hibernate session and retrieves values for the given 
   * <code>Locale</code> and have name suffixes reflecting the 
   * <code>Locale</code> for which the document's messages apply.
   * For this specific implementation, resources are looked up in 
   * a hierarchy of database values in a manner identical to that 
   * performed by <code>java.util.ResourceBundle.getBundle().</code>.
   * </p>
   *
   * <p>The base URL passed to our constructor must contain the base name
   * of a the hibernate configuration file.</p>
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $ $Date: 2004/08/27 03:22:24 $
   */
  public class HibernateResources extends CollectionResourcesBase {
  
      /**
       * <p>The <code>Log</code> instance for this class.</p>
       */
      private static final Log log = LogFactory.getLog(HibernateResources.class);
  
      // ----------------------------------------------------------- Constructors
  
      /**
       * <p>Create a new 
       * {@link org.apache.commons.resources.Resources} instance with the specified
       * logical name and base resource URL.</p>
       *
       * @param name Logical name of the new instance
       * @param base Base URL of the Hibernate configuration file.
       */
      public HibernateResources(String name, String base) {
          super(name, base);
      }
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * <p>Return a <code>Map</code> containing the name-value mappings for
       * the specified base URL and requested <code>Locale</code>, if there
       * are any.  If there are no defined mappings for the specified
       * <code>Locale</code>, return an empty <code>Map</code> instead.</p>
       *
       * <p>Concrete subclasses must override this method to perform the
       * appropriate lookup.  A typical implementation will construct an
       * absolute URL based on the specified base URL and <code>Locale</code>,
       * retrieve the specified resource file (if any), and parse it into
       * a <code>Map</code> structure.</p>
       *
       * <p>Caching of previously retrieved <code>Map</code>s (if any) should
       * be performed by callers of this method.  Therefore, this method should
       * always attempt to retrieve the specified resource and load it
       * appropriately.</p>
       *
       * @param baseUrl Base URL of the resource files for this 
       * {@link org.apache.commons.resources.Resources} instance
       * @param locale <code>Locale</code> for which name-value mappings
       *  are requested
       */
      protected Map getLocaleMap(String baseUrl, Locale locale) {
  
          if (log.isDebugEnabled()) {
              log.debug("Loading database configuration '" + locale + "' resources from base '" +
                      baseUrl + "'");
          }
          
          Properties props = new Properties();
          Session session = null;
          try {            
              // TODO - change this to load the specified hibernate config file (baseUrl)
              SessionFactory sessionFactory =
                  new Configuration().configure().buildSessionFactory();
              session = sessionFactory.openSession();
              Query q = session.getNamedQuery("QueryByLocale");
              q.setString(0, locale.toString());
      		q.list();
      		List msgs = q.list();
      		for (Iterator iter = msgs.iterator(); iter.hasNext();) {
                  DatabaseBasicMessage msg = (DatabaseBasicMessage) iter.next();
                  props.put(msg.getKey(), msg.getValue());
              }
      		session.close();
          
          } catch (HibernateException e) {
              e.printStackTrace();
          }
  
          return props;
  
          
  
      }
  
  
      public void init() throws ResourcesException {
          super.init();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/TorqueResources.java
  
  Index: TorqueResources.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/TorqueResources.java,v 1.1 2004/08/27 03:22:24 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:24 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import java.util.Locale;
  import java.util.Map;
  import java.util.Properties;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.resources.ResourcesException;
  
  /**
   * <p>Concrete implementation of 
   * {@link org.apache.commons.resources.Resources} that 
   * retrieves values from a database via Torque for the given 
   * <code>Locale</code> and have name suffixes reflecting the 
   * <code>Locale</code> for which the document's messages apply.
   * For this specific implementation, resources are looked up in 
   * a hierarchy of database values in a manner identical to that 
   * performed by <code>java.util.ResourceBundle.getBundle().</code>.
   * </p>
   *
   * <p>The base URL passed to our constructor must contain the base name
   * of a the Torque configuration file.</p>
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $ $Date: 2004/08/27 03:22:24 $
   */
  public class TorqueResources extends CollectionResourcesBase {
  
      /**
       * <p>The <code>Log</code> instance for this class.</p>
       */
      private static final Log log = LogFactory.getLog(TorqueResources.class);
  
      // ----------------------------------------------------------- Constructors
  
      /**
       * <p>Create a new 
       * {@link org.apache.commons.resources.Resources} instance with the specified
       * logical name and base resource URL.</p>
       *
       * @param name Logical name of the new instance
       * @param base Base URL of the Torque configuration file.
       */
      public TorqueResources(String name, String base) {
          super(name, base);
      }
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * <p>Return a <code>Map</code> containing the name-value mappings for
       * the specified base URL and requested <code>Locale</code>, if there
       * are any.  If there are no defined mappings for the specified
       * <code>Locale</code>, return an empty <code>Map</code> instead.</p>
       *
       * <p>Concrete subclasses must override this method to perform the
       * appropriate lookup.  A typical implementation will construct an
       * absolute URL based on the specified base URL and <code>Locale</code>,
       * retrieve the specified resource file (if any), and parse it into
       * a <code>Map</code> structure.</p>
       *
       * <p>Caching of previously retrieved <code>Map</code>s (if any) should
       * be performed by callers of this method.  Therefore, this method should
       * always attempt to retrieve the specified resource and load it
       * appropriately.</p>
       *
       * @param baseUrl Base URL of the resource files for this 
       * {@link org.apache.commons.resources.Resources} instance
       * @param locale <code>Locale</code> for which name-value mappings
       *  are requested
       */
      protected Map getLocaleMap(String baseUrl, Locale locale) {
  
          if (log.isDebugEnabled()) {
              log.debug("Loading database configuration '" + locale + "' resources from base '" +
                      baseUrl + "'");
          }
          
          Properties props = new Properties();
          
          return props;
  
      }
  
  
      public void init() throws ResourcesException {
          super.init();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/IBatisResourcesFactory.java
  
  Index: IBatisResourcesFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/IBatisResourcesFactory.java,v 1.1 2004/08/27 03:22:24 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:24 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import org.apache.commons.resources.Resources;
  import org.apache.commons.resources.ResourcesException;
  
  /**
   * <p>Concrete implementation of 
   * {@link org.apache.commons.resources.ResourcesFactory} that creates
   * {@link org.apache.commons.resources.Resources} instances that wraps 
   * retrieves values from a database via the iBatis framework for the given 
   * <code>Locale</code> and have name suffixes reflecting the 
   * <code>Locale</code> for which the document's messages apply.
   * For this specific implementation, resources are looked up in 
   * a hierarchy of database values in a manner identical to that 
   * performed by <code>java.util.ResourceBundle.getBundle().</code>.
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $
   */
  public class IBatisResourcesFactory extends ResourcesFactoryBase {
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * <p>Create and return a new {@link org.apache.commons.resources.Resources} 
       * instance with the specified logical name, after calling its <code>init()</code>
       * method and delegating the relevant properties.</p>
       *
       * @param name Logical name of the {@link org.apache.commons.resources.Resources} 
       * instance to create
       * 
       * @param config Configuration string for this resource (if any)
       *
       * @exception ResourcesException if a {@link org.apache.commons.resources.Resources} 
       * instance of the specified logical name cannot be created.
       */
      protected Resources createResources(String name, String config)
          throws ResourcesException {
  
          Resources res = new IBatisResources(name, config);
          res.setReturnNull(isReturnNull());
          res.init();
          return (res);
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/TorqueResourcesFactory.java
  
  Index: TorqueResourcesFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/TorqueResourcesFactory.java,v 1.1 2004/08/27 03:22:24 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:24 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import org.apache.commons.resources.Resources;
  import org.apache.commons.resources.ResourcesException;
  
  /**
   * <p>Concrete implementation of 
   * {@link org.apache.commons.resources.ResourcesFactory} that creates
   * {@link org.apache.commons.resources.Resources} instances that 
   * retrieves values from a database via Torque for the given 
   * <code>Locale</code> and have name suffixes reflecting the 
   * <code>Locale</code> for which the document's messages apply.
   * For this specific implementation, resources are looked up in 
   * a hierarchy of database values in a manner identical to that 
   * performed by <code>java.util.ResourceBundle.getBundle().</code>.
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $
   */
  public class TorqueResourcesFactory extends ResourcesFactoryBase {
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * <p>Create and return a new {@link org.apache.commons.resources.Resources} 
       * instance with the specified logical name, after calling its <code>init()</code>
       * method and delegating the relevant properties.</p>
       *
       * @param name Logical name of the {@link org.apache.commons.resources.Resources} 
       * instance to create
       * 
       * @param config Configuration string for this resource (if any)
       *
       * @exception ResourcesException if a {@link org.apache.commons.resources.Resources} 
       * instance of the specified logical name cannot be created.
       */
      protected Resources createResources(String name, String config)
          throws ResourcesException {
  
          Resources res = new TorqueResources(name, config);
          res.setReturnNull(isReturnNull());
          res.init();
          return (res);
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/HibernateBasicMessage.java
  
  Index: HibernateBasicMessage.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/java/org/apache/commons/resources/impl/HibernateBasicMessage.java,v 1.1 2004/08/27 03:22:24 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:24 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  
  
  /**
   * BasicMessage to allow standard Hibernate 
   * configuration (no complex keys).
   * 
   * @author James Mitchell
   *
   */
  public class HibernateBasicMessage extends BasicMessage {
  
      public HibernateBasicMessage() {
          super();
      }
      /**
       * 
       * @param id  The id (primary key) for this message.
       * @param locale The locale used to retrieve the value for the specified key
       * @param key  The key for this message.
       * @param value The value for this message.
       */
      public HibernateBasicMessage(String locale, String key, Object[] values) {
          super(key, values);
          this.locale = locale;
          
      }
      
      private String locale = null;
  
      /**
       * @return Returns the locale.
       */
      public String getLocale() {
          return locale;
      }
  
      /**
       * @param locale The locale to set.
       */
      public void setLocale(String locale) {
          this.locale = locale;
      }
      
      public void setKey(String key) {
          this.key = key;
      }
      public void setValue(String value) {
          this.values = new String[]{value};
      }
      public String getValue() {
          if (values == null || values.length < 1) {
              throw new IllegalStateException("The retrived value for msg " + 
                      this.key + "was null");
          }
          if (values.length > 1) {
              throw new IllegalStateException("There were more than one values " +
              		"retrived value for msg " + 
                      this.key);
          }
          return (String)getValues()[0];
      }
      
      public boolean equals(Object obj) {
      	if (obj instanceof HibernateBasicMessage){
      		if (((HibernateBasicMessage)obj).getKey().equals(this.key) && 
      				((HibernateBasicMessage)obj).getLocale().equals(this.locale)){
      			return true;
      		}
      	}
          return false;
      }
  
      public int hashCode() {
          return super.hashCode();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/SqlMapConfig.properties
  
  Index: SqlMapConfig.properties
  ===================================================================
  driver=org.hsqldb.jdbcDriver
  url=jdbc:hsqldb:.
  username=sa
  password=
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/SqlMapConfig.xml
  
  Index: SqlMapConfig.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE sql-map-config
      PUBLIC "-//iBATIS.com//DTD SQL Map Config 1.0//EN"
      "http://www.ibatis.com/dtd/sql-map-config.dtd">
  
  <sql-map-config>
  
    <properties resource="SqlMapConfig.properties" />
  
    <settings cacheModelsEnabled="true"/> 
  
    <datasource name="simple"
                factory-class="com.ibatis.db.sqlmap.datasource.SimpleDataSourceFactory"
                default="true">
      <property name="JDBC.Driver" value="${driver}"/>
      <property name="JDBC.ConnectionURL" value="${url}"/>
      <property name="JDBC.Username" value="${username}"/>
      <property name="JDBC.Password" value="${password}"/>
      <property name="JDBC.DefaultAutoCommit" value="true" />
      <property name="Pool.MaximumActiveConnections" value="10"/>
      <property name="Pool.MaximumIdleConnections" value="5"/>
      <property name="Pool.MaximumCheckoutTime" value="120000"/>
      <property name="Pool.TimeToWait" value="500"/>
      <property name="Pool.PingQuery" value="select 1 from RESOURCES"/>
      <property name="Pool.PingEnabled" value="false"/>
      <property name="Pool.PingConnectionsOlderThan" value="1"/>
      <property name="Pool.PingConnectionsNotUsedFor" value="1"/>
      <property name="Pool.QuietMode" value="true"/>
    </datasource>
  
    <sql-map resource="org/apache/commons/resources/impl/MessageResources.xml" />
  
  </sql-map-config>
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/iBatis-init.sql
  
  Index: iBatis-init.sql
  ===================================================================
  -- Script to create an example database
  ------------------------------------
  
  DROP TABLE RESOURCES;
  
  create table resources ( 
    locale            varchar(10)      not null,
    msgKey            varchar(255)     not null,
    val               varchar(255),
    Primary Key(
      locale,
      msgKey
    )
  );
  
  Insert into resources (locale, msgKey, val) Values ('', 'test.base', '[Base] ONLY');
  Insert into resources (locale, msgKey, val) Values ('', 'test.specific', '[Base] SPECIFIC');
  Insert into resources (locale, msgKey, val) Values ('', 'test.inherit', '[Base] INHERIT');
  Insert into resources (locale, msgKey, val) Values ('', 'test.message', '[Base] REPLACE {0} WITH {1}');
  
  Insert into resources (locale, msgKey, val) Values ('en', 'test.specific', '[en] SPECIFIC');
  Insert into resources (locale, msgKey, val) Values ('en', 'test.inherit', '[en] INHERIT');
  
  Insert into resources (locale, msgKey, val) Values ('en_US', 'test.specific', '[en_US] SPECIFIC');
  
  Insert into resources (locale, msgKey, val) Values ('fr', 'test.specific', '[fr] SPECIFIC');
  Insert into resources (locale, msgKey, val) Values ('fr', 'test.inherit', '[fr] INHERIT');
  
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/Torque.properties
  
  Index: Torque.properties
  ===================================================================
  torque.database.default=resources
  torque.database.bookstore.driver = org.hsqldb.jdbcDriver
  torque.database.bookstore.url = jdbc:hsqldb:.
  torque.database.bookstore.username = sa
  torque.database.bookstore.password = 
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/hibernate.cfg.xml
  
  Index: hibernate.cfg.xml
  ===================================================================
  <?xml version='1.0' encoding="UTF-8"?>
  <!DOCTYPE hibernate-configuration
      PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
      
  <hibernate-configuration>
  
      <session-factory>
  
  		<!-- database connection -->
          <property name="hibernate.dialect">net.sf.hibernate.dialect.HSQLDialect</property>
          <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
          <property name="hibernate.connection.url">jdbc:hsqldb:.</property>
  		<!--
  			you would typically need this for your database
          <property name="hibernate.connection.username">resourcesTest</property>
          <property name="hibernate.connection.password">resourcesTest</property>
  		-->
          <property name="hibernate.connection.pool_size">4</property>
          <property name="hibernate.statement_cache.size">100</property>
          <property name="hibernate.show_sql">true</property>
  		<property name="hibernate.jdbc.batch_size">0</property>
  		<property name="hibernate.cglib.use_reflection_optimizer">true</property>
  
          <mapping resource="org/apache/commons/resources/impl/HibernateBasicMessage.hbm.xml"/>
  
      </session-factory>
  
  </hibernate-configuration>
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/hibernate.properties
  
  Index: hibernate.properties
  ===================================================================
  ######################
  ### Query Language ###
  ######################
  
  ## define query language constants / function names
  
  hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'
  
  
  
  #################
  ### Platforms ###
  #################
  
  ## JNDI Datasource
  
  #hibernate.connection.datasource jdbc/test
  #hibernate.connection.username db2
  #hibernate.connection.password db2
  
  
  ## HypersonicSQL
  
  hibernate.dialect net.sf.hibernate.dialect.HSQLDialect
  hibernate.connection.driver_class org.hsqldb.jdbcDriver
  hibernate.connection.username sa
  hibernate.connection.password
  hibernate.connection.url jdbc:hsqldb:hsql://localhost
  hibernate.connection.url jdbc:hsqldb:test
  hibernate.connection.url jdbc:hsqldb:.
  
  
  ## PostgreSQL
  
  #hibernate.dialect net.sf.hibernate.dialect.PostgreSQLDialect
  #hibernate.connection.driver_class org.postgresql.Driver
  #hibernate.connection.url jdbc:postgresql:template1
  #hibernate.connection.username pg
  #hibernate.connection.password
  #hibernate.query.substitutions yes 'Y', no 'N'
  
  
  ## DB2
  
  #hibernate.dialect net.sf.hibernate.dialect.DB2Dialect
  #hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
  #hibernate.connection.url jdbc:db2:test
  #hibernate.connection.username db2
  #hibernate.connection.password db2
  
  
  ## DB2/400 
  
  #hibernate.dialect net.sf.hibernate.dialect.DB2400Dialect
  #hibernate.connection.username user
  #hibernate.connection.password password 
  
  ## Native driver
  #hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver 
  #hibernate.connection.url jdbc:db2://systemname
  
  ## Toolbox driver
  #hibernate.connection.driver_class com.ibm.as400.access.AS400JDBCDriver 
  #hibernate.connection.url jdbc:as400://systemname
  
  
  ## MySQL
  
  #hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
  #hibernate.connection.driver_class org.gjt.mm.mysql.Driver
  #hibernate.connection.driver_class com.mysql.jdbc.Driver
  #hibernate.connection.url jdbc:mysql:///test
  #hibernate.connection.username root
  #hibernate.connection.password 
  
  
  ## Oracle
  
  #hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect
  #hibernate.dialect net.sf.hibernate.dialect.OracleDialect
  #hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
  #hibernate.connection.username ora
  #hibernate.connection.password ora
  #hibernate.connection.url jdbc:oracle:thin:@localhost:1521:test
  
  
  ## Sybase
  
  #hibernate.dialect net.sf.hibernate.dialect.SybaseDialect
  #hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver
  #hibernate.connection.username sa
  #hibernate.connection.password sasasa
  #hibernate.connection.rl jdbc:sybase:Tds:co3061835-a:5000/tempdb
  
  
  ## Mckoi SQL
  
  #hibernate.dialect net.sf.hibernate.dialect.MckoiDialect
  #hibernate.connection.driver_class com.mckoi.JDBCDriver
  #hibernate.connection.url jdbc:mckoi:///
  #hibernate.connection.url jdbc:mckoi:local://C:/mckoi1.00/db.conf
  #hibernate.connection.username admin
  #hibernate.connection.password nimda
  
  
  ## SAP DB
  
  #hibernate.dialect net.sf.hibernate.dialect.SAPDBDialect
  #hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
  #hibernate.connection.url jdbc:sapdb://localhost/TST
  #hibernate.connection.username TEST
  #hibernate.connection.password TEST
  #hibernate.query.substitutions yes 'Y', no 'N'
  
  
  ## MS SQL Server
  
  #hibernate.dialect net.sf.hibernate.dialect.SQLServerDialect
  #hibernate.connection.username sa
  #hibernate.connection.password sa
  
  ## JSQL Driver
  #hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver
  #hibernate.connection.url jdbc:JSQLConnect://1E1/test
  
  ## JTURBO Driver
  #hibernate.connection.driver_class com.newatlanta.jturbo.driver.Driver
  #hibernate.connection.url jdbc:JTurbo://1E1:1433/test
  
  ## WebLogic Driver
  #hibernate.connection.driver_class weblogic.jdbc.mssqlserver4.Driver
  #hibernate.connection.url jdbc:weblogic:mssqlserver4:1E1:1433
  
  ## Microsoft Driver (not recommended!)
  #hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
  #hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor
  
  ## jTDS (not supported!)
  #hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
  #hibernate.connection.url jdbc:jtds:sqlserver://1E1/test;SelectMethod=cursor
  #hibernate.jdbc.use_scrollable_resultset false
  
  ## Interbase
  
  #hibernate.dialect net.sf.hibernate.dialect.InterbaseDialect
  #hibernate.connection.username sysdba
  #hibernate.connection.password masterkey
  
  ## DO NOT specify hibernate.connection.sqlDialect
  
  ## InterClient
  
  #hibernate.connection.driver_class interbase.interclient.Driver
  #hibernate.connection.url jdbc:interbase://localhost:3060/C:/firebird/test.gdb
  
  ## Pure Java
  
  #hibernate.connection.driver_class org.firebirdsql.jdbc.FBDriver
  #hibernate.connection.url jdbc:firebirdsql:localhost/3050:/firebird/test.gdb
  
  
  ## Pointbase
  
  #hibernate.dialect net.sf.hibernate.dialect.PointbaseDialect
  #hibernate.connection.driver_class com.pointbase.jdbc.jdbcUniversalDriver
  #hibernate.connection.url jdbc:pointbase:embedded:sample
  #hibernate.connection.username PBPUBLIC
  #hibernate.connection.password PBPUBLIC
  
  
  
  #################################
  ### Hibernate Connection Pool ###
  #################################
  
  hibernate.connection.pool_size 1
  
  
  
  ###########################
  ### C3P0 Connection Pool###
  ###########################
  
  #hibernate.c3p0.max_size 2
  #hibernate.c3p0.min_size 2
  #hibernate.c3p0.timeout 5000
  #hibernate.c3p0.max_statements 100
  #hibernate.c3p0.idle_test_period 3000
  #hibernate.c3p0.acquire_increment 2
  ##hibernate.c3p0.validate false
  
  
  
  ###################################
  ### Apache DBCP Connection Pool ###
  ###################################
  
  ## connection pool
  
  #hibernate.dbcp.maxActive 100
  #hibernate.dbcp.whenExhaustedAction 1
  #hibernate.dbcp.maxWait 120000
  #hibernate.dbcp.maxIdle 10
  
  ## prepared statement cache
  
  #hibernate.dbcp.ps.maxActive 100
  #hibernate.dbcp.ps.whenExhaustedAction 1
  #hibernate.dbcp.ps.maxWait 120000
  #hibernate.dbcp.ps.maxIdle 10
  
  ## optional query to validate pooled connections:
  
  #hibernate.dbcp.validationQuery select 1 from dual
  #hibernate.dbcp.testOnBorrow true
  #hibernate.dbcp.testOnReturn false
  
  
  
  ##############################
  ### Proxool Connection Pool###
  ##############################
  
  ## Properties for external configuration of Proxool
  
  hibernate.proxool.pool_alias pool1
  
  ## Only need one of the following
  
  #hibernate.proxool.existing_pool true
  #hibernate.proxool.xml proxool.xml
  #hibernate.proxool.properties proxool.properties
  
  ## Or, alternatively, all of these
  ## Standard configuration properties of Proxool
  
  #hibernate.proxool.house-keeping-sleep-time 30000
  #hibernate.proxool.house-keeping-test-sql 
  #hibernate.proxool.maximum-connection-count 4
  #hibernate.proxool.maximum-connection-lifetime 4
  #hibernate.proxool.simultaneous-build-throttle 2
  #hibernate.proxool.maximum-active-time 500
  #hibernate.proxool.minimum-connection-count 2
  #hibernate.proxool.fatal-sql-exception
  #hibernate.proxool.prototype-count
  #hibernate.proxool.statistics
  #hibernate.proxool.recently-started-threshold
  #hibernate.proxool.overload-without-refusal-lifetime
  
  
  
  #################################
  ### Plugin ConnectionProvider ###
  #################################
  
  ## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)
  
  #hibernate.connection.provider_class net.sf.hibernate.connection.DriverManagerConnectionProvider
  #hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
  #hibernate.connection.provider_class net.sf.hibernate.connection.C3P0ConnectionProvider
  #hibernate.connection.provider_class net.sf.hibernate.connection.DBCPConnectionProvider
  #hibernate.connection.provider_class net.sf.hibernate.connection.ProxoolConnectionProvider
  
  
  
  #######################
  ### Transaction API ###
  #######################
  
  ## the Transaction API abstracts application code from the underlying JTA or JDBC transactions
  
  #hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
  #hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory
  
  
  ## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
  ## default is java:comp/UserTransaction
  ## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class
  
  #jta.UserTransaction jta/usertransaction
  #jta.UserTransaction javax.transaction.UserTransaction
  #jta.UserTransaction UserTransaction
  
  
  ## to use JCS caching with JTA, Hibernate must be able to obtain the JTA TransactionManager
  
  #hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.JBossTransactionManagerLookup
  #hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
  #hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
  #hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.OrionTransactionManagerLookup
  #hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.ResinTransactionManagerLookup
  
  
  
  ##############################
  ### Miscellaneous Settings ###
  ##############################
  
  ## print all generated SQL to the console
  
  #hibernate.show_sql true
  
  
  ## auto schema export
  
  #hibernate.hbm2ddl.auto create-drop
  #hibernate.hbm2ddl.auto create
  #hibernate.hbm2ddl.auto update
  
  
  ## specify a JDBC isolation level
  
  #hibernate.connection.isolation 4
  
  
  ## set the JDBC fetch size
  
  #hibernate.jdbc.fetch_size 25
  
  
  ## set the maximum JDBC 2 batch size (a nonzero value enables batching)
  
  hibernate.jdbc.batch_size 0
  
  
  ## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)
  
  #hibernate.jdbc.use_scrollable_resultset true
  
  
  ## use streams when writing binary types to / from JDBC
  
  hibernate.jdbc.use_streams_for_binary true
  
  
  ## use JDBC 3 PreparedStatement.getGeneratedKeys to get the identifier of an inserted row
  
  #hibernate.jdbc.use_get_generated_keys true
  
  
  ## specify a default schema for unqualified tablenames
  
  #hibernate.default_schema test
  
  
  ## use a custom stylesheet for XML generation (if not specified, hibernate-default.xslt will be used)
  
  #hibernate.xml.output_stylesheet C:/Hibernate/net/sf/hibernate/hibernate-default.xslt
  
  
  ## enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default)
  
  #hibernate.use_outer_join false
  
  
  ## set the maximum depth of the outer join fetch tree
  
  hibernate.max_fetch_depth 1
  
  
  ## enable CGLIB reflection optimizer (enabled by default)
  
  #hibernate.cglib.use_reflection_optimizer false
  
  
  
  ##########################
  ### Second-level Cache ###
  ##########################
  
  ## optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache) 
  
  #hibernate.cache.use_minimal_puts true
  
  
  ## enable the query cache
  
  hibernate.cache.use_query_cache true
  
  
  ## choose a cache implementation
  
  #hibernate.cache.provider_class net.sf.ehcache.hibernate.Provider
  #hibernate.cache.provider_class net.sf.hibernate.cache.EmptyCacheProvider
  hibernate.cache.provider_class net.sf.hibernate.cache.HashtableCacheProvider
  #hibernate.cache.provider_class net.sf.hibernate.cache.TreeCacheProvider
  #hibernate.cache.provider_class net.sf.hibernate.cache.OSCacheProvider
  #hibernate.cache.provider_class net.sf.hibernate.cache.JCSCacheProvider
  #hibernate.cache.provider_class net.sf.hibernate.cache.SwarmCacheProvider
  
  
  
  ############
  ### JNDI ###
  ############
  
  ## specify a JNDI name for the SessionFactory
  
  #hibernate.session_factory_name hibernate/session_factory
  
  
  ## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
  ## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
  ## is the best approach in an application server
  
  #file system
  #hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
  #hibernate.jndi.url file:/
  
  #WebSphere
  #hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
  #hibernate.jndi.url iiop://localhost:900/
  
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/MessageResources.xml
  
  Index: MessageResources.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!DOCTYPE sql-map
      PUBLIC "-//iBATIS.com//DTD SQL Map 1.0//EN"
      "http://www.ibatis.com/dtd/sql-map.dtd">
  
  <sql-map name="MessageResources">
  
    <result-map name="bundle-result" 
  		class="org.apache.commons.resources.impl.DatabaseBasicMessage">
      <property name="locale"  type="VARCHAR" column="locale"/>
      <property name="key"     type="VARCHAR" column="msgKey"/>
      <property name="value"   type="VARCHAR" column="val"/>
    </result-map>
  
    <mapped-statement name="getBundleByLocale"
                      result-map="bundle-result">
      select locale, msgKey, val
      from RESOURCES
      where LOCALE = #value#
    </mapped-statement>
  
  </sql-map>
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/HibernateBasicMessage.hbm.xml
  
  Index: HibernateBasicMessage.hbm.xml
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE hibernate-mapping SYSTEM 
  	"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
  
  
  <hibernate-mapping>
  
      <class name="org.apache.commons.resources.impl.HibernateBasicMessage" table="resources">
  
      	<composite-id>
  		 <key-property name="locale"	type="java.lang.String"	column="locale"/>
  		 <key-property name="key"	type="java.lang.String"	column="msgKey"/>
  		</composite-id>
  
          <property name="value" type="java.lang.String" column="val"/>
      </class>
  
  	<query name="QueryByLocale">
  		
  		    from 
  		    	org.apache.commons.resources.impl.HibernateBasicMessage as msgRes
  		    where 
  		    	msgRes.locale = ?
  		
  	</query>
  
  </hibernate-mapping>
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/TorqueResourcesTestCase.java
  
  Index: TorqueResourcesTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/TorqueResourcesTestCase.java,v 1.1 2004/08/27 03:22:25 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:25 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import java.net.URL;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  /**
   * <p>Unit tests for
   * <code>org.apache.commons.resources.impl.TorqueResources</code>.
   * </p>
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $ $Date: 2004/08/27 03:22:25 $
   */
  
  public class TorqueResourcesTestCase
      extends CollectionResourcesBaseTestCase {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      // ----------------------------------------------------------- Constructors
  
  
      public TorqueResourcesTestCase(String name) {
          super(name);
      }
  
  
      // --------------------------------------------------- Overall Test Methods
  
  
      // Set up instance variables required by this test case
      public void setUp() throws Exception {
          factory = new TorqueResourcesFactory();
          resources = factory.getResources(
                  NAME, 
                  "Torque.cfg.xml");
          
      }
  
  	// Return the tests included in this test suite
      public static Test suite() {
          return (new TestSuite(TorqueResourcesTestCase.class));
      }
  
      // Tear down the instance variables required by this test case
      public void tearDown() {
          resources = null;
          factory = null;
      }
  
  
      // ------------------------------------------------ Individual Test Methods
  
  
      // ------------------------------------------------------ Protected Methods
      protected String getBase() throws Exception
      {
          // default file name
          URL url = 
              TorqueResourcesTestCase.class.getResource
              ("Torque.cfg.xml");
      
          if (url == null) {
              fail("URL NOT FOUND");
          }
          String string = url.toExternalForm();
          String base = string.substring(0, string.length() - 11);
          return base;
      }
  
  
      // ------------------------------------------------------ Private Methods
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/HibernateResourcesTestCase.java
  
  Index: HibernateResourcesTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/HibernateResourcesTestCase.java,v 1.1 2004/08/27 03:22:25 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:25 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  
  import java.net.URL;
  import java.sql.Connection;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import net.sf.hibernate.HibernateException;
  import net.sf.hibernate.Session;
  import net.sf.hibernate.SessionFactory;
  import net.sf.hibernate.cfg.Configuration;
  
  /**
   * <p>Unit tests for
   * <code>org.apache.commons.resources.impl.HibernateResources</code>.
   * </p>
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $ $Date: 2004/08/27 03:22:25 $
   */
  
  public class HibernateResourcesTestCase
      extends CollectionResourcesBaseTestCase {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      // ----------------------------------------------------------- Constructors
  
  
      public HibernateResourcesTestCase(String name) {
          super(name);
      }
  
  
      // --------------------------------------------------- Overall Test Methods
  
  
      // Set up instance variables required by this test case
      public void setUp() throws Exception {
          factory = new HibernateResourcesFactory();
          resources = factory.getResources(
                  NAME, 
                  "hibernate.cfg.xml");
          String sql = "";
          sql += "create table resources (" ;
          sql +="  locale            varchar(10)      not null,";
          sql +="  msgKey            varchar(255)     not null,";
          sql +="  val               varchar(255),";
          sql +="  Primary Key(";
          sql +="    locale,";
          sql +="    msgKey";
          sql +="  )";
          sql +=" )";
          
          runSql(sql);
          runSql("Insert into resources (locale, msgKey, val) Values ('', 'test.base', '[Base] ONLY');");
          runSql("Insert into resources (locale, msgKey, val) Values ('', 'test.specific', '[Base] SPECIFIC');");
          runSql("Insert into resources (locale, msgKey, val) Values ('', 'test.inherit', '[Base] INHERIT');");
          runSql("Insert into resources (locale, msgKey, val) Values ('', 'test.message', '[Base] REPLACE {0} WITH {1}');");
          runSql("Insert into resources (locale, msgKey, val) Values ('en', 'test.specific', '[en] SPECIFIC');");
          runSql("Insert into resources (locale, msgKey, val) Values ('en', 'test.inherit', '[en] INHERIT');");
          runSql("Insert into resources (locale, msgKey, val) Values ('en_US', 'test.specific', '[en_US] SPECIFIC');");
          runSql("Insert into resources (locale, msgKey, val) Values ('fr', 'test.specific', '[fr] SPECIFIC');");
          runSql("Insert into resources (locale, msgKey, val) Values ('fr', 'test.inherit', '[fr] INHERIT');");
          
      }
  
  	// Return the tests included in this test suite
      public static Test suite() {
          return (new TestSuite(HibernateResourcesTestCase.class));
      }
  
      // Tear down the instance variables required by this test case
      public void tearDown() {
          try{
          	runSql("drop table resources");
          }catch(Exception e){
          	// not really necessary to fail if creation also fails
          	e.printStackTrace();
          }
          resources = null;
          factory = null;
      }
  
  
      // ------------------------------------------------ Individual Test Methods
  
  
      // ------------------------------------------------------ Protected Methods
      protected String getBase() throws Exception
      {
          // default file name
          URL url = 
              HibernateResourcesTestCase.class.getResource
              ("hibernate.cfg.xml");
      
          if (url == null) {
              fail("URL NOT FOUND");
          }
          String string = url.toExternalForm();
          String base = string.substring(0, string.length() - 11);
          return base;
      }
  
  
      // ------------------------------------------------------ Private Methods
  
      /**
  	 * @param sql
  	 * @throws SQLException
  	 */
  	private void runSql(String sql) throws SQLException {
  		Session session = null;
          try {            
              // TODO - change this to load the specified hibernate config file (baseUrl)
              SessionFactory sessionFactory =
                  new Configuration().configure().buildSessionFactory();
              session = sessionFactory.openSession();
              
              Connection cn = session.connection();
              Statement st = cn.createStatement();
              st.execute(sql);
      		session.close();
          
          } catch (HibernateException e) {
              e.printStackTrace();
          }
  	}
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/IBatisResourcesTestCase.java
  
  Index: IBatisResourcesTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/resources/contrib/src/test/org/apache/commons/resources/impl/IBatisResourcesTestCase.java,v 1.1 2004/08/27 03:22:25 jmitchell Exp $
   * $Revision: 1.1 $
   * $Date: 2004/08/27 03:22:25 $
   *
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   * 
   *  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 org.apache.commons.resources.impl;
  import java.io.Reader;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import com.ibatis.common.resources.Resources;
  import com.ibatis.db.jdbc.SimpleDataSource;
  import com.ibatis.db.sqlmap.SqlMap;
  import com.ibatis.db.sqlmap.XmlSqlMapBuilder;
  import com.ibatis.db.util.ScriptRunner;
  
  /**
   * <p>Unit tests for
   * <code>org.apache.commons.resources.impl.iBatisResources</code>.
   * </p>
   *
   * @author James Mitchell
   * @version $Revision: 1.1 $ $Date: 2004/08/27 03:22:25 $
   */
  
  public class IBatisResourcesTestCase
      extends CollectionResourcesBaseTestCase {
  
  
      // ----------------------------------------------------- Instance Variables
  	 protected static SqlMap sqlMap;
  
      // ----------------------------------------------------------- Constructors
  
  
      public IBatisResourcesTestCase(String name) {
          super(name);
      }
  
  
      // --------------------------------------------------- Overall Test Methods
  
  
      // Set up instance variables required by this test case
      public void setUp() throws Exception {
      	
          initSqlMap("SqlMapConfig.xml");
          initScript("iBatis-init.sql");
          factory = new IBatisResourcesFactory();
          resources = factory.getResources(NAME, getBase());
      }
  
  	// Return the tests included in this test suite
      public static Test suite() {
          return (new TestSuite(IBatisResourcesTestCase.class));
      }
  
      // Tear down the instance variables required by this test case
      public void tearDown() {
          SimpleDataSource ds = (SimpleDataSource) sqlMap.getCurrentDataSource();
          ds.forceCloseAll();
          resources = null;
          factory = null;
      }
  
  
      // ------------------------------------------------ Individual Test Methods
  
  
      // ------------------------------------------------------ Protected Methods
      protected String getBase() throws Exception
      {
          return "SqlMapConfig.xml";
      }
  
      // ------------------------------------------------------ Private Methods
      protected void initSqlMap(String configFile) throws Exception {
          Reader reader = Resources.getResourceAsReader(configFile);
          sqlMap = XmlSqlMapBuilder.buildSqlMap(reader);
          reader.close();
        }
      protected void initScript(String script) throws Exception {
          Reader reader = Resources.getResourceAsReader(script);
          Connection conn = sqlMap.getCurrentDataSource().getConnection();
          ScriptRunner runner = new ScriptRunner();
          runner.setStopOnError(false);
          runner.setLogWriter(null);
          runner.setErrorLogWriter(null);
          runner.runScript(conn, reader);
          conn.commit();
          
  		String query = "SELECT * from resources";
  
  		PreparedStatement stmt = conn.prepareStatement(query);
  		ResultSet rs = stmt.executeQuery();
  
  		while (rs.next()) {
  		   System.out.println( rs.getString(1));
  		}
  		
          conn.close();
          reader.close();
        }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org