01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.sql.rowset.serial;
19:
20: import java.net.URL;
21: import java.sql.Array;
22: import java.sql.Blob;
23: import java.sql.Clob;
24: import java.sql.SQLException;
25: import java.sql.Struct;
26: import java.sql.Types;
27: import java.util.HashMap;
28:
29: class DefaultUDTMap<T> {
30:
31: public static HashMap<String, Class<?>> DEFAULTMAP = new HashMap<String, Class<?>>();
32:
33: public static boolean isDefault(int type) {
34: return (type == Types.ARRAY || type == Types.BLOB
35: || type == Types.CLOB || type == Types.DATALINK
36: || type == Types.STRUCT || type == Types.JAVA_OBJECT);
37: }
38:
39: public static SerialDatalink[] processDatalink(Object[] elements)
40: throws SerialException {
41: SerialDatalink[] ret = new SerialDatalink[elements.length];
42: for (int i = 0; i < elements.length; i++) {
43: ret[i] = new SerialDatalink((URL) elements[i]);
44: }
45: return ret;
46: }
47:
48: public static Struct[] processStruct(Object[] elements)
49: throws SerialException {
50: Struct[] ret = new Struct[elements.length];
51: for (int i = 0; i < elements.length; i++) {
52: ret[i] = (Struct) elements[i];
53: }
54: return ret;
55: }
56:
57: public static Array[] processArray(Object[] elements)
58: throws SerialException {
59: Array[] ret = new Array[elements.length];
60: for (int i = 0; i < elements.length; i++) {
61: ret[i] = (Array) elements[i];
62: }
63: return ret;
64: }
65:
66: public static Clob[] processClob(Object[] elements)
67: throws SQLException {
68: Clob[] ret = new Clob[elements.length];
69: for (int i = 0; i < elements.length; i++) {
70: ret[i] = new SerialClob((Clob) elements[i]);
71: }
72: return ret;
73: }
74:
75: public static Blob[] processBlob(Object[] elements)
76: throws SQLException {
77: Blob[] ret = new Blob[elements.length];
78: for (int i = 0; i < elements.length; i++) {
79: ret[i] = new SerialBlob((Blob) elements[i]);
80: }
81: return ret;
82: }
83:
84: public static Object[] processObject(Object[] elements)
85: throws SerialException {
86: Object[] ret = new Object[elements.length];
87: for (int i = 0; i < elements.length; i++) {
88: ret[i] = new SerialJavaObject(elements[i]);
89: // TODO according to RI, should do like this, but does it make
90: // sense?
91: elements[i] = ret[i];
92: }
93: return ret;
94: }
95: }
|