You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2014/02/03 16:11:40 UTC

svn commit: r1563944 - in /db/derby/code/trunk: java/engine/org/apache/derby/vti/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/ tools/javadoc/

Author: rhillegas
Date: Mon Feb  3 15:11:40 2014
New Revision: 1563944

URL: http://svn.apache.org/r1563944
Log:
DERBY-6117: Add a context-aware table function which could be used as an example in user docs; commit derby-6117-03-aa-ArchiveVTI.diff.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/vti/ForwardingVTI.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ArchiveVTI.java   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java
    db/derby/code/trunk/tools/javadoc/publishedapi.ant

Modified: db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java?rev=1563944&r1=1563943&r2=1563944&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/vti/ForeignTableVTI.java Mon Feb  3 15:11:40 2014
@@ -120,7 +120,7 @@ import org.apache.derby.iapi.util.IdUtil
  * select lastName from foreignEmployee where employeeID = 2;
  * </pre>
  */
-public	class   ForeignTableVTI extends VTITemplate implements  RestrictedVTI
+public	class   ForeignTableVTI extends ForwardingVTI implements  RestrictedVTI
 {
     ////////////////////////////////////////////////////////////////////////
     //
@@ -138,7 +138,9 @@ public	class   ForeignTableVTI extends V
 
     private String  _foreignSchemaName;
     private String  _foreignTableName;
+    
     private String  _connectionURL;
+    private Connection  _foreignConnection;     // if null, we use _connectionURL to make a Connection
 
     private String[]    _columnNames;
     private Restriction _restriction;
@@ -147,7 +149,6 @@ public	class   ForeignTableVTI extends V
     // the actual query
     private int[]               _columnNumberMap;
     private PreparedStatement   _foreignPreparedStatement;
-    private ResultSet           _foreignResultSet;
 
     ////////////////////////////////////////////////////////////////////////
     //
@@ -155,6 +156,23 @@ public	class   ForeignTableVTI extends V
     //
     ////////////////////////////////////////////////////////////////////////
 
+    /**
+     * <p>
+     * Construct from the foreign schema and table name and a foreign connection.
+     * </p>
+     */
+    public  ForeignTableVTI
+        (
+         String foreignSchemaName,
+         String foreignTableName,
+         Connection foreignConnection
+         )
+    {
+        _foreignSchemaName = foreignSchemaName;
+        _foreignTableName = foreignTableName;
+        _foreignConnection = foreignConnection;
+    }
+    
     protected  ForeignTableVTI
         (
          String foreignSchemaName,
@@ -237,103 +255,28 @@ public	class   ForeignTableVTI extends V
             _restriction = null;
             _columnNumberMap = null;
 
-            if ( _foreignResultSet != null ) { _foreignResultSet.close(); }
+            if ( getWrappedResultSet() != null ) { getWrappedResultSet().close(); }
             if ( _foreignPreparedStatement != null ) { _foreignPreparedStatement.close(); }
 
-            _foreignResultSet = null;
+            wrapResultSet( null );
             _foreignPreparedStatement = null;
+            _foreignConnection = null;
         }
     }
 
     public  boolean next()  throws SQLException
     {
-        if ( !isClosed() && (_foreignResultSet == null) )
+        if ( !isClosed() && (getWrappedResultSet() == null) )
         {
             _foreignPreparedStatement = prepareStatement
-                ( getForeignConnection( _connectionURL ), makeQuery() );
-            _foreignResultSet = _foreignPreparedStatement.executeQuery();
+                ( getForeignConnection( _connectionURL, _foreignConnection ), makeQuery() );
+            wrapResultSet( _foreignPreparedStatement.executeQuery() );
         }
 
-        return _foreignResultSet.next();
+        return getWrappedResultSet().next();
     }
 
-    public boolean isClosed() { return (_connectionURL == null); }
-
-    public  boolean wasNull()   throws SQLException
-    { return _foreignResultSet.wasNull(); }
-
-    public  ResultSetMetaData   getMetaData()   throws SQLException
-    { return _foreignResultSet.getMetaData(); }
-
-    public  InputStream 	getAsciiStream(int i) throws SQLException
-    { return _foreignResultSet.getAsciiStream( mapColumnNumber( i ) ); }
-    
-    public  BigDecimal 	getBigDecimal(int i) throws SQLException
-    { return _foreignResultSet.getBigDecimal( mapColumnNumber( i ) ); }
-
-    @Deprecated
-    public  BigDecimal 	getBigDecimal(int i, int scale) throws SQLException
-    { return _foreignResultSet.getBigDecimal( mapColumnNumber( i ), scale ); }
-    
-    public  InputStream 	getBinaryStream(int i)  throws SQLException
-    { return _foreignResultSet.getBinaryStream( mapColumnNumber( i ) ); }
-    
-    public  Blob 	getBlob(int i)  throws SQLException
-    { return _foreignResultSet.getBlob( mapColumnNumber( i ) ); }
-    
-    public  boolean 	getBoolean(int i) throws SQLException
-    { return _foreignResultSet.getBoolean( mapColumnNumber( i ) ); }
-    
-    public  byte 	getByte(int i)    throws SQLException
-    { return _foreignResultSet.getByte( mapColumnNumber( i ) ); }
-    
-    public  byte[] 	getBytes(int i) throws SQLException
-    { return _foreignResultSet.getBytes( mapColumnNumber( i ) ); }
-    
-    public  Reader 	getCharacterStream(int i) throws SQLException
-    { return _foreignResultSet.getCharacterStream( mapColumnNumber( i ) ); }
-
-    public  Clob 	getClob(int i)  throws SQLException
-    { return _foreignResultSet.getClob( mapColumnNumber( i ) ); }
-
-    public  Date 	getDate(int i)  throws SQLException
-    { return _foreignResultSet.getDate( mapColumnNumber( i ) ); }
-
-    public  Date 	getDate(int i, Calendar cal)    throws SQLException
-    { return _foreignResultSet.getDate( mapColumnNumber( i ), cal ); }
-
-    public  double 	getDouble(int i)    throws SQLException
-    { return _foreignResultSet.getDouble( mapColumnNumber( i ) ); }
-
-    public  float 	getFloat(int i) throws SQLException
-    { return _foreignResultSet.getFloat( mapColumnNumber( i ) ); }
-
-    public  int 	getInt(int i)   throws SQLException
-    { return _foreignResultSet.getInt( mapColumnNumber( i ) ); }
-
-    public  long 	getLong(int i)  throws SQLException
-    { return _foreignResultSet.getLong( mapColumnNumber( i ) ); }
-
-    public  Object 	getObject(int i)    throws SQLException
-    { return _foreignResultSet.getObject( mapColumnNumber( i ) ); }
-
-    public  short 	getShort(int i) throws SQLException
-    { return _foreignResultSet.getShort( mapColumnNumber( i ) ); }
-
-    public  String 	getString(int i)    throws SQLException
-    { return _foreignResultSet.getString( mapColumnNumber( i ) ); }
-
-    public  Time 	getTime(int i)  throws SQLException
-    { return _foreignResultSet.getTime( mapColumnNumber( i ) ); }
-
-    public  Time 	getTime(int i, Calendar cal)    throws SQLException
-    { return _foreignResultSet.getTime( mapColumnNumber( i ), cal ); }
-
-    public  Timestamp 	getTimestamp(int i) throws SQLException
-    { return _foreignResultSet.getTimestamp( mapColumnNumber( i ) ); }
-
-    public  Timestamp 	getTimestamp(int i, Calendar cal)   throws SQLException
-    { return _foreignResultSet.getTimestamp( mapColumnNumber( i ), cal ); }
+    public boolean isClosed() { return ( (_connectionURL == null) && (_foreignConnection == null) ); }
 
     ////////////////////////////////////////////////////////////////////////
     //
@@ -365,9 +308,11 @@ public	class   ForeignTableVTI extends V
     ////////////////////////////////////////////////////////////////////////
 
     private static  Connection  getForeignConnection
-        ( String connectionURL )
+        ( String connectionURL, Connection foreignConnection )
         throws SQLException
     {
+        if ( foreignConnection != null ) { return foreignConnection; }
+        
         Connection  conn = _connections.get( connectionURL );
 
         if ( conn == null )
@@ -453,7 +398,8 @@ public	class   ForeignTableVTI extends V
      * foreign query.
      * </p>
      */
-    private int mapColumnNumber( int derbyNumber )
+    @Override
+    protected int mapColumnNumber( int derbyNumber )
     {
         return _columnNumberMap[ derbyNumber - 1 ];
     }

Added: db/derby/code/trunk/java/engine/org/apache/derby/vti/ForwardingVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/vti/ForwardingVTI.java?rev=1563944&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/vti/ForwardingVTI.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/vti/ForwardingVTI.java Mon Feb  3 15:11:40 2014
@@ -0,0 +1,185 @@
+/*
+
+   Derby - Class org.apache.derby.vti.ForwardingVTI
+
+   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.vti;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.derby.iapi.services.io.ArrayUtil;
+import org.apache.derby.iapi.util.IdUtil;
+
+/**
+ * <p>
+ * This class contains a table function which forwards its behavior to
+ * another ResultSet wrapped inside it.
+ * </p>
+ */
+public	class   ForwardingVTI extends VTITemplate
+{
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	CONSTANTS
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	STATE
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    private ResultSet           _wrappedResultSet;
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	CONSTRUCTOR
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Construct from another ResultSet.
+     * </p>
+     */
+    public  ForwardingVTI() { super(); }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	SUPPORT FUNCTIONS
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /** Poke in another ResultSet to which we forward method calls. */
+    public  final   void    wrapResultSet( ResultSet wrappedResultSet ) { _wrappedResultSet = wrappedResultSet; }
+
+    /** Get the wrapped ResultSet. */
+    public  final   ResultSet   getWrappedResultSet() { return _wrappedResultSet; }
+
+    /** This overridable method maps the ForwardVTI's column numbers to those of the wrapped ResultSet */
+    protected int mapColumnNumber( int ourColumnNumber )    { return ourColumnNumber; }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	ResultSet BEHAVIOR
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    public  void    close() throws SQLException { _wrappedResultSet.close(); }
+
+    public  boolean next()  throws SQLException { return _wrappedResultSet.next(); }
+
+    public boolean isClosed() throws SQLException { return _wrappedResultSet.isClosed(); }
+
+    public  boolean wasNull()   throws SQLException
+    { return _wrappedResultSet.wasNull(); }
+
+    public  ResultSetMetaData   getMetaData()   throws SQLException
+    { return _wrappedResultSet.getMetaData(); }
+
+    public  InputStream 	getAsciiStream(int i) throws SQLException
+    { return _wrappedResultSet.getAsciiStream( mapColumnNumber( i ) ); }
+    
+    public  BigDecimal 	getBigDecimal(int i) throws SQLException
+    { return _wrappedResultSet.getBigDecimal( mapColumnNumber( i ) ); }
+
+    @Deprecated
+    public  BigDecimal 	getBigDecimal(int i, int scale) throws SQLException
+    { return _wrappedResultSet.getBigDecimal( mapColumnNumber( i ), scale ); }
+    
+    public  InputStream 	getBinaryStream(int i)  throws SQLException
+    { return _wrappedResultSet.getBinaryStream( mapColumnNumber( i ) ); }
+    
+    public  Blob 	getBlob(int i)  throws SQLException
+    { return _wrappedResultSet.getBlob( mapColumnNumber( i ) ); }
+    
+    public  boolean 	getBoolean(int i) throws SQLException
+    { return _wrappedResultSet.getBoolean( mapColumnNumber( i ) ); }
+    
+    public  byte 	getByte(int i)    throws SQLException
+    { return _wrappedResultSet.getByte( mapColumnNumber( i ) ); }
+    
+    public  byte[] 	getBytes(int i) throws SQLException
+    { return _wrappedResultSet.getBytes( mapColumnNumber( i ) ); }
+    
+    public  Reader 	getCharacterStream(int i) throws SQLException
+    { return _wrappedResultSet.getCharacterStream( mapColumnNumber( i ) ); }
+
+    public  Clob 	getClob(int i)  throws SQLException
+    { return _wrappedResultSet.getClob( mapColumnNumber( i ) ); }
+
+    public  Date 	getDate(int i)  throws SQLException
+    { return _wrappedResultSet.getDate( mapColumnNumber( i ) ); }
+
+    public  Date 	getDate(int i, Calendar cal)    throws SQLException
+    { return _wrappedResultSet.getDate( mapColumnNumber( i ), cal ); }
+
+    public  double 	getDouble(int i)    throws SQLException
+    { return _wrappedResultSet.getDouble( mapColumnNumber( i ) ); }
+
+    public  float 	getFloat(int i) throws SQLException
+    { return _wrappedResultSet.getFloat( mapColumnNumber( i ) ); }
+
+    public  int 	getInt(int i)   throws SQLException
+    { return _wrappedResultSet.getInt( mapColumnNumber( i ) ); }
+
+    public  long 	getLong(int i)  throws SQLException
+    { return _wrappedResultSet.getLong( mapColumnNumber( i ) ); }
+
+    public  Object 	getObject(int i)    throws SQLException
+    { return _wrappedResultSet.getObject( mapColumnNumber( i ) ); }
+
+    public  short 	getShort(int i) throws SQLException
+    { return _wrappedResultSet.getShort( mapColumnNumber( i ) ); }
+
+    public  String 	getString(int i)    throws SQLException
+    { return _wrappedResultSet.getString( mapColumnNumber( i ) ); }
+
+    public  Time 	getTime(int i)  throws SQLException
+    { return _wrappedResultSet.getTime( mapColumnNumber( i ) ); }
+
+    public  Time 	getTime(int i, Calendar cal)    throws SQLException
+    { return _wrappedResultSet.getTime( mapColumnNumber( i ), cal ); }
+
+    public  Timestamp 	getTimestamp(int i) throws SQLException
+    { return _wrappedResultSet.getTimestamp( mapColumnNumber( i ) ); }
+
+    public  Timestamp 	getTimestamp(int i, Calendar cal)   throws SQLException
+    { return _wrappedResultSet.getTimestamp( mapColumnNumber( i ), cal ); }
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/vti/ForwardingVTI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ArchiveVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ArchiveVTI.java?rev=1563944&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ArchiveVTI.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ArchiveVTI.java Mon Feb  3 15:11:40 2014
@@ -0,0 +1,231 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.ArchiveVTI
+
+   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.derbyTesting.functionTests.tests.lang;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import org.apache.derby.vti.AwareVTI;
+import org.apache.derby.vti.ForeignTableVTI;
+import org.apache.derby.vti.ForwardingVTI;
+import org.apache.derby.vti.RestrictedVTI;
+import org.apache.derby.vti.Restriction;
+import org.apache.derby.vti.VTIContext;
+
+/**
+ * <p>
+ * This table function acts like a union view on a set of archive tables.
+ * The idea is that the old contents of a main table are periodically moved to
+ * archive tables whose names start with $tableName$suffix. Each bulk
+ * move of rows results in the creation of a new archive table. The archive
+ * tables live in the same schema as the main table and have its shape. This
+ * table function unions the main table together with all of its archived snapshots.
+ * So, for instance, you might have the following set of tables, which this table
+ * function unions together:
+ * </p>
+ *
+ * <pre>
+ *  T1
+ *  T1_ARCHIVE_1
+ *  T1_ARCHIVE_2
+ *   ...
+ *  T1_ARCHIVE_N
+ * </pre>
+ *
+ * <p>
+ * This table function may appear in user documentation. If you change the behavior
+ * of this table function, make sure that you adjust the user documentation linked from
+ * DERBY-6117.
+ * </p>
+ */
+public class ArchiveVTI extends ForwardingVTI implements AwareVTI, RestrictedVTI
+{
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	CONSTANTS
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	STATE
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    private Connection  _connection;
+    private String          _archiveSuffix;
+    private VTIContext  _vtiContext;
+    private ArrayList<String>   _tableNames;
+    private int         _tableIdx;
+    
+    private String[]    _columnNames;
+    private Restriction _restriction;
+
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  TABLE FUNCTION
+    //
+    /////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Entry point for creating an ArchiveVTI which is bound to a Derby table function
+     * by a CREATE FUNCTION statement which looks like this:
+     * </p>
+     *
+     * <pre>
+     *
+     * </pre>
+     *
+     * @param archiveSuffix All of the archive tables have names of the form $tablename$archiveSuffix.
+     */
+    public  static  ArchiveVTI  archiveVTI( String archiveSuffix ) throws SQLException
+    { return new ArchiveVTI( archiveSuffix ); }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	CONSTRUCTOR
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /** Construct from the suffix which flags all of the relevant tables. */
+    public  ArchiveVTI( String archiveSuffix )    throws SQLException
+    {
+        _connection = DriverManager.getConnection( "jdbc:default:connection" );
+        _archiveSuffix = archiveSuffix;
+    }
+
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  AwareVTI BEHAVIOR
+    //
+    /////////////////////////////////////////////////////////////////////////
+
+    public  VTIContext  getContext() { return _vtiContext; }
+    public  void    setContext( VTIContext context )    { _vtiContext = context; }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	RestrictedVTI BEHAVIOR
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    public  void    initScan
+        ( String[] columnNames, Restriction restriction )
+        throws SQLException
+    {
+        _columnNames = new String[ columnNames.length ];
+        System.arraycopy( columnNames, 0, _columnNames, 0, columnNames.length );
+        _restriction = restriction;
+    }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	ResultSet BEHAVIOR
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    public boolean next()   throws SQLException
+    {
+        if ( _tableNames == null )
+        {
+            getTableNames();
+            _tableIdx = 0;
+            loadResultSet();
+        }
+
+        while ( !super.next() )
+        {
+            _tableIdx++;
+            if ( _tableIdx >= _tableNames.size() ) { return false; }
+            loadResultSet();
+        }
+
+        return true;
+    }
+
+    public  void    close() throws SQLException
+    {
+        if ( getWrappedResultSet() != null ) { getWrappedResultSet().close(); }
+        wrapResultSet( null );
+        _connection = null;
+    }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	UTILITY METHODS
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Get cursors on all the tables which we are going to union together.
+     * </p>
+     */
+    private void    getTableNames() throws SQLException
+    {
+        _tableNames = new ArrayList<String>();
+        _tableNames.add( getContext().vtiTable() );
+
+        DatabaseMetaData    dbmd = getConnection().getMetaData();
+        ResultSet   candidates = dbmd.getTables
+            ( null, getContext().vtiSchema(), getContext().vtiTable() + _archiveSuffix + "%", null );
+
+        while ( candidates.next() )
+        {
+            _tableNames.add( candidates.getString( "TABLE_NAME" ) );
+        }
+        candidates.close();
+    }
+    
+    /**
+     * <p>
+     * Compile the query against the next table and use its ResultSet until
+     * it's drained.
+     * </p>
+     */
+    private void    loadResultSet() throws SQLException
+    {
+        if ( getWrappedResultSet() != null ) { getWrappedResultSet().close(); }
+        
+        ForeignTableVTI     nextRS = new ForeignTableVTI
+            ( getContext().vtiSchema(), _tableNames.get( _tableIdx ), getConnection() );
+        nextRS.initScan( _columnNames, _restriction );
+
+        wrapResultSet( nextRS );
+    }
+
+    /**
+     * <p>
+     * Get this database session's connection to the database.
+     * </p>
+     */
+    private Connection  getConnection() throws SQLException
+    {
+        return _connection;
+    }
+    
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ArchiveVTI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java?rev=1563944&r1=1563943&r2=1563944&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java Mon Feb  3 15:11:40 2014
@@ -168,6 +168,64 @@ public class AwareVTITest  extends Gener
         assertResults( ucv, rows, false );
     }
     
+    /**
+     * <p>
+     * Test the ArchiveVTI table function. This table function may be an example
+     * in the Derby user docs. If you break this table function, then you need to
+     * adjust the user docs accordingly. That documentation should be linked from
+     * DERBY-6117.
+     * </p>
+     */
+    public void test_03_ArchiveVTI() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement
+            (
+             conn,
+             "create table t1\n" +
+             "(\n" +
+             "    keyCol int,\n" +
+             "    aCol int,\n" +
+             "    bCol int\n" +
+             ")\n"
+             );
+        goodStatement( conn, "create table t1_archive_001 as select * from t1 with no data" );
+        goodStatement( conn, "create table t1_archive_002 as select * from t1 with no data" );
+        goodStatement( conn, "insert into t1_archive_002 values ( 1, 100, 1000 ), ( 2, 200, 2000 ), ( 3, 300, 3000 )" );
+        goodStatement( conn, "insert into t1_archive_001 values ( 4, 400, 4000 ), ( 5, 500, 5000 ), ( 6, 600, 6000 )" );
+        goodStatement( conn, "insert into t1 values ( 7, 700, 7000 ), ( 8, 800, 8000 ), ( 9, 900, 9000 )" );
+        goodStatement
+            (
+             conn,
+             "create function t1( archiveSuffix varchar( 32672 ) ) returns table\n" +
+             "(\n" +
+             "    keyCol int,\n" +
+             "    aCol int,\n" +
+             "    bCol int\n" +
+             ")\n" +
+             "language java parameter style derby_jdbc_result_set reads sql data\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.ArchiveVTI.archiveVTI'\n"
+             );
+        
+        assertResults
+            (
+             conn,
+             "select keyCol, bCol from table( t1( '_ARCHIVE_' ) ) s\n" +
+             "where keyCol between 3 and 7\n" +
+             "order by keyCol\n",
+             new String[][]
+             {
+                 { "3", "3000" },
+                 { "4", "4000" },
+                 { "5", "5000" },
+                 { "6", "6000" },
+                 { "7", "7000" },
+             },
+             false
+             );
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // ROUTINES

Modified: db/derby/code/trunk/tools/javadoc/publishedapi.ant
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/javadoc/publishedapi.ant?rev=1563944&r1=1563943&r2=1563944&view=diff
==============================================================================
--- db/derby/code/trunk/tools/javadoc/publishedapi.ant (original)
+++ db/derby/code/trunk/tools/javadoc/publishedapi.ant Mon Feb  3 15:11:40 2014
@@ -53,7 +53,9 @@ org/apache/derby/tools/dblook.java
 # package: org.apache.derby.vti
 
 org/apache/derby/vti/AwareVTI.java
+org/apache/derby/vti/AwareVTI.java
 org/apache/derby/vti/ForeignTableVTI.java
+org/apache/derby/vti/ForwardingVTI.java
 org/apache/derby/vti/RestrictedVTI.java
 org/apache/derby/vti/Restriction.java
 org/apache/derby/vti/StringColumnVTI.java