001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package com.sun.sql.rowset;
043:
044: import java.sql.SQLException;
045: import java.text.MessageFormat;
046: import java.util.Locale;
047: import java.util.ResourceBundle;
048:
049: import javax.sql.rowset.RowSetMetaDataImpl;
050:
051: /**
052: *
053: * Implements {@link com.sun.sql.rowset.RowSetMetaDataX}
054: *
055: */
056: public class RowSetMetaDataXImpl extends RowSetMetaDataImpl implements
057: RowSetMetaDataX {
058:
059: private static ResourceBundle rb = ResourceBundle.getBundle(
060: "com.sun.sql.rowset.Bundle", Locale.getDefault()); // NOI18N
061:
062: String[] columnClassName;
063: boolean[] definitelyWritable;
064: boolean[] readOnly;
065: boolean[] writable;
066:
067: public void setColumnCount(int columnCount) throws SQLException {
068: super .setColumnCount(columnCount);
069:
070: /*
071: * If the columnCount is Integer.MAX_VALUE,
072: * we do not initialize.
073: * even if we try to initialize the colCount with
074: * columnCount = Integer.MAx_VALUE-1, we'll run out
075: * of memory. This is to pass TCK.
076: */
077: if (!(columnCount == Integer.MAX_VALUE)) {
078: columnClassName = new String[columnCount + 1];
079: definitelyWritable = new boolean[columnCount + 1];
080: readOnly = new boolean[columnCount + 1];
081: writable = new boolean[columnCount + 1];
082: }
083: }
084:
085: public void setColumnClassName(int columnIndex, String className)
086: throws SQLException {
087: checkColumnIndex(columnIndex);
088: columnClassName[columnIndex] = className;
089: }
090:
091: public void setDefinitelyWritable(int columnIndex, boolean value)
092: throws SQLException {
093: checkColumnIndex(columnIndex);
094: definitelyWritable[columnIndex] = value;
095: }
096:
097: public void setReadOnly(int columnIndex, boolean value)
098: throws SQLException {
099: checkColumnIndex(columnIndex);
100: readOnly[columnIndex] = value;
101: }
102:
103: public void setWritable(int columnIndex, boolean value)
104: throws SQLException {
105: checkColumnIndex(columnIndex);
106: writable[columnIndex] = value;
107: }
108:
109: public String getColumnClassName(int columnIndex)
110: throws SQLException {
111: checkColumnIndex(columnIndex);
112: String className = columnClassName[columnIndex];
113: if (className.equals("byte[]")) {
114: className = new byte[0].getClass().getName(); //"[B";
115: } else if (className.equals("char[]")) {
116: className = new char[0].getClass().getName(); //"[C";
117: } else if (className.equals("short[]")) {
118: className = new short[0].getClass().getName(); //"[S";
119: } else if (className.equals("int[]")) {
120: className = new int[0].getClass().getName(); //"[I";
121: } else if (className.equals("long[]")) {
122: className = new long[0].getClass().getName(); //"[J";
123: } else if (className.equals("float[]")) {
124: className = new float[0].getClass().getName(); //"[F";
125: } else if (className.equals("double[]")) {
126: className = new double[0].getClass().getName(); //"[D";
127: } else if (className.equals("boolean[]")) {
128: className = new boolean[0].getClass().getName(); //"[Z";
129: }
130: return className;
131: }
132:
133: public boolean isDefinitelyWritable(int columnIndex)
134: throws SQLException {
135: checkColumnIndex(columnIndex);
136: return definitelyWritable[columnIndex];
137: }
138:
139: public boolean isReadOnly(int columnIndex) throws SQLException {
140: checkColumnIndex(columnIndex);
141: return readOnly[columnIndex];
142: }
143:
144: public boolean isWritable(int columnIndex) throws SQLException {
145: checkColumnIndex(columnIndex);
146: return writable[columnIndex];
147: }
148:
149: private void checkColumnIndex(int columnIndex) throws SQLException {
150: if (columnIndex <= 0 || columnIndex > getColumnCount()) {
151: throw new SQLException(MessageFormat.format(rb
152: .getString("INVALID_COLUMN_INDEX"), //NOI18N
153: new Object[] { new Integer(columnIndex) }));
154: }
155: }
156: }
|