MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbOpenJPAUtility.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.openjpa;
19 
20 import java.util.BitSet;
21 
22 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
23 import org.apache.openjpa.kernel.OpenJPAStateManager;
24 import org.apache.openjpa.meta.ClassMetaData;
25 import org.apache.openjpa.meta.FieldMetaData;
26 
30 public class NdbOpenJPAUtility {
31 
33  protected static String[] javaTypeNames = {
34  "boolean", /* 0: boolean */
35  "byte", /* 1: byte */
36  "char", /* 2: char */
37  "double", /* 3: double */
38  "float", /* 4: float */
39  "int", /* 5: int */
40  "long", /* 6: long */
41  "short", /* 7: short */
42  "Object", /* 8: Object */
43  "String", /* 9: String */
44  "Number", /* 10: Number */
45  "Array", /* 11: Array */
46  "Collection", /* 12: Collection */
47  "Map", /* 13: Map */
48  "java.util.Date", /* 14: java.util.Date */
49  "PC", /* 15: PC */
50  "Boolean", /* 16: Boolean */
51  "Byte", /* 17: Byte */
52  "Character", /* 18: Character */
53  "Double", /* 19: Double */
54  "Float", /* 20: Float */
55  "Integer", /* 21: Integer */
56  "Long", /* 22: Long */
57  "Short", /* 23: Short */
58  "BigDecimal", /* 24: BigDecimal */
59  "BigInteger", /* 25: BigInteger */
60  "Locale", /* 26: Locale */
61  "PC Untyped", /* 27: PC Untyped */
62  "Calendar", /* 28: Calendar */
63  "OID", /* 29: OID */
64  "InputStream", /* 30: InputStream */
65  "InputReader" /* 31: InputReader */
66  };
67 
68  public static String getJavaTypeName(int javaType) {
69  if (javaType < javaTypeNames.length) {
70  return javaTypeNames[javaType];
71  } else {
72  switch (javaType) {
73  case JavaSQLTypes.SQL_DATE:
74  return "java.sql.Date";
75  case JavaSQLTypes.TIME:
76  return "java.sql.Time";
77  case JavaSQLTypes.TIMESTAMP:
78  return "java.sql.Timestamp";
79  default: return "unsupported";
80  }
81  }
82  }
83 
84  public static String printBitSet(OpenJPAStateManager sm, BitSet fields) {
85  ClassMetaData classMetaData = sm.getMetaData();
86  FieldMetaData[] fieldMetaDatas = classMetaData.getFields();
87  StringBuffer buffer = new StringBuffer("[");
88  if (fields != null) {
89  String separator = "";
90  for (int i = 0; i < fields.size(); ++i) {
91  if (fields.get(i)) {
92  buffer.append(separator);
93  buffer.append(i);
94  buffer.append(" ");
95  buffer.append(fieldMetaDatas[i].getName());
96  separator = ";";
97  }
98  }
99  }
100  buffer.append("] ");
101  return buffer.toString();
102  }
103 
104 }