Package org.objectweb.speedo.jdo

Source Code of org.objectweb.speedo.jdo.JDOSpeedo

/**
* Copyright (C) 2001-2005 France Telecom R&D
*/
package org.objectweb.speedo.jdo;

import org.objectweb.speedo.AbstractSpeedo;
import org.objectweb.speedo.lib.BooleanHelper;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.pm.jdo.api.JDOPOManagerFactoryItf;
import org.objectweb.util.monolog.api.BasicLevel;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import javax.jdo.JDOUserException;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.datastore.DataStoreCache;
import javax.jdo.listener.InstanceLifecycleListener;

/**
* This class is a client helper which permits to create a new speedo
* instance. Due to the JDO constraint the persistence manager
* factory implementation must have a public empty contructor. But the use of
* the fractal component (www.objectweb.org/fractal) needs to use a
* fractal implementation to initialize components. Then this class is an
* implementation of the PersistentManagerFactory interface which delegates all
* calls on a persistent manager factory delegate. The constructor of this class
* make the components creation and their initialization via Julia (fractal
* implementation).
*
* @author S.Chassande-Barrioz
*/
public class JDOSpeedo
    extends AbstractSpeedo
    implements PersistenceManagerFactory {

    private static final long serialVersionUID = 8894700146086754548L;

    private static final Map INSTANCES = new HashMap();

    // method called by the JDOHelper.getPersistenceManagerFactory method
    public static PersistenceManagerFactory getPersistenceManagerFactory(
            Properties props) throws Throwable {
        return getPersistenceManagerFactory((Map) props);
    }
    // method called by the JDOHelper.getPersistenceManagerFactory method
    public static PersistenceManagerFactory getPersistenceManagerFactory(
            Map m) throws Throwable {
      AbstractSpeedo instance;
        synchronized (INSTANCES) {
            instance = (AbstractSpeedo) INSTANCES.get(m);
            if (instance == null) {
                instance = new JDOSpeedo(m);
                INSTANCES.put(m, instance);
            }
        }
        return (PersistenceManagerFactory) instance;
    }

    public static void clearInstances() {
        INSTANCES.clear();
    }

    public JDOSpeedo() throws Throwable {
        super();
    }
    public JDOSpeedo(Map props) throws Throwable {
        super(props);
    }

    protected void throwUserException(String msg) {
        throw new JDOUserException(msg);
    }
   
    protected void applyProperties(Map props, Map pmfProps) throws Throwable {
      super.applyProperties(props, pmfProps);
        for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
            Map.Entry me = (Map.Entry) it.next();
            String key = (String) me.getKey();
            String value = (String) me.getValue();
            boolean knownProperty = true;
            boolean print = true;
            if (JDO_OPTION_RETAIN_VALUES.equals(key)) {
                ((JDOPOManagerFactoryItf) delegate).setRetainValues(Boolean.valueOf(value).booleanValue());

            } else if (JDO_OPTION_RESTORE_VALUES.equals(key)) {
                ((JDOPOManagerFactoryItf) delegate).setRestoreValues(Boolean.valueOf(value).booleanValue());

            } else if (JDO_OPTION_IGNORE_CACHE.equals(key)) {
                ((JDOPOManagerFactoryItf) delegate).setIgnoreCache(Boolean.valueOf(value).booleanValue());

            } else if (JDO_OPTION_NON_TRANSACTIONAL_READ.equals(key)) {
                ((JDOPOManagerFactoryItf) delegate).setNontransactionalRead(Boolean.valueOf(value).booleanValue());

            } else if (JDO_OPTION_NON_TRANSACTIONAL_WRITE.equals(key)) {
                ((JDOPOManagerFactoryItf) delegate).setNontransactionalWrite(Boolean.valueOf(value).booleanValue());

            } else if (JDO_OPTION_MULTITREADED.equals(key)) {
                ((JDOPOManagerFactoryItf) delegate).setMultithreaded(Boolean.valueOf(value).booleanValue());

            } else if (JDO_PERSISTENCE_MANAGER_FACTORY_CLASS.equals(key)) {
              print = false;
            } else {
                knownProperty = false;
            }
            if (knownProperty) {
              if (print) {
                logger.log(BasicLevel.INFO, key + ": " + value);
              }
                it.remove();
            }
        }
    }

  protected boolean isOptimisticTransaction(Map props) {
        return BooleanHelper.parse(
            getProperty(props, JDO_OPTION_OPTIMISTIC, "false", true),
            false);
  }

    public Personality getPersonality() {
        return Personality.JDO;
    }
    public PersistenceManager getPersistenceManager() {
        if (!isPropertiesInitialized) {
            try {
                Properties p = getProperties();
                getSpeedoComponent(p);
                init(p);
            } catch(Throwable e) {
                System.err.println("Error during the initilization of the Speedo " +
                "persistence manager factory:");
                e.printStackTrace(System.err);
                return null;
            }          
        }
       
        return ((JDOPOManagerFactoryItf) delegate).getPersistenceManager();
    }

    public PersistenceManager getPersistenceManager(String s, String s1) {
        if (!isPropertiesInitialized) {
            try {
                Properties p = getProperties();
                getSpeedoComponent(p);
                init(p);
            } catch(Throwable e) {
                System.err.println("Error during the initilization of the Speedo " +
                "persistence manager factory:");
                e.printStackTrace(System.err);
                return null;
            }          
        }
        return ((JDOPOManagerFactoryItf) delegate).getPersistenceManager(s, s1);
    }

    public void setConnectionUserName(String s) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionUserName(s);
    }

    public String getConnectionUserName() {
        return ((JDOPOManagerFactoryItf) delegate).getConnectionUserName();
    }

    public void setConnectionPassword(String s) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionPassword(s);
    }

    public void setConnectionURL(String s) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionURL(s);
    }

    public String getConnectionURL() {
        return ((JDOPOManagerFactoryItf) delegate).getConnectionURL();
    }

    public void setConnectionDriverName(String s) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionDriverName(s);
    }

    public String getConnectionDriverName() {
        return ((JDOPOManagerFactoryItf) delegate).getConnectionDriverName();
    }

    public void setConnectionFactoryName(String s) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionFactoryName(s);
    }

    public String getConnectionFactoryName() {
        return ((JDOPOManagerFactoryItf) delegate).getConnectionFactoryName();
    }

    public void setConnectionFactory(Object o) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionFactory(o);
    }

    public Object getConnectionFactory() {
        return ((JDOPOManagerFactoryItf) delegate).getConnectionFactory();
    }

    public void setConnectionFactory2Name(String s) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionFactory2Name(s);
    }

    public String getConnectionFactory2Name() {
        return ((JDOPOManagerFactoryItf) delegate).getConnectionFactory2Name();
    }

    public void setConnectionFactory2(Object o) {
        ((JDOPOManagerFactoryItf) delegate).setConnectionFactory2(o);
    }

    public Object getConnectionFactory2() {
        return ((JDOPOManagerFactoryItf) delegate).getConnectionFactory2();
    }

    public void setMultithreaded(boolean b) {
        ((JDOPOManagerFactoryItf) delegate).setMultithreaded(b);
    }

    public boolean getMultithreaded() {
        return ((JDOPOManagerFactoryItf) delegate).getMultithreaded();
    }

    public void setOptimistic(boolean b) {
        ((JDOPOManagerFactoryItf) delegate).setOptimistic(b);
    }

    public boolean getOptimistic() {
        return ((JDOPOManagerFactoryItf) delegate).getOptimistic();
    }

    public void setRetainValues(boolean b) {
        ((JDOPOManagerFactoryItf) delegate).setRetainValues(b);
    }

    public boolean getRetainValues() {
        return ((JDOPOManagerFactoryItf) delegate).getRetainValues();
    }

    public void setRestoreValues(boolean b) {
        ((JDOPOManagerFactoryItf) delegate).setRestoreValues(b);
    }

    public boolean getRestoreValues() {
        return ((JDOPOManagerFactoryItf) delegate).getRestoreValues();
    }

    public void setNontransactionalRead(boolean b) {
        ((JDOPOManagerFactoryItf) delegate).setNontransactionalRead(b);
    }

    public boolean getNontransactionalRead() {
        return ((JDOPOManagerFactoryItf) delegate).getNontransactionalRead();
    }

    public void setNontransactionalWrite(boolean b) {
        ((JDOPOManagerFactoryItf) delegate).setNontransactionalWrite(b);
    }

    public boolean getNontransactionalWrite() {
        return ((JDOPOManagerFactoryItf) delegate).getNontransactionalWrite();
    }

    public void setIgnoreCache(boolean b) {
        ((JDOPOManagerFactoryItf) delegate).setIgnoreCache(b);
    }

    public boolean getIgnoreCache() {
        return ((JDOPOManagerFactoryItf) delegate).getIgnoreCache();
    }

    public Properties getProperties() {
        return ((JDOPOManagerFactoryItf) delegate).getProperties();
    }

    public Collection supportedOptions() {
        return ((JDOPOManagerFactoryItf) delegate).supportedOptions();
    }

    public void close() {
        ((JDOPOManagerFactoryItf) delegate).close();
        stopComponent();
    }
   
    public DataStoreCache getDataStoreCache() {
        return ((JDOPOManagerFactoryItf) delegate).getDataStoreCache();
    }

    public String getMapping() {
        return ((JDOPOManagerFactoryItf) delegate).getMapping();
    }

    public boolean isClosed() {
        return ((JDOPOManagerFactoryItf) delegate).isClosed();
    }

    public void setMapping(String arg0) {
        ((JDOPOManagerFactoryItf) delegate).setMapping(arg0);
    }

    public void evict(Object arg0) {
        ((JDOPOManagerFactoryItf) delegate).evict(arg0);
    }

    public void evictAll() {
        ((JDOPOManagerFactoryItf) delegate).evictAll();
    }
   
    public void evictAll(Class arg0, boolean arg1) {
        ((JDOPOManagerFactoryItf) delegate).evictAll(arg0, arg1);
    }

    public void evictAll(Collection arg0) {
        ((JDOPOManagerFactoryItf) delegate).evictAll(arg0);
    }

    public void evictAll(Object[] arg0) {
        ((JDOPOManagerFactoryItf) delegate).evictAll(arg0);
    }
    public void pin(Object arg0) {
        ((JDOPOManagerFactoryItf) delegate).pin(arg0);
    }

    public void pinAll(Class arg0, boolean arg1) {
        ((JDOPOManagerFactoryItf) delegate).pinAll(arg0, arg1);
    }

    public void pinAll(Collection arg0) {
        ((JDOPOManagerFactoryItf) delegate).pinAll(arg0);
    }

    public void pinAll(Object[] arg0) {
        ((JDOPOManagerFactoryItf) delegate).pinAll(arg0);
    }

    public void unpin(Object arg0) {
        ((JDOPOManagerFactoryItf) delegate).unpin(arg0);
    }

    public void unpinAll(Class arg0, boolean arg1) {
        ((JDOPOManagerFactoryItf) delegate).unpinAll(arg0, arg1);
    }

    public void unpinAll(Collection arg0) {
        ((JDOPOManagerFactoryItf) delegate).unpinAll(arg0);
    }

    public void unpinAll(Object[] arg0) {
        ((JDOPOManagerFactoryItf) delegate).unpinAll(arg0);
    }
   
    public void addInstanceLifecycleListener(
            InstanceLifecycleListener arg0,
            Class[] arg1) {
        ((JDOPOManagerFactoryItf) delegate).addInstanceLifecycleListener(arg0, arg1);
    }
    public void removeInstanceLifecycleListener(InstanceLifecycleListener arg0) {
        ((JDOPOManagerFactoryItf) delegate).removeInstanceLifecycleListener(arg0);
    }
  /* (non-Javadoc)
   * @see javax.jdo.PersistenceManagerFactory#getDetachAllOnCommit()
   */
  public boolean getDetachAllOnCommit() {
    // TODO Auto-generated method stub
    return false;
  }
  /* (non-Javadoc)
   * @see javax.jdo.PersistenceManagerFactory#setDetachAllOnCommit(boolean)
   */
  public void setDetachAllOnCommit(boolean arg0) {
    // TODO Auto-generated method stub
   
  }
   
}
TOP

Related Classes of org.objectweb.speedo.jdo.JDOSpeedo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.