MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndexImpl.java
1 /*
2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
18 package com.mysql.clusterj.tie;
19 
20 import java.util.Arrays;
21 
22 import com.mysql.ndbjtie.ndbapi.NdbDictionary.IndexConst;
23 import com.mysql.ndbjtie.ndbapi.NdbDictionary.TableConst;
24 import com.mysql.clusterj.core.store.Index;
25 import com.mysql.clusterj.core.util.I18NHelper;
26 import com.mysql.clusterj.core.util.Logger;
27 import com.mysql.clusterj.core.util.LoggerFactoryService;
28 
32 class IndexImpl implements Index {
33 
35  static final I18NHelper local = I18NHelper
36  .getInstance(IndexImpl.class);
37 
39  static final Logger logger = LoggerFactoryService.getFactory()
40  .getInstance(IndexImpl.class);
41 
42  private String tableName;
43 
45  private String name;
46 
48  private int noOfColumns;
49 
51  private String[] columnNames;
52 
54  private boolean unique;
55 
57  private String internalName;
58 
64  public IndexImpl(IndexConst ndbIndex, String indexAlias) {
65  this.internalName = ndbIndex.getName();
66  this.tableName = ndbIndex.getTable();
67  this.name = indexAlias;
68  this.unique = ndbIndex.getType() == IndexConst.Type.UniqueHashIndex;
69  this.noOfColumns = ndbIndex.getNoOfColumns();
70  this.columnNames = new String[noOfColumns];
71  for (int i = 0; i < noOfColumns; ++i) {
72  String columnName = ndbIndex.getColumn(i).getName();
73  this.columnNames[i] = columnName;
74  }
75  if (logger.isDetailEnabled()) logger.detail(toString());
76  }
77 
84  public IndexImpl(TableConst ndbTable) {
85  this.internalName = "PRIMARY";
86  this.name = "PRIMARY";
87  this.tableName = ndbTable.getName();
88  this.unique = true;
89  this.noOfColumns = ndbTable.getNoOfPrimaryKeys();
90  this.columnNames = new String[noOfColumns];
91  for (int i = 0; i < noOfColumns; ++i) {
92  this.columnNames[i] = ndbTable.getPrimaryKey(i);
93  }
94  if (logger.isDetailEnabled()) logger.detail(toString());
95  }
96 
97  public boolean isUnique() {
98  return unique;
99  }
100 
101  public String getName() {
102  return name;
103  }
104 
105  public String getInternalName() {
106  return internalName;
107  }
108 
109  public String[] getColumnNames() {
110  return columnNames;
111  }
112 
113  @Override
114  public String toString() {
115  return "IndexImpl name: " + name + " internal name: " + internalName + " table: " + tableName + " unique: " + unique + " columns: " + Arrays.toString(columnNames);
116  }
117 
118 }