db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r916014 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/ap...
Date Wed, 24 Feb 2010 22:39:50 GMT
Author: rhillegas
Date: Wed Feb 24 22:39:49 2010
New Revision: 916014

URL: http://svn.apache.org/viewvc?rev=916014&view=rev
Log:
DERBY-4550: Commit Sylvain Leroux's patch which adds qualified identifiers to ij.

Added:
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/QualifiedIdentifier.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/holdCursorIJ.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/holdCursorIJ.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cursorerrors.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/holdCursorIJ.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ConnectionEnv.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/holdCursorIJ.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/holdCursorIJ.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/holdCursorIJ.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/holdCursorIJ.out
Wed Feb 24 22:39:49 2010
@@ -1,20 +1,20 @@
 ij> --
---   Licensed to the Apache Software Foundation (ASF) under one or more
---   contributor license agreements.  See the NOTICE file distributed with
---   this work for additional information regarding copyright ownership.
---   The ASF licenses this file to You under the Apache License, Version 2.0
---   (the "License"); you may not use this file except in compliance with
---   the License.  You may obtain a copy of the License at
---
---      http://www.apache.org/licenses/LICENSE-2.0
---
---   Unless required by applicable law or agreed to in writing, software
---   distributed under the License is distributed on an "AS IS" BASIS,
---   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
---   See the License for the specific language governing permissions and
---   limitations under the License.
---
--- create a table
+-----   Licensed to the Apache Software Foundation (ASF) under one or more
+-----   contributor license agreements.  See the NOTICE file distributed with
+-----   this work for additional information regarding copyright ownership.
+-----   The ASF licenses this file to You under the Apache License, Version 2.0
+-----   (the "License"); you may not use this file except in compliance with
+-----   the License.  You may obtain a copy of the License at
+-----
+-----      http://www.apache.org/licenses/LICENSE-2.0
+-----
+-----   Unless required by applicable law or agreed to in writing, software
+-----   distributed under the License is distributed on an "AS IS" BASIS,
+-----   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-----   See the License for the specific language governing permissions and
+-----   limitations under the License.
+-----
+----- create a table
 create table t1(c11 int, c12 int);
 0 rows inserted/updated/deleted
 ij> -- insert data into tables
@@ -60,7 +60,7 @@
 No current row
 ij> close jdk4;
 ij> next jdk4;
-IJ ERROR: Unable to establish cursor
+IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
 ij> -- clean up.
 close jdk1;
 ij> close jdk2;
@@ -110,16 +110,16 @@
 -----
 1 |1          
 ij> -- wont' be able to drop table because of cursors jdk1 and jdk4
--- in DerbyNetClient, cursor is closed on server and DROP TABLE succeeds
+----- in DerbyNetClient, cursor is closed on server and DROP TABLE succeeds
 drop table t1;
 ERROR X0X95: Operation 'DROP TABLE' cannot be performed on object 'T1' because there is an
open ResultSet dependent on that object.
 ij> commit;
 ij> -- drop table still won't work because jdk4 is still open after commit
--- in DerbyNetClient, the table is already dropped
+----- in DerbyNetClient, the table is already dropped
 drop table t1;
 ERROR X0X95: Operation 'DROP TABLE' cannot be performed on object 'T1' because there is an
open ResultSet dependent on that object.
 ij> -- close cursor jdk4 and try then deleting the table
--- in DerbyNetClient, the table is already dropped
+----- in DerbyNetClient, the table is already dropped
 close jdk4;
 ij> drop table t1;
 0 rows inserted/updated/deleted
@@ -145,12 +145,12 @@
 -----
 1 |1          
 ij> -- try to change the isolation level. will give error because of jdk1 and jdk4
--- no error in DerbyNetClient because cursor is closed on server
+----- no error in DerbyNetClient because cursor is closed on server
 set current isolation RR;
 ERROR X0X03: Invalid transaction state - held cursor requires same isolation level
 ij> commit;
 ij> -- attempt to change isolation level should give error because of jdk4 hold cursor
--- no error in DerbyNetClient because cursor is closed on server
+----- no error in DerbyNetClient because cursor is closed on server
 set isolation = REPEATABLE READ;
 ERROR X0X03: Invalid transaction state - held cursor requires same isolation level
 ij> -- close jdk4 and then should be able to change isolation
@@ -172,11 +172,11 @@
 -----
 1 |1          
 ij> -- following should fail because of cursor jdk4
--- no error in DerbyNetClient because cursor is closed on server
+----- no error in DerbyNetClient because cursor is closed on server
 set isolation RS;
 ERROR X0X03: Invalid transaction state - held cursor requires same isolation level
 ij> -- following should fail because of cursor jdk4
--- no error in DerbyNetClient because cursor is closed on server
+----- no error in DerbyNetClient because cursor is closed on server
 set isolation UR;
 ERROR X0X03: Invalid transaction state - held cursor requires same isolation level
 ij> close jdk4;
@@ -313,7 +313,7 @@
 No current row
 ij> close jdk4;
 ij> first jdk4;
-IJ ERROR: Unable to establish cursor
+IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
 ij> -- ninth test - close the updateable holdable cursor after commit
 ----- we get npe
 get with hold cursor jdk4 as 'SELECT * FROM T1 FOR UPDATE';

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/holdCursorIJ.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/holdCursorIJ.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/holdCursorIJ.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/holdCursorIJ.out
Wed Feb 24 22:39:49 2010
@@ -1,20 +1,20 @@
 ij> --
---   Licensed to the Apache Software Foundation (ASF) under one or more
---   contributor license agreements.  See the NOTICE file distributed with
---   this work for additional information regarding copyright ownership.
---   The ASF licenses this file to You under the Apache License, Version 2.0
---   (the "License"); you may not use this file except in compliance with
---   the License.  You may obtain a copy of the License at
---
---      http://www.apache.org/licenses/LICENSE-2.0
---
---   Unless required by applicable law or agreed to in writing, software
---   distributed under the License is distributed on an "AS IS" BASIS,
---   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
---   See the License for the specific language governing permissions and
---   limitations under the License.
---
--- create a table
+-----   Licensed to the Apache Software Foundation (ASF) under one or more
+-----   contributor license agreements.  See the NOTICE file distributed with
+-----   this work for additional information regarding copyright ownership.
+-----   The ASF licenses this file to You under the Apache License, Version 2.0
+-----   (the "License"); you may not use this file except in compliance with
+-----   the License.  You may obtain a copy of the License at
+-----
+-----      http://www.apache.org/licenses/LICENSE-2.0
+-----
+-----   Unless required by applicable law or agreed to in writing, software
+-----   distributed under the License is distributed on an "AS IS" BASIS,
+-----   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-----   See the License for the specific language governing permissions and
+-----   limitations under the License.
+-----
+----- create a table
 create table t1(c11 int, c12 int);
 0 rows inserted/updated/deleted
 ij> -- insert data into tables
@@ -60,7 +60,7 @@
 No current row
 ij> close jdk4;
 ij> next jdk4;
-IJ ERROR: Unable to establish cursor
+IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
 ij> -- clean up.
 close jdk1;
 ij> close jdk2;
@@ -313,7 +313,7 @@
 No current row
 ij> close jdk4;
 ij> first jdk4;
-IJ ERROR: Unable to establish cursor
+IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
 ij> -- ninth test - close the updateable holdable cursor after commit
 ----- we get npe
 get with hold cursor jdk4 as 'SELECT * FROM T1 FOR UPDATE';

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cursorerrors.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cursorerrors.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cursorerrors.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/cursorerrors.out
Wed Feb 24 22:39:49 2010
@@ -114,7 +114,7 @@
 ERROR 22012: Attempt to divide by zero.
 ij> -- next should fail, since no cursor
 next c12;
-IJ ERROR: Unable to establish cursor
+IJ ERROR: Unable to establish cursor C12@CONNECTION0
 ij> -- join #2, error on 2nd row on left
 get cursor c13 as 'select * from t1 a, t1 b where b.c1 = 1 and a.c1/a.c1 = 1';
 ij> -- (1, 1)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/holdCursorIJ.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/holdCursorIJ.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/holdCursorIJ.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/holdCursorIJ.out
Wed Feb 24 22:39:49 2010
@@ -60,7 +60,7 @@
 No current row
 ij> close jdk4;
 ij> next jdk4;
-IJ ERROR: Unable to establish cursor
+IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
 ij> -- clean up.
 close jdk1;
 ij> close jdk2;
@@ -313,7 +313,7 @@
 No current row
 ij> close jdk4;
 ij> first jdk4;
-IJ ERROR: Unable to establish cursor
+IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
 ij> -- ninth test - close the updateable holdable cursor after commit
 -- we get npe
 get with hold cursor jdk4 as 'SELECT * FROM T1 FOR UPDATE';

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
Wed Feb 24 22:39:49 2010
@@ -28,7 +28,7 @@
 ij> remove s;
 ij> -- now it won't find s
 execute s;
-IJ ERROR: Unable to establish prepared statement S
+IJ ERROR: Unable to establish prepared statement S@CONNECTION0
 ij> prepare s as 'select * from t where i=?';
 ij> -- fails, needs parameter
 execute s;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
Wed Feb 24 22:39:49 2010
@@ -241,4 +241,99 @@
 ij> -- Observe behavior with empty string:
 describe '';
 IJ ERROR: No table exists with the name (missing)
+ij> --
+-- DERBY-4550: qualified identifiers
+--
+
+-- setup source db
+connect 'jdbc:derby:wombat;user=fred' as DERBY4550_1;
+ij(DERBY4550_1)> create table t1(a int, b int);
+0 rows inserted/updated/deleted
+ij(DERBY4550_1)> insert into t1(a,b) values (1,100), (2,200), (3,300);
+3 rows inserted/updated/deleted
+ij(DERBY4550_1)> prepare fred_select as 'select a from t1';
+ij(DERBY4550_1)> -- setup destination db
+connect 'jdbc:derby:wombat;user=alice' as DERBY4550_2;
+ij(DERBY4550_2)> create table t2(a int);
+0 rows inserted/updated/deleted
+ij(DERBY4550_2)> -- execute prepared statements
+autocommit off;
+ij(DERBY4550_2)> execute fred_select@DERBY4550_1;
+A          
+-----------
+1          
+2          
+3          
+ij(DERBY4550_2)> execute 'insert into t2(a) values(?)' using fred_select@DERBY4550_1;
+1 row inserted/updated/deleted
+1 row inserted/updated/deleted
+1 row inserted/updated/deleted
+ij(DERBY4550_2)> commit;
+ij(DERBY4550_2)> remove fred_select@DERBY4550_1;
+ij(DERBY4550_2)> -- check result
+select a from t2;
+A          
+-----------
+1          
+2          
+3          
+ij(DERBY4550_2)> -- prepare in a different connection/switch/execute
+prepare fred_select2@DERBY4550_1 as 'select b from t1';
+ij(DERBY4550_2)> set connection DERBY4550_1;
+ij(DERBY4550_1)> execute fred_select2;
+B          
+-----------
+100        
+200        
+300        
+ij(DERBY4550_1)> remove fred_select2;
+ij(DERBY4550_1)> -- setup cursor/switch connection/use
+get scroll insensitive cursor fred_cursor as 'select b from t1';
+ij(DERBY4550_1)> set connection DERBY4550_2;
+ij(DERBY4550_2)> next fred_cursor@DERBY4550_1;
+B          
+-----------
+100        
+ij(DERBY4550_2)> -- getcurrentrownumber fred_cursor@DERBY4550_1;
+last fred_cursor@DERBY4550_1;
+B          
+-----------
+300        
+ij(DERBY4550_2)> previous fred_cursor@DERBY4550_1;
+B          
+-----------
+200        
+ij(DERBY4550_2)> first fred_cursor@DERBY4550_1;
+B          
+-----------
+100        
+ij(DERBY4550_2)> after last fred_cursor@DERBY4550_1;
+No current row
+ij(DERBY4550_2)> before first fred_cursor@DERBY4550_1;
+No current row
+ij(DERBY4550_2)> relative 2 fred_cursor@DERBY4550_1;
+B          
+-----------
+200        
+ij(DERBY4550_2)> absolute 1 fred_cursor@DERBY4550_1;
+B          
+-----------
+100        
+ij(DERBY4550_2)> close fred_cursor@DERBY4550_1;
+ij(DERBY4550_2)> -- non-existant connection
+prepare fred_select@XXXX as 'values(1)';
+IJ ERROR: No connection exists with the name XXXX
+ij(DERBY4550_2)> -- async statements
+async a@DERBY4550_1 'select a from t1';
+ij(DERBY4550_2)> wait for a@DERBY4550_1;
+A          
+-----------
+1          
+2          
+3          
+ij(DERBY4550_2)> -- non existant statement
+wait for xxxx@DERBY4550_1;
+IJ ERROR: No async statement exists with the name XXXX@DERBY4550_1
+ij(DERBY4550_2)> disconnect DERBY4550_2;
+ij> disconnect DERBY4550_1;
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out
Wed Feb 24 22:39:49 2010
@@ -2527,9 +2527,9 @@
 ij> prepare p1 as 'select 1 from all1 where si like ?';
 ERROR 42884: No authorized routine named 'LIKE' of type 'FUNCTION' having compatible arguments
was found.
 ij> execute p1 using 'values 1';
-IJ ERROR: Unable to establish prepared statement P1
+IJ ERROR: Unable to establish prepared statement P1@CONNECTION0
 ij> execute p1 using 'values ''1''';
-IJ ERROR: Unable to establish prepared statement P1
+IJ ERROR: Unable to establish prepared statement P1@CONNECTION0
 ij> -- conversions involving non-canonical date, time, and timestamp strings
 create table t (d date, t time, ts timestamp);
 0 rows inserted/updated/deleted

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out
Wed Feb 24 22:39:49 2010
@@ -137,7 +137,7 @@
 ij> drop table date;
 0 rows inserted/updated/deleted
 ij> remove date;
-IJ ERROR: Unable to establish prepared statement DATE
+IJ ERROR: Unable to establish prepared statement DATE@CONNECTION0
 ij> -- TIME
 create table time (time time);
 0 rows inserted/updated/deleted
@@ -174,7 +174,7 @@
 ij> drop table time;
 0 rows inserted/updated/deleted
 ij> remove time;
-IJ ERROR: Unable to establish prepared statement TIME
+IJ ERROR: Unable to establish prepared statement TIME@CONNECTION0
 ij> -- TIMESTAMP
 create table timestamp (timestamp timestamp);
 0 rows inserted/updated/deleted
@@ -211,7 +211,7 @@
 ij> drop table timestamp;
 0 rows inserted/updated/deleted
 ij> remove timestamp;
-IJ ERROR: Unable to establish prepared statement TIMESTAMP
+IJ ERROR: Unable to establish prepared statement TIMESTAMP@CONNECTION0
 ij> -- 
 create table DOMAIN (domain int);
 0 rows inserted/updated/deleted

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
Wed Feb 24 22:39:49 2010
@@ -89,3 +89,59 @@
 -- Observe behavior with empty string:
 describe '';
 
+--
+-- DERBY-4550: qualified identifiers
+--
+
+-- setup source db
+connect 'jdbc:derby:wombat;user=fred' as DERBY4550_1;
+create table t1(a int, b int);
+insert into t1(a,b) values (1,100), (2,200), (3,300);
+prepare fred_select as 'select a from t1';
+
+-- setup destination db
+connect 'jdbc:derby:wombat;user=alice' as DERBY4550_2;
+create table t2(a int);
+
+-- execute prepared statements
+autocommit off;
+execute fred_select@DERBY4550_1;
+execute 'insert into t2(a) values(?)' using fred_select@DERBY4550_1;
+commit;
+remove fred_select@DERBY4550_1;
+
+-- check result
+select a from t2;
+
+-- prepare in a different connection/switch/execute
+prepare fred_select2@DERBY4550_1 as 'select b from t1';
+set connection DERBY4550_1;
+execute fred_select2;
+remove fred_select2;
+
+-- setup cursor/switch connection/use
+get scroll insensitive cursor fred_cursor as 'select b from t1';
+set connection DERBY4550_2;
+next fred_cursor@DERBY4550_1;
+-- getcurrentrownumber fred_cursor@DERBY4550_1;
+last fred_cursor@DERBY4550_1;
+previous fred_cursor@DERBY4550_1;
+first fred_cursor@DERBY4550_1;
+after last fred_cursor@DERBY4550_1;
+before first fred_cursor@DERBY4550_1;
+relative 2 fred_cursor@DERBY4550_1;
+absolute 1 fred_cursor@DERBY4550_1;
+close fred_cursor@DERBY4550_1;
+
+-- non-existant connection
+prepare fred_select@XXXX as 'values(1)';
+
+-- async statements
+async a@DERBY4550_1 'select a from t1';
+wait for a@DERBY4550_1;
+
+-- non existant statement
+wait for xxxx@DERBY4550_1;
+
+disconnect DERBY4550_2;
+disconnect DERBY4550_1;

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ConnectionEnv.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ConnectionEnv.java?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ConnectionEnv.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ConnectionEnv.java Wed Feb
24 22:39:49 2010
@@ -144,6 +144,10 @@
 		return sessions;
 	}
 
+	Session getSession(String name) {
+		return (Session) sessions.get(name);
+	}
+
 	Session setCurrentSession(String name) {
 		currSession = (Session) sessions.get(name);
 		return currSession;

Added: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/QualifiedIdentifier.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/QualifiedIdentifier.java?rev=916014&view=auto
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/QualifiedIdentifier.java
(added)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/QualifiedIdentifier.java
Wed Feb 24 22:39:49 2010
@@ -0,0 +1,46 @@
+/*
+
+   Derby - Class org.apache.derby.impl.tools.ij.QualifiedIdentifier
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.tools.ij;
+/**
+ * A qualified identifier made of a session name and a local name
+ */
+class QualifiedIdentifier {
+	private String sessionName;
+	private String localName;
+
+	QualifiedIdentifier(String sessionName, String localName) {
+		this.sessionName = sessionName;
+		this.localName = localName;
+	}
+	
+	public String getLocalName() {
+		return localName;
+	}
+	
+	public String getSessionName() {
+		return sessionName;
+	}
+	
+	public String toString() {
+		return localName + "@" + sessionName;
+	}
+}

Propchange: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/QualifiedIdentifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj?rev=916014&r1=916013&r2=916014&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj Wed Feb 24 22:39:49
2010
@@ -308,6 +308,45 @@
 	void haveConnection() {
 		JDBCDisplayUtil.checkNotNull(theConnection, "connection");
 	}
+	
+	/**
+		Find a session by its name. Throws an exception if the session does 
+		not exists.
+	*/
+	Session findSession(String name) {
+		Session session = currentConnEnv.getSession(name);
+		
+		if (session == null)
+			throw ijException.noSuchConnection(name);
+		
+		return session;
+	}
+	
+	/**
+		Find a prepared statement. Throws an exception if the session does 
+		not exists or the prepared statement can't be found.
+	*/
+	PreparedStatement findPreparedStatement(QualifiedIdentifier qi) {
+		Session session = findSession(qi.getSessionName());
+		PreparedStatement ps = session.getPreparedStatement(qi.getLocalName());
+		
+		JDBCDisplayUtil.checkNotNull(ps, "prepared statement " + qi);
+		
+		return ps;
+	}
+	
+	/**
+		Find a cursor. Throws an exception if the session does not exits or
+		it deosn't have the correspondig cursor.
+	*/
+	ResultSet findCursor(QualifiedIdentifier qi) {
+		Session 	session	= findSession(qi.getSessionName());
+		ResultSet	c		= session.getCursor(qi.getLocalName());
+		
+		JDBCDisplayUtil.checkNotNull(c, "cursor " + qi);
+		
+		return c;
+	}
 
 	/**
 		We do not reuse statement objects at all, because
@@ -405,10 +444,11 @@
 		a select only waits for the execute to complete; the
 		logic to step through the result set is in the caller.
 	 **/
-	ijResult executeAsync(String stmt, String name) {
-		AsyncStatement as = new AsyncStatement(theConnection, stmt);
+	ijResult executeAsync(String stmt, QualifiedIdentifier qi) {
+		Session sn = findSession(qi.getSessionName());
+		AsyncStatement as = new AsyncStatement(sn.getConnection(), stmt);
 
-		currentConnEnv.getSession().addAsyncStatement(name,as);
+		sn.addAsyncStatement(qi.getLocalName(),as);
 
 		as.start();
 
@@ -1252,7 +1292,8 @@
 
 TOKEN :
 {	/* Operators and punctuation -- to avoid lexical errors for SQL-J stuff, mostly */
-	<COMMA: ",">
+	<AT: "@">
+|	<COMMA: ",">
 |   <LEFT_PAREN: "(">
 |   <RIGHT_PAREN: ")">
 |   <DOUBLE_QUOTE: "\"">
@@ -2136,18 +2177,19 @@
 :
 {
 	Token t;
-	String i;
+	QualifiedIdentifier qi;
 	PreparedStatement ps;
 	String sVal;
 }
 {
-	<PREPARE> i=identifier() <AS> t=<STRING>
+	<PREPARE> qi=qualifiedIdentifier() <AS> t=<STRING>
 	{
-		haveConnection();
+		Session session = findSession(qi.getSessionName());
+
 		sVal = stringValue(t.image);
-		ps = theConnection.prepareStatement(sVal);
+		ps = session.getConnection().prepareStatement(sVal);
 		JDBCDisplayUtil.checkNotNull(ps,"prepared statement");
-		currentConnEnv.getSession().addPreparedStatement(i,ps);
+		session.addPreparedStatement(qi.getLocalName(),ps);
 
 		// all we want callers to see are the warnings.
 		SQLWarning w = ps.getWarnings();
@@ -2167,7 +2209,7 @@
 	Token scrolling = null;
 	Token withtoken = null;
 	int holdType = theConnection.getHoldability();
-	String c;
+	QualifiedIdentifier qi;
 	Statement st = null;
 	String sVal;
 	ResultSet rs = null;
@@ -2175,19 +2217,21 @@
 }
 {
 	<GET> [ scrolling = <SCROLL>  scrollType = scrollType()]
-	[ withtoken = <WITH> holdType = holdType()] <CURSOR> c=identifier() <AS>
s=<STRING>
+		  [ withtoken = <WITH> holdType = holdType()] 
+	      <CURSOR> qi=qualifiedIdentifier() <AS> s=<STRING>
 	{
 		sVal = stringValue(s.image);
 		try {
+			Session sn = findSession(qi.getSessionName());
+			
 			st = theConnection.createStatement(
 				scrollType, ResultSet.CONCUR_READ_ONLY, holdType);
 			JDBCDisplayUtil.checkNotNull(st,"cursor");
-			st.setCursorName(c);
+			st.setCursorName(qi.getLocalName());
 			rs = st.executeQuery(sVal);
 			JDBCDisplayUtil.checkNotNull(rs,"cursor");
-			Session sn = currentConnEnv.getSession();
-			sn.addCursorStatement(c,st);
-			sn.addCursor(c,rs);
+			sn.addCursorStatement(qi.getLocalName(),st);
+			sn.addCursor(qi.getLocalName(),rs);
 		} catch (SQLException e) {
 			if (rs!=null) rs.close();
 			if (st!=null) st.close();
@@ -2248,18 +2292,13 @@
 :
 {
 	int row;
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<ABSOLUTE> row = intLiteral() c=identifier()
+	<ABSOLUTE> row = intLiteral() qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return utilInstance.absolute(rs, row);
 	}
 }
@@ -2270,18 +2309,13 @@
 :
 {
 	int row;
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<RELATIVE> row = intLiteral() c=identifier()
+	<RELATIVE> row = intLiteral() qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return utilInstance.relative(rs, row);
 	}
 }
@@ -2291,18 +2325,13 @@
 throws SQLException
 :
 {
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<BEFORE> <FIRST> c=identifier()
+	<BEFORE> <FIRST> qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return utilInstance.beforeFirst(rs);
 	}
 }
@@ -2312,18 +2341,13 @@
 throws SQLException
 :
 {
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<FIRST> c=identifier()
+	<FIRST> qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return utilInstance.first(rs);
 	}
 }
@@ -2333,17 +2357,13 @@
 throws SQLException
 :
 {
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<NEXT> c=identifier()
+	<NEXT> qi=qualifiedIdentifier()
 	{
-		haveConnection();
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		// Verify that we have JDBC 2.0
+		ResultSet rs = findCursor(qi);
 		return new ijRowResult(rs, rs.next());
 	}
 }
@@ -2353,18 +2373,13 @@
 throws SQLException
 :
 {
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<AFTER> <LAST> c=identifier()
+	<AFTER> <LAST> qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return utilInstance.afterLast(rs);
 	}
 }
@@ -2374,18 +2389,13 @@
 throws SQLException
 :
 {
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<LAST> c=identifier()
+	<LAST> qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return utilInstance.last(rs);
 	}
 }
@@ -2395,18 +2405,13 @@
 throws SQLException
 :
 {
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 }
 {
-	<PREVIOUS> c=identifier()
+	<PREVIOUS> qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return utilInstance.previous(rs);
 	}
 }
@@ -2416,18 +2421,13 @@
 throws SQLException
 :
 {
-	ResultSet rs;
-	String c;
+	QualifiedIdentifier qi;
 }
 {
-	<GETCURRENTROWNUMBER> c=identifier()
+	<GETCURRENTROWNUMBER> qi=qualifiedIdentifier()
 	{
-		haveConnection();
 		// Verify that we have JDBC 2.0
-		Session s = currentConnEnv.getSession();
-		rs = (ResultSet) s.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-
+		ResultSet rs = findCursor(qi);
 		return new ijVectorResult(utilInstance.getCurrentRowNumber(rs), null);
 	}
 }
@@ -2437,23 +2437,22 @@
 throws SQLException
 :
 {
-	String c;
-	ResultSet rs;
+	QualifiedIdentifier qi;
 	Statement s;
 }
 {
-	<CLOSE> c=identifier()
+	<CLOSE> qi=qualifiedIdentifier()
 	{
-		haveConnection();
-		Session sn = currentConnEnv.getSession();
-		rs = (ResultSet) sn.getCursor(c);
-		JDBCDisplayUtil.checkNotNull(rs,"cursor");
-		s = (Statement) sn.getCursorStatement(c);
-		JDBCDisplayUtil.checkNotNull(s,"cursor");
+		Session sn = findSession(qi.getSessionName());
+		
+		ResultSet rs = sn.getCursor(qi.getLocalName());
+		JDBCDisplayUtil.checkNotNull(rs,"cursor " + qi);
+		s = (Statement) sn.getCursorStatement(qi.getLocalName());
+		JDBCDisplayUtil.checkNotNull(s,"cursor" + qi);
 		rs.close();
 		s.close();
-		sn.removeCursor(c);
-		sn.removeCursorStatement(c);
+		sn.removeCursor(qi.getLocalName());
+		sn.removeCursorStatement(qi.getLocalName());
 
 		return null;
 	}
@@ -2521,31 +2520,31 @@
 throws SQLException
 :
 {
-	String i = null;
+	QualifiedIdentifier qi = null;
 	Token s = null;
 	PreparedStatement ps;
 	String sVal = null;
 
-	String iUsing = null;
+	QualifiedIdentifier qiUsing = null;
 	Token sUsing = null;
 	Token	usingObject = null;
 }
 {
 	<EXECUTE> 
-	( i=identifier()
+	( qi=qualifiedIdentifier()
 	| s=<STRING>
 	)
-	( <USING> ( iUsing=identifier()
+	( <USING> ( qiUsing=qualifiedIdentifier()
 			| sUsing=<STRING>
 			)
 	)?
 	{
-	    if (iUsing!=null || sUsing!=null) { // parameters in use
+	    if (qiUsing!=null || sUsing!=null) { // parameters in use
 			String sUsingVal = null;
 			PreparedStatement psUsing;
 			SQLWarning warns = null;
 
-			haveConnection();
+			// haveConnection();
 
 			/*
 				Steps:
@@ -2559,9 +2558,8 @@
 				get the prepared statement
 			 */
 			boolean closeWhenDone = false; // will we close the ps when done?
-    		if (i!=null) {
-				ps = (PreparedStatement) currentConnEnv.getSession().getPreparedStatement(i);
-				JDBCDisplayUtil.checkNotNull(ps,"prepared statement "+i);
+    		if (qi!=null) {
+    			ps = findPreparedStatement(qi);
     		}
     		else { // (s!=null)
 				sVal = stringValue(s.image);
@@ -2575,9 +2573,8 @@
 			/*
 				execute the using statement
 			 */
-    		if (iUsing!=null) {
-				psUsing = (PreparedStatement) currentConnEnv.getSession().getPreparedStatement(iUsing);
-				JDBCDisplayUtil.checkNotNull(psUsing,"prepared statement "+iUsing);
+    		if (qiUsing!=null) {
+    			psUsing = findPreparedStatement(qiUsing);
     		}
     		else { // (sUsing!=null)
 				sUsingVal = stringValue(sUsing.image);
@@ -2668,10 +2665,9 @@
 				throw ijException.noUsingResults();
 		}
 		else { // no parameters in use
-	    	if (i!=null) {
+	    	if (qi!=null) {
 				haveConnection();
-				ps = (PreparedStatement) currentConnEnv.getSession().getPreparedStatement(i);
-				JDBCDisplayUtil.checkNotNull(ps,"prepared statement "+i);
+				ps = findPreparedStatement(qi);
 				ps.execute();
 
 				return new ijStatementResult(ps,false);
@@ -2699,12 +2695,12 @@
 :
 {
 	Token s = null;
-	String n = null;
+	QualifiedIdentifier qi;
 }
 {
-	<ASYNC> n=identifier() s=<STRING>
+	<ASYNC> qi=qualifiedIdentifier() s=<STRING>
 	{
-	    return executeAsync(stringValue(s.image), n);
+	    return executeAsync(stringValue(s.image), qi);
 	}
 }
 
@@ -2724,13 +2720,14 @@
 :
 {
 	Token s = null;
-	String n = null;
+	QualifiedIdentifier qi;
 }
 {
-	<WAIT> <FOR> n=identifier()
+	<WAIT> <FOR> qi=qualifiedIdentifier()
 	{
-		AsyncStatement as = currentConnEnv.getSession().getAsyncStatement(n);
-		if (as == null) throw ijException.noSuchAsyncStatement(n);
+		Session sn = findSession(qi.getSessionName());
+		AsyncStatement as = sn.getAsyncStatement(qi.getLocalName());
+		if (as == null) throw ijException.noSuchAsyncStatement(qi.toString());
 		try {
 		    as.join(); // we wait for it to finish.
 		} catch (InterruptedException ie) {
@@ -2752,18 +2749,17 @@
 throws SQLException
 :
 {
-	String i;
+	QualifiedIdentifier qi;
 	PreparedStatement ps;
 }
 {
-	<REMOVE> i=identifier()
+	<REMOVE> qi=qualifiedIdentifier()
 	{
-		haveConnection();
-		Session s = currentConnEnv.getSession();
-		ps = (PreparedStatement) s.getPreparedStatement(i);
-		JDBCDisplayUtil.checkNotNull(ps,"prepared statement "+i);
+		Session s = findSession(qi.getSessionName());
+		ps = (PreparedStatement) s.getPreparedStatement(qi.getLocalName());
+		JDBCDisplayUtil.checkNotNull(ps,"prepared statement "+qi);
 		ps.close();
-		s.removePreparedStatement(i);
+		s.removePreparedStatement(qi.getLocalName());
 
 		return null;
 	}
@@ -3087,6 +3083,27 @@
 }
 
 /**
+	A qualified identifier is localName [ <AT> sessionName ]
+*/
+QualifiedIdentifier
+qualifiedIdentifier() :
+{
+	String	sn	= null;
+	String	ln	= null;
+}
+{
+	ln=identifier() [ <AT> sn=identifier() ]
+	{
+		if (sn == null) {
+			haveConnection();
+			sn = currentConnEnv.getSession().getName();
+		}
+		
+		return new QualifiedIdentifier(sn, ln);
+	}
+}
+
+/**
     A case/connection respectful identifier.
 
     Like an ordinary identifier(), but require a connection in order



Mime
View raw message