Source Code Cross Referenced for AbstractSpeedo.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Speedo_1.4.5 » org.objectweb.speedo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Speedo: an implementation of JDO compliant personality on top of JORM generic
0003:         * I/O sub-system.
0004:         * Copyright (C) 2001-2004 France Telecom R&D
0005:         *
0006:         * This library is free software; you can redistribute it and/or
0007:         * modify it under the terms of the GNU Lesser General Public
0008:         * License as published by the Free Software Foundation; either
0009:         * version 2 of the License, or (at your option) any later version.
0010:         *
0011:         * This library is distributed in the hope that it will be useful,
0012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014:         * Lesser General Public License for more details.
0015:         *
0016:         * You should have received a copy of the GNU Lesser General Public
0017:         * License along with this library; if not, write to the Free Software
0018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0019:         *
0020:         *
0021:         *
0022:         * Contact: speedo@objectweb.org
0023:         *
0024:         * Authors: S.Chassande-Barrioz.
0025:         *
0026:         */package org.objectweb.speedo;
0027:
0028:        import java.util.ArrayList;
0029:        import java.util.Arrays;
0030:        import java.util.Collection;
0031:        import java.util.Collections;
0032:        import java.util.HashMap;
0033:        import java.util.Iterator;
0034:        import java.util.Map;
0035:        import java.util.Properties;
0036:
0037:        import javax.naming.InitialContext;
0038:        import javax.naming.NamingException;
0039:
0040:        import org.objectweb.fractal.adl.Factory;
0041:        import org.objectweb.fractal.adl.FactoryFactory;
0042:        import org.objectweb.fractal.api.Component;
0043:        import org.objectweb.fractal.api.control.BindingController;
0044:        import org.objectweb.fractal.api.control.ContentController;
0045:        import org.objectweb.fractal.util.Fractal;
0046:        import org.objectweb.jorm.api.PMapper;
0047:        import org.objectweb.jorm.mapper.rdb.lib.ConnectionSpecJDBC;
0048:        import org.objectweb.perseus.cache.api.CacheAttributeController;
0049:        import org.objectweb.perseus.concurrency.pessimistic.PessimisticConcurrencyManagerAC;
0050:        import org.objectweb.perseus.dependency.api.DependencyGraph;
0051:        import org.objectweb.perseus.persistence.concurrency.PConcurrencyManager;
0052:        import org.objectweb.perseus.persistence.api.TransactionalPersistenceManagerAttributeController;
0053:        import org.objectweb.perseus.persistence.api.WorkingSetFilter;
0054:        import org.objectweb.perseus.pool.api.PoolAttributes;
0055:        import org.objectweb.speedo.api.Debug;
0056:        import org.objectweb.speedo.api.SpeedoException;
0057:        import org.objectweb.speedo.api.SpeedoProperties;
0058:        import org.objectweb.speedo.api.SpeedoVersion;
0059:        import org.objectweb.speedo.api.TransactionListener;
0060:        import org.objectweb.speedo.jmx.JMXConfigurator;
0061:        import org.objectweb.speedo.jmx.api.MX4J_HtmlAdaptorCA;
0062:        import org.objectweb.speedo.lib.BooleanHelper;
0063:        import org.objectweb.speedo.lib.FractalHelper;
0064:        import org.objectweb.speedo.lib.Personality;
0065:        import org.objectweb.speedo.locale.LocaleHelper;
0066:        import org.objectweb.speedo.mapper.api.JormFactoryAttributes;
0067:        import org.objectweb.speedo.mapper.api.MapperAttributes;
0068:        import org.objectweb.speedo.mapper.rdb.JDBCMapperAttributes;
0069:        import org.objectweb.speedo.mim.api.MemoryInstanceManagerAttribute;
0070:        import org.objectweb.speedo.pm.api.POManagerFactoryItf;
0071:        import org.objectweb.speedo.pm.api.POManagerInstanciatorAC;
0072:        import org.objectweb.speedo.pm.api.POManagerItf;
0073:        import org.objectweb.speedo.query.api.QueryManager;
0074:        import org.objectweb.speedo.query.api.QueryManagerAttribute;
0075:        import org.objectweb.speedo.sequence.api.SequenceManager;
0076:        import org.objectweb.speedo.workingset.lib.AbstractTransaction;
0077:        import org.objectweb.util.monolog.Monolog;
0078:        import org.objectweb.util.monolog.api.BasicLevel;
0079:        import org.objectweb.util.monolog.api.Loggable;
0080:        import org.objectweb.util.monolog.api.Logger;
0081:        import org.objectweb.util.monolog.api.LoggerFactory;
0082:
0083:        /**
0084:         * This class is a client helper which permits to create a new speedo
0085:         * instance. Due to the personality constraint the POManagerFactoryItf
0086:         * implementation must have a public empty contructor. But the use of
0087:         * the fractal components (www.objectweb.org/fractal) needs to use a
0088:         * fractal implementation (Julia) to initialize the speedo component. 
0089:         * 
0090:         * This class is an implementation of the POManagerFactoryItf interface which 
0091:         * delegates all calls on a delegate, the real component. 
0092:         * This class is responsible of the Speedo configuration from a set of property
0093:         * specified by a Map (String optionName, Object value). Configuring Speedo
0094:         * means to assign parameter to some components or maybe change the architecture
0095:         * of Speedo (change some component).
0096:         *
0097:         * This class must be subclassed for each personality of Speedo.
0098:         * 
0099:         * @author S.Chassande-Barrioz
0100:         */
0101:        public abstract class AbstractSpeedo implements  POManagerFactoryItf,
0102:                SpeedoProperties {
0103:
0104:            private static final long serialVersionUID = 8894700146086754547L;
0105:
0106:            private final static String LOGGER_NAME = SpeedoProperties.LOGGER_NAME
0107:                    + ".init";
0108:
0109:            private final static String OPTIMISTIC_CONCURRENCY_TEMPLATE = "org.objectweb.perseus.concurrency.optimistic.OptimisticConcurrencyManager";
0110:            private final static String DBDELEGATE_CONCURRENCY_TEMPLATE = "org.objectweb.perseus.persistence.concurrency.PDbDelegateConcurrencyManager";
0111:            public final static String PM_POOL_PATH = "po-manager-pool";
0112:            public final static String PMI_PATH = "po-manager-instanciator";
0113:            public final static String MIM_PATH = "memory-instance-manager";
0114:            public final static String MEMORY_CACHE_PATH = "tpm.cache-manager";
0115:            public final static String DEPENDENCY_GRAPH_PATH = "tpm.dependency-graph";
0116:            public final static String QUERY_CACHE_PATH = "compiled-query-cache";
0117:            public final static String QUERY_MANAGER = "query-manager";
0118:            public final static String CONNECTION_POOL_PATH = "mapper.pool";
0119:            public final static String MONOLOG_FACTORY_PATH = "monolog-factory";
0120:            public final static String PRIMITIVE_MAPPER_PATH = "mapper.mapper";
0121:            public final static String JORM_FACTORY_PATH = "mapper.jorm-factory";
0122:            public final static String COMPOSITE_TPM_PATH = "tpm";
0123:            public final static String TPM_PATH = "tpm.transactional-persistence-manager";
0124:            public final static String PMF_PATH = "po-manager-factory";
0125:            public final static String JMX_AGENT_PATH = "agent";
0126:            public final static String HTML_JMX_AGENT_PATH = JMX_AGENT_PATH
0127:                    + ".html";
0128:
0129:            private final static String FRACTAL_PROVIDER = "fractal.provider";
0130:            private final static String DEFAULT_FRACTAL_PROVIDER = "org.objectweb.fractal.julia.Julia";
0131:
0132:            private final static String JULIA_LOADER = "julia.loader";
0133:            private final static String DEFAULT_JULIA_LOADER = "org.objectweb.fractal.julia.loader.DynamicLoader";
0134:
0135:            private final static String JULIA_CONFIG = "julia.config";
0136:            private final static String DEFAULT_JULIA_CONFIG = "julia.cfg";
0137:
0138:            private static Factory factory = null;
0139:
0140:            private static Factory getADLFactory() throws Exception {
0141:                if (factory == null) {
0142:                    factory = FactoryFactory
0143:                            .getFactory(FactoryFactory.FRACTAL_BACKEND);
0144:                }
0145:                return factory;
0146:            }
0147:
0148:            /**
0149:             * The persistence manager factory delegate
0150:             */
0151:            protected POManagerFactoryItf delegate = null;
0152:            protected Logger logger = null;
0153:            protected Component speedo = null;
0154:            protected boolean isPropertiesInitialized = false;
0155:
0156:            protected boolean jmxOn = false;
0157:
0158:            public AbstractSpeedo() {
0159:            }
0160:
0161:            /**
0162:             * It creates and initializes a real POManagerFactory with
0163:             * Julia (Fractal implementation).
0164:             */
0165:            public AbstractSpeedo(Map props) throws Throwable {
0166:                try {
0167:                    init(props);
0168:                    isPropertiesInitialized = true;
0169:                } catch (Throwable e) {
0170:                    System.err
0171:                            .println("Error during the instanciation of the Speedo "
0172:                                    + "persistence manager factory:");
0173:                    e.printStackTrace(System.err);
0174:                    throw e;
0175:                }
0176:            }
0177:
0178:            public abstract Personality getPersonality();
0179:
0180:            protected abstract void throwUserException(String msg);
0181:
0182:            protected abstract boolean isOptimisticTransaction(Map props);
0183:
0184:            public void stopComponent() {
0185:                logger.log(BasicLevel.INFO, "Stopping Speedo");
0186:                try {
0187:                    Fractal.getLifeCycleController(speedo).stopFc();
0188:                } catch (Exception e) {
0189:                    logger.log(BasicLevel.ERROR, "Cannot stop Speedo: ", e);
0190:                }
0191:            }
0192:
0193:            public POManagerFactoryItf getPMFComponent() throws Exception {
0194:                return delegate;
0195:            }
0196:
0197:            public Object getConcurrencyManagerComponent() throws Exception {
0198:                return getSubComponent(speedo, "tpm.concurrency-manager");
0199:            }
0200:
0201:            public DependencyGraph getDependencyGraph() throws Exception {
0202:                Component cmC = (Component) getConcurrencyManagerComponent();
0203:                Object dg = Fractal.getBindingController(cmC).lookupFc(
0204:                        "dependency-graph");
0205:                return (DependencyGraph) dg;
0206:            }
0207:
0208:            public Collection getMemoryCacheEntries() throws Exception {
0209:                Component cm = getSubComponent(speedo, MEMORY_CACHE_PATH);
0210:                Component cmC = getSubComponent(cm, "cache-manager");
0211:                CacheAttributeController cacheAttr = (CacheAttributeController) Fractal
0212:                        .getAttributeController(cmC);
0213:                return cacheAttr.getCurrentEntryIdentifiers();
0214:            }
0215:
0216:            public POManagerFactoryItf getDelegate() {
0217:                return delegate;
0218:            }
0219:
0220:            // IMPLEMENTATION OF THE POManagerFactoryItf INTERFACE //
0221:            //-----------------------------------------------------//
0222:
0223:            public POManagerItf getPOManager() {
0224:                return delegate.getPOManager();
0225:            }
0226:
0227:            public POManagerItf lookup() {
0228:                return delegate.lookup();
0229:            }
0230:
0231:            public SequenceManager getSequenceManager() {
0232:                return delegate.getSequenceManager();
0233:            }
0234:
0235:            public void setSequenceManager(SequenceManager sequenceManager) {
0236:                delegate.setSequenceManager(sequenceManager);
0237:            }
0238:
0239:            public QueryManager getQueryManager() {
0240:                return delegate.getQueryManager();
0241:            }
0242:
0243:            public void setQueryManager(QueryManager queryManager) {
0244:                delegate.setQueryManager(queryManager);
0245:            }
0246:
0247:            public void unbindPM() {
0248:                delegate.unbindPM();
0249:            }
0250:
0251:            public void bindPM2Thread(POManagerItf pm) {
0252:                delegate.bindPM2Thread(pm);
0253:            }
0254:
0255:            public void poManagerClosed(POManagerItf pr) {
0256:                delegate.poManagerClosed(pr);
0257:            }
0258:
0259:            public void clean() {
0260:                delegate.clean();
0261:            }
0262:
0263:            public Properties getProperties() {
0264:                return delegate.getProperties();
0265:            }
0266:
0267:            // methods for speedo configuration //
0268:            //----------------------------------//
0269:
0270:            protected Component getSpeedoComponent(Map props) throws Throwable {
0271:                if (speedo == null) {
0272:                    //use Julia as Fractal implementation
0273:                    System.setProperty(FRACTAL_PROVIDER,
0274:                            DEFAULT_FRACTAL_PROVIDER);
0275:                    System.setProperty(JULIA_LOADER, DEFAULT_JULIA_LOADER);
0276:                    System.setProperty(JULIA_CONFIG, DEFAULT_JULIA_CONFIG);
0277:
0278:                    //Allocate a Logger through the LoggerFactory component
0279:                    Monolog.initialize();
0280:                    LoggerFactory loggerFactory = Monolog.monologFactory;
0281:                    logger = loggerFactory.getLogger(LOGGER_NAME);
0282:
0283:                    //Choose the fractal template according to the JMX option
0284:                    String templateName;
0285:                    if (props != null
0286:                            && BooleanHelper.parse(getProperty(props, JMX,
0287:                                    "false", false), false)) {
0288:                        templateName = "SpeedoJMX";
0289:                    } else {
0290:                        templateName = "Speedo";
0291:                    }
0292:                    //Choose the fractal template corresponding to the personality
0293:                    templateName = getPersonality().getPersonalityClassName(
0294:                            "org.objectweb.speedo", templateName);
0295:
0296:                    //instanciate the Speedo component
0297:                    Component speedoTemplate = null;
0298:                    try {
0299:                        speedoTemplate = (Component) getADLFactory()
0300:                                .newComponent(
0301:                                        templateName,
0302:                                        Collections.singletonMap("template",
0303:                                                "true"));
0304:                        speedo = Fractal.getFactory(speedoTemplate)
0305:                                .newFcInstance();
0306:                    } catch (Throwable e) {
0307:                        System.err
0308:                                .println("Error during the template loading or the "
0309:                                        + "component instanciation '"
0310:                                        + speedoTemplate + "': ");
0311:                        throw e;
0312:                    }
0313:                    Fractal.getNameController(speedo).setFcName(
0314:                            "org.objectweb.speedo");
0315:                    delegate = (POManagerFactoryItf) speedo
0316:                            .getFcInterface("po-manager-factory");
0317:                }
0318:                return speedo;
0319:            }
0320:
0321:            public void init(Map pmfProps) throws Throwable {
0322:                getSpeedoComponent(pmfProps);
0323:                logger.log(BasicLevel.INFO, "Speedo "
0324:                        + SpeedoVersion.SPEEDO_VERSION
0325:                        + LocaleHelper.getSpeedoRB().getString("start"));
0326:                configure(pmfProps);
0327:                delegate.getProperties().putAll(pmfProps);
0328:                Fractal.getLifeCycleController(speedo).startFc();
0329:                if (jmxOn) {
0330:                    new JMXConfigurator(speedo, logger).init();
0331:                }
0332:                logger.log(BasicLevel.INFO, "Speedo "
0333:                        + SpeedoVersion.SPEEDO_VERSION
0334:                        + LocaleHelper.getSpeedoRB().getString("ready"));
0335:            }
0336:
0337:            protected void configure(Map pmfProps) throws Throwable {
0338:                Map props = new HashMap(pmfProps);
0339:                applyProperties(props, pmfProps);
0340:                //Warn the unknwon properties
0341:                for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
0342:                    Map.Entry me = (Map.Entry) it.next();
0343:                    String key = (String) me.getKey();
0344:                    if (key.startsWith(CACHE_CLASS_POLICY + "(")
0345:                            || key.startsWith(USER_CACHE_CLASS_POLICY + "(")
0346:                            || key.startsWith(PREFETCH_ON_GENCLASS + "(")
0347:                            || key.startsWith(PREFETCH_ON_QUERY + "(")
0348:                            || key.startsWith(PREFETCH_ON_EXTENT + "(")
0349:                            || key.startsWith(SHAREABLE)) {
0350:                        continue;
0351:                    }
0352:                    String value = (String) me.getValue();
0353:                    logger.log(BasicLevel.WARN, "The (" + key + ", " + value
0354:                            + ") property is not managed");
0355:                }
0356:            }
0357:
0358:            protected void applyProperties(Map props, Map pmfProps)
0359:                    throws Throwable {
0360:                //Debug Mode
0361:                String strval = getProperty(props, SpeedoProperties.DEBUG,
0362:                        null, true);
0363:                if (strval != null) {
0364:                    Debug.ON = Boolean.valueOf(strval).booleanValue();
0365:                    logger.log(BasicLevel.INFO, SpeedoProperties.DEBUG + ": "
0366:                            + Debug.ON);
0367:                }
0368:                configureMIM(getSubComponent(speedo, MIM_PATH), props);
0369:                configurePOMI(getSubComponent(speedo, PMI_PATH), props);
0370:                boolean useConnectionFactory = configureMapper(props);
0371:                configurePool(getSubComponent(speedo, PM_POOL_PATH),
0372:                        "PersistenceManager pool: ", PM_POOL_MIN, PM_POOL_MAX,
0373:                        PM_POOL_TTL, PM_POOL_INACTIVETTL, PM_POOL_TIMEOUT,
0374:                        props);
0375:                configureCache(getSubComponent(speedo, MEMORY_CACHE_PATH),
0376:                        "Persistent objects cache: ", CACHE_SIZE,
0377:                        CACHE_AUTO_CLEAN_SIZE, CACHE_AUTO_CLEAN_THRESHOLD,
0378:                        CACHE_REPLCAEMENT, props);
0379:                configureCache(getSubComponent(speedo, QUERY_CACHE_PATH),
0380:                        "Compiled query cache: ", COMPILED_QUERY_CACHE_SIZE,
0381:                        COMPILED_QUERY_CACHE_AUTO_CLEAN_SIZE,
0382:                        COMPILED_QUERY_CACHE_AUTO_CLEAN_THRESHOLD,
0383:                        COMPILED_QUERY_CACHE_POLICY, props);
0384:                configureTPM(getSubComponent(speedo, TPM_PATH),
0385:                        "Transactionnal persistence manager: ",
0386:                        TRANSACTION_FILTERS, props);
0387:
0388:                strval = getProperty(props, IMRICATED_PM_ALLOWED, "false", true);
0389:                boolean imbricatedPM = Boolean.valueOf(strval).booleanValue();
0390:                if (imbricatedPM) {
0391:                    logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB()
0392:                            .getString("pmreused"));
0393:                }
0394:
0395:                configurePrefetching(props);
0396:                configureConcurrencyManager(props);
0397:                configureTransaction(props, pmfProps, useConnectionFactory);
0398:                jmxOn = configureJMX(props);
0399:            }
0400:
0401:            protected String getProperty(Map m, String propName,
0402:                    String defaultValue, boolean remove) {
0403:                Object res = remove ? m.remove(propName) : m.get(propName);
0404:                if (res instanceof  String) {
0405:                    return (String) res;
0406:                } else {
0407:                    return defaultValue;
0408:                }
0409:            }
0410:
0411:            protected boolean removeProps(Map props, String[] wanted) {
0412:                boolean found = false;
0413:                for (int i = 0; i < wanted.length; i++) {
0414:                    found |= props.remove(wanted[i]) != null;
0415:                }
0416:                return found;
0417:            }
0418:
0419:            private Component getSubComponent(Component parent, String path)
0420:                    throws Exception {
0421:                return FractalHelper.getSubComponent(parent, path, logger);
0422:            }
0423:
0424:            private void configureMIM(Component mimC, Map props)
0425:                    throws Exception {
0426:                MemoryInstanceManagerAttribute mima = (MemoryInstanceManagerAttribute) Fractal
0427:                        .getAttributeController(mimC);
0428:                mima.setPersonality(getPersonality());
0429:            }
0430:
0431:            private void configurePOMI(Component pomiC, Map props)
0432:                    throws Exception {
0433:                POManagerInstanciatorAC pomiac = (POManagerInstanciatorAC) Fractal
0434:                        .getAttributeController(pomiC);
0435:                pomiac.setPOManagerTemplateName("org.objectweb.speedo.pm."
0436:                        + getPersonality().getName() + ".lib."
0437:                        + getPersonality().getName().toUpperCase()
0438:                        + "POManager");
0439:                pomiac
0440:                        .setTransactionTemplateName("org.objectweb.speedo.workingset."
0441:                                + getPersonality().getName()
0442:                                + ".lib."
0443:                                + getPersonality().getName().toUpperCase()
0444:                                + "TransactionImpl");
0445:            }
0446:
0447:            private void configurePool(Component pool, String poolLabel,
0448:                    String minProp, String maxProp, String ttlProp,
0449:                    String inactivettlProp, String timeoutProp, Map props)
0450:                    throws Exception {
0451:                String strval = null;
0452:                int poolMinSize = -2;
0453:                int poolMaxSize = -2;
0454:                long poolTTL = -2;
0455:                long poolInactiveTTL = -2;
0456:                long poolTimeout = -2;
0457:                boolean conf = false;
0458:                StringBuffer sb = new StringBuffer(poolLabel);
0459:                final String sep = ", ";
0460:                if (minProp != null) {
0461:                    strval = getProperty(props, minProp, "", true);
0462:                    if (strval.length() > 0) {
0463:                        poolMinSize = Integer.parseInt(strval);
0464:                        if (conf) {
0465:                            sb.append(sep);
0466:                        }
0467:                        sb.append("min=" + strval);
0468:                        conf = true;
0469:                    }
0470:                }
0471:                if (maxProp != null) {
0472:                    strval = getProperty(props, maxProp, "", true);
0473:                    if (strval.length() > 0) {
0474:                        if (strval.equalsIgnoreCase("nolimit")) {
0475:                            poolMaxSize = -1;
0476:                        } else {
0477:                            poolMaxSize = Integer.parseInt(strval);
0478:                        }
0479:                        if (conf) {
0480:                            sb.append(sep);
0481:                        }
0482:                        sb.append("max=" + strval);
0483:                        conf = true;
0484:                    }
0485:                }
0486:                if (ttlProp != null) {
0487:                    strval = getProperty(props, ttlProp, "", true);
0488:                    if (strval.length() > 0) {
0489:                        try {
0490:                            poolTTL = 1000 * Long.parseLong(strval);
0491:                        } catch (NumberFormatException e) {
0492:                            poolTTL = -1;
0493:                            strval = "NOTTL";
0494:                        }
0495:                        if (conf) {
0496:                            sb.append(sep);
0497:                        }
0498:                        sb.append("ttl=" + strval);
0499:                        conf = true;
0500:                    }
0501:                }
0502:                if (inactivettlProp != null) {
0503:                    strval = getProperty(props, inactivettlProp, "", true);
0504:                    if (strval.length() > 0) {
0505:                        try {
0506:                            poolInactiveTTL = 1000 * Long.parseLong(strval);
0507:                        } catch (NumberFormatException e) {
0508:                            poolInactiveTTL = -1;
0509:                            strval = "NOTTL";
0510:                        }
0511:                        if (conf) {
0512:                            sb.append(sep);
0513:                        }
0514:                        sb.append("inactivettlProp=" + strval);
0515:                        conf = true;
0516:                    }
0517:                }
0518:                if (timeoutProp != null) {
0519:                    strval = getProperty(props, timeoutProp, "", true);
0520:                    if (strval.length() > 0) {
0521:                        try {
0522:                            poolTimeout = Long.parseLong(strval);
0523:                        } catch (NumberFormatException e) {
0524:                            poolTimeout = -1;
0525:                            strval = "WAIT";
0526:                        }
0527:                        if (conf) {
0528:                            sb.append(sep);
0529:                        }
0530:                        sb.append("timeout=" + strval);
0531:                        conf = true;
0532:                    }
0533:                }
0534:                if (conf) {
0535:                    logger.log(BasicLevel.INFO, sb.toString());
0536:                    PoolAttributes poolAttr;
0537:                    try {
0538:                        poolAttr = (PoolAttributes) Fractal
0539:                                .getAttributeController(pool);
0540:                    } catch (Exception e) {
0541:                        Component[] children = Fractal.getContentController(
0542:                                speedo).getFcSubComponents();
0543:                        String[] strs = new String[children.length];
0544:                        for (int i = 0; i < strs.length; ++i) {
0545:                            strs[i] = Fractal.getNameController(children[i])
0546:                                    .getFcName();
0547:                        }
0548:                        throw new RuntimeException("" + Arrays.asList(strs));
0549:                    }
0550:                    if (poolMaxSize > -2) {
0551:                        poolAttr.setMaxSize(poolMaxSize);
0552:                    }
0553:                    if (poolMinSize > -2) {
0554:                        poolAttr.setMinSize(poolMinSize);
0555:                    }
0556:                    if (poolTTL > -2) {
0557:                        poolAttr.setTTL(poolTTL);
0558:                    }
0559:                    if (poolInactiveTTL > -2) {
0560:                        poolAttr.setInactiveTTL(poolInactiveTTL);
0561:                    }
0562:                    if (poolTimeout > -2) {
0563:                        poolAttr.setTimeout(poolTimeout);
0564:                    }
0565:                }
0566:            }
0567:
0568:            /**
0569:             * Configures the memory cache.
0570:             * @param cm is the cache composite component
0571:             * @param props is the speedo initialisation properties
0572:             */
0573:            private void configureCache(Component cm, String cacheLabel,
0574:                    String sizeProp, String autoCleanSizeProp,
0575:                    String autoCleanThresholdProp, String policyProp, Map props)
0576:                    throws Exception {
0577:                int cacheSize = -2;
0578:                String autoCleanSize = null;
0579:                String autoCleanThreshold = null;
0580:                String policy = null;
0581:                //configure the cache size
0582:                StringBuffer sb = new StringBuffer(cacheLabel);
0583:                final String sep = ", ";
0584:                boolean conf = false;
0585:                String strval = getProperty(props, sizeProp, "", true);
0586:                if (strval.length() > 0) {
0587:                    if (strval.equalsIgnoreCase("nolimit")) {
0588:                        cacheSize = CacheAttributeController.NO_LIMIT;
0589:                    } else {
0590:                        cacheSize = Integer.parseInt(strval);
0591:                    }
0592:                    if (conf) {
0593:                        sb.append(sep);
0594:                    }
0595:                    sb.append("max size=" + strval);
0596:                    conf = true;
0597:                }
0598:
0599:                //configure the cache auto clean size
0600:                strval = getProperty(props, autoCleanSizeProp, "", true);
0601:                if (strval.length() > 0) {
0602:                    autoCleanSize = strval;
0603:                    if (conf) {
0604:                        sb.append(sep);
0605:                    }
0606:                    sb.append("auto replacement size=" + strval);
0607:                    conf = true;
0608:                }
0609:
0610:                //configure the cache auto clean size
0611:                strval = getProperty(props, autoCleanThresholdProp, "", true);
0612:                if (strval.length() > 0) {
0613:                    autoCleanThreshold = strval;
0614:                    if (conf) {
0615:                        sb.append(sep);
0616:                    }
0617:                    sb.append("auto replacement threshold=" + strval);
0618:                    conf = true;
0619:                }
0620:
0621:                //configure the replacement policy of the cache (Replacement manager)
0622:                strval = getProperty(props, policyProp, "", true);
0623:                if (strval.length() > 0) {
0624:                    policy = strval;
0625:                    if (conf) {
0626:                        sb.append(sep);
0627:                    }
0628:                    sb.append("replacement policy=" + strval);
0629:                    conf = true;
0630:                }
0631:                if (!conf) {
0632:                    return;
0633:                }
0634:                logger.log(BasicLevel.INFO, sb.toString());
0635:                Component cmC = getSubComponent(cm, "cache-manager");
0636:                CacheAttributeController cacheAttr = (CacheAttributeController) Fractal
0637:                        .getAttributeController(cmC);
0638:                if (cacheSize > -2) {
0639:                    cacheAttr.setMaxObjects(cacheSize);
0640:                }
0641:                if (autoCleanSize != null) {
0642:                    cacheAttr.setAutoCleanSize(autoCleanSize);
0643:                }
0644:                if (autoCleanThreshold != null) {
0645:                    cacheAttr.setAutoCleanThreshold(autoCleanThreshold);
0646:                }
0647:                if (policy != null) {
0648:                    String tempName = null;
0649:                    if (CACHE_REPLCAEMENT_LRU.equalsIgnoreCase(policy)) {
0650:                    } else if (CACHE_REPLCAEMENT_MRU.equalsIgnoreCase(policy)) {
0651:                        tempName = "org.objectweb.perseus.cache.replacement.lib.MRUReplacementManager";
0652:                    } else if (CACHE_REPLCAEMENT_FIFO.equalsIgnoreCase(policy)) {
0653:                        tempName = "org.objectweb.perseus.cache.replacement.lib.FIFOReplacementManager";
0654:                    } else {
0655:                        logger.log(BasicLevel.ERROR,
0656:                                new SpeedoException(
0657:                                        "Unmanaged cache replacement policy: "
0658:                                                + policy));
0659:                    }
0660:                    if (tempName != null) {
0661:                        //unbind the rm from the composite
0662:                        Fractal.getBindingController(cm).unbindFc(
0663:                                "replacement-manager");
0664:                        //unbind the rm from the primitive cm
0665:                        Fractal.getBindingController(cmC).unbindFc(
0666:                                "replacement-manager");
0667:                        //unbind the primitive cm from the old rm
0668:                        Fractal.getBindingController(
0669:                                getSubComponent(cm, "replacement-manager"))
0670:                                .unbindFc("unbind-manager");
0671:
0672:                        //remove the old rm from the composite
0673:                        Fractal.getContentController(cm).removeFcSubComponent(
0674:                                getSubComponent(cm, "replacement-manager"));
0675:
0676:                        //instanciate the new component
0677:                        Component new_rm = (Component) getADLFactory()
0678:                                .newComponent(tempName, null);
0679:                        Fractal.getNameController(new_rm).setFcName(
0680:                                "replacement-manager");
0681:
0682:                        //Add the new rm in the composite
0683:                        Fractal.getContentController(cm).addFcSubComponent(
0684:                                new_rm);
0685:
0686:                        Object rm = new_rm
0687:                                .getFcInterface("replacement-manager");
0688:                        //bind the rm to the composite
0689:                        Fractal.getBindingController(cm).bindFc(
0690:                                "replacement-manager", rm);
0691:                        //bind the rm to the primitive cm
0692:                        Fractal.getBindingController(cmC).bindFc(
0693:                                "replacement-manager", rm);
0694:                        //bind the primitive cm to the new rm
0695:                        Fractal.getBindingController(new_rm).bindFc(
0696:                                "unbind-manager",
0697:                                cmC.getFcInterface("unbind-manager"));
0698:                    }
0699:                }
0700:            }
0701:
0702:            /**
0703:             * Configures the transactional persistence manager
0704:             * @param tpm is the component
0705:             * @param props is the speedo initialisation properties
0706:             */
0707:            private void configureTPM(Component tpm, String tpmLabel,
0708:                    String filtersProp, Map props) throws Exception {
0709:                String strval = getProperty(props, filtersProp, "", true);
0710:                Collection filters = new ArrayList(1);
0711:                //configure the list of filters (separated by ",")
0712:                if (strval.length() > 0) {
0713:                    filters = new ArrayList();
0714:                    String filterClassName;
0715:                    while (strval.length() > 0) {
0716:                        int coma = strval.indexOf(",");
0717:                        if (coma != -1) {
0718:                            filterClassName = strval.substring(0, coma);
0719:                            strval = strval.substring(coma + 1);
0720:                        } else {
0721:                            filterClassName = strval;
0722:                            strval = "";
0723:                        }
0724:                        try {
0725:                            //instanciate a filter class
0726:                            WorkingSetFilter filter = (WorkingSetFilter) Class
0727:                                    .forName(filterClassName).newInstance();
0728:                            //add it to the list
0729:                            filters.add(filter);
0730:                        } catch (Exception e) {
0731:                            System.err
0732:                                    .println("Error during the configuration of the tpm");
0733:                            e.printStackTrace(System.err);
0734:                            throw e;
0735:                        }
0736:                    }
0737:                }
0738:                //add the filters to the tpm
0739:                if (!filters.isEmpty()) {
0740:                    TransactionalPersistenceManagerAttributeController tpmAttr = (TransactionalPersistenceManagerAttributeController) Fractal
0741:                            .getAttributeController(tpm);
0742:                    tpmAttr.setFilters(filters);
0743:                }
0744:            }
0745:
0746:            private void configureTransaction(Map props, Map pmfProps,
0747:                    boolean useConnectionFactory) throws Exception {
0748:                //deprecated properties
0749:                final String TM_NAME_old = "org.objectweb.perseus.connector.ra.jdo.TMName";
0750:                String strval = getProperty(props, TM_NAME_old, "", true);
0751:                if (strval.length() > 0) {
0752:                    logger.log(BasicLevel.WARN, "Property " + TM_NAME_old
0753:                            + " is deprecated, you must use " + TM_NAME);
0754:                    if (getProperty(props, TM_NAME, null, true) == null) {
0755:                        pmfProps.put(TM_NAME, strval);
0756:                    }
0757:                }
0758:
0759:                // Transaction managed by an application server
0760:                strval = getProperty(props, MANAGED, "", false);
0761:                if (strval.length() > 0) {
0762:                    boolean b = BooleanHelper.parse(strval, false);
0763:                    if (!useConnectionFactory && b) {
0764:                        String msg = "In a managed environnement, a connection factory is required";
0765:                        logger.log(BasicLevel.ERROR, msg);
0766:                        throwUserException(msg);
0767:                    }
0768:                    logger.log(BasicLevel.INFO, MANAGED
0769:                            + LocaleHelper.getSpeedoRB().getString("speedused")
0770:                            + (b ? LocaleHelper.getSpeedoRB().getString(
0771:                                    "managed") : LocaleHelper.getSpeedoRB()
0772:                                    .getString("standalone")));
0773:
0774:                    //TransactionManager JNDI name
0775:                    strval = getProperty(props, TM_NAME, "", true);
0776:                    logger.log(BasicLevel.INFO, TM_NAME
0777:                            + "="
0778:                            + (strval.length() > 0 ? strval : LocaleHelper
0779:                                    .getSpeedoRB().getString("tmspec")));
0780:                } else {
0781:                    props.remove(TM_NAME);
0782:                }
0783:
0784:                //Listener of Transaction life cycle (statistic)
0785:                strval = getProperty(props, TX_LISTENER, "", true);
0786:                if (strval.length() > 0) {
0787:                    try {
0788:                        AbstractTransaction.txListener = (TransactionListener) Class
0789:                                .forName(strval).newInstance();
0790:                        if (AbstractTransaction.txListener instanceof  Loggable) {
0791:                            ((Loggable) AbstractTransaction.txListener)
0792:                                    .setLoggerFactory(Monolog.monologFactory);
0793:                        }
0794:                        logger.log(BasicLevel.INFO, "Transaction listener: "
0795:                                + strval);
0796:                    } catch (Exception e) {
0797:                        logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB()
0798:                                .getString("txlisten")
0799:                                + " ('" + strval + "'): ", e);
0800:                    }
0801:                }
0802:            }
0803:
0804:            private void configureConcurrencyManager(Map props)
0805:                    throws Exception {
0806:                String tempName;
0807:                StringBuffer sb = new StringBuffer(LocaleHelper.getSpeedoRB()
0808:                        .getString("txconcmgt"));
0809:                String strval = getProperty(props, TRANSACTION_LOCKING,
0810:                        SPEEDO_TRANSACTION_LOCKING, true);
0811:                boolean dbLocking = strval.equals(DB_TRANSACTION_LOCKING);
0812:                boolean optimistic = isOptimisticTransaction(props);
0813:                ;
0814:                if (dbLocking && optimistic) {
0815:                    logger.log(BasicLevel.WARN, sb.toString()
0816:                            + LocaleHelper.getSpeedoRB().getString("dbpessim"));
0817:                    optimistic = false;
0818:                }
0819:                sb.append("mode=").append(
0820:                        (optimistic ? LocaleHelper.getSpeedoRB().getString(
0821:                                "optim") : LocaleHelper.getSpeedoRB()
0822:                                .getString("pessim")));
0823:                //fetch the composite TPM
0824:                Component composite_tpm = getSubComponent(speedo,
0825:                        COMPOSITE_TPM_PATH);
0826:                Component cm = getSubComponent(composite_tpm,
0827:                        "concurrency-manager");
0828:                if (dbLocking) {
0829:                    tempName = DBDELEGATE_CONCURRENCY_TEMPLATE;
0830:                    sb
0831:                            .append(LocaleHelper.getSpeedoRB().getString(
0832:                                    "concdeleg"));
0833:                } else {
0834:                    sb
0835:                            .append(LocaleHelper.getSpeedoRB().getString(
0836:                                    "concspeed"));
0837:                    if (!optimistic) {
0838:                        //Configure the pessimistic concurrency manager
0839:
0840:                        //policy= mutex | rw-fifo | rw-reader
0841:                        strval = getProperty(props,
0842:                                TRANSACTION_LOCKING_PESSIMISTIC_POLICY,
0843:                                TRANSACTION_LOCKING_PESSIMISTIC_POLICY_RW_FIFO,
0844:                                true);
0845:                        PessimisticConcurrencyManagerAC pcmAC = null;
0846:                        if (!strval
0847:                                .equals(TRANSACTION_LOCKING_PESSIMISTIC_POLICY_RW_FIFO)) {
0848:                            pcmAC = (PessimisticConcurrencyManagerAC) Fractal
0849:                                    .getAttributeController(cm);
0850:                            strval = strval.toUpperCase();
0851:                            if (!strval.startsWith("POLICY_")) {
0852:                                strval = "POLICY_" + strval;
0853:                            }
0854:                            pcmAC.setPolicy(strval);
0855:                            sb.append(
0856:                                    LocaleHelper.getSpeedoRB().getString(
0857:                                            "lockpol")).append(strval);
0858:                        }
0859:
0860:                        //locking level = instance | field
0861:                        strval = getProperty(props,
0862:                                TRANSACTION_LOCKING_LEVEL_ENABLETHIN, "false",
0863:                                true);
0864:                        boolean b = BooleanHelper.parse(strval, false);
0865:                        if (b) {
0866:                            logger.log(BasicLevel.INFO, LocaleHelper
0867:                                    .getSpeedoRB().getString("thinlock"));
0868:                            pcmAC = (PessimisticConcurrencyManagerAC) Fractal
0869:                                    .getAttributeController(cm);
0870:                            pcmAC.setThinkLockAllowed(true);
0871:                            sb.append(LocaleHelper.getSpeedoRB().getString(
0872:                                    "thlklvl"));
0873:                        }
0874:                        logger.log(BasicLevel.INFO, sb.toString());
0875:                        return;
0876:                    }
0877:                    tempName = OPTIMISTIC_CONCURRENCY_TEMPLATE;
0878:                }
0879:                //optimistic or dblocking
0880:                logger.log(BasicLevel.INFO, sb.toString());
0881:
0882:                ContentController tpmCC = Fractal
0883:                        .getContentController(composite_tpm);
0884:                //fetch the primitive concurrency manager
0885:                BindingController tpmBC = Fractal
0886:                        .getBindingController(getSubComponent(composite_tpm,
0887:                                "transactional-persistence-manager"));
0888:                tpmBC.unbindFc("concurrency-manager");
0889:
0890:                //Remove the old pessimistic concurrency manager
0891:                BindingController cmBC = Fractal.getBindingController(cm);
0892:                String[] bds = cmBC.listFc();
0893:                for (int i = 0; i < bds.length; i++) {
0894:                    cmBC.unbindFc(bds[i]);
0895:                }
0896:                tpmCC.removeFcSubComponent(cm);
0897:
0898:                //instanciate the new ConcurrencyManager
0899:                cm = (Component) getADLFactory().newComponent(tempName, null);
0900:                //Add the new concurrency manager into the composite
0901:                tpmCC.addFcSubComponent(cm);
0902:                //bind the server interface of the new concurrency manager
0903:                cmBC = Fractal.getBindingController(cm);
0904:                if (dbLocking) {
0905:                    cmBC.bindFc(PConcurrencyManager.STATE_MANAGER_BINDING,
0906:                            tpmCC.getFcInternalInterface("state-manager"));
0907:                    cmBC.bindFc(PConcurrencyManager.STORAGE_MANAGER_BINDING,
0908:                            tpmCC.getFcInternalInterface("storage-manager"));
0909:                } else {//optimistic
0910:                    cmBC.bindFc(PConcurrencyManager.DEPENDENCY_GRAPH_BINDING,
0911:                            getSubComponent(composite_tpm, "dependency-graph")
0912:                                    .getFcInterface("dependency-graph"));
0913:                }
0914:
0915:                //bind the client interface of the new ConcurrencyManager
0916:                tpmBC.bindFc("concurrency-manager", cm
0917:                        .getFcInterface("concurrency-manager"));
0918:            }
0919:
0920:            private void configurePrefetching(Map props) throws Throwable {
0921:                //Data prefetching on queries
0922:                boolean prefetch = true;
0923:                StringBuffer sb = new StringBuffer(LocaleHelper.getSpeedoRB()
0924:                        .getString("prefetch"));
0925:                String strval = getProperty(props, PREFETCH, "", true);
0926:                if (strval.length() > 0) {
0927:                    prefetch = BooleanHelper.parse(strval, false);
0928:                }
0929:                Component qm = getSubComponent(speedo, QUERY_MANAGER);
0930:                QueryManagerAttribute qma = ((QueryManagerAttribute) Fractal
0931:                        .getAttributeController(qm));
0932:                if (!prefetch) {
0933:                    qma.setPrefetchActivatedOnQuery(false);
0934:                    qma.setPrefetchActivatedOnExtent(false);
0935:                    logger.log(BasicLevel.INFO, sb.append(
0936:                            LocaleHelper.getSpeedoRB().getString("NONE"))
0937:                            .toString());
0938:                    return;
0939:                }
0940:                boolean prefetchOnQuery = qma.getPrefetchActivatedOnQuery();
0941:                boolean prefetchOnExtent = qma.getPrefetchActivatedOnExtent();
0942:                boolean prefetchOnGenClass = true;
0943:                String sep = ", ";
0944:
0945:                boolean oneOf = false;
0946:                strval = getProperty(props, PREFETCH_ON_QUERY, "", true);
0947:                if (strval.length() > 0) {
0948:                    prefetchOnQuery = BooleanHelper.parse(strval, false);
0949:                }
0950:                if (prefetchOnQuery) {
0951:                    if (oneOf) {
0952:                        sb.append(sep);
0953:                    }
0954:                    sb.append(LocaleHelper.getSpeedoRB().getString("QUERY"));
0955:                }
0956:                oneOf |= prefetchOnQuery;
0957:                qma.setPrefetchActivatedOnQuery(prefetchOnQuery);
0958:
0959:                strval = getProperty(props, PREFETCH_ON_EXTENT, "", true);
0960:                if (strval.length() > 0) {
0961:                    prefetchOnExtent = BooleanHelper.parse(strval, false);
0962:                }
0963:                if (prefetchOnExtent) {
0964:                    if (oneOf) {
0965:                        sb.append(sep);
0966:                    }
0967:                    sb.append(LocaleHelper.getSpeedoRB().getString("EXTENT"));
0968:                }
0969:                oneOf |= prefetchOnExtent;
0970:                qma.setPrefetchActivatedOnExtent(prefetchOnExtent);
0971:
0972:                strval = getProperty(props, PREFETCH_ON_GENCLASS, "", true);
0973:                if (strval.length() > 0) {
0974:                    prefetchOnGenClass = BooleanHelper.parse(strval, false);
0975:                }
0976:                if (prefetchOnGenClass) {
0977:                    if (oneOf) {
0978:                        sb.append(sep);
0979:                    }
0980:                    sb.append(LocaleHelper.getSpeedoRB()
0981:                            .getString("COLLECTION"));
0982:                }
0983:                oneOf |= prefetchOnGenClass;
0984:
0985:                logger.log(BasicLevel.INFO, sb.toString());
0986:            }
0987:
0988:            /**
0989:             * Configures the mapper component
0990:             * @param props is the properties of Speedo
0991:             * @return true if a connection factory is used, false if the JDBC driver is
0992:             * used directly.
0993:             * @throws Throwable if an error or an exception occurs
0994:             */
0995:            private boolean configureMapper(Map props) throws Throwable {
0996:                boolean useConnectionFactory;
0997:                String mapperName = getProperty(props, MAPPER_NAME,
0998:                        "rdb.automatic", true);
0999:
1000:                Component component = getSubComponent(speedo,
1001:                        PRIMITIVE_MAPPER_PATH);
1002:                String strval = null;
1003:                //Choose the mapper in according to the connection factory (JCA or JDBC)
1004:                String cfName = getProperty(props,
1005:                        JDO_OPTION_CONNECTION_FACTORY_NAME, null, true);
1006:                useConnectionFactory = cfName != null && cfName.length() > 0;
1007:                Object o = Fractal.getAttributeController(component);
1008:                MapperAttributes ma = (MapperAttributes) o;
1009:                if (useConnectionFactory) {
1010:                    Object cf = null;
1011:                    //There is a connection factory
1012:                    try {
1013:                        InitialContext ic = new InitialContext();
1014:                        cf = ic.lookup(cfName);
1015:                    } catch (NamingException e) {
1016:                        throw new SpeedoException(
1017:                                "Problem to get the connection factory in JNDI ("
1018:                                        + cfName + ")", e);
1019:                    }
1020:                    if (cf == null) {
1021:                        throw new SpeedoException(
1022:                                "No connection factory registered in JNDI with the name "
1023:                                        + cfName);
1024:                    } else if (cf instanceof  ConnectionSpecJDBC) {
1025:                        // Use the JDBC Mapper ==> nothing to do
1026:                    } else if (cf instanceof  javax.sql.DataSource) {
1027:                        // Use the JDBC Mapper ==> nothing to do
1028:                    } else if (cf instanceof  javax.resource.cci.ConnectionFactory) {
1029:                        throw new SpeedoException(
1030:                                "JCA datasource no yet supported");
1031:                    } else {
1032:                        throw new SpeedoException(
1033:                                "The connection factory registered "
1034:                                        + "in JNDI is not supported by Speedo "
1035:                                        + cfName + " => " + cf);
1036:                    }
1037:                    boolean ignoring = removeProps(props, new String[] {
1038:                            JDO_OPTION_CONNECTION_DRIVER_NAME_OLD,
1039:                            JDO_OPTION_CONNECTION_DRIVER_NAME_OLD2,
1040:                            JDO_OPTION_CONNECTION_DRIVER_NAME,
1041:                            JDO_OPTION_CONNECTION_URL,
1042:                            JDO_OPTION_CONNECTION_USER_NAME,
1043:                            JDO_OPTION_CONNECTION_PASSWORD });
1044:                    if (ignoring) {
1045:                        logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB()
1046:                                .getString("ignjdbcinfo"));
1047:                    }
1048:                    ignoring = removeProps(props, new String[] {
1049:                            CONNECTION_POOL_MIN, CONNECTION_POOL_MAX,
1050:                            CONNECTION_POOL_TTL, CONNECTION_POOL_TIMEOUT });
1051:                    if (ignoring) {
1052:                        logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB()
1053:                                .getString("ignconninfo"));
1054:                    }
1055:
1056:                    //Assign the connection factory to the mapper
1057:                    logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB()
1058:                            .getString("connfact")
1059:                            + LocaleHelper.getSpeedoRB().getString("jndinm")
1060:                            + cfName
1061:                            + LocaleHelper.getSpeedoRB().getString("factfound")
1062:                            + cf
1063:                            + LocaleHelper.getSpeedoRB().getString("mappernm")
1064:                            + mapperName);
1065:                    PMapper mapper = (PMapper) component
1066:                            .getFcInterface("mapper");
1067:                    mapper.setMapperName(mapperName);
1068:                    mapper.setConnectionFactory(cf);
1069:
1070:                } else {
1071:                    JDBCMapperAttributes jdbcma = (JDBCMapperAttributes) ma;
1072:
1073:                    //deprecated properties
1074:                    strval = getProperty(props,
1075:                            JDO_OPTION_CONNECTION_DRIVER_NAME_OLD, "", true);
1076:                    if (strval.length() > 0) {
1077:                        logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB()
1078:                                .getString("property")
1079:                                + " "
1080:                                + JDO_OPTION_CONNECTION_DRIVER_NAME_OLD
1081:                                + LocaleHelper.getSpeedoRB().getString(
1082:                                        "deprecuse")
1083:                                + JDO_OPTION_CONNECTION_DRIVER_NAME);
1084:                        if (getProperty(props,
1085:                                JDO_OPTION_CONNECTION_DRIVER_NAME, null, false) == null) {
1086:                            props
1087:                                    .put(JDO_OPTION_CONNECTION_DRIVER_NAME,
1088:                                            strval);
1089:                        }
1090:                    }
1091:                    strval = getProperty(props,
1092:                            JDO_OPTION_CONNECTION_DRIVER_NAME_OLD2, "", true);
1093:                    if (strval.length() > 0) {
1094:                        logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB()
1095:                                .getString("property")
1096:                                + " "
1097:                                + JDO_OPTION_CONNECTION_DRIVER_NAME_OLD2
1098:                                + LocaleHelper.getSpeedoRB().getString(
1099:                                        "deprecuse")
1100:                                + JDO_OPTION_CONNECTION_DRIVER_NAME);
1101:                        if (getProperty(props,
1102:                                JDO_OPTION_CONNECTION_DRIVER_NAME, null, false) == null) {
1103:                            props
1104:                                    .put(JDO_OPTION_CONNECTION_DRIVER_NAME,
1105:                                            strval);
1106:                        }
1107:                    }
1108:                    String jdbcDriverCN = getProperty(props,
1109:                            JDO_OPTION_CONNECTION_DRIVER_NAME, null, true);
1110:                    String jdbcUser = getProperty(props,
1111:                            JDO_OPTION_CONNECTION_USER_NAME, null, true);
1112:                    String jdbcUrl = getProperty(props,
1113:                            JDO_OPTION_CONNECTION_URL, null, true);
1114:                    String jdbcPass = getProperty(props,
1115:                            JDO_OPTION_CONNECTION_PASSWORD, null, true);
1116:                    logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB()
1117:                            .getString("jdbcdrv")
1118:                            + LocaleHelper.getSpeedoRB().getString("driver")
1119:                            + jdbcDriverCN
1120:                            + LocaleHelper.getSpeedoRB().getString("url")
1121:                            + jdbcUrl
1122:                            + LocaleHelper.getSpeedoRB().getString("user")
1123:                            + jdbcUser
1124:                            + LocaleHelper.getSpeedoRB().getString("mappernm")
1125:                            + mapperName);
1126:                    jdbcma.setMapperName(mapperName);
1127:                    jdbcma.setDriverClassName(jdbcDriverCN);
1128:                    jdbcma.setURL(jdbcUrl);
1129:                    jdbcma.setUserName(jdbcUser);
1130:                    jdbcma.setPassword(jdbcPass);
1131:                    jdbcma.setPoolConnection(true);
1132:
1133:                    //configure the pool of connection
1134:                    configurePool(
1135:                            getSubComponent(speedo, CONNECTION_POOL_PATH),
1136:                            "Connection pool: ", CONNECTION_POOL_MIN,
1137:                            CONNECTION_POOL_MAX, CONNECTION_POOL_TTL,
1138:                            CONNECTION_POOL_INACTIVETTL,
1139:                            CONNECTION_POOL_TIMEOUT, props);
1140:                }
1141:                strval = (String) props.remove(CONNECTION_CHECK);
1142:                if (strval != null) {
1143:                    boolean v = BooleanHelper.parse(strval, false);
1144:                    ma.setCheckConnectivityAtStartup(v);
1145:                    if (!v) {
1146:                        logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB()
1147:                                .getString("noconnchk"));
1148:                    }
1149:                }
1150:
1151:                //initialize the JormFactory with the mappingStructureRule attribute
1152:                byte mappingStructureRule = JormFactoryAttributes.CREATE_IF_REQUIRED;
1153:                strval = getProperty(props, MAPPING_STRUCTURE, "", true);
1154:                if (strval.length() > 0) {
1155:                    mappingStructureRule = getMappingStructure(strval);
1156:                    if (mappingStructureRule == -1) {
1157:                        mappingStructureRule = JormFactoryAttributes.CREATE_IF_REQUIRED;
1158:                        logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB()
1159:                                .getString("unexpprop")
1160:                                + MAPPING_STRUCTURE
1161:                                + LocaleHelper.getSpeedoRB()
1162:                                        .getString("pfound")
1163:                                + strval
1164:                                + LocaleHelper.getSpeedoRB().getString(
1165:                                        "pexpect")
1166:                                + MAPPING_STRUCTURE_DN
1167:                                + " | "
1168:                                + MAPPING_STRUCTURE_DD
1169:                                + " | "
1170:                                + MAPPING_STRUCTURE_CIR
1171:                                + " | "
1172:                                + MAPPING_STRUCTURE_FC + "]");
1173:                    }
1174:                }
1175:                component = getSubComponent(speedo, JORM_FACTORY_PATH);
1176:                JormFactoryAttributes jfa = (JormFactoryAttributes) Fractal
1177:                        .getAttributeController(component);
1178:                jfa.setMappingStructureRule(mappingStructureRule);
1179:                logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB()
1180:                        .getString("datast")
1181:                        + getMappingStructureString(mappingStructureRule));
1182:                jfa.setPersonality(getPersonality());
1183:
1184:                Properties jormFactoryProperties = new Properties();
1185:                for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
1186:                    Map.Entry me = (Map.Entry) it.next();
1187:                    String key = (String) me.getKey();
1188:                    String value = (String) me.getValue();
1189:                    boolean knownProperty = true;
1190:                    if (key.indexOf('(') != -1) {
1191:                        jormFactoryProperties.put(key, value);
1192:                    } else {
1193:                        knownProperty = false;
1194:                    }
1195:                    if (knownProperty) {
1196:                        logger.log(BasicLevel.INFO, key + ": " + value);
1197:                        it.remove();
1198:                    }
1199:                }
1200:                jfa.setSpeedoProperties(jormFactoryProperties);
1201:
1202:                return useConnectionFactory;
1203:            }
1204:
1205:            private boolean configureJMX(Map props) throws Throwable {
1206:                String val = (String) props.remove(JMX);
1207:                if (!BooleanHelper.parse(val, false)) {
1208:                    return false;
1209:                }
1210:                //JMX must me configured
1211:                if (Monolog.monologFactory.getLogger(JMX).isLoggable(
1212:                        BasicLevel.DEBUG)) {
1213:                    //active MX4J logging
1214:                    System.setProperty("mx4j.log.priority", "debug");
1215:                }
1216:                val = (String) props.remove(JMX_HTTP_PORT);
1217:                int port = 0;
1218:                if (val != null) {
1219:                    try {
1220:                        port = Integer.parseInt(val);
1221:                    } catch (NumberFormatException e) {
1222:                        logger.log(BasicLevel.WARN, LocaleHelper.getSpeedoRB()
1223:                                .getString("badhttp")
1224:                                + val);
1225:                        port = -1;
1226:                    }
1227:                }
1228:                Component component = getSubComponent(speedo,
1229:                        HTML_JMX_AGENT_PATH);
1230:                if (port < 0) {
1231:                    //unbind the html sub component
1232:                    Fractal.getBindingController(component)
1233:                            .unbindFc("adminAtt");
1234:                    // remove the html sub component from the agent component.
1235:                    Fractal.getContentController(
1236:                            getSubComponent(speedo, JMX_AGENT_PATH))
1237:                            .removeFcSubComponent(component);
1238:                    logger.log(BasicLevel.INFO, LocaleHelper.getSpeedoRB()
1239:                            .getString("jmxactiv"));
1240:                } else {
1241:                    if (port == 0) {
1242:                        //TODO: find a free port for the http console
1243:                        port = 8000;
1244:                    }
1245:                    //get the host
1246:                    String host = (String) props.remove(JMX_HTTP_HOST);
1247:                    if (host == null || host.length() == 0) {
1248:                        host = JMX_HTTP_DEFAULT_HOST;
1249:                    }
1250:                    //Assign the port and the host to the component
1251:                    MX4J_HtmlAdaptorCA att = (MX4J_HtmlAdaptorCA) Fractal
1252:                            .getAttributeController(component);
1253:                    att.setPort(port);
1254:                    att.setHost(host);
1255:                    logger
1256:                            .log(BasicLevel.INFO, LocaleHelper.getSpeedoRB()
1257:                                    .getString("jmxhttp")
1258:                                    + port
1259:                                    + LocaleHelper.getSpeedoRB().getString(
1260:                                            "forhost")
1261:                                    + host
1262:                                    + LocaleHelper.getSpeedoRB().getString(
1263:                                            "activated"));
1264:                }
1265:                return true;
1266:            }
1267:
1268:            public static String getMappingStructureString(byte b) {
1269:                switch (b) {
1270:                case JormFactoryAttributes.DO_NOTHING:
1271:                    return MAPPING_STRUCTURE_DN;
1272:                case JormFactoryAttributes.DELETE_DATA:
1273:                    return MAPPING_STRUCTURE_DD;
1274:                case JormFactoryAttributes.FORCE_CREATE:
1275:                    return MAPPING_STRUCTURE_FC;
1276:                case JormFactoryAttributes.CREATE_IF_REQUIRED:
1277:                    return MAPPING_STRUCTURE_CIR;
1278:                default:
1279:                    return "UNKNOWN";
1280:                }
1281:            }
1282:
1283:            public static byte getMappingStructure(String strval) {
1284:                if (MAPPING_STRUCTURE_DN.equals(strval)) {
1285:                    return JormFactoryAttributes.DO_NOTHING;
1286:                } else if (MAPPING_STRUCTURE_DD.equals(strval)) {
1287:                    return JormFactoryAttributes.DELETE_DATA;
1288:                } else if (MAPPING_STRUCTURE_CIR.equals(strval)) {
1289:                    return JormFactoryAttributes.CREATE_IF_REQUIRED;
1290:                } else if (MAPPING_STRUCTURE_FC.equals(strval)) {
1291:                    return JormFactoryAttributes.FORCE_CREATE;
1292:                } else {
1293:                    return -1;
1294:                }
1295:
1296:            }
1297:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.