18 package com.mysql.clusterj.tie;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
25 import com.mysql.clusterj.core.store.Column;
26 import com.mysql.clusterj.core.store.PartitionKey;
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;
33 import com.mysql.ndbjtie.ndbapi.NdbRecord;
34 import com.mysql.ndbjtie.ndbapi.NdbDictionary.ColumnConst;
35 import com.mysql.ndbjtie.ndbapi.NdbDictionary.TableConst;
40 class TableImpl
implements Table {
43 static final I18NHelper local = I18NHelper
44 .getInstance(TableImpl.class);
47 static final Logger logger = LoggerFactoryService.getFactory()
48 .getInstance(TableImpl.class);
54 private String[] columnNames;
57 private String[] primaryKeyColumnNames;
60 private String[] partitionKeyColumnNames;
66 private String[] indexNames;
69 private int[] lengths;
75 private int bufferSize;
78 private int maximumColumnId;
81 private int maximumColumnLength = 0;
83 public TableImpl(TableConst ndbTable,
String[] indexNames) {
84 this.tableName = ndbTable.getName();
86 List<String> partitionKeyColumnNameList =
new ArrayList<String>();
87 List<String> primaryKeyColumnNameList =
new ArrayList<String>();
89 int noOfColumns = ndbTable.getNoOfColumns();
90 ColumnImpl[] columnImpls =
new ColumnImpl[noOfColumns];
91 columnNames =
new String[noOfColumns];
92 for (
int i = 0;
i < noOfColumns; ++
i) {
93 ColumnConst column = ndbTable.getColumn(
i);
95 if (column.getPartitionKey()) {
96 partitionKeyColumnNameList.add(column.getName());
98 if (column.getPrimaryKey()) {
99 primaryKeyColumnNameList.add(column.getName());
101 ColumnConst ndbColumn = ndbTable.getColumn(
i);
102 String columnName = ndbColumn.getName();
103 ColumnImpl columnImpl =
new ColumnImpl(tableName, ndbColumn);
104 columns.put(columnName, columnImpl);
105 columnImpls[
i] = columnImpl;
106 columnNames[
i] = columnName;
108 int columnId = ndbColumn.getColumnNo();
109 if (columnId > maximumColumnId) {
110 maximumColumnId = columnId;
114 offsets =
new int[maximumColumnId + 1];
115 lengths =
new int[maximumColumnId + 1];
117 for (
int i = 0;
i < noOfColumns; ++
i) {
118 ColumnImpl columnImpl = columnImpls[
i];
119 int columnId = columnImpl.getColumnId();
120 int columnSpace = columnImpl.getColumnSpace();
121 lengths[columnId] = columnSpace;
123 offset += columnSpace;
124 if (columnSpace > maximumColumnLength ) {
125 maximumColumnLength = columnSpace;
129 this.primaryKeyColumnNames =
130 primaryKeyColumnNameList.toArray(
new String[primaryKeyColumnNameList.size()]);
131 this.partitionKeyColumnNames =
132 partitionKeyColumnNameList.toArray(
new String[partitionKeyColumnNameList.size()]);
133 this.indexNames = indexNames;
136 public Column getColumn(
String columnName) {
137 return columns.get(columnName);
144 public String[] getPrimaryKeyColumnNames() {
145 return primaryKeyColumnNames;
148 public String[] getPartitionKeyColumnNames() {
149 return partitionKeyColumnNames;
152 public PartitionKey createPartitionKey() {
153 PartitionKeyImpl result =
new PartitionKeyImpl();
154 result.setTable(tableName);
158 public String[] getIndexNames() {
162 public String[] getColumnNames() {
166 public int getMaximumColumnId() {
167 return maximumColumnId;
170 public int getBufferSize() {
174 public int[] getOffsets() {
178 public int[] getLengths() {
182 public int getMaximumColumnLength() {
183 return maximumColumnLength;