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.bindings;
21 import com.mysql.cluster.ndbj.Ndb;
22 import com.mysql.cluster.ndbj.NdbApiException;
23 import com.mysql.cluster.ndbj.NdbClusterConnection;
24 import com.mysql.clusterj.ClusterJDatastoreException;
25 import com.mysql.clusterj.core.store.Db;
26 import com.mysql.clusterj.core.util.I18NHelper;
27 import com.mysql.clusterj.core.util.Logger;
28 import com.mysql.clusterj.core.util.LoggerFactoryService;
33 public class ClusterConnectionImpl
34 implements com.mysql.clusterj.core.store.ClusterConnection {
36 /** My message translator */
37 static final I18NHelper local = I18NHelper.getInstance(ClusterConnectionImpl.class);
40 static final Logger logger = LoggerFactoryService.getFactory()
41 .getInstance(com.mysql.clusterj.core.store.ClusterConnection.class);
43 /** Ndb_cluster_connection: one per factory. */
44 protected NdbClusterConnection clusterConnection;
46 public ClusterConnectionImpl(String connectString) {
48 clusterConnection = NdbClusterConnection.create(connectString);
49 } catch (NdbApiException ndbApiException) {
50 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
55 public void connect(int connectRetries, int connectDelay, boolean verbose) {
57 clusterConnection.connect(connectRetries, connectDelay, verbose);
58 } catch (NdbApiException ndbApiException) {
59 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
64 public Db createDb(String database, int maxTransactions) {
66 Ndb ndb = clusterConnection.createNdb(database, maxTransactions);
67 return new DbImpl(ndb);
68 } catch (NdbApiException ndbApiException) {
69 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
74 public void waitUntilReady(int connectTimeoutBefore, int connectTimeoutAfter) {
76 clusterConnection.waitUntilReady(connectTimeoutBefore, connectTimeoutAfter);
77 } catch (NdbApiException ndbApiException) {
78 throw new ClusterJDatastoreException(local.message("ERR_Datastore"),