Project

General

Profile

lobs.diff

Igor Skornyakov, 11/25/2022 12:48 PM

Download (5.32 KB)

View differences:

rules/schema/import.xml 2022-11-25 17:43:53 +0000
97 97
**     OM  20210602          Improved error reporting.
98 98
**     OM  20220325          The hardcode [data]/[namespace] is gone. Using [p2j.cfg.xml] now to locate
99 99
**                           database import settings. Dropped dead code.
100
**    IAS  20221125          Make location of LOB files configurable for import
100 101
-->
101 102

  
102 103
<!--
......
188 189
   
189 190
   <!-- global variables -->
190 191
   <variable name="dataPath"        type="java.lang.String" />
192
   <variable name="lobPath"         type="java.lang.String" />
191 193
   <variable name="dataFile"        type="java.io.File" />
192 194
   <variable name="checkTypes"      init="false" />
193 195
   <variable name="maxThreads"      init="8" />
......
264 266
         <action>dataPath = sprintf("data/dump/%s/", dbName)</action>
265 267
      </rule>
266 268
      
269
   	  <rule>!dataPath.endsWith("/")
270
     	 <action>dataPath = dataPath.concat("/")</action>
271
      </rule>
272
      
273
   	  <rule>lobPath == null
274
   		 <action>lobPath = "lobs"</action>
275
   	  </rule>
276

  
277
      <rule>!imp.isAbsolute(lobPath)
278
         <action>lobPath = sprintf("%s%s/", dataPath, lobPath)</action>
279
      </rule>
280

  
267 281
      <rule>printfln("INFO:  Data export files will be read from '%s'", dataPath)</rule>
268 282
      <rule>!io.exists(dataPath, false)
269 283
         <action>
......
300 314
      
301 315
      <post-rules>
302 316
         <!-- all mappings have been added; initialize the import worker -->
303
         <rule>imp.initialize(ormProps, dataPath)</rule>
317
         <rule>imp.initialize(ormProps, dataPath, lobPath)</rule>
304 318
      </post-rules>
305 319
   </rule-set>
306 320
   
src/com/goldencode/p2j/schema/ImportWorker.java 2022-11-25 17:45:11 +0000
167 167
**     OM  20221007          Wasted a value in ID_GEN_SEQUENCE's initialization because some dialects have
168 168
**                           issues when requesting the CurVal if positioned at start.
169 169
**     OM  20221013          Insert a file-path separator in sequence dump file path if one is needed.
170
**    IAS  20221125          Make location of LOB files configurable for import
170 171
*/
171 172

  
172 173
/*
......
228 229
import java.io.*;
229 230
import java.nio.*;
230 231
import java.nio.charset.*;
232
import java.nio.file.*;
231 233
import java.sql.*;
232 234
import java.sql.Statement;
233 235
import java.util.*;
......
323 325
   /** Directory path containing export files for the database being imported */
324 326
   static String dataPath = null;
325 327
   
328
   /** Directory path containing export LOB data for the database being imported */
329
   static String lobPath = null;
330

  
326 331
   /** The database we import into. */
327 332
   static Database database = null;
328 333
   
......
680 685
       *          Path of directory containing data export files, and parent directory of LOB
681 686
       *          export directory, if any.
682 687
       */
683
      public void initialize(Properties props, String dataPath)
688
      public void initialize(Properties props, String dataPath, String lobPath)
684 689
      {
685 690
         ImportWorker.dataPath = dataPath;
691
         ImportWorker.lobPath = lobPath;
692
         
686 693
         String databaseName = props.getProperty(Settings.DATABASE_NAME);
687 694
         ImportWorker.database = new Database(databaseName, Database.Type.PRIMARY, true);
688 695
         
......
714 721
         startTime = System.currentTimeMillis();
715 722
      }
716 723
      
724
      /** Check is file path is absolute.
725
       * 
726
       * @param path
727
       *        file path to be checked
728
       * @return <code>true</code> is file path is absolute. 
729
       */
730
      public boolean isAbsolute(String path)
731
      {
732
         return Paths.get(path).isAbsolute();
733
      }
717 734
      /**
718 735
       * Open a new database session.
719 736
       *
src/com/goldencode/p2j/schema/PropertyMapper.java 2022-11-25 17:43:40 +0000
49 49
**     OM  20210602          Public field member name change.
50 50
**     OM  20210619          Removed references to ImportWorker static field.
51 51
**     CA  20220520          Fixed dataPath when is not ending with file separator.
52
**    IAS  20221125          Make location of LOB files configurable for import/
52 53
*/
53 54

  
54 55
/*
......
135 136
public final class PropertyMapper
136 137
implements SchemaParserTokenTypes
137 138
{
138
   /** Short name of directory containing LOB data, if any; child of data dump directory */
139
   private static final String lobDir = "lobs" + File.separatorChar;
139
//   /** Short name of directory containing LOB data, if any; child of data dump directory */
140
//   private static final String lobDir = "lobs" + File.separatorChar;
140 141
   
141 142
   /** The metadata for this property. */
142 143
   private final PropertyMeta propertyMeta;
......
399 400
    */
400 401
   private static byte[] readLobData(String locator)
401 402
   {
402
      String path = ImportWorker.dataPath;
403
      String path = ImportWorker.lobPath;
403 404
      if (!path.endsWith(File.separator))
404 405
      {
405 406
         path = path + File.separator;
406 407
      }
407
      path = path + lobDir + locator;
408
      path = path + locator;
408 409
      File file = new File(path);
409 410
      if (!file.exists())
410 411
      {