2 * Copyright 2010 Sun Microsystems, Inc.
3 * All rights reserved. Use is subject to license terms.
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.
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.
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
19 package com.mysql.clusterj.bindings;
21 import java.util.HashMap;
24 import com.mysql.cluster.ndbj.NdbColumn;
25 import com.mysql.cluster.ndbj.NdbTable;
27 import com.mysql.clusterj.ClusterJDatastoreException;
28 import com.mysql.clusterj.ClusterJFatalInternalException;
30 import com.mysql.clusterj.core.store.Column;
32 import com.mysql.clusterj.core.util.I18NHelper;
33 import com.mysql.clusterj.core.util.Logger;
34 import com.mysql.clusterj.core.util.LoggerFactoryService;
39 class ColumnImpl implements Column {
41 /** My message translator */
42 static final I18NHelper local = I18NHelper
43 .getInstance(ColumnImpl.class);
46 static final Logger logger = LoggerFactoryService.getFactory()
47 .getInstance(ColumnImpl.class);
49 /** The charset map. This map converts between the database charset name
50 * and the charset name used in Java Charset.
52 static private Map<String, String> charsetMap = new HashMap<String, String>();
54 charsetMap.put("latin1", "windows-1252");
55 charsetMap.put("utf8", "UTF-8");
56 charsetMap.put("sjis", "SJIS");
57 charsetMap.put("big5", "big5");
60 /** The ndb column metadata instance */
61 private NdbColumn column;
63 /** The native charset name */
64 private String nativeCharsetName;
66 /** The ISO charset name */
67 private String charsetName;
69 /** The ndb column type for the column */
70 private Column.Type columnType;
72 /** The table this column belongs to */
73 private NdbTable table;
75 private int prefixLength;
77 private String tableName;
79 private String columnName;
81 public ColumnImpl(NdbTable table, NdbColumn column) {
83 this.columnName = column.getName();
85 this.tableName = table.getName();
86 this.columnType = convertType(this.column.getType());
87 switch(column.getType()) {
107 private void mapCharsetName() {
108 this.nativeCharsetName = column.getCharsetName();
109 this.charsetName = charsetMap.get(nativeCharsetName);
110 if (charsetName == null) {
111 throw new ClusterJDatastoreException(
112 local.message("ERR_Unknown_Charset_Name",
113 tableName, columnName, nativeCharsetName));
117 public String getName() {
121 public Column.Type getType() {
125 private Type convertType(com.mysql.cluster.ndbj.NdbColumn.Type type) {
127 case Bigint: return Column.Type.Bigint;
128 case Bigunsigned: return Column.Type.Bigunsigned;
129 case Binary: return Column.Type.Binary;
130 case Bit: return Column.Type.Bit;
131 case Blob: return Column.Type.Blob;
132 case Char: return Column.Type.Char;
133 case Date: return Column.Type.Date;
134 case Datetime: return Column.Type.Datetime;
135 case Decimal: return Column.Type.Decimal;
136 case Decimalunsigned: return Column.Type.Decimalunsigned;
137 case Double: return Column.Type.Double;
138 case Float: return Column.Type.Float;
139 case Int: return Column.Type.Int;
140 case Longvarbinary: return Column.Type.Longvarbinary;
141 case Longvarchar: return Column.Type.Longvarchar;
142 case Mediumint: return Column.Type.Mediumint;
143 case Mediumunsigned: return Column.Type.Mediumunsigned;
144 case Olddecimal: return Column.Type.Olddecimal;
145 case Olddecimalunsigned: return Column.Type.Olddecimalunsigned;
146 case Smallint: return Column.Type.Smallint;
147 case Smallunsigned: return Column.Type.Smallunsigned;
148 case Text: return Column.Type.Text;
149 case Time: return Column.Type.Time;
150 case Timestamp: return Column.Type.Timestamp;
151 case Tinyint: return Column.Type.Tinyint;
152 case Tinyunsigned: return Column.Type.Tinyunsigned;
153 case Undefined: return Column.Type.Undefined;
154 case Unsigned: return Column.Type.Unsigned;
155 case Varbinary: return Column.Type.Varbinary;
156 case Varchar: return Column.Type.Varchar;
157 case Year: return Column.Type.Year;
158 default: throw new ClusterJFatalInternalException(
159 local.message("ERR_Unknown_Column_Type",
160 table.getName(), column.getName(), type.toString()));
164 public String getCharsetName() {
168 public int getPrefixLength() {
169 if (prefixLength != 0) {
172 throw new ClusterJFatalInternalException(local.message(
173 "ERR_Prefix_Length_Not_Defined", tableName, columnName));
177 public int getColumnId() {
178 throw new ClusterJFatalInternalException("Not implemented");
181 public int getColumnSpace() {
182 throw new ClusterJFatalInternalException("Not implemented");
185 public int getPrecision() {
186 throw new ClusterJFatalInternalException("Not implemented");
189 public int getScale() {
190 throw new ClusterJFatalInternalException("Not implemented");