CVS: plexus-components/hibernate/src/java/org/apache/plexus/hibernate DefaultPersister.java,NONE,1.1 DefaultHibernateService.java,NONE,1.1 Persister.java,NONE,1.1 HibernateService.java,NONE,1.1
[email protected] Tue, 20 May 2003 18:25:01 -0500
| Newsgroups | gmane.comp.java.plexus.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/plexus/plexus-components/hibernate/src/java/org/apache/plexus/hibernate In directory eng.werken.com:/tmp/cvs-serv9604/hibernate/src/java/org/apache/plexus/hibernate Added Files: DefaultPersister.java DefaultHibernateService.java Persister.java HibernateService.java Log Message: A hibernate component. --- NEW FILE: DefaultPersister.java --- package org.apache.plexus.hibernate; import java.util.List; import org.apache.avalon.framework.logger.AbstractLogEnabled; /** * TODO Document DefaultPersister * * @author <a href="mailto:[email protected]">Dan Diephouse</a> * @since May 14, 2003 */ public class DefaultPersister extends AbstractLogEnabled implements Persister { Class clazz; /** * @see org.apache.plexus.hibernate.Persister#setClass(java.lang.Class) */ public void setClass(Class clazz) { this.clazz = clazz; } /** * @see org.apache.plexus.hibernate.Persister#save(java.lang.Object) */ public void save(Object o) { // TODO Auto-generated method stub } /** * @see org.apache.plexus.hibernate.Persister#load(java.lang.Object) */ public Object load(Object id) { // TODO Auto-generated method stub return null; } /** * @see org.apache.plexus.hibernate.Persister#delete(java.lang.Object) */ public void delete(Object o) { // TODO Auto-generated method stub } /** * @see org.apache.plexus.hibernate.Persister#selectAll() */ public List selectAll() { // TODO Auto-generated method stub return null; } } --- NEW FILE: DefaultHibernateService.java --- package org.apache.plexus.hibernate; import java.util.Properties; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLogEnabled; import net.sf.hibernate.HibernateException; import net.sf.hibernate.MappingException; import net.sf.hibernate.SessionFactory; /** * Hibernate service. * * @author <a href="mailto:[email protected]">Dan Diephouse</a> * @since May 10, 2003 */ public class DefaultHibernateService extends AbstractLogEnabled implements HibernateService, Configurable, Initializable { SessionFactory sessionFactory; net.sf.hibernate.cfg.Configuration hibConfig; /** * @see org.apache.plexus.hibernate.HibernateService#getSessionFactory() */ public SessionFactory getSessionFactory() { return sessionFactory; } /** * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) */ public void configure(Configuration config) throws ConfigurationException { hibConfig = new net.sf.hibernate.cfg.Configuration(); String mapping = config.getAttribute( "mapping" ); try { getLogger().debug("Configuration mapping " + mapping); hibConfig.configure( mapping ); } catch (HibernateException e) { throw new ConfigurationException( "Mapping problem.", e ); } Configuration[] classes = config.getChild( "classes" ).getChildren(); if ( classes != null ) { configureClasses( classes ); } Configuration[] properties = config.getChild( "properties" ).getChildren(); Properties props = new Properties(); for ( int i = 0; i < properties.length; i++ ) { props.setProperty( properties[i].getAttribute("name"), properties[i].getAttribute("value") ); } hibConfig.addProperties( props ); } private void configureClasses(Configuration[] classes) throws ConfigurationException { for ( int i = 0; i < classes.length; i++ ) { try { hibConfig.addClass( Class.forName( classes[i].getValue() ) ); } catch ( ClassNotFoundException e ) { throw new ConfigurationException( "Could not find class " + classes[i].getValue(), e ); } catch (MappingException e) { throw new ConfigurationException( "Mapping problem.", e ); } } } /** * @see org.apache.avalon.framework.activity.Initializable#initialize() */ public void initialize() throws Exception { getLogger().info( "Initializing Hibernate." ); sessionFactory = hibConfig.buildSessionFactory(); } public net.sf.hibernate.cfg.Configuration getConfiguration() { return hibConfig; } } --- NEW FILE: Persister.java --- package org.apache.plexus.hibernate; import java.util.List; /** * A Persister for objects that isn't tied to Hibernate. * * @author <a href="mailto:[email protected]">Dan Diephouse</a> * @since May 12, 2003 */ public interface Persister { public void setClass( Class clazz ); public void save( Object o ); public Object load( Object id ); public void delete( Object o ); public List selectAll(); } --- NEW FILE: HibernateService.java --- package org.apache.plexus.hibernate; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.cfg.Configuration; /* ---------------------------------------------------------------------------- * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Plexus", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [email protected]. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ---------------------------------------------------------------------------- * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ---------------------------------------------------------------------------- */ public interface HibernateService { String ROLE = HibernateService.class.getName(); SessionFactory getSessionFactory(); Configuration getConfiguration(); }