MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClusterConnectionImpl.java
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.bindings;
20 
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;
29 
34  implements com.mysql.clusterj.core.store.ClusterConnection {
35 
37  static final I18NHelper local = I18NHelper.getInstance(ClusterConnectionImpl.class);
38 
40  static final Logger logger = LoggerFactoryService.getFactory()
41  .getInstance(com.mysql.clusterj.core.store.ClusterConnection.class);
42 
44  protected NdbClusterConnection clusterConnection;
45 
46  public ClusterConnectionImpl(String connectString) {
47  try {
48  clusterConnection = NdbClusterConnection.create(connectString);
49  } catch (NdbApiException ndbApiException) {
50  throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
51  ndbApiException);
52  }
53  }
54 
55  public void connect(int connectRetries, int connectDelay, boolean verbose) {
56  try {
57  clusterConnection.connect(connectRetries, connectDelay, verbose);
58  } catch (NdbApiException ndbApiException) {
59  throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
60  ndbApiException);
61  }
62  }
63 
64  public Db createDb(String database, int maxTransactions) {
65  try {
66  Ndb ndb = clusterConnection.createNdb(database, maxTransactions);
67  return new DbImpl(ndb);
68  } catch (NdbApiException ndbApiException) {
69  throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
70  ndbApiException);
71  }
72  }
73 
74  public void waitUntilReady(int connectTimeoutBefore, int connectTimeoutAfter) {
75  try {
76  clusterConnection.waitUntilReady(connectTimeoutBefore, connectTimeoutAfter);
77  } catch (NdbApiException ndbApiException) {
78  throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
79  ndbApiException);
80  }
81  }
82 
83 }