2 Copyright 2010 Sun Microsystems, Inc.
3 All rights reserved. Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package com.mysql.clusterj.openjpa;
21 import com.mysql.clusterj.core.util.I18NHelper;
22 import com.mysql.clusterj.core.util.Logger;
23 import com.mysql.clusterj.core.util.LoggerFactoryService;
27 import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory;
29 import org.apache.openjpa.kernel.Bootstrap;
30 import org.apache.openjpa.kernel.StoreManager;
32 import org.apache.openjpa.lib.conf.ConfigurationProvider;
35 * BrokerFactory for use with the Ndb runtime.
38 @SuppressWarnings("serial")
39 public class NdbOpenJPABrokerFactory extends JDBCBrokerFactory {
41 /** My message translator */
42 static final I18NHelper local = I18NHelper.getInstance(NdbOpenJPABrokerFactory.class);
45 static final Logger logger = LoggerFactoryService.getFactory().getInstance(NdbOpenJPABrokerFactory.class);
48 * Factory method for constructing a factory from properties. Invoked from
49 * {@link Bootstrap#newBrokerFactory}.
51 public static NdbOpenJPABrokerFactory newInstance(ConfigurationProvider cp) {
52 NdbOpenJPAConfigurationImpl conf = new NdbOpenJPAConfigurationImpl();
54 return new NdbOpenJPABrokerFactory(conf);
58 * Factory method for obtaining a possibly-pooled factory from properties.
59 * Invoked from {@link Bootstrap#getBrokerFactory}.
61 public static NdbOpenJPABrokerFactory getInstance(ConfigurationProvider cp) {
62 Map<String, Object> props = cp.getProperties();
63 Object key = toPoolKey(props);
64 NdbOpenJPABrokerFactory factory = (NdbOpenJPABrokerFactory)
65 getPooledFactoryForKey(key);
69 factory = newInstance(cp);
75 * Construct the factory with the given option settings; however, the
76 * factory construction methods are recommended.
78 public NdbOpenJPABrokerFactory(NdbOpenJPAConfiguration conf) {
80 if (logger.isInfoEnabled()) {
81 StringBuffer buffer = new StringBuffer();
82 buffer.append("connectString: " + conf.getConnectString());
83 buffer.append("; connectDelay: " + conf.getConnectDelay());
84 buffer.append("; connectVerbose: " + conf.getConnectVerbose());
85 buffer.append("; connectTimeoutBefore: " + conf.getConnectTimeoutBefore());
86 buffer.append("; connectTimeoutAfter: " + conf.getConnectTimeoutAfter());
87 buffer.append("; maxTransactions: " + conf.getMaxTransactions());
88 buffer.append("; default database: " + conf.getDatabase());
89 logger.info(buffer.toString());
94 protected StoreManager newStoreManager() {
95 return new NdbOpenJPAStoreManager();