18 package com.mysql.clusterj.tie;
20 import java.util.IdentityHashMap;
23 import com.mysql.ndbjtie.ndbapi.Ndb;
24 import com.mysql.ndbjtie.ndbapi.Ndb_cluster_connection;
26 import com.mysql.clusterj.ClusterJDatastoreException;
27 import com.mysql.clusterj.ClusterJFatalInternalException;
29 import com.mysql.clusterj.core.store.Db;
31 import com.mysql.clusterj.core.util.I18NHelper;
32 import com.mysql.clusterj.core.util.Logger;
33 import com.mysql.clusterj.core.util.LoggerFactoryService;
46 .
getInstance(com.mysql.clusterj.core.store.ClusterConnection.class);
50 loadSystemLibrary(
"ndbclient");
59 final String connectString;
65 private Map<DbImpl, Object> dbs =
new IdentityHashMap<DbImpl, Object>();
73 this.connectString = connectString;
77 logger.info(local.
message(
"INFO_Create_Cluster_Connection", connectString, nodeId));
80 static protected void loadSystemLibrary(
String name) {
84 System.loadLibrary(name);
85 }
catch (UnsatisfiedLinkError e) {
86 path = getLoadLibraryPath();
87 message = local.
message(
"ERR_Failed_Loading_Library",
88 name, path,
"UnsatisfiedLinkError", e.getLocalizedMessage());
89 logger.fatal(message);
91 }
catch (SecurityException e) {
92 path = getLoadLibraryPath();
93 message = local.
message(
"ERR_Failed_Loading_Library",
94 name, path,
"SecurityException", e.getLocalizedMessage());
95 logger.fatal(message);
103 private static String getLoadLibraryPath() {
106 path = System.getProperty(
"java.library.path");
107 }
catch (Exception ex) {
108 path =
"<Exception: " + ex.getMessage() +
">";
114 public void connect(
int connectRetries,
int connectDelay,
boolean verbose) {
116 int returnCode =
clusterConnection.connect(connectRetries, connectDelay, verbose?1:0);
120 public Db createDb(
String database,
int maxTransactions) {
128 DbImpl result =
new DbImpl(
this, ndb, maxTransactions);
129 dbs.put(result, null);
133 public void waitUntilReady(
int connectTimeoutBefore,
int connectTimeoutAfter) {
135 int returnCode =
clusterConnection.wait_until_ready(connectTimeoutBefore, connectTimeoutAfter);
139 private void checkConnection() {
141 throw new ClusterJFatalInternalException(local.
message(
"ERR_Cluster_Connection_Must_Not_Be_Null"));
146 String connectString,
int nodeId) {
147 if (returnCode >= 0) {
151 throwError(returnCode, clusterConnection, connectString, nodeId);
160 String connectString,
int nodeId) {
161 if (
object != null) {
164 throwError(null, clusterConnection, connectString, nodeId);
169 if (clusterConnection == null) {
170 String message = local.
message(
"ERR_Connect", connectString, nodeId);
171 logger.error(message);
172 throw new ClusterJDatastoreException(message);
177 String connectString,
int nodeId) {
178 String message = clusterConnection.get_latest_error_msg();
179 int errorCode = clusterConnection.get_latest_error();
180 String msg = local.
message(
"ERR_NdbError", returnCode, errorCode, message, connectString, nodeId);
181 throw new ClusterJDatastoreException(msg);
184 public void close() {
185 if (clusterConnection != null) {
186 logger.info(local.
message(
"INFO_Close_Cluster_Connection", connectString, nodeId));
188 clusterConnection = null;
192 public void close(Db db) {
196 public int dbCount() {