db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject svn commit: r512109 [1/2] - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/ engine/org/apache/derby/impl/load/ engine/org/apache/derby/impl/sql/catalog/ engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTe...
Date Tue, 27 Feb 2007 02:06:38 GMT
Author: suresht
Date: Mon Feb 26 18:06:37 2007
New Revision: 512109

URL: http://svn.apache.org/viewvc?view=rev&rev=512109
Log:
DERBY-378 (partial)
This patch adds some code required to support import/export of table with
clob, blob(large objects) data types. Clob/Blobs data can be exported to 
an external file that different from the main export file. Location of the 
lob data in the external file will be written to the main export file. 
When writing the lob data to an external file, no conversion is done for the 
binary data , clob data will be written using the user specified code set. 

1)This patch implements following two new procedure to support 
exporting LOBS to an external file name:

SYSCS_UTIL.SYSCS_EXPORT_TABLE_LOBS_IN_EXTFILE(..)
SYSCS_UTIL.SYSCS_EXPORT_QUERY_LOBS_IN_EXTFILE(..)

2)This patch implements following two new procedure that allow
 import of large object data  stored in a external file.
(for example exported previously using the above export procedures). 

SYSCS_UTIL.SYSCS_IMPORT_DATA_LOBS_IN_EXTFILE(...)
SYSCS_UTIL.SYSCS_IMPORT_TABLE_LOBS_IN_EXTFILE(..)

3) import/export of table with clob,blob types will also work 
with single input/output file, using the exiting import/export
procedures. In this can binary data is converted into hex format before 
exporting and the data hex is converted to binary on import. 
Clob data is exported similar to other char types. 



Added:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportBlob.java   (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Export.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportAbstract.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteDataAbstract.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportReadData.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportResultSetMetaData.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ieptests.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/importExport.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk16/ieptests.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk16/importExport.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/iepnegativetests.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/iepnegativetests_ES.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ieptests.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/importExport.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLTypeAndOpsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/iepnegativetests.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ieptests.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/importExport.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java Mon Feb 26 18:06:37 2007
@@ -1111,6 +1111,39 @@
 		conn.commit();
 	}
 
+
+    /**
+     * Export data from a table to given files. Large objects 
+     * are exported to a separate file and the reference to it is written 
+     * in the main export file. 
+     * <p>
+     * Will be called by system procedure:
+     * SYSCS_EXPORT_TABLE_LOBS_IN_EXTFILE(IN SCHEMANAME  VARCHAR(128), 
+     * IN TABLENAME    VARCHAR(128),  IN FILENAME VARCHAR(32672) , 
+     * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
+     * IN CODESET VARCHAR(128), IN LOBSFILENAME VARCHAR(32672))
+     * @exception  StandardException  Standard exception policy.
+     **/
+    public static void SYSCS_EXPORT_TABLE_LOBS_IN_EXTFILE(
+    String  schemaName,
+    String  tableName,
+    String  fileName,
+    String  columnDelimiter,
+    String  characterDelimiter,
+    String  codeset,
+    String  lobsFileName)
+        throws SQLException
+    {
+        Connection conn = getDefaultConn();
+        Export.exportTable(conn, schemaName , tableName , fileName ,
+                           columnDelimiter , characterDelimiter, 
+                           codeset, lobsFileName);
+        //export finished successfully, issue a commit 
+        conn.commit();
+    }
+
+	
+
 	
 	/**
      * Export data from a  select statement to given file.
@@ -1139,6 +1172,43 @@
 		conn.commit();
 	}
 
+    
+
+    /**
+     * Export data from a  select statement to given file. Large objects 
+     * are exported to a separate file and the reference to it is written 
+     * in the main export file. 
+     * <p>
+     * Will be called as 
+     * SYSCS_EXPORT_QUERY_LOBS_IN_EXTFILE(IN SELECTSTATEMENT  VARCHAR(32672),
+     * IN FILENAME VARCHAR(32672) , 
+     * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
+     * IN CODESET VARCHAR(128), IN LOBSFILENAME VARCHAR(32672))
+     *
+     * @exception  StandardException  Standard exception policy.
+     **/
+    public static void SYSCS_EXPORT_QUERY_LOBS_IN_EXTFILE(
+    String  selectStatement,
+    String  fileName,
+    String  columnDelimiter,
+    String  characterDelimiter,
+    String  codeset,
+    String  lobsFileName)
+        throws SQLException
+    {
+        Connection conn = getDefaultConn();
+        Export.exportQuery(conn, selectStatement, fileName ,
+                           columnDelimiter , characterDelimiter, 
+                           codeset, lobsFileName);
+
+        //export finished successfully, issue a commit 
+        conn.commit();
+    }
+
+
+
+
+
 	/**
      * Import  data from a given file to a table.
      * <p>
@@ -1162,7 +1232,8 @@
 		Connection conn = getDefaultConn();
 		try{
 			Import.importTable(conn, schemaName , tableName , fileName ,
-								   columnDelimiter , characterDelimiter, codeset, replace);
+                               columnDelimiter , characterDelimiter, codeset, 
+                               replace, false);
 		}catch(SQLException se)
 		{
 			//issue a rollback on any errors
@@ -1174,8 +1245,50 @@
 	}
 
 
+    /**
+     * Import  data from a given file to a table. Data for large object 
+     * columns is in an external file, the reference to it is in the main 
+     * input file. Read the lob data from the external file using the 
+     * lob location info in the main import file. 
+     * <p>
+     * Will be called by system procedure as
+     * SYSCS_IMPORT_TABLE_LOBS_IN_EXTFILE(IN SCHEMANAME  VARCHAR(128), 
+     * IN TABLENAME    VARCHAR(128),  IN FILENAME VARCHAR(32672) , 
+     * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
+     * IN CODESET VARCHAR(128), IN  REPLACE SMALLINT)
+     * @exception  StandardException  Standard exception policy.
+     **/
+    public static void SYSCS_IMPORT_TABLE_LOBS_IN_EXTFILE(
+    String  schemaName,
+    String  tableName,
+    String  fileName,
+    String  columnDelimiter,
+    String  characterDelimiter,
+    String  codeset,
+    short   replace)
+        throws SQLException
+    {
+        Connection conn = getDefaultConn();
+        try{
+            Import.importTable(conn, schemaName , tableName , fileName ,
+                               columnDelimiter , characterDelimiter, 
+                               codeset, replace, 
+                               true //lobs in external file
+                               );
+        }catch(SQLException se)
+        {
+            //issue a rollback on any errors
+            conn.rollback();
+            throw  se;
+        }
+        //import finished successfull, commit it.
+        conn.commit();
+    }
+
+
+
 	/**
-     * Import data from a given file into the specified table columns from the 
+      * Import data from a given file into the specified table columns from the 
 	 * specified columns in the file.
      * <p>
      * Will be called as 
@@ -1204,7 +1317,7 @@
 			Import.importData(conn, schemaName , tableName ,
 								  insertColumnList, columnIndexes, fileName,
 								  columnDelimiter, characterDelimiter, 
-								  codeset, replace);
+								  codeset, replace, false);
 		}catch(SQLException se)
 		{
 			//issue a rollback on any errors
@@ -1215,6 +1328,55 @@
 		//import finished successfull, commit it.
 		conn.commit();
 	}
+
+
+    /**
+     * Import data from a given file into the specified table columns 
+     * from the  specified columns in the file. Data for large object 
+     * columns is in an  external file, the reference to it is in the 
+     * main input file. Read the lob data from the external file using 
+     * the lob location info in the main import file. 
+     * <p>
+     * Will be called as 
+     * SYSCS_IMPORT_DATA_LOBS_IN_EXTFILE(IN SCHEMANAME VARCHAR(128), 
+     *               IN TABLENAME VARCHAR(128),
+     *               IN INSERTCOLUMNLIST VARCHAR(32762), 
+     *               IN COLUMNINDEXES VARCHAR(32762),
+     *               IN FILENAME VARCHAR(32762), IN COLUMNDELIMITER CHAR(1), 
+     *               IN CHARACTERDELIMITER CHAR(1), IN CODESET VARCHAR(128), 
+     *               IN REPLACE SMALLINT)
+     *
+     * @exception  StandardException  Standard exception policy.
+     **/
+    public static void SYSCS_IMPORT_DATA_LOBS_IN_EXTFILE(
+    String  schemaName,
+    String  tableName,
+    String  insertColumnList,
+    String  columnIndexes,
+    String  fileName,
+    String  columnDelimiter,
+    String  characterDelimiter,
+    String  codeset,
+    short   replace)
+        throws SQLException
+    {
+        Connection conn = getDefaultConn();
+        try{
+            Import.importData(conn, schemaName , tableName ,
+                              insertColumnList, columnIndexes, fileName,
+                              columnDelimiter, characterDelimiter, 
+                              codeset, replace, true);
+        }catch(SQLException se)
+        {
+            //issue a rollback on any errors
+            conn.rollback();
+            throw  se;
+        }
+
+        //import finished successfull, commit it.
+        conn.commit();
+    }
+
 
 	/**
      * Perform bulk insert using the specificed vti .

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java Mon Feb 26 18:06:37 2007
@@ -48,13 +48,14 @@
 class ColumnInfo {
 
 	private ArrayList vtiColumnNames ;
-	private ArrayList insertColumnNames;
+    private ArrayList insertColumnNames;
     private ArrayList columnTypes ;
+    private ArrayList jdbcColumnTypes;
 	private int noOfColumns;
 	private ArrayList columnPositions;
 	private boolean createolumnNames = true;
 	private int expectedNumberOfCols ; //number of Columns that are suppose
-	                                       // to be in the file to imported  
+                                       // to be in the file to imported  
 	private Connection conn;
 	private String tableName;
 	private String schemaName;
@@ -81,6 +82,7 @@
 		vtiColumnNames = new ArrayList(1);
 		insertColumnNames = new ArrayList(1);
 		columnTypes = new ArrayList(1);
+        jdbcColumnTypes = new ArrayList(1);
 		noOfColumns = 0;
 		this.conn = conn;
 
@@ -187,7 +189,8 @@
 
 				insertColumnNames.add(columnName);
 				String sqlType = typeName + getTypeOption(typeName , columnSize , columnSize , decimalDigits);
-				columnTypes.add(noOfColumns , sqlType);
+				columnTypes.add(sqlType);
+                jdbcColumnTypes.add(new Integer(dataType));
 				noOfColumns++;
 			}else
 			{
@@ -210,8 +213,6 @@
 				 type == java.sql.Types.BIT ||
 				 type == java.sql.Types.JAVA_OBJECT ||
 				 type == java.sql.Types.OTHER ||
-				 type == java.sql.Types.CLOB ||
-				 type == java.sql.Types.BLOB ||
 				 type == StoredFormatIds.XML_TYPE_ID); 
 	}
 
@@ -363,6 +364,93 @@
 		return foundTable;
 	}
 
+
+    /*
+     * Returns the the expected vti data column types in a String format. 
+     * Format : (COLUMN NAME : TYPE [, COLUMN NAME : TYPE]*)
+     * eg: COLUMN1:1 (java.sql.Types.CHAR) , COLUMN2: -1(LONGVARCHAR) , 
+     * COLUMN3 : 2004 (BLOB)
+     */
+	public String getExpectedVtiColumnTypesAsString() {
+
+        StringBuffer vtiColumnTypes = new StringBuffer();
+        // expected types of data in the import file, based on 
+        // the how columns in the data file are  mapped to 
+        // the table  columns. 
+        boolean first = true;
+        for (int i =0 ; i < noOfColumns && i < vtiColumnNames.size(); i++) {
+            if (first) 
+                first = false;
+            else
+                vtiColumnTypes.append(",");
+
+            vtiColumnTypes.append(vtiColumnNames.get(i) + ":" + 
+                                  jdbcColumnTypes.get(i));
+        }   
+
+		if(first) {
+            // there is no information about column types.
+			return null;
+        }
+		else
+			return vtiColumnTypes.toString();
+	}
+
+
+    /*
+     * Get the expected vti data column types. This information was 
+     * passed earlies as string to the vti. This rourine extract the 
+     * information from the string.
+     * @param columnTypesStr  import data column type information , 
+     *                        encoded as string. 
+     * @param noOfColumns     number of columns in the import file.
+     * 
+     * @see getExpectedVtiColumnTypesAsString()
+     */
+    public static int[] getExpectedVtiColumnTypes(String columnTypesStr, 
+                                                  int noOfColumns) 
+    {
+
+        // extract the table column types. Break the comma seperated 
+        // column types into java.sql.Types int values from the columnTypes 
+        // string that got passed to the import VTI.
+
+        //eg: COLUMN1:1 (java.sql.Types.CHAR) , COLUMN2: -1(LONGVARCHAR) , 
+        //COLUMN3 : 2004 (BLOB)
+
+        int[] vtiColumnTypes = new int[noOfColumns];
+
+        // expected column type information is only available 
+        // for the columns that are being imported from the file.
+        // columns type information is not required when 
+        // a column in the data file is not one of the 
+        // imported column, just assume they are of VARCHAR type. 
+        
+        for (int i = 0 ; i < noOfColumns ; i++)
+            vtiColumnTypes[i] = java.sql.Types.VARCHAR;
+
+        StringTokenizer st = new StringTokenizer(columnTypesStr , ",");
+        while (st.hasMoreTokens()) 
+        {
+            String colTypeInfo = (st.nextToken()).trim();
+            int colTypeOffset = colTypeInfo.indexOf(":");
+
+            // column names format is "COLUMN" + columnNumner
+            int colIndex = (new Integer(colTypeInfo.substring(6, 
+                                        colTypeOffset))).intValue();
+            int colType = (new Integer(colTypeInfo.substring(
+                                          colTypeOffset+1))).intValue();
+
+            // column numbers start with 1. Check if user by mistake has 
+            // specified a column number that is large than than the 
+            // number of columns exist in the file, if that is the case
+            // don't assign the type.
+            if (colIndex <=  noOfColumns) 
+                vtiColumnTypes[colIndex-1] = colType;
+            
+        }
+        return vtiColumnTypes;
+    }
 }
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Export.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Export.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Export.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Export.java Mon Feb 26 18:06:37 2007
@@ -35,7 +35,8 @@
 public class Export extends ExportAbstract{
 
 	private String outputFileName;
-
+	/* Name of the file to  which large object data has to be exported */
+	private String lobsFileName;
 
 	private void doExport() throws SQLException
 	{
@@ -58,9 +59,9 @@
 	}
 	
 	private Export(Connection con, String schemaName , 
-					   String tableName, String selectStatement ,
-					   String outputFileName, String characterDelimeter,
-					   String columnDelimeter, String codeset)
+				   String tableName, String selectStatement ,
+				   String outputFileName, String characterDelimeter, 
+				   String columnDelimeter, String codeset)
 		throws SQLException{
 		this.con = con;
 		this.schemaName = schemaName;
@@ -77,6 +78,24 @@
 		}
 	}
 
+
+    /**
+     * Set the file name to which larg object data has to be exported, and 
+     * also set flag to indicate that large objects are exported to a 
+     * different file. 
+     * @param lobsFileName  the file to to which lob data has to be exported.
+     * @exception SQLException  if file name is null. 
+     */
+	private void setLobsExtFileName(String lobsFileName) throws SQLException
+	{
+		if (lobsFileName == null)
+			throw LoadError.dataFileNull();
+		this.lobsFileName = lobsFileName;
+		lobsInExtFile = true;
+	}
+
+
+
 	/**
 	 * SYSCS_EXPORT_TABLE  system Procedure from ij or from a Java application
 	 * invokes  this method to perform export of  a table data to a file.
@@ -103,6 +122,44 @@
 		fex.doExport();
 	}
 
+
+	
+    /**
+     * SYSCS_EXPORT_TABLE_LOBS_IN_EXTFILE system procedure from ij 
+     * or from a Java application invokes  this method to perform 
+     * export of a table data to a file. Large object data is exported 
+     * to a different file and the reference to it is stored in the
+     *  main output file. 
+     * @param con	 The Cloudscape database connection URL for the 
+     *               database containing the table
+     * @param schemaName  schema name of the table data is being exported from
+     * @param tableName   Name of the Table from which data has to be exported.
+     * @param outputFileName  Name of the file to which data has to be exported.
+     * @param columnDelimeter  Delimiter that seperates columns 
+     *                         in the output file.
+     * @param characterDelimeter Delimiter that is used to quote 
+     *                           non-numeric types.
+     * @param codeset            Codeset that should be used to 
+     *                           write the data to the file/
+     * @param lobsFileName       Name of the file to which large object 
+     *                           data has to be exported.
+     * @exception SQL Exception on errors
+     */
+
+    public static void exportTable(Connection con, String schemaName, 
+                                   String tableName, String outputFileName,  
+                                   String columnDelimeter, String characterDelimeter,
+                                   String codeset, String lobsFileName)
+        throws SQLException {
+
+        Export fex = new Export(con, schemaName, tableName, null,
+                                outputFileName,	characterDelimeter,   
+                                columnDelimeter, codeset);
+        fex.setLobsExtFileName(lobsFileName);
+        fex.doExport();
+    }
+
+
 	
 	/**
 	 * SYSCS_EXPORT_QUERY  system Procedure from ij or from a Java application
@@ -127,13 +184,53 @@
 	}
 
 
+
+    /**
+     * SYSCS_EXPORT_QUERY_LOBS_IN_EXTFILE system Procedure from ij 
+     * or from a Java application invokes this method to perform 
+     * export of the data retrieved by select  statement to a file.
+     * Large object data is exported to a different file  and the reference 
+     * to it is stored in the main output file. 
+     * @param con	 The Cloudscape database connection URL for 
+     *               the database containing the table
+     * @param selectStatement    select query that is used to export the data
+     * @param outputFileName Name of the file to  which data has to be exported.
+     * @param columnDelimeter  Delimiter that seperates columns in 
+     *                         the output file
+     * @param characterDelimeter  Delimiter that is used to quote 
+     *                            non-numeric types
+     * @param codeset Codeset that should be used to write the data to the file
+     * @param lobsFileName Name of the file to which 
+     *                     large object data has to be exported.
+     * @exception SQL Exception on errors
+     */
+    public static void exportQuery(Connection con, String selectStatement,
+                                   String outputFileName, String columnDelimeter, 
+                                   String characterDelimeter, String codeset, 
+                                   String lobsFileName)
+        throws SQLException {
+		
+        Export fex = new Export(con, null, null, selectStatement,
+                                outputFileName,characterDelimeter,
+                                columnDelimeter, codeset);
+        fex.setLobsExtFileName(lobsFileName);
+        fex.doExport();
+    }
+
+
 	/**
 	 * For internal use only
 	 * @exception	Exception if there is an error
 	 */
 	//returns the control file reader corresponding to the control file passed
 	protected ExportWriteDataAbstract getExportWriteData() throws Exception {
-		return new ExportWriteData(outputFileName, controlFileReader);
+		if (lobsInExtFile) 
+			return new ExportWriteData(outputFileName, 
+									   lobsFileName,
+									   controlFileReader);
+		else 
+			return new ExportWriteData(outputFileName,
+									   controlFileReader);
 	}
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportAbstract.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportAbstract.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportAbstract.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportAbstract.java Mon Feb 26 18:06:37 2007
@@ -26,6 +26,8 @@
 import java.sql.ResultSetMetaData;
 import java.sql.Types;
 import java.util.Date;
+import java.io.InputStream;
+import java.io.Reader;
 
 /**
  * 
@@ -40,7 +42,7 @@
   protected String entityName;  //this can be a plain table name or qualified with schema also
   protected String schemaName;
   protected String selectStatement ;
-  
+  protected boolean lobsInExtFile = false;
 
   //following makes the resultset using select * from entityName
   protected ResultSet resultSetForEntity() throws Exception {
@@ -52,15 +54,64 @@
     return rs;
   }
 
-  //convert resultset data to string array
-  public String[] getOneRowAtATime(ResultSet rs) throws Exception {
+    /** convert resultset data for the current row to string array. 
+     * If large objects are being exported to an external file, 
+     * then write the lob  data into the external file and store 
+     * the lob data location  in the string array for that column.
+     * @param rs   resultset that contains the data to export.
+     * @param isLargeBinary  boolean array, whose elements will
+     *                      be true, if the column type is blob/or 
+     *                      other large binary type, otherwise false. 
+     * @param isLargeChar   boolean array, whose elements will
+     *                      be true, if the column type is clob/ 
+     *                      other large char type, otherwise false. 
+     * @return A string array of the row data to write to export file.
+     * @exception  Exception  if any errors during conversion. 
+     */
+    private String[] getOneRowAtATime(ResultSet rs, 
+                                      boolean[] isLargeBinary, 
+                                      boolean[] isLargeChar) 
+        throws Exception 
+	{
     int columnCount = exportResultSetForObject.getColumnCount();
 
 	ResultSetMetaData rsm=rs.getMetaData();
     if (rs.next()){
        String[] rowObjects = new String[columnCount];
        for (int colNum = 0; colNum < columnCount; colNum++) {
-       		rowObjects[colNum]=rs.getString(colNum + 1);
+           if (lobsInExtFile && 
+               (isLargeChar[colNum] || isLargeBinary[colNum])) 
+           {	
+               String LobExtLocation;
+               if (isLargeBinary[colNum]) {
+
+                   // get input stream that has the column value as a 
+                   // stream of uninterpreted bytes; if the value is SQL NULL, 
+                   // the return value  is null
+                   InputStream is = rs.getBinaryStream(colNum + 1);
+                   LobExtLocation = 
+                       exportWriteData.writeBinaryColumnToExternalFile(is);
+               } else {
+                   // It is clob data, get character stream that has 
+                   // the column value. if the value is SQL NULL, the 
+                   // return value  is null
+                   Reader ir = rs.getCharacterStream(colNum + 1);
+                   LobExtLocation  = 
+                       exportWriteData.writeCharColumnToExternalFile(ir);
+               }
+               rowObjects[colNum]= LobExtLocation;
+
+               // when lob data is written to the main export file, binary 
+               // data is written in hex format. getString() call on binary 
+               // columns returns the data in hex format, no special handling 
+               // required. In case of large char tpe like Clob, data 
+               // is written to main export file  similar to other char types. 
+               
+               // TODO : handling of Nulls. 
+           }
+		   else {
+			   rowObjects[colNum]=rs.getString(colNum + 1);
+           }
        }
        return rowObjects;
     }
@@ -85,26 +136,42 @@
 			ResultSetMetaData rsmeta = rs.getMetaData();
 			int ncols = rsmeta.getColumnCount();
 			boolean[] isNumeric = new boolean[ncols];
+			boolean[] isLargeChar = new boolean[ncols];
+			boolean[] isLargeBinary = new boolean[ncols];
 			for (int i = 0; i < ncols; i++) {
 				int ctype = rsmeta.getColumnType(i+1);
 				if (ctype == Types.BIGINT || ctype == Types.DECIMAL || ctype == Types.DOUBLE ||
 						ctype == Types.FLOAT ||ctype == Types.INTEGER || ctype == Types.NUMERIC ||
 						ctype == Types.REAL ||ctype == Types.SMALLINT || ctype == Types.TINYINT)
     				isNumeric[i] = true;
-				else
+				else 
 					isNumeric[i] = false;
+					
+				if (ctype == Types.CLOB)
+					isLargeChar[i] = true;
+				else 
+					isLargeChar[i]= false;
+				
+				if (ctype == Types.BLOB) 
+					isLargeBinary[i] = true;
+				else 
+					isLargeBinary[i] = false;
 			}
+
+
 			exportWriteData = getExportWriteData();
 			exportWriteData.writeColumnDefinitionOptionally(
 						exportResultSetForObject.getColumnDefinition(),
 						exportResultSetForObject.getColumnTypes());
 			exportWriteData.setColumnLengths(controlFileReader.getColumnWidths());
 
-       		//get one row at a time and write it to the output file
-       		String[] oneRow = getOneRowAtATime(rs);
+       		// get one row at a time and write it to the output file
+            String[] oneRow = getOneRowAtATime(rs, 
+                                               isLargeBinary, 
+                                               isLargeChar);
        		while (oneRow != null) {
          		exportWriteData.writeData(oneRow, isNumeric);
-         		oneRow = getOneRowAtATime(rs);
+                oneRow = getOneRowAtATime(rs, isLargeBinary, isLargeChar);
        		}
 		}
 	} finally {
@@ -115,6 +182,4 @@
 			rs.close();
     }
   }
-
-
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java Mon Feb 26 18:06:37 2007
@@ -24,6 +24,9 @@
 import java.io.FileOutputStream;
 import java.io.BufferedOutputStream;
 import java.io.OutputStreamWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.Reader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Date;
@@ -36,36 +39,69 @@
 final class ExportWriteData extends ExportWriteDataAbstract
 	implements java.security.PrivilegedExceptionAction {
 
-  private String outputFileName;
-  // i18n support - instead of using DataOutputStream.writeBytes - use
-  // OutputStreamWriter.write with the correct codeset.
-  private OutputStreamWriter aStream;
-
-  //writes data into the o/p file using control file properties
-  ExportWriteData(String outputFileName, ControlInfo controlFileReader)
-  throws Exception {
-    this.outputFileName = outputFileName;
-    this.controlFileReader = controlFileReader;
-    loadPropertiesInfo();
-
-	try {
-		java.security.AccessController.doPrivileged(this);
-	} catch (java.security.PrivilegedActionException pae) {
-		throw pae.getException();
+	private String outputFileName;
+	private String lobsFileName;
+	private boolean lobsInExtFile = false;
+	private long lobFileOffset = 0;
+
+	// i18n support - instead of using DataOutputStream.writeBytes - use
+	// OutputStreamWriter.write with the correct codeset.
+	private OutputStreamWriter aStream;
+	private OutputStreamWriter lobCharStream;
+	private BufferedOutputStream lobOutBinaryStream;
+	private ByteArrayOutputStream lobByteArrayStream;
+
+    // temporary buffers userd to read/write the lob data.
+    private byte[] byteBuf; 
+    private char[] charBuf;
+
+	//writes data into the o/p file using control file properties
+	ExportWriteData(String outputFileName, ControlInfo controlFileReader)
+		throws Exception {
+		this.outputFileName = outputFileName;
+		this.controlFileReader = controlFileReader;
+		init();
+	}
+	
+	//writes data into the o/p file using control file properties
+	ExportWriteData(String outputFileName, 
+					String lobsFileName,
+					ControlInfo controlFileReader)
+		throws Exception {
+		this.outputFileName = outputFileName;
+		this.lobsFileName = lobsFileName;
+		this.controlFileReader = controlFileReader;
+		lobsInExtFile = true;
+        byteBuf = new byte[8192];
+        charBuf = new char[8192];
+		init();
 	}
 
-  }
+	private void init() throws Exception 
+	{
+		loadPropertiesInfo();
+		try {
+			java.security.AccessController.doPrivileged(this);
+		} catch (java.security.PrivilegedActionException pae) {
+			throw pae.getException();
+		}
+
+	}
 
   public final Object run() throws Exception {
-	  openFile();
+	  openFiles();
 	  return null;
   }
 
   //prepares the o/p file for writing
-  private void openFile() throws Exception {
+  private void openFiles() throws Exception {
     try {
       URL url = new URL(outputFileName);
       outputFileName = url.getFile();
+	  if (lobsInExtFile) {
+		  url = new URL(lobsFileName);
+		  lobsFileName = url.getFile();
+	  }
     } catch (MalformedURLException ex) {}
     FileOutputStream anOutputStream = new FileOutputStream(outputFileName);
     BufferedOutputStream buffered = new BufferedOutputStream(anOutputStream);
@@ -73,6 +109,22 @@
     aStream = dataCodeset == null ?
     		new OutputStreamWriter(buffered) :
     		new OutputStreamWriter(buffered, dataCodeset);    	        
+
+    // if lobs are exported to an external file, then 
+    // setup the required streams to write lob data.
+    if (lobsInExtFile) 
+    {
+        // setup streams to write large objects into the external file. 
+        FileOutputStream lobOutputStream = new FileOutputStream(lobsFileName);
+        lobOutBinaryStream = new BufferedOutputStream(lobOutputStream);
+
+        // helper stream to convert char data to binary, after conversion
+        // data is written to lobOutBinaryStream.
+        lobByteArrayStream = new ByteArrayOutputStream();
+        lobCharStream =  dataCodeset == null ?
+            new OutputStreamWriter(lobByteArrayStream) :
+            new OutputStreamWriter(lobByteArrayStream, dataCodeset);    	        
+	}
   }
 
   /**if control file says true for column definition, write it as first line of the
@@ -131,7 +183,108 @@
     }
   }
 
-  /**write the passed row into the data file
+
+	
+    /*
+     * Writes the binary data in the given input stream to an 
+     * external lob export file, and return it's location 
+     * information in the file as string. Location information 
+     * is written in the main export file. 
+     * @param istream   input streams that contains a binary column data.
+     * @return Location where the column data written in the external file. 
+     * @exception Exception  if any error occurs while writing the data.  
+     */
+    String writeBinaryColumnToExternalFile(InputStream istream) 
+        throws Exception
+    {
+        // read data from the input stream and write it to 
+        // the lob export file and also calculate the amount
+        // of data written in bytes. 
+
+        long blobSize = 0;
+        int noBytes = 0 ;
+        noBytes = istream.read(byteBuf) ;
+        while(noBytes != -1) 
+        {
+            lobOutBinaryStream.write(byteBuf, 0 , noBytes);
+            blobSize += noBytes;
+            noBytes = istream.read(byteBuf) ;
+        }
+
+        // close the input stream. 
+        istream.close();
+
+        // flush the output binary stream. 
+        lobOutBinaryStream.flush();
+				
+        // Encode a lob location information as string. This is 
+        // stored in the main export file. It will be used 
+        // to retrive this blob data on import. 
+        // Format is :  <fileName> : <lobOffset> : <size of lob>
+        String lobLocation = lobsFileName + ":" + 
+            lobFileOffset + ":" +  blobSize;
+		
+        // update the offset, this will be  where next 
+        // large object data  will be written. 
+        lobFileOffset += blobSize;
+
+        return lobLocation;
+    }
+
+    /*
+     * Writes the clob data in the given input Reader to an 
+     * external lob export file, and return it's location 
+     * information in the file as string. Location information 
+     * is written in the main export file. 
+     * @param ir   Reader that contains a clob column data.
+     * @return Location where the column data written in the external file. 
+     * @exception Exception  if any error occurs while writing the data.   
+     */
+    String writeCharColumnToExternalFile(Reader ir) 
+        throws Exception
+    {
+
+        // read data from the input stream and write it to 
+        // the lob export file and also calculate the amount
+        // of data written in bytes. 
+
+        long clobSize = 0;
+        int noChars = 0 ;
+        noChars = ir.read(charBuf) ;
+        while(noChars != -1) 
+		{
+            // characters data is converted to bytes using 
+            // the user specified code set. 
+            lobByteArrayStream.reset();
+            lobCharStream.write(charBuf, 0 , noChars);
+            lobCharStream.flush();
+			
+            clobSize += lobByteArrayStream.size();
+            lobByteArrayStream.writeTo(lobOutBinaryStream);
+            noChars  = ir.read(charBuf) ;
+        }
+
+        // close the input reader. 
+        ir.close();
+        // flush the output binary stream. 
+        lobOutBinaryStream.flush();
+
+        // Encode this lob location information as string. This will 
+        // be written to the main export file. It will be used 
+        // to retrive this blob data on import. 
+        // Format is :  <fileName> : <lobOffset> : <size of lob>
+        String lobLocation = lobsFileName + ":" + 
+            lobFileOffset + ":" +  clobSize;
+
+        // update the offset, this will be  where next 
+        // large object data  will be written. 		
+        lobFileOffset += clobSize;
+        return lobLocation;
+    }
+	
+
+
+    /**write the passed row into the data file
  	* @exception	Exception if there is an error
 	*/
   public void writeData(String[] oneRow, boolean[] isNumeric) throws Exception {
@@ -157,6 +310,18 @@
   public void noMoreRows() throws IOException {
     aStream.flush();
     aStream.close();
+    if (lobsInExtFile) {
+        // close the streams associated with lob data.
+        if (lobOutBinaryStream != null) {
+            lobOutBinaryStream.flush();
+            lobOutBinaryStream.close();
+        }
+        if (lobCharStream != null) 
+            lobCharStream.close();
+        if (lobByteArrayStream != null)
+            lobByteArrayStream.close();
+    }
+    
 //    System.err.print(new Date(System.currentTimeMillis()) + " ");
 //    System.err.println("Export finished");
 //    System.setErr(System.out);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteDataAbstract.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteDataAbstract.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteDataAbstract.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteDataAbstract.java Mon Feb 26 18:06:37 2007
@@ -20,6 +20,8 @@
  */
 
 package org.apache.derby.impl.load;
+import java.io.InputStream;
+import java.io.Reader;
 
 abstract class ExportWriteDataAbstract {
 
@@ -64,6 +66,30 @@
 
   //write the passed row into the data file
   public abstract void writeData(String[] oneRow, boolean[] isNumeric) throws Exception;
+
+    /*
+     * Writes the binary data in the given input stream to an 
+     * external lob export file, and return it's location 
+     * information in the file as string. Location information 
+     * is written in the main export file. 
+     * @param istream   input streams that contains a binary column data.
+     * @return Location where the column data written in the external file. 
+     * @exception Exception  if any error occurs while writing the data.  
+     */
+    abstract String writeBinaryColumnToExternalFile(InputStream istream) 
+        throws Exception;
+    
+    /*
+     * Writes the clob data in the given input Reader to an 
+     * external lob export file, and return it's location 
+     * information in the file as string. Location information 
+     * is written in the main export file. 
+     * @param ir   Reader that contains a clob column data.
+     * @return Location where the column data written in the external file. 
+     * @exception Exception  if any error occurs while writing the data.   
+     */
+    abstract String writeCharColumnToExternalFile(Reader ir) 
+        throws Exception;
 
   //if nothing more to write, then close the file and write a message of completion
   //in message file

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java Mon Feb 26 18:06:37 2007
@@ -48,16 +48,20 @@
 	 * @exception Exception on error 
 	 */
 	public Import(String inputFileName, String columnDelimiter,
-					  String characterDelimiter,  String codeset, 
-					  int noOfColumnsExpected) throws SQLException 
+                  String characterDelimiter,  String codeset, 
+                  int noOfColumnsExpected,  String columnTypes, 
+                  boolean lobsInExtFile) throws SQLException 
 	{
 
 		try{
 			this.inputFileName = inputFileName;
-			this.noOfColumnsExpected = noOfColumnsExpected;
+            this.noOfColumnsExpected = noOfColumnsExpected;
+            this.tableColumnTypesStr = columnTypes;
 			controlFileReader = new ControlInfo();
 			controlFileReader.setControlProperties(characterDelimiter,
 												   columnDelimiter, codeset);
+            this.lobsInExtFile = lobsInExtFile;
+
 			doImport();
 
 		}catch(Exception e)
@@ -88,20 +92,23 @@
 	 * @param codeset           Codeset of the data in the file
 	 * @param replace          Indicates whether the data in table has to be replaced or
 	 *                         appended.(0 - append , > 0 Replace the data)
+     * @param lobsInExtFile true, if the lobs data is stored in an external file,
+     *                      and the reference to it is stored in the main import file.
  	 * @exception SQL Exception on errors
 	 */
 
 	public static void importTable(Connection connection, String schemaName, 
-                              String tableName, String inputFileName,  
-							  String columnDelimiter, String characterDelimiter,
-							  String codeset, short replace)
+                                   String tableName, String inputFileName,  
+                                   String columnDelimiter, 
+                                   String characterDelimiter,String codeset, 
+                                   short replace, boolean lobsInExtFile)
 		throws SQLException {
 
 
 		performImport(connection,  schemaName,  null, //No columnList 
 					  null , //No column indexes
 					  tableName, inputFileName, columnDelimiter, 
-					  characterDelimiter, codeset, replace);
+					  characterDelimiter, codeset, replace, lobsInExtFile);
 	}
 
 
@@ -123,21 +130,24 @@
 	 * @param codeset           Codeset of the data in the file
 	 * @param replace          Indicates whether the data in table has to be replaced or
 	 *                         appended.(0 - append , > 0 Replace the data)
+     * @param lobsInExtFile true, if the lobs data is stored in an external file,
+     *                      and the reference is stored in the main import file.
  	 * @exception SQL Exception on errors
 	 */
 	public static void importData(Connection connection, String schemaName,
-								  String tableName, String insertColumnList, 
-								  String columnIndexes,
-								  String inputFileName, String columnDelimiter, 
-								  String characterDelimiter,
-								  String codeset, short replace)
+                                  String tableName, String insertColumnList, 
+                                  String columnIndexes, String inputFileName, 
+                                  String columnDelimiter, 
+                                  String characterDelimiter,
+                                  String codeset, short replace, 
+                                  boolean lobsInExtFile)
 		throws SQLException 
 	{
 		
 
 			performImport(connection,  schemaName,  insertColumnList,columnIndexes, 
 						  tableName, inputFileName, columnDelimiter, 
-						  characterDelimiter, codeset, replace);
+						  characterDelimiter, codeset, replace, lobsInExtFile);
 	}
 
 
@@ -149,13 +159,18 @@
 	 * INTEGER)  from new org.apache.derby.impl.load.Import('extin/Tutor1.asc') as importvti;
 	 *
 	 */
-	private static void performImport(Connection connection, String schemaName, 
-									  String insertColumnList, String columnIndexes,
-									  String tableName, 
-									  String inputFileName,  String  columnDelimiter, 
-									  String characterDelimiter, String codeset, 
-									  short replace)
-		throws SQLException 
+	private static void performImport(Connection connection, 
+                                      String schemaName, 
+                                      String insertColumnList, 
+                                      String columnIndexes,
+                                      String tableName, 
+                                      String inputFileName,  
+                                      String  columnDelimiter, 
+                                      String characterDelimiter, 
+                                      String codeset, 
+                                      short replace, 
+                                      boolean lobsInExtFile)
+        throws SQLException 
 	{
 
 		if (connection == null)
@@ -193,7 +208,11 @@
 		sb.append(",") ;
 		sb.append(	(codeset !=null ? "'" + codeset + "'" : null));
 		sb.append(", ");
-		sb.append( columnInfo.getExpectedNumberOfColumnsInFile());
+        sb.append( columnInfo.getExpectedNumberOfColumnsInFile());
+        sb.append(", ");
+        sb.append( "'" + columnInfo.getExpectedVtiColumnTypesAsString() + "'");
+        sb.append(", ");
+        sb.append(lobsInExtFile);
 		sb.append(" )") ;
 
 		String importvti = sb.toString();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java Mon Feb 26 18:06:37 2007
@@ -45,6 +45,10 @@
   ResultSetMetaData importResultSetMetaData;
   int noOfColumnsExpected;
 
+  protected boolean lobsInExtFile = false;
+
+  String tableColumnTypesStr;
+  int[] tableColumnTypes;
   private boolean wasNull;
 
 	static final String COLUMNNAMEPREFIX = "COLUMN";
@@ -71,10 +75,12 @@
     columnNames = new String[numberOfColumns];
     loadColumnNames();
     nextRow = new String[numberOfColumns];
-
+    tableColumnTypes = ColumnInfo.getExpectedVtiColumnTypes(tableColumnTypesStr,
+                                                            numberOfColumns);
 	// get the ResultSetMetaData now as we know it's needed
 	importResultSetMetaData =
-		new ImportResultSetMetaData(numberOfColumns, columnNames, columnWidths);
+		new ImportResultSetMetaData(numberOfColumns, columnNames, columnWidths,
+                                    tableColumnTypes);
 
 
     //FIXME don't go through the resultset here. just for testing
@@ -84,6 +90,7 @@
   void loadColumnNames() {
     for (int i=1; i<=numberOfColumns; i++)
       columnNames[i-1] = COLUMNNAMEPREFIX + i;
+
   }
 
 
@@ -130,14 +137,61 @@
  	* @exception	SQLException if there is an error
 	*/
   public String getString(int columnIndex) throws SQLException {
-    if (columnIndex <= numberOfColumns) {
 
+    if (columnIndex <= numberOfColumns) {
 		String val = nextRow[columnIndex-1];
+		if (isColumnInExtFile(columnIndex)) {
+            // a clob column data is stored in an external 
+            // file, the reference to it is in the main file. 
+            // read the data from the external file using the 
+            // reference from the main file. 
+			val = importReadData.getClobColumnFromExtFile(val);
+        }
 		wasNull = (val == null);
-       return val;
+		return val;
     }
     else {
        throw LoadError.invalidColumnNumber(numberOfColumns);
     }
   }
+
+	
+    /**
+     * Returns <code> java.sql.Blob </code> type object that 
+     * contains the columnn data from the import file. 
+     * @param columnIndex number of the column. starts at 1.
+     * @exception SQLException if any occurs during create of the blob object.
+     */
+	public java.sql.Blob getBlob(int columnIndex) throws SQLException {
+
+		if (lobsInExtFile) 
+        {
+            // lob data is in another file, read from the external file.
+            return importReadData.getBlobColumnFromExtFile(
+                                         nextRow[columnIndex-1]);
+        } else {
+            // data is in the main export file, stored in hex format.
+            return new ImportBlob(nextRow[columnIndex-1]);
+        }
+	}
+
+
+    /**
+     * Check if for this column type, real data is stored in an 
+     * external file and only the reference is in the main import 
+     * file.
+     * @param colIndex number of the column. starts at 1.
+     * @return         true, if the column data in a different file 
+     *                 from the main import file , otherwise false.
+     */
+	private boolean isColumnInExtFile(int colIndex) 
+	{
+		if (lobsInExtFile && 
+            (tableColumnTypes[colIndex -1] == java.sql.Types.BLOB || 
+             tableColumnTypes[colIndex -1] == java.sql.Types.CLOB ))
+			return true;
+		else 
+			return false;
+
+	}
 }

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportBlob.java?view=auto&rev=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportBlob.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportBlob.java Mon Feb 26 18:06:37 2007
@@ -0,0 +1,199 @@
+/*
+
+   Derby - Class org.apache.derby.impl.load.ImportBlob
+
+   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.load;
+import org.apache.derby.iapi.services.io.LimitInputStream;
+import org.apache.derby.iapi.util.StringUtil;
+import java.sql.Blob;
+import java.sql.SQLException;
+import java.io.InputStream;
+
+/**
+ * This class implements  <code > java.sql.BLOB interface </code>.  
+ * Objects created using the <code> ImportBlob </code> class  are 
+ * intended to be be used to create a blob object of the data  stored 
+ * in an import file or as an hex string.  Only the routines that 
+ * are needed read the blob data for the blob columns by the 
+ * inserts done through the VTI  have real implementations, 
+ * Other routines are dummy ones to satisfy <code> java.sql.Blob </code> 
+ * interface.
+ */
+
+class ImportBlob implements java.sql.Blob {
+
+    private ImportLobFile lobFile;
+	private long blobPosition;
+	private long blobLength;
+    private byte[] blobData = null;
+
+
+    /**
+     * Create a import Blob object, that reads <code> length </code> amount of 
+     * data  from an external file, starting at <code> position </code>. 
+     * @param lobFile  lob file resource object, using which data is read.
+     * @param position  byte offset in the file, of this blob columb data. 
+     * @param length   length of this blob object data. 
+     */
+    public ImportBlob(ImportLobFile lobFile, long position, long length) 
+	{
+		this.lobFile = lobFile;
+		this.blobPosition = position;
+		this.blobLength = length;
+	}
+
+
+    /**
+     * Create a import Blob object, whose value is the give hex data string.  
+     * @param hexData  data in the hex format, that this blob object contains. 
+     */
+    public ImportBlob(String hexData) 
+    {
+        // convert the given blob data in the hex format to a byte array.
+        blobData = StringUtil.fromHexString(hexData, 0, hexData.length());
+        blobLength = blobData.length;
+    }
+
+
+  /**
+   * Returns the number of bytes in this <code>BLOB</code>  object.
+   * @return length of the <code>BLOB</code> in bytes
+   * @exception SQLException on any error.
+   */
+	public long length() throws SQLException {
+		return blobLength;
+	}
+
+
+    /**
+     * Returns  <code>BLOB</code> value designated by this
+     * <code>Blob</code> object as a input stream.
+     *
+     * @return a stream containing the <code>BLOB</code> data
+     * @exception SQLException if any error occurs while setting up 
+     *                         this blob data in the import file as stream. 
+     */
+	public java.io.InputStream getBinaryStream () throws SQLException
+	{
+		try {
+            InputStream fis;
+            if(blobData != null) {
+                fis = new java.io.ByteArrayInputStream(blobData);
+                // wrap the InputStream with a LimitInputStream class,
+                // only the length of the  
+                LimitInputStream  limitIn = new  LimitInputStream(fis);
+                limitIn.setLimit((int) blobLength);
+                return limitIn;
+
+            } else {
+                return lobFile.getBinaryStream(blobPosition, blobLength);
+            }
+		} catch (Exception e) {
+			throw LoadError.unexpectedError(e);
+		}
+	}
+
+    
+    /** following rotines does not have implmentation because there are not
+     * used by the VTI that is used to import the data. 
+     */
+
+    /**
+     * This routine is not used by the VTI to read the data, so no 
+     * implementatio  is provided , an exception is thrown if used.  
+     *
+     * @see java.sql.Blob 
+     */
+	public byte[] getBytes(long pos, int length) throws SQLException {
+		throw LoadError.unexpectedError(
+                         new Exception("Method not implemented"));
+	}
+
+    /**
+     * This routine is not used by the VTI to read the data, so no 
+     * implementatio  is provided , an exception is thrown if used.  
+     *
+     * @see java.sql.Blob 
+     */
+	public long position(byte pattern[], long start) throws SQLException
+	{
+		throw LoadError.unexpectedError(
+                        new Exception("Method not implemented"));
+	}
+
+    /**
+     * This routine is not used by the VTI to read the data, so no 
+     * implementation is provided , an exception is thrown if used.  
+     *
+     * @see java.sql.Blob
+     */
+	public long position(Blob pattern, long start) throws SQLException {
+		throw LoadError.unexpectedError(
+                            new Exception("Method not implemented"));
+	}
+
+
+    /**
+     * This routine is not used by the VTI to read the data, so no 
+     * implementation  is provided , an exception is thrown if used.  
+     *
+     * @see java.sql.Blob
+     */
+    public int setBytes(long pos, byte[] bytes) throws SQLException {
+		throw LoadError.unexpectedError(new Exception("Method not implemented"));
+	}
+
+    /**
+     * This routine is not used by the VTI to read the data, so no 
+     * implementation  is provided , an exception is thrown if used.  
+     *
+     * @see java.sql.Blob
+     */
+    public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
+	{
+		throw LoadError.unexpectedError(
+                        new Exception("Method not implemented"));
+	}
+
+    /**
+     * This routine is not used by the VTI to read the data, so no 
+     * implementation  is provided , an exception is thrown if used.  
+     *
+     * @see java.sql.Blob
+     */
+    public java.io.OutputStream setBinaryStream(long pos) throws SQLException 
+	{
+		throw LoadError.unexpectedError(
+                         new Exception("Method not implemented"));
+	}
+
+    /**
+     * This routine is not used by the VTI to read the data, so no 
+     * implementation  is provided , an exception is thrown if used.  
+     *
+     * @see java.sql.Blob
+     */
+    public void truncate(long len) throws SQLException {
+		throw LoadError.unexpectedError(
+                        new Exception("Method not implemented"));
+	}
+}
+
+

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportBlob.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java?view=auto&rev=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java Mon Feb 26 18:06:37 2007
@@ -0,0 +1,258 @@
+/*
+
+   Derby - Class org.apache.derby.impl.load.ImportLobFile
+
+   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.load;
+import java.io.*;
+import org.apache.derby.iapi.services.io.LimitInputStream;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+
+
+/**
+ * Helper class to read large object data at random locations 
+ * from a file that contains large object data. 
+ */
+
+class ImportLobFile 
+{
+    private ImportFileInputStream lobInputStream = null;
+    private LimitInputStream  lobLimitIn;
+    private Reader lobReader = null;
+    private String lobFileName;
+    private String dataCodeset; 
+    
+
+    /*
+     * Create a ImportLobFile object.
+     * @param fileName  the file which gas LOB Data.
+     * @param  dataCodeset the code set to use char data in the file.
+     */
+    ImportLobFile(String fileName, String dataCodeset) throws Exception {
+        this.lobFileName = fileName;
+        this.dataCodeset = dataCodeset;
+        openLobFile(lobFileName);
+    }
+
+
+    /* 
+     * Open the lob file and setup the stream required to read the data.
+     * @param lobFileName name of the file that contains lob data.
+     * @exception  Exception  if an error occurs.     
+     */
+    private void openLobFile(final String lobFileName) 
+        throws Exception 
+    {
+        RandomAccessFile lobRaf;
+        try {
+            // open the lob file under a privelged block.
+            try {
+                lobRaf = (RandomAccessFile)AccessController.doPrivileged
+                (new java.security.PrivilegedExceptionAction(){
+                        public Object run() throws IOException{
+                            return new RandomAccessFile(lobFileName, "r");
+                        }   
+                    }
+                 );    	
+            } catch (PrivilegedActionException pae) {
+                throw pae.getException();
+            }
+        } catch (FileNotFoundException ex) {
+            throw LoadError.dataFileNotFound(lobFileName);
+        } 
+        
+        // set up stream to read from input file, starting from 
+        // any offset in the file. Users can specify columns in 
+        // any order or skip some during import. So it is 
+        // is required  for this stream have ability to read from 
+        // any offset in the file. 
+
+        lobInputStream = new ImportFileInputStream(lobRaf);
+
+        // wrap the lobInputStream with a LimitInputStream class,
+        // This will help in making sure only the specific amout 
+        // of data is read from the file, for example to read one 
+        // column data from the file. 
+        lobLimitIn = new  LimitInputStream(lobInputStream);
+
+        // setup a reader on top of the stream, so that calls 
+        // to read the clob data from the file can read the 
+        // with approapriate  data code set. 
+        lobReader = dataCodeset == null ?
+    		new InputStreamReader(lobLimitIn) : 
+            new InputStreamReader(lobLimitIn, dataCodeset);    
+    }
+
+
+    /*
+     * Returns a stream that points to the lob data from file at the 
+     * given <code> offset </code>.
+     * at the specified offset. 
+     * @param offset  byte offset of the column data in the file. 
+     * @param length  length of the the data.
+     * @exception  IOException  if any I/O error occurs.     
+     */
+    public InputStream getBinaryStream(long offset, long length) 
+        throws IOException {
+        lobInputStream.seek(offset);
+        lobLimitIn.clearLimit();
+        lobLimitIn.setLimit((int) length);
+        return lobLimitIn;
+    }
+
+
+    /* 
+     * Returns the clob data at the given location as String. 
+     * @param offset  byte offset of the column data in the file. 
+     * @param length  length of the the data.
+     * @exception  IOException  on any I/O error.     
+     */
+    public String getString(int offset, int length) throws IOException {
+        lobInputStream.seek(offset);
+        lobLimitIn.clearLimit();
+        lobLimitIn.setLimit((int) length);
+
+        // read data from the file, and return it as string. 
+        StringBuffer sb = new StringBuffer();
+        char[] buf= new char[1024];
+        int noChars = lobReader.read(buf , 0 , 1024);
+        while (noChars != -1) {
+            sb.append(buf , 0 , noChars);
+            noChars = lobReader.read(buf , 0 , 1024);
+        }
+		return sb.toString();
+    }
+
+
+    /* 
+     * close all the resources realate to the lob file.
+     */
+    public void close() throws IOException {
+
+        if (lobReader != null) {
+            lobReader.close();
+            // above call also will close the 
+            // stream under it. 
+        } else {
+
+            if (lobLimitIn != null) {
+                lobLimitIn.close();
+                // above close call , will also 
+                // close the lobInputStream
+            } else {
+                if (lobInputStream != null)
+                    lobInputStream.close();
+            }
+        }
+    }
+}
+
+
+/**
+ * An InputStream, which can stream data from a file, starting from 
+ * any offset in the file. This stream operates on top of a 
+ * RandomAccessFile object. This class overrides InputStream methods to 
+ * read from the given RandomAccessFile and provides an addtional method
+ * <code> seek(..) </code> to postion the stream at offset in the file. 
+ */
+
+class ImportFileInputStream extends InputStream 
+{
+
+    private RandomAccessFile raf = null;
+    private long currentPosition = 0 ;
+    private long fileLength = 0;
+
+    /**
+     * Create a <code> ImportFileInputStreamm object  </code> for 
+     * the given  file.  
+     * @param raf  file the stream reads from. 
+     * @exception  IOException  if any I/O error occurs.
+     */
+    ImportFileInputStream(RandomAccessFile raf)  
+        throws IOException
+    {
+        this.raf = raf;
+        this.fileLength = raf.length();
+    }
+
+    /*
+     * sets the file offset at which the next read will occur. 
+     * @param offset byte offset in the file.
+     * @exception  IOException  if an I/O error occurs.     
+     */
+    void seek(long offset) throws IOException {
+        raf.seek(offset);
+        currentPosition = offset;
+    }
+
+
+    /** overide following input stream methods to read data from the 
+     *  from the current postion of the file. 
+     */
+    
+
+    /**
+     * Reads a byte of data from this input stream. 
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public int read() throws IOException {
+        return raf.read();
+    }
+
+    /**
+     * Reads up to <code>length</code> bytes of data from this input stream
+     * into given array. This method blocks until some input is
+     * available.
+     *
+     * @param      buf     the buffer into which the data is read.
+     * @param      offset   the start offset of the data.
+     * @param      length   the maximum number of bytes read.
+     * @return     the total number of bytes read into the buffer, or
+     *             <code>-1</code> if there is no more data because the end of
+     *             the file has been reached.
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public int read(byte buf[], int offset, int length) throws IOException {
+        return raf.read(buf, offset, length);
+    }
+
+
+    /**
+     * Returns the number of bytes that can be read from this stream.
+     * @return     the number of bytes that can be read from this stream.
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public int available() throws IOException
+    {
+        return (int) (fileLength - currentPosition);
+    }
+
+
+    /**
+     * Closes this input stream and releases any associated resources
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public void close() throws IOException {
+        if (raf != null)
+            raf.close();
+    }   
+}
+

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportReadData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportReadData.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportReadData.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportReadData.java Mon Feb 26 18:06:37 2007
@@ -30,6 +30,7 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import org.apache.derby.iapi.services.sanity.SanityManager;
+import java.sql.SQLException;
 
 final class ImportReadData implements java.security.PrivilegedExceptionAction {
   //Read data from this file
@@ -101,7 +102,14 @@
   protected char[] fieldStopDelimiter;
   protected int fieldStopDelimiterLength;
   protected boolean hasDelimiterAtEnd;
-  
+
+
+  // variables realted to reading lob data from files.
+  private ImportLobFile lobFile; // lob file object 
+  private String lobFileName; // current file name
+  private int lobOffset; // offset of the current large object
+  private int lobLength; //length of the current large object
+
 
   //load the control file properties info locally, since we need to refer to them
   //all the time while looking for tokens
@@ -271,6 +279,11 @@
        bufferedReader.close();
        streamOpenForReading = false;
     }
+
+    // close external lob file resources.
+    if (lobFile !=null) {
+        lobFile.close();
+    }
   }
 
   //actually looks at the data file to find how many columns make up a row
@@ -914,6 +927,77 @@
       delimiterIndex = returnValue;
     }
   }
+
+	
+    /* following are the routines that are used to read lob data stored
+     * in a external import file for clob/blob columns, the reference 
+     * to external file is stored in the main import file.
+     */
+
+    /**
+     * Returns a clob columnn data stored at the specified location.
+     * @param lobLocationStr location of the clob data.
+     * @exception  SQLException  on any errors. 
+     */
+    String getClobColumnFromExtFile(String lobLocationStr) 
+        throws SQLException 
+    {
+		try {
+            initExternalLobFile(lobLocationStr);
+            return lobFile.getString(lobOffset,lobLength);
+		}catch(Exception ex) {
+			throw LoadError.unexpectedError(ex);
+		}
+	}
+
+    /**
+     * Returns a blob columnn data stored at the specified location as
+     * a java.sql.Blob object. 
+     * @param lobLocationStr location of the clob data.
+     * @exception  SQLException  on any errors. 
+     */
+    java.sql.Blob getBlobColumnFromExtFile(String lobLocationStr)
+        throws SQLException
+    {
+        initExternalLobFile(lobLocationStr);
+        return new ImportBlob(lobFile, lobOffset, lobLength);
+    }
+
+    /**
+     * Extract the file name, offset and length from the given lob 
+     * location and setup the file resources to read the data from 
+     * the file on first  invocaton. 
+     *
+     * @param lobLocationStr location of the clob data.
+     * @exception  SQLException  on any errors. 
+     */
+    private void initExternalLobFile(String lobLocationStr) 
+        throws SQLException 
+    {
+        
+		// extract file name, offset, and the length from the 
+		// given lob location. Lob location string format is 
+		// fileName:offset:length
+ 
+		int lengthIndex = lobLocationStr.lastIndexOf(":") ;
+		int offsetIndex = lobLocationStr.lastIndexOf(":", lengthIndex -1);
+
+		lobLength = Integer.parseInt(lobLocationStr.substring(lengthIndex + 1));
+		lobOffset = Integer.parseInt(lobLocationStr.substring(offsetIndex+1, 
+														lengthIndex));
+		lobFileName = lobLocationStr.substring(0 , offsetIndex);
+
+
+        if (lobFile == null) {
+            // open external file where the lobs are stored.
+            try {
+                lobFile = new ImportLobFile(lobFileName, 
+                                            controlFileReader.getDataCodeset());
+            }catch(Exception ex) {
+                throw LoadError.unexpectedError(ex);
+            }
+        }
+    }
 }
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportResultSetMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportResultSetMetaData.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportResultSetMetaData.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportResultSetMetaData.java Mon Feb 26 18:06:37 2007
@@ -31,12 +31,17 @@
   private final int numberOfColumns;
   private final String[] columnNames;
   private final int[] columnWidths;
+  // types of the table columns that the data is imported. 
+  private final int[] tableColumnTypes ; 
 
-  public ImportResultSetMetaData(int numberOfColumns, String[] columnNames,
-  int[] columnWidths) {
+  public ImportResultSetMetaData(int numberOfColumns, 
+                                 String[] columnNames,
+                                 int[] columnWidths, 
+                                 int[] tableColumnTypes) {
     this.numberOfColumns = numberOfColumns;
     this.columnNames = columnNames;
     this.columnWidths = columnWidths;
+    this.tableColumnTypes = tableColumnTypes;
   }
 
 	public int getColumnCount() {
@@ -44,12 +49,27 @@
   }
 
 	public String getColumnName(int column) {
-    return columnNames[column-1];
+        return columnNames[column-1];
   }
 
 	public int getColumnType(int column) {
-    return java.sql.Types.VARCHAR;
-  }
+
+        // if the table column type is BLOB/CLOB , then the 
+        // data in the import files will converted to 
+        // BLOB/CLOB type objects. So the vti result column 
+        // type for blob/clob is same as  table column type. 
+        // Data for Other types is considered is of VARCHAR type, 
+        // and they are casted to table column type, if needed 
+        // while doing the select from the VTI. 
+
+		if (tableColumnTypes[column -1] ==  java.sql.Types.BLOB)
+			return java.sql.Types.BLOB;
+		else
+            if (tableColumnTypes[column -1] ==  java.sql.Types.CLOB)
+                return java.sql.Types.CLOB;
+            else
+                return java.sql.Types.VARCHAR;
+    }
 
 	public int isNullable(int column) {
     return columnNullableUnknown;
@@ -60,4 +80,5 @@
     else
        return columnWidths[column-1];
   }
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Mon Feb 26 18:06:37 2007
@@ -9200,6 +9200,8 @@
         create_10_1_system_procedures(tc, sysUtilUUID);
         // add 10.2 specific system procedures
         create_10_2_system_procedures(tc, sysUtilUUID);
+        // add 10.3 specific system procedures
+        create_10_3_system_procedures(tc, sysUtilUUID);
     }
 
     /**
@@ -9972,6 +9974,201 @@
 				0,
 				1,
                 RoutineAliasInfo.READS_SQL_DATA,
+                (TypeDescriptor) null,
+                tc);
+        }
+    }
+
+
+
+    /**
+     * Create system procedures added in version 10.3.
+     * <p>
+     * Create 10.3 system procedures, called by either code creating new
+     * database, or code doing hard upgrade from previous version.
+     * <p>
+     *
+     * @param sysUtilUUID   uuid of the SYSUTIL schema.
+     *
+     * @exception  StandardException  Standard exception policy.
+     **/
+    void create_10_3_system_procedures(
+    TransactionController   tc,
+    UUID                    sysUtilUUID)
+        throws StandardException
+    {
+
+        /* SYSCS_EXPORT_TABLE_LOBS_IN_EXTFILE(IN SCHEMANAME  VARCHAR(128), 
+         * IN TABLENAME    VARCHAR(128), IN FILENAME VARCHAR(32672) , 
+         * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
+         * IN CODESET VARCHAR(128), IN LOBSFILENAME VARCHAR(32672) )
+         */
+		
+        {
+            // procedure argument names
+            String[] arg_names = {"schemaName", "tableName" , 
+                                  "fileName"," columnDelimiter", 
+                                  "characterDelimiter", "codeset", 
+                                  "lobsFileName"};
+
+            // procedure argument types
+            TypeDescriptor[] arg_types = {
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128), 
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672)
+            };
+
+            createSystemProcedureOrFunction(
+               "SYSCS_EXPORT_TABLE_LOBS_IN_EXTFILE",
+                sysUtilUUID,
+                arg_names,
+                arg_types,
+				0,
+				0,
+				RoutineAliasInfo.READS_SQL_DATA,
+                (TypeDescriptor) null,
+                tc);
+        }
+
+        
+        /* SYSCS_EXPORT_QUERY_LOBS_IN_EXTFILE(
+         * IN SELECTSTATEMENT  VARCHAR(32672), 
+         * IN FILENAME VARCHAR(32672) , 
+         * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
+         * IN CODESET VARCHAR(128))
+         */
+        {
+            // procedure argument names
+            String[] arg_names = {"selectStatement", "fileName",
+                                  " columnDelimiter", "characterDelimiter",
+                                  "codeset", "lobsFileName"};
+
+            // procedure argument types
+            TypeDescriptor[] arg_types = {
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672), 
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672)
+            };
+
+            createSystemProcedureOrFunction(
+                "SYSCS_EXPORT_QUERY_LOBS_IN_EXTFILE",
+                sysUtilUUID,
+                arg_names,
+                arg_types,
+                0,
+                0,
+                RoutineAliasInfo.READS_SQL_DATA,
+                (TypeDescriptor) null,
+                tc);
+        }
+
+        		
+        /*  SYSCS_IMPORT_TABLE_LOBS_IN_EXTFILE(IN SCHEMANAME VARCHAR(128), 
+         *  IN TABLENAME VARCHAR(128),  IN FILENAME VARCHAR(32762), 
+         *  IN COLUMNDELIMITER CHAR(1), IN CHARACTERDELIMITER  CHAR(1),  
+         *  IN CODESET VARCHAR(128) , IN  REPLACE SMALLINT)
+         */
+        {
+            // procedure argument names
+            String[] arg_names = {"schemaName", "tableName", "fileName",
+                                  " columnDelimiter", "characterDelimiter", 
+                                  "codeset", "replace"};
+
+            // procedure argument types
+            TypeDescriptor[] arg_types = {
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128), 
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR,	128),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.SMALLINT),
+            };
+
+            createSystemProcedureOrFunction(
+               "SYSCS_IMPORT_TABLE_LOBS_IN_EXTFILE",
+               sysUtilUUID,
+               arg_names,
+               arg_types,
+               0,
+               0,
+               RoutineAliasInfo.MODIFIES_SQL_DATA,
+               (TypeDescriptor) null,
+               tc);
+        }
+
+        /*  SYSCS_IMPORT_DATA_LOBS_IN_EXTFILE(IN SCHEMANAME VARCHAR(128), 
+         *  IN TABLENAME VARCHAR(128), IN INSERTCOLUMNLIST VARCHAR(32762), 
+         *  IN COLUMNINDEXES VARCHAR(32762), IN IN FILENAME VARCHAR(32762), 
+         *  IN COLUMNDELIMITER CHAR(1), IN CHARACTERDELIMITER  CHAR(1),  
+         *  IN CODESET VARCHAR(128) , IN  REPLACE SMALLINT)
+         */
+        {
+            // procedure argument names
+            String[] arg_names = {"schemaName", "tableName", 
+                                  "insertColumnList","columnIndexes",
+                                  "fileName", " columnDelimiter", 
+                                  "characterDelimiter", 
+                                  "codeset", "replace"};
+
+            // procedure argument types
+            TypeDescriptor[] arg_types = {
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128), 
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 128),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR, 32672),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.CHAR, 1),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.VARCHAR,	128),
+                DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                Types.SMALLINT),
+            };
+
+
+            createSystemProcedureOrFunction(
+                "SYSCS_IMPORT_DATA_LOBS_IN_EXTFILE",
+                sysUtilUUID,
+                arg_names,
+                arg_types,
+                0,
+                0,
+                RoutineAliasInfo.MODIFIES_SQL_DATA,
                 (TypeDescriptor) null,
                 tc);
         }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?view=diff&rev=512109&r1=512108&r2=512109
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Mon Feb 26 18:06:37 2007
@@ -592,21 +592,6 @@
 				numVTICols = 0;
 			}
 
-            try
-            {
-                for( int i = 1; i <= numVTICols; i++)
-                {
-                    int columnType = rsmd.getColumnType(i);
-                    if( columnType == Types.BLOB || columnType == Types.CLOB)
-                        throw StandardException.newException(SQLState.LANG_VTI_BLOB_CLOB_UNSUPPORTED, 
-                                                             getVTIName(), rsmd.getColumnName( i));
-                }
-            }
-            catch( SQLException sqle)
-            {
-                throw StandardException.unexpectedUserException(sqle);
-            }
-
 			resultColumns = (ResultColumnList) getNodeFactory().getNode(
 												C_NodeTypes.RESULT_COLUMN_LIST,
 												getContextManager());



Mime
View raw message