db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject svn commit: r527319 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/load/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/tools/ testing/org/apache/derbyTest...
Date Tue, 10 Apr 2007 21:51:28 GMT
Author: suresht
Date: Tue Apr 10 14:51:27 2007
New Revision: 527319

URL: http://svn.apache.org/viewvc?view=rev&rev=527319
Log:
DERBY-378 (partial)
This patch makes lob file to be created in the same location 
as main export file , if the specified lob file name is 
unqualified. i.e fileName string just contains the name 
of the file. And also improved error messages for couple
of user error cases. 

Added test cases for the above and also modified some existing 
test cases to perform import/export using different codeset. 


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Export.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/ImportLobFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportReadData.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportLobTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java

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=527319&r1=527318&r2=527319
==============================================================================
--- 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 Tue Apr 10 14:51:27
2007
@@ -26,6 +26,10 @@
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.*;    
+import org.apache.derby.iapi.error.PublicAPI;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.error.StandardException;
+
 
 /**
  * This class provides ways to export data from
@@ -88,8 +92,12 @@
      */
 	private void setLobsExtFileName(String lobsFileName) throws SQLException
 	{
-		if (lobsFileName == null)
-			throw LoadError.dataFileNull();
+		if (lobsFileName == null) {
+            throw PublicAPI.wrapStandardException(
+                      StandardException.newException(
+                      SQLState.LOB_DATA_FILE_NULL));
+        }
+
 		this.lobsFileName = lobsFileName;
 		lobsInExtFile = true;
 	}

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=527319&r1=527318&r2=527319
==============================================================================
--- 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 Tue Apr
10 14:51:27 2007
@@ -31,6 +31,7 @@
 import java.net.URL;
 import java.util.Date;
 import java.io.IOException;
+import java.io.File;
 
 //this class takes the passed row and writes it into the data file using the
 //properties from the control file
@@ -122,7 +123,18 @@
         if (lobsInExtFile) 
         {
             // setup streams to write large objects into the external file. 
-            lobOutputStream = new FileOutputStream(lobsFileName);
+            File lobsFile =  new File(lobsFileName);
+            if (lobsFile.getParentFile() == null) {
+                // lob file name is unqualified. Make lobs file 
+                // parent directory is same as the the main export file. 
+                // lob file should get created at the same location 
+                // as the main export file.
+                lobsFile = new File((new File (outputFileName)).getParentFile(),
+                                    lobsFileName);
+
+            }
+
+            lobOutputStream = new FileOutputStream(lobsFile);
             lobOutBinaryStream = new BufferedOutputStream(lobOutputStream);
 
             // helper stream to convert char data to binary, after conversion

Modified: 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=diff&rev=527319&r1=527318&r2=527319
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportLobFile.java Tue Apr
10 14:51:27 2007
@@ -20,10 +20,19 @@
  */
 
 package org.apache.derby.impl.load;
-import java.io.*;
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.FileNotFoundException;
 import org.apache.derby.iapi.services.io.LimitInputStream;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
+import org.apache.derby.iapi.error.PublicAPI;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.error.StandardException;
 
 
 /**
@@ -36,28 +45,26 @@
     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.
+     * @param lobFile  the file which has the LOB Data.
+     * @param dataCodeset the code set to use char data in the file.
      */
-    ImportLobFile(String fileName, String dataCodeset) throws Exception {
-        this.lobFileName = fileName;
+    ImportLobFile(File lobFile, String dataCodeset) throws Exception {
         this.dataCodeset = dataCodeset;
-        openLobFile(lobFileName);
+        openLobFile(lobFile);
     }
 
 
     /* 
      * Open the lob file and setup the stream required to read the data.
-     * @param lobFileName name of the file that contains lob data.
+     * @param lobFile the file that contains lob data.
      * @exception  Exception  if an error occurs.     
      */
-    private void openLobFile(final String lobFileName) 
+    private void openLobFile(final File lobFile) 
         throws Exception 
     {
         RandomAccessFile lobRaf;
@@ -67,7 +74,7 @@
                 lobRaf = (RandomAccessFile)AccessController.doPrivileged
                 (new java.security.PrivilegedExceptionAction(){
                         public Object run() throws IOException{
-                            return new RandomAccessFile(lobFileName, "r");
+                            return new RandomAccessFile(lobFile, "r");
                         }   
                     }
                  );    	
@@ -75,7 +82,10 @@
                 throw pae.getException();
             }
         } catch (FileNotFoundException ex) {
-            throw LoadError.dataFileNotFound(lobFileName);
+            throw PublicAPI.wrapStandardException(
+                      StandardException.newException(
+                      SQLState.LOB_DATA_FILE_NOT_FOUND, 
+                      lobFile.getPath()));
         } 
         
         // set up stream to read from input file, starting from 

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=527319&r1=527318&r2=527319
==============================================================================
--- 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 Tue Apr
10 14:51:27 2007
@@ -27,6 +27,7 @@
 import java.io.InputStreamReader;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 import org.apache.derby.iapi.services.sanity.SanityManager;
@@ -1050,8 +1051,17 @@
                 // each lob column in the table has it's own file handle. 
                 // separate file handles are must, lob stream objects
                 // can not be reused until the whole row is inserted.
-                lobFileHandles[colIndex-1] = new ImportLobFile(lobFileName, 
-                                         controlFileReader.getDataCodeset());
+                File lobsFile = new File (lobFileName);
+                if (lobsFile.getParentFile() == null) {
+                    // lob file name is unqualified. lob file 
+                    // is expected to be in the same location as
+                    // the import file.
+                    lobsFile = new File((
+                                new File(inputFileName)).getParentFile(),
+                                        lobFileName);
+                }
+                lobFileHandles[colIndex-1] = new ImportLobFile(lobsFile, 
+                                             controlFileReader.getDataCodeset());
             }catch(Exception ex) {
                 throw LoadError.unexpectedError(ex);
             }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?view=diff&rev=527319&r1=527318&r2=527319
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Tue Apr 10 14:51:27
2007
@@ -3870,6 +3870,18 @@
                 <arg>hexString</arg>
             </msg>
 
+            <msg>
+                <name>XIE0P.S</name>
+                <text>Lob data file {0} referenced in the import file not found.</text>
+                <arg>fileName</arg>
+            </msg>
+
+            <msg>
+                <name>XIE0Q.S</name>
+                <text>Lob data file name cannot be null. </text>
+            </msg>
+
+
         </family>
 
 

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?view=diff&rev=527319&r1=527318&r2=527319
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Tue Apr 10 14:51:27 2007
@@ -1709,6 +1709,9 @@
 	String PERIOD_AS_CHAR_DELIMITER_NOT_ALLOWED                    ="XIE0K.S";
 	String TABLE_NOT_FOUND                                         ="XIE0M.S";
 	String IMPORTFILE_HAS_INVALID_HEXSTRING                        ="XIE0N.S";
+	String LOB_DATA_FILE_NOT_FOUND                                 ="XIE0P.S";
+	String LOB_DATA_FILE_NULL                                      ="XIE0Q.S";
+
 
 
     /*

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportLobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportLobTest.java?view=diff&rev=527319&r1=527318&r2=527319
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportLobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportLobTest.java
Tue Apr 10 14:51:27 2007
@@ -107,6 +107,9 @@
         // delete the rows from the import table.
         s.executeUpdate("DELETE FROM BOOKS_IMP");
         s.close();
+        // delete the export files. 
+        SupportFilesSetup.deleteFile(fileName);
+        SupportFilesSetup.deleteFile(lobsFileName);
     }
 
     
@@ -267,6 +270,30 @@
         verifyData(" * ");
     }
 
+    /**
+     * Test import/export of a table, using 
+     * SYSCS_EXPORT_TABLE_LOBS_TO_EXTFILE and 
+     * SYSCS_IMPORT_TABLE_LOBS_FROM_EXTFILE  procedures, 
+     * with an unqualified lob data file name as parameter
+     * for the export procedure.
+     */
+    public void testImportTableExportTableLobsInUnqalifiedExtFile()  
+        throws SQLException, IOException
+    {
+        // test export procedure with unqulified lob data  file name
+        // lob data file should get crated at the same location, where
+        // the main export file is created. And also perform import/export
+        // using "UTF-16" code set.
+        
+        doExportTableLobsToExtFile("APP", "BOOKS", fileName, 
+                                    "\t", "|", "UTF-16", 
+                                   "unql_books_lobs.dat");
+	    doImportTableLobsFromExtFile("APP", "BOOKS_IMP", fileName, 
+                                     "\t", "|", "UTF-16", 0);
+        verifyData(" * ");
+    }
+
+
     
     /*
      * Test import/export of all the columns using 
@@ -277,9 +304,9 @@
         throws SQLException, IOException
     {
         doExportQueryLobsToExtFile("select * from BOOKS", fileName,
-                                   null, null , null, lobsFileName);
+                                  null, null, "8859_1", lobsFileName);
 	    doImportDataLobsFromExtFile(null, "BOOKS_IMP", null, null, fileName, 
-                                   null, null, null, 0);
+                                   null, null , "8859_1", 0);
         verifyData(" * ");
 
         // perform import with column names specified in random order.
@@ -371,6 +398,44 @@
             assertSQLState(JDBC.vmSupportsJDBC4() ? "38000": "XIE0J", e);
         }
     }
+
+
+
+    /**
+     * Test import/export of a table, using 
+     * SYSCS_EXPORT_TABLE_LOBS_TO_EXTFILE and 
+     * SYSCS_IMPORT_TABLE_LOBS_FROM_EXTFILE  procedures, with an unqualified
+     * lobs file name as an argument value.
+     */
+    public void testImportTableExportWithInvalidLobFileName()  
+        throws SQLException, IOException
+    {
+        // test export of lob data with lob file name parameter 
+        // value as null,  it should fail.
+        try {
+            doExportTableLobsToExtFile("APP", "BOOKS", fileName, 
+                                       null, null , null, 
+                                       null);
+        }catch (SQLException e) {
+            assertSQLState("XIE0Q", e);
+        }
+
+        // export of lob data into an external file.
+        doExportTableLobsToExtFile("APP", "BOOKS", fileName, 
+                                   null, null , null, 
+                                   lobsFileName);
+        // delete the lob data file, and then perfom the import.
+        // import should fail with lob data file not found error. 
+        SupportFilesSetup.deleteFile(lobsFileName);
+        try {
+            // missing lob file, refered by the main import file.
+            doImportTableLobsFromExtFile("APP", "BOOKS_IMP", fileName, 
+                                         null, null, null, 0);
+        }catch (SQLException e) {
+            assertSQLState(JDBC.vmSupportsJDBC4() ? "38000": "XIE0P", e);
+        }
+    }
+
 
 
     /* 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java?view=diff&rev=527319&r1=527318&r2=527319
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
Tue Apr 10 14:51:27 2007
@@ -266,4 +266,19 @@
             throw (MalformedURLException) e.getException();
         } 
     }
+
+
+    public static boolean deleteFile(final String fileName) 
+    {
+        Boolean ret = (Boolean) AccessController.doPrivileged
+            (new java.security.PrivilegedAction() {
+                        
+                    public Object run() {
+                        return Boolean.valueOf((new File(fileName)).delete());
+                    }
+                }
+             );
+            
+        return ret.booleanValue();
+    }
 }



Mime
View raw message