com/quadcap/sql/meta/MetaCursor.java
Go to the documentation of this file.00001
package com.quadcap.sql.meta;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
import java.io.IOException;
00042
00043
00044
00045
00046
import java.util.Vector;
00047
00048
00049
import java.sql.ResultSet;
00050
import java.sql.SQLException;
00051
00052
import com.quadcap.sql.Column;
00053
import com.quadcap.sql.Cursor;
00054
import com.quadcap.sql.Database;
00055
import com.quadcap.sql.Expression;
00056
import com.quadcap.sql.Relation;
00057
import com.quadcap.sql.Row;
00058
import com.quadcap.sql.Session;
00059
import com.quadcap.sql.StaticCursor;
00060
import com.quadcap.sql.Table;
00061
00062
import com.quadcap.sql.types.*;
00063
00064
import com.quadcap.util.Debug;
00065
00066
00067
00068
00069
00070
00071 public class MetaCursor extends StaticCursor {
00072 static TypeVarChar typeString =
new TypeVarChar(-1);
00073 static TypeInt typeInt =
new TypeInt();
00074 static TypeSmallInt typeShort =
new TypeSmallInt();
00075 static TypeAny typeAny =
new TypeAny();
00076 static TypeBinary typeBinary =
new TypeBinary(1);
00077
00078 StaticCursor sc;
00079 Expression predicate;
00080
00081
00082
00083
00084 public MetaCursor(
Session session,
Expression predicate)
00085
throws SQLException
00086 {
00087 super(session,
new Vector());
00088
try {
00089 session.
getTableWriteLock(
"#Schema");
00090 }
catch (IOException e) {
00091
throw new SQLException(e.toString());
00092 }
00093
this.session = session;
00094
this.predicate =
predicate;
00095 Vector vec =
new Vector();
00096 vec.addElement(null);
00097
sc =
new StaticCursor(session, vec);
00098 }
00099
00100
00101
00102
00103 public static MetaCursor create(
Session session,
Column[] cols)
00104
throws SQLException {
00105
MetaCursor c =
new MetaCursor(session, null);
00106 c.
addColumns(cols);
00107
return c;
00108 }
00109
00110
00111
00112
00113 boolean rowMatch(
Row row)
throws SQLException {
00114
if (
predicate == null)
return true;
00115
sc.
updateRow(0, row);
00116
sc.
absolute(1);
00117
Value v =
predicate.
getValue(session,
sc);
00118
return (v instanceof
ValueBoolean && ((
ValueBoolean)v).
isTrue());
00119 }
00120
00121
00122
00123
00124 void addColumns(
Column[] cols)
throws SQLException {
00125
for (
int i = 0; i < cols.length; i++) {
00126 addColumn(cols[i]);
00127
sc.
addColumn(cols[i]);
00128 }
00129 }
00130
00131
00132
00133
00134
00135 void doTableName(
int col,
Row row, String name)
throws SQLException {
00136
int idx = name.indexOf(
'.');
00137
if (idx > 0) {
00138 row.set(col,
new ValueString(name.substring(0, idx)));
00139 row.set(col+1,
new ValueString(name.substring(idx+1)));
00140 }
else {
00141 row.set(col,
new ValueString(
""));
00142 row.set(col+1,
new ValueString(name));
00143 }
00144 }
00145
00146 static Column[]
cColumnPrivileges = {
00147
new Column(
"TABLE_CAT",
typeString),
00148
new Column(
"TABLE_SCHEM",
typeString),
00149
new Column(
"TABLE_NAME",
typeString),
00150
new Column(
"COLUMN_NAME",
typeString),
00151
new Column(
"GRANTOR",
typeString),
00152
new Column(
"GRANTEE",
typeString),
00153
new Column(
"PRIVILEGE",
typeString),
00154
new Column(
"IS_GRANTABLE",
typeString)
00155 };
00156
00157 static Column[]
cCatalogs = {
00158
new Column(
"TABLE_CAT",
typeString)
00159 };
00160
00161 static Column[]
cProcedureColumns = {
00162
new Column(
"PROCEDURE_CAT",
typeString),
00163
new Column(
"PROCEDURE_SCHEM",
typeString),
00164
new Column(
"PROCEDURE_NAME",
typeString),
00165
new Column(
"COLUMN_NAME",
typeString),
00166
new Column(
"COLUMN_TYPE",
typeShort),
00167
new Column(
"DATA_TYPE",
typeShort),
00168
new Column(
"TYPE_NAME",
typeString),
00169
new Column(
"PRECISION",
typeInt),
00170
new Column(
"LENGTH",
typeInt),
00171
new Column(
"SCALE",
typeShort),
00172
new Column(
"RADIX",
typeInt),
00173
new Column(
"NULLABLE",
typeShort),
00174
new Column(
"REMARKS",
typeString),
00175 };
00176
00177 static Column[]
cProcedures = {
00178
new Column(
"PROCEDURE_CAT",
typeString),
00179
new Column(
"PROCEDURE_SCHEM",
typeString),
00180
new Column(
"PROCEDURE_NAME",
typeString),
00181
new Column(
"reserved1",
typeString),
00182
new Column(
"reserved2",
typeString),
00183
new Column(
"reserved3",
typeString),
00184
new Column(
"REMARKS",
typeString),
00185
new Column(
"PROCEDURE_TYPE",
typeShort)
00186 };
00187
00188 static Column[]
cTablePrivileges = {
00189
new Column(
"TABLE_CAT",
typeString),
00190
new Column(
"TABLE_SCHEM",
typeString),
00191
new Column(
"TABLE_NAME",
typeString),
00192
new Column(
"GRANTOR",
typeString),
00193
new Column(
"GRANTEE",
typeString),
00194
new Column(
"PRIVILEGE",
typeString),
00195
new Column(
"IS_GRANTABLE",
typeString)
00196 };
00197
00198 static Column[]
cUdts= {
00199
new Column(
"TYPE_CAT",
typeString),
00200
new Column(
"TYPE_SCHEM",
typeString),
00201
new Column(
"TYPE_NAME",
typeString),
00202
new Column(
"CLASS_NAME",
typeString),
00203
new Column(
"DATA_TYPE",
typeShort),
00204
new Column(
"REMARKS",
typeString)
00205 };
00206
00207 static Column[]
cVersionColumns = {
00208
new Column(
"SCOPE",
typeShort),
00209
new Column(
"COLUMN_NAME",
typeString),
00210
new Column(
"DATA_TYPE",
typeShort),
00211
new Column(
"TYPE_NAME",
typeString),
00212
new Column(
"COLUMN_SIZE",
typeInt),
00213
new Column(
"BUFFER_LENGTH",
typeInt),
00214
new Column(
"DECIMAL_DIGITS",
typeInt),
00215
new Column(
"PSEUDO_COLUMN",
typeShort)
00216 };
00217
00218
00219
00220
00221 public static Cursor find(
Session session, String name)
00222
throws SQLException
00223 {
00224
if (name.equalsIgnoreCase(
"SYSTEM.CATALOGS")) {
00225
return create(session,
cCatalogs);
00226 }
else if (name.equalsIgnoreCase(
"SYSTEM.COLUMNS")) {
00227
return new MetaColumns(session, null);
00228 }
else if (name.equalsIgnoreCase(
"SYSTEM.COLUMNPRIVILEGES")) {
00229
return create(session,
cColumnPrivileges);
00230 }
else if (name.equalsIgnoreCase(
"SYSTEM.CROSSREFERENCE")) {
00231
return new MetaCrossReference(session, null);
00232 }
else if (name.equalsIgnoreCase(
"SYSTEM.INDEXINFO")) {
00233
return new MetaIndexInfo(session, null);
00234 }
else if (name.equalsIgnoreCase(
"SYSTEM.PRIMARYKEYS")) {
00235
return new MetaPrimaryKeys(session, null);
00236 }
else if (name.equalsIgnoreCase(
"SYSTEM.PROCEDURECOLUMNS")) {
00237
return create(session,
cProcedureColumns);
00238 }
else if (name.equalsIgnoreCase(
"SYSTEM.PROCEDURES")) {
00239
return create(session,
cProcedures);
00240 }
else if (name.equalsIgnoreCase(
"SYSTEM.SCHEMAS")) {
00241
return new MetaSchemas(session);
00242 }
else if (name.equalsIgnoreCase(
"SYSTEM.TABLES")) {
00243
return new MetaTables(session, null);
00244 }
else if (name.equalsIgnoreCase(
"SYSTEM.TABLEPRIVILEGES")) {
00245
return create(session,
cTablePrivileges);
00246 }
else if (name.equalsIgnoreCase(
"SYSTEM.TABLETYPES")) {
00247
return new MetaTableTypes(session);
00248 }
else if (name.equalsIgnoreCase(
"SYSTEM.VERSIONCOLUMNS")) {
00249
return create(session,
cVersionColumns);
00250 }
else if (name.equalsIgnoreCase(
"SYSTEM.TYPEINFO")) {
00251
return new MetaTypes(session);
00252 }
else if (name.equalsIgnoreCase(
"SYSTEM.UDTS")) {
00253
return create(session,
cUdts);
00254 }
00255
return null;
00256 }
00257 }