Package org.objectweb.speedo.mapper.jca

Source Code of org.objectweb.speedo.mapper.jca.JCAMapper

/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.objectweb.speedo.mapper.jca;

import org.objectweb.jorm.api.PException;
import org.objectweb.jorm.api.JormConfigurator;
import org.objectweb.jorm.lib.MapperJCA;
import org.objectweb.util.monolog.api.LoggerFactory;
import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.speedo.api.ExceptionHelper;
import org.objectweb.speedo.api.SpeedoProperties;
import org.objectweb.speedo.api.SpeedoRuntimeException;
import org.objectweb.speedo.mapper.api.MapperAttributes;
import org.objectweb.medor.eval.prefetch.lib.PrefetchCacheImpl;
import org.objectweb.perseus.persistence.api.ConnectionHolderFactory;
import org.objectweb.perseus.persistence.api.ConnectionHolder;
import org.objectweb.perseus.persistence.api.PersistenceException;
import org.objectweb.perseus.pool.api.Pool;

public class JCAMapper extends MapperJCA
        implements MapperAttributes, LifeCycleController, ConnectionHolderFactory {

    public final static String MONOLOG_FACTORY_BINDING = "monolog-factory";
  public final static String POOL_BINDING = "pool";
    public final static String LOGGER_NAME
            = SpeedoProperties.LOGGER_NAME + ".rt.mapper.jca";
    public final static String RESOUCE_ADAPTER_BINDINNG = "resouce-adapter";

    private boolean started;

    private boolean initialized = false;
   
    private boolean checkConnectivityAtStartup = true;

  private Pool pool;

    public JCAMapper() throws PException {
    }

    public boolean getCheckConnectivityAtStartup() {
        return checkConnectivityAtStartup;
    }
    public void setCheckConnectivityAtStartup(boolean b) {
        checkConnectivityAtStartup = b;
    }
    // IMPLEMENTATION OF THE UserBindingController INTERFACE //
    //-------------------------------------------------------//

    public Object getFcBindings(String s) {
        if (MONOLOG_FACTORY_BINDING.equals(s))
            return getLoggerFactory();
        else if (RESOUCE_ADAPTER_BINDINNG.equals(s))
            return getConnectionFactory();
        else if (POOL_BINDING.equals(s))
            return pool;
        return null;
    }

    public void addFcBinding(String s, Object o) {
        if (MONOLOG_FACTORY_BINDING.equals(s))
            setLoggerFactory((LoggerFactory) o);
        else if (POOL_BINDING.equals(s))
      pool = (Pool) o;
        else if (RESOUCE_ADAPTER_BINDINNG.equals(s))
            try {
                setConnectionFactory(o);
            } catch (PException e) {
                throw new SpeedoRuntimeException(
                        "Impossible to assign the connection factory to the mapper", e);
            }
    }

    public void removeFcBinding(String s, Object o) {
        if (MONOLOG_FACTORY_BINDING.equals(s))
            setLoggerFactory(null);
        else if (POOL_BINDING.equals(s))
      pool = null;
        else if (RESOUCE_ADAPTER_BINDINNG.equals(s))
            try {
                setConnectionFactory(null);
            } catch (PException e) {
                throw new SpeedoRuntimeException(
                        "Impossible to remove the connection factory to the mapper", e);
            }
    }


    // IMPLEMENTATION OF THE Pool INTERFACE //
    //--------------------------------------//
  public ConnectionHolder createConnectionHolder() throws PersistenceException {
    return null;
  }

    // IMPLEMENTATION OF THE LifeCycleController INTERFACE //
    //-----------------------------------------------------//

    public String getFcState() {
        return started ? STARTED : STOPPED;
    }

    public void startFc() {
        started = true;
        if (!initialized) {
            try {

        JormConfigurator jc = getJormConfigurator();
        jc.setLoggerFactory(getLoggerFactory());
                setJormConfigurator(jc);
        PrefetchCacheImpl pc = new PrefetchCacheImpl(
            getLoggerFactory().getLogger(
                "org.objectweb.speedo.rt.query.prefetch"));
        setPrefetchCache(pc);
                start();
                initialized = true;
            } catch (PException e) {
                throw new RuntimeException(
                        "Impossible to configure the mapper: "
                        + ExceptionHelper.getNested(e).getMessage());
            }
        }
    }

    public void stopFc() {
        started = false;
    }

}
TOP

Related Classes of org.objectweb.speedo.mapper.jca.JCAMapper

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.