abstractresultset.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 886 行 · 第 1/2 页
JAVA
886 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.db.jdbc;import com.caucho.sql.SQLExceptionWrapper;import com.caucho.util.L10N;import java.io.IOException;import java.io.InputStream;import java.io.Reader;import java.math.BigDecimal;import java.sql.*;import java.util.Calendar;import java.util.Map;/** * The JDBC statement implementation. */abstract public class AbstractResultSet implements java.sql.ResultSet { protected final static L10N L = new L10N(AbstractResultSet.class); private int _rowNumber; public boolean absolute(int row) throws SQLException { if (row < getRow()) return false; while (getRow() < row) { if (! next()) return false; } return true; } public void afterLast() { } public void beforeFirst() { } public void cancelRowUpdates() { } public void clearWarnings() { } public void deleteRow() { } public int getRow() throws SQLException { if (_rowNumber < 0) throw new SQLException("can't call getRow() after close()"); return _rowNumber; } public boolean isBeforeFirst() throws SQLException { return getRow() == 0; } public boolean isAfterLast() { return false; } public boolean isFirst() throws SQLException { return _rowNumber == 1; } public boolean first() throws SQLException { return isFirst(); } public boolean isLast() throws SQLException { return false; } public boolean last() throws SQLException { return isLast(); } public int getConcurrency() { return 0; } public String getCursorName() { return null; } abstract public java.sql.Statement getStatement() throws SQLException; abstract public java.sql.ResultSetMetaData getMetaData() throws SQLException; abstract public boolean next() throws SQLException; abstract public boolean wasNull() throws SQLException; abstract public int findColumn(String columnName) throws SQLException; public int getType() { return 0; } public BigDecimal getBigDecimal(int columnIndex) throws SQLException { return null; } public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { return getBigDecimal(columnIndex).setScale(scale); } public BigDecimal getBigDecimal(String columnName) throws SQLException { return getBigDecimal(findColumn(columnName)); } public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { return getBigDecimal(findColumn(columnName), scale); } /** * Returns the boolean value for the column. */ public boolean getBoolean(int columnIndex) throws SQLException { String v = getString(columnIndex); return (v != null && ! v.equals("") && ! v.equals("0") && ! v.equals("n")); } /** * Returns the boolean value for the named column. */ public boolean getBoolean(String columnName) throws SQLException { return getBoolean(findColumn(columnName)); } public byte getByte(int columnIndex) throws SQLException { return (byte) getInt(columnIndex); } public byte getByte(String columnName) throws SQLException { return getByte(findColumn(columnName)); } /** * Returns the byte value for the column. */ public byte []getBytes(int columnIndex) throws SQLException { try { Blob blob = getBlob(columnIndex); if (blob == null) return null; int length = (int) blob.length(); byte []bytes = new byte[length]; InputStream is = blob.getBinaryStream(); try { int offset = 0; int sublen; while (length > 0 && (sublen = is.read(bytes, offset, length)) > 0) { offset += sublen; length -= sublen; } } finally { is.close(); } return bytes; } catch (IOException e) { throw new SQLExceptionWrapper(e); } } public byte []getBytes(String columnName) throws SQLException { return getBytes(findColumn(columnName)); } public Reader getCharacterStream(int columnIndex) throws SQLException { throw new UnsupportedOperationException(); } public Reader getCharacterStream(String columnName) throws SQLException { return getCharacterStream(findColumn(columnName)); } public java.sql.Date getDate(int columnIndex) throws SQLException { throw new UnsupportedOperationException(); } public java.sql.Date getDate(String columnName) throws SQLException { return getDate(findColumn(columnName)); } public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException { return getDate(columnIndex); } public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException { return getDate(findColumn(columnName), cal); } /** * Returns the double value for the column. */ public double getDouble(int columnIndex) throws SQLException { String v = getString(columnIndex); if (v == null) return 0; else return Double.parseDouble(v); } /** * Returns the double value for the named column. */ public double getDouble(String columnName) throws SQLException { return getDouble(findColumn(columnName)); } public int getFetchDirection() { return 0; } public int getFetchSize() { return 0; } /** * Returns the float value for the column. */ public float getFloat(int columnIndex) throws SQLException { return (float) getDouble(columnIndex); } /** * Returns the float value for the named column. */ public float getFloat(String columnName) throws SQLException { return (float) getDouble(findColumn(columnName)); } /** * Returns the integer value for the column. */ public int getInt(int columnIndex) throws SQLException { String v = getString(columnIndex); if (v == null) return 0; else return Integer.parseInt(v); } /** * Returns the integer value for the named column. */ public int getInt(String columnName) throws SQLException { return getInt(findColumn(columnName)); } /** * Returns the long value for the column. */ public long getLong(int columnIndex) throws SQLException { String v = getString(columnIndex); if (v == null) return 0; else return Long.parseLong(v); } /** * Returns the long value for the named column. */ public long getLong(String columnName) throws SQLException { return getLong(findColumn(columnName)); } public Object getObject(int columnIndex) throws SQLException { return getString(columnIndex); } public Object getObject(String columnName) throws SQLException { return getObject(findColumn(columnName)); } public Object getObject(int columnIndex, Map<String,Class<?>> map) throws SQLException { return getObject(columnIndex); } public Object getObject(String columnName, Map<String,Class<?>> map) throws SQLException { return getObject(findColumn(columnName), map); } public short getShort(int columnIndex) throws SQLException { return (short) getInt(columnIndex); } public short getShort(String columnName) throws SQLException { return getShort(findColumn(columnName)); } abstract public String getString(int columnIndex) throws SQLException; public String getString(String columnName) throws SQLException { return getString(findColumn(columnName)); } public Time getTime(int columnIndex) throws SQLException { throw new UnsupportedOperationException(); } public Time getTime(String columnName) throws SQLException { return getTime(findColumn(columnName)); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?