Quadcap Embeddable Database

com/quadcap/sql/ViewCursor.java

Go to the documentation of this file.
00001 package com.quadcap.sql; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.Externalizable; 00042 import java.io.IOException; 00043 import java.io.ObjectInput; 00044 import java.io.ObjectOutput; 00045 00046 import java.util.Enumeration; 00047 import java.util.Hashtable; 00048 import java.util.Vector; 00049 00050 import java.sql.SQLException; 00051 00052 import com.quadcap.util.Debug; 00053 00054 /** 00055 * This cursor performs the name mapping associated with the (optional) 00056 * column list of the <code>CREATE VIEW</code> statement. 00057 * 00058 * @author Stan Bailes 00059 */ 00060 public class ViewCursor extends CursorImpl { 00061 Cursor cursor; 00062 View view; 00063 00064 public ViewCursor(Session session, View view, 00065 Cursor cursor, Vector names) 00066 throws SQLException 00067 { 00068 super(session, view.getName()); 00069 this.view = view; 00070 this.cursor = cursor; 00071 if (names.size() > cursor.getColumnCount()) { 00072 throw new SQLException("Too many names in view column list", 00073 "42000"); 00074 } 00075 if (names.size() < cursor.getColumnCount()) { 00076 //#ifdef TRACE 00077 if (Trace.bit(2)) { 00078 Debug.println("cursor = " + cursor); 00079 for (int i = 0; i < names.size(); i++) { 00080 Debug.println("name[" + i + "] = " + 00081 names.elementAt(i).toString()); 00082 } 00083 } 00084 //#endif 00085 throw new SQLException("Not enough names in view column list", 00086 "42000"); 00087 } 00088 for (int i = 0; i < names.size(); i++) { 00089 String name = (String)names.elementAt(i); 00090 addColumn(new Column(name, 00091 cursor.getColumn(i+1).getType())); 00092 } 00093 resolveColumns(); 00094 } 00095 00096 public long size() throws SQLException { return -1; } 00097 00098 public Row getRow() throws SQLException { 00099 return cursor.getRow(); 00100 } 00101 00102 public void updateRow(Row row) throws SQLException { 00103 view.checkRow(session, cursor, row); 00104 cursor.updateRow(row); 00105 } 00106 00107 public void insertRow(Row row) throws SQLException { 00108 view.checkRow(session, cursor, row); 00109 cursor.insertRow(row); 00110 } 00111 00112 public void deleteRow() throws SQLException { 00113 cursor.deleteRow(); 00114 } 00115 00116 public void beforeFirst() throws SQLException { 00117 cursor.beforeFirst(); 00118 } 00119 00120 public void afterLast() throws SQLException { 00121 cursor.afterLast(); 00122 } 00123 00124 public boolean absolute(int row) throws SQLException { 00125 return cursor.absolute(row); 00126 } 00127 00128 public boolean next() throws SQLException { 00129 return cursor.next(); 00130 } 00131 00132 public boolean isWritable(int column) throws SQLException { 00133 return cursor.isWritable(column); 00134 } 00135 00136 public int getColumnCount() throws SQLException { 00137 return cursor.getColumnCount(); 00138 } 00139 public void close() throws SQLException { 00140 cursor.close(); 00141 } 00142 }