001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.mapper.jca;
018:
019: import org.objectweb.jorm.api.PException;
020: import org.objectweb.jorm.api.JormConfigurator;
021: import org.objectweb.jorm.lib.MapperJCA;
022: import org.objectweb.util.monolog.api.LoggerFactory;
023: import org.objectweb.fractal.api.control.LifeCycleController;
024: import org.objectweb.speedo.api.ExceptionHelper;
025: import org.objectweb.speedo.api.SpeedoProperties;
026: import org.objectweb.speedo.api.SpeedoRuntimeException;
027: import org.objectweb.speedo.mapper.api.MapperAttributes;
028: import org.objectweb.medor.eval.prefetch.lib.PrefetchCacheImpl;
029: import org.objectweb.perseus.persistence.api.ConnectionHolderFactory;
030: import org.objectweb.perseus.persistence.api.ConnectionHolder;
031: import org.objectweb.perseus.persistence.api.PersistenceException;
032: import org.objectweb.perseus.pool.api.Pool;
033:
034: public class JCAMapper extends MapperJCA implements MapperAttributes,
035: LifeCycleController, ConnectionHolderFactory {
036:
037: public final static String MONOLOG_FACTORY_BINDING = "monolog-factory";
038: public final static String POOL_BINDING = "pool";
039: public final static String LOGGER_NAME = SpeedoProperties.LOGGER_NAME
040: + ".rt.mapper.jca";
041: public final static String RESOUCE_ADAPTER_BINDINNG = "resouce-adapter";
042:
043: private boolean started;
044:
045: private boolean initialized = false;
046:
047: private boolean checkConnectivityAtStartup = true;
048:
049: private Pool pool;
050:
051: public JCAMapper() throws PException {
052: }
053:
054: public boolean getCheckConnectivityAtStartup() {
055: return checkConnectivityAtStartup;
056: }
057:
058: public void setCheckConnectivityAtStartup(boolean b) {
059: checkConnectivityAtStartup = b;
060: }
061:
062: // IMPLEMENTATION OF THE UserBindingController INTERFACE //
063: //-------------------------------------------------------//
064:
065: public Object getFcBindings(String s) {
066: if (MONOLOG_FACTORY_BINDING.equals(s))
067: return getLoggerFactory();
068: else if (RESOUCE_ADAPTER_BINDINNG.equals(s))
069: return getConnectionFactory();
070: else if (POOL_BINDING.equals(s))
071: return pool;
072: return null;
073: }
074:
075: public void addFcBinding(String s, Object o) {
076: if (MONOLOG_FACTORY_BINDING.equals(s))
077: setLoggerFactory((LoggerFactory) o);
078: else if (POOL_BINDING.equals(s))
079: pool = (Pool) o;
080: else if (RESOUCE_ADAPTER_BINDINNG.equals(s))
081: try {
082: setConnectionFactory(o);
083: } catch (PException e) {
084: throw new SpeedoRuntimeException(
085: "Impossible to assign the connection factory to the mapper",
086: e);
087: }
088: }
089:
090: public void removeFcBinding(String s, Object o) {
091: if (MONOLOG_FACTORY_BINDING.equals(s))
092: setLoggerFactory(null);
093: else if (POOL_BINDING.equals(s))
094: pool = null;
095: else if (RESOUCE_ADAPTER_BINDINNG.equals(s))
096: try {
097: setConnectionFactory(null);
098: } catch (PException e) {
099: throw new SpeedoRuntimeException(
100: "Impossible to remove the connection factory to the mapper",
101: e);
102: }
103: }
104:
105: // IMPLEMENTATION OF THE Pool INTERFACE //
106: //--------------------------------------//
107: public ConnectionHolder createConnectionHolder()
108: throws PersistenceException {
109: return null;
110: }
111:
112: // IMPLEMENTATION OF THE LifeCycleController INTERFACE //
113: //-----------------------------------------------------//
114:
115: public String getFcState() {
116: return started ? STARTED : STOPPED;
117: }
118:
119: public void startFc() {
120: started = true;
121: if (!initialized) {
122: try {
123:
124: JormConfigurator jc = getJormConfigurator();
125: jc.setLoggerFactory(getLoggerFactory());
126: setJormConfigurator(jc);
127: PrefetchCacheImpl pc = new PrefetchCacheImpl(
128: getLoggerFactory()
129: .getLogger(
130: "org.objectweb.speedo.rt.query.prefetch"));
131: setPrefetchCache(pc);
132: start();
133: initialized = true;
134: } catch (PException e) {
135: throw new RuntimeException(
136: "Impossible to configure the mapper: "
137: + ExceptionHelper.getNested(e)
138: .getMessage());
139: }
140: }
141: }
142:
143: public void stopFc() {
144: started = false;
145: }
146:
147: }
|