18 package com.mysql.clusterj.tie;
20 import com.mysql.ndbjtie.ndbapi.NdbDictionary.DictionaryConst;
21 import com.mysql.ndbjtie.ndbapi.NdbDictionary.IndexConst;
22 import com.mysql.ndbjtie.ndbapi.NdbDictionary.TableConst;
23 import com.mysql.ndbjtie.ndbapi.NdbDictionary.DictionaryConst.ListConst.Element;
24 import com.mysql.ndbjtie.ndbapi.NdbDictionary.DictionaryConst.ListConst.ElementArray;
26 import com.mysql.clusterj.core.store.Index;
27 import com.mysql.clusterj.core.store.Table;
29 import com.mysql.clusterj.core.util.I18NHelper;
30 import com.mysql.clusterj.core.util.Logger;
31 import com.mysql.clusterj.core.util.LoggerFactoryService;
36 class DictionaryImpl
implements com.mysql.clusterj.core.store.Dictionary {
39 static final I18NHelper local = I18NHelper
40 .getInstance(DictionaryImpl.class);
43 static final Logger logger = LoggerFactoryService.getFactory()
44 .getInstance(DictionaryImpl.class);
46 private DictionaryConst ndbDictionary;
48 public DictionaryImpl(DictionaryConst ndbDictionary) {
49 this.ndbDictionary = ndbDictionary;
52 public Table getTable(
String tableName) {
53 TableConst ndbTable = ndbDictionary.getTable(tableName);
54 if (ndbTable == null) {
56 ndbTable = ndbDictionary.getTable(tableName.toLowerCase());
58 if (ndbTable == null) {
61 return new TableImpl(ndbTable, getIndexNames(ndbTable.getName()));
65 if (
"PRIMARY$KEY".equals(indexName)) {
67 TableConst ndbTable = ndbDictionary.getTable(tableName);
68 if (ndbTable == null) {
70 ndbTable = ndbDictionary.getTable(tableName.toLowerCase());
72 handleError(ndbTable, ndbDictionary,
"");
73 return new IndexImpl(ndbTable);
75 IndexConst ndbIndex = ndbDictionary.getIndex(indexName, tableName);
76 if (ndbIndex == null) {
78 ndbIndex = ndbDictionary.getIndex(indexName, tableName.toLowerCase());
80 handleError(ndbIndex, ndbDictionary, indexAlias);
81 return new IndexImpl(ndbIndex, indexAlias);
86 com.mysql.ndbjtie.ndbapi.NdbDictionary.DictionaryConst.List indexList =
87 com.mysql.ndbjtie.ndbapi.NdbDictionary.DictionaryConst.List.create();
90 int returnCode = ndbDictionary.listIndexes(indexList, tableName);
91 handleError(returnCode, ndbDictionary, tableName);
92 int count = indexList.count();
93 result =
new String[count];
94 if (logger.isDetailEnabled()) logger.detail(
"Found " + count +
" indexes for " + tableName);
95 ElementArray elementArray = indexList.elements();
96 for (
int i = 0;
i < count; ++
i) {
97 Element element = elementArray.at(
i);
98 handleError(element, ndbDictionary,
String.valueOf(
i));
99 String indexName = element.name();
100 result[
i] = indexName;
104 com.mysql.ndbjtie.ndbapi.NdbDictionary.DictionaryConst.List.delete(indexList);
109 protected static void handleError(
int returnCode, DictionaryConst ndbDictionary,
String extra) {
110 if (returnCode == 0) {
113 Utility.throwError(returnCode, ndbDictionary.getNdbError(), extra);
117 protected static void handleError(Object
object, DictionaryConst ndbDictionary,
String extra) {
118 if (
object != null) {
121 Utility.throwError(null, ndbDictionary.getNdbError(), extra);