]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
e700962708d1654404c0d61aec1630877a7edf62
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright 2010 Sun Microsystems, Inc.
3    All rights reserved. Use is subject to license terms.
4
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.
8
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.
13
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
17 */
18
19 package com.mysql.clusterj.openjpa;
20
21 import com.mysql.clusterj.core.util.I18NHelper;
22 import com.mysql.clusterj.core.util.Logger;
23 import com.mysql.clusterj.core.util.LoggerFactoryService;
24
25 import java.util.Map;
26
27 import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory;
28
29 import org.apache.openjpa.kernel.Bootstrap;
30 import org.apache.openjpa.kernel.StoreManager;
31
32 import org.apache.openjpa.lib.conf.ConfigurationProvider;
33
34 /**
35  * BrokerFactory for use with the Ndb runtime.
36  *
37  */
38 @SuppressWarnings("serial")
39 public class NdbOpenJPABrokerFactory extends JDBCBrokerFactory {
40
41     /** My message translator */
42     static final I18NHelper local = I18NHelper.getInstance(NdbOpenJPABrokerFactory.class);
43
44     /** My logger */
45     static final Logger logger = LoggerFactoryService.getFactory().getInstance(NdbOpenJPABrokerFactory.class);
46
47     /**
48      * Factory method for constructing a factory from properties. Invoked from
49      * {@link Bootstrap#newBrokerFactory}.
50      */
51     public static NdbOpenJPABrokerFactory newInstance(ConfigurationProvider cp) {
52         NdbOpenJPAConfigurationImpl conf = new NdbOpenJPAConfigurationImpl();
53         cp.setInto(conf);
54         return new NdbOpenJPABrokerFactory(conf);
55     }
56
57     /**
58      * Factory method for obtaining a possibly-pooled factory from properties.
59      * Invoked from {@link Bootstrap#getBrokerFactory}.
60      */
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);
66         if (factory != null)
67             return factory;
68
69         factory = newInstance(cp);
70         pool(key, factory);
71         return factory;
72     }
73
74     /**
75      * Construct the factory with the given option settings; however, the
76      * factory construction methods are recommended.
77      */
78     public NdbOpenJPABrokerFactory(NdbOpenJPAConfiguration conf) {
79         super(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());
90         }
91     }
92
93     @Override
94     protected StoreManager newStoreManager() {
95         return new NdbOpenJPAStoreManager();
96     }
97
98 }