2 Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18 package com.mysql.clusterj.openjpa;
20 import java.util.BitSet;
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;
27 /** Grab bag of utility methods
30 public class NdbOpenJPAUtility {
32 /** JavaType names corresponding to org.apache.openjpa.meta.JavaTypes */
33 protected static String[] javaTypeNames = {
34 "boolean", /* 0: boolean */
37 "double", /* 3: double */
38 "float", /* 4: float */
41 "short", /* 7: short */
42 "Object", /* 8: Object */
43 "String", /* 9: String */
44 "Number", /* 10: Number */
45 "Array", /* 11: Array */
46 "Collection", /* 12: Collection */
48 "java.util.Date", /* 14: java.util.Date */
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 */
64 "InputStream", /* 30: InputStream */
65 "InputReader" /* 31: InputReader */
68 public static String getJavaTypeName(int javaType) {
69 if (javaType < javaTypeNames.length) {
70 return javaTypeNames[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";
84 public static String printBitSet(OpenJPAStateManager sm, BitSet fields) {
85 ClassMetaData classMetaData = sm.getMetaData();
86 FieldMetaData[] fieldMetaDatas = classMetaData.getFields();
87 StringBuffer buffer = new StringBuffer("[");
89 String separator = "";
90 for (int i = 0; i < fields.size(); ++i) {
92 buffer.append(separator);
95 buffer.append(fieldMetaDatas[i].getName());
101 return buffer.toString();