1 Reply Latest reply on Mar 4, 2016 10:28 PM by alwu-Oracle

    How to add ID using Bulk Loader ?

    3180035

      I am loading RDF data into Oracle 12c using Bulk Loader.

      I performed the following steps

      1] Created a PDB

      2] Enabled RDF semantic

      3] Created a tablespace create tablespace rdf_users datafile 'rdf_users02.dbf' size 100m;
      4] Create User create user rajesh indentified by shah default tablespace = rdf_users;
      5] Create Table CREATE TABLE karan123 (id NUMBER, triple SDO_RDF_TRIPLE_S);

      6] Create Model EXECUTE SEM_APIS.CREATE_SEM_MODEL(karan456, 'karan123', 'triple');

       

       

      Now from the example given in the documentation I wrote this simple code to load the RDF.

       

      import java.io.File;

      import java.io.FileInputStream;

      import java.io.InputStream;

      import java.io.PrintStream;

       

       

      import oracle.spatial.rdf.client.jena.GraphOracleSem;

      import oracle.spatial.rdf.client.jena.Oracle;

       

      public class BatchLoader {

       

        public static void main(String[] args) throws Exception {

        String szJdbcURL = "jdbc:oracle:thin:@localhost:1521/PROJOWL2";

           String szUser    = "";

           String szPasswd  = "";

           String szModelName = "karan456";

       

       

           Oracle oracle = new Oracle(szJdbcURL, szUser, szPasswd);

           //Model model = ModelOracleSem.createOracleSemModel(oracle, szModelName);

         

         

           GraphOracleSem graph = new GraphOracleSem(oracle, szModelName);

           PrintStream psOut = System.out;

           String dirname = "C:\\Users\\karan\\Desktop\\rdffiles";

           File fileDir = new File(dirname);

           String[] szAllFiles = fileDir.list();

         

           for (int idx = 0; idx < szAllFiles.length; idx++) {

             String szIndFileName = dirname + File.separator + szAllFiles[idx];

             psOut.println("process to [ID = " + idx + " ] file " + szIndFileName);

             psOut.flush();

           

             try{

             InputStream is = new FileInputStream(szIndFileName);

               graph.getBulkUpdateHandler().prepareBulk(

                   is,                    // input stream

                   "<http://www.PhoneLab.com/ontologies/PhoneLab.owl",  // base URI

                   "N-TRIPLE",             // data file type: can be RDF/XML, N-TRIPLE, etc.

                   "rdf_users",               // tablespace

                   null,                  // flags

                   null,                  // listener

                   null                   // staging table name.

                   );

               is.close();

             }catch(Throwable  t){

             psOut.println("Hit exception " + t.getMessage());    

             }

           }

           graph.getBulkUpdateHandler().completeBulk(

             null,  // flags for invoking SEM_APIS.bulk_load_from_staging_table

             null   // staging table name

           );

           graph.close();

           oracle.dispose();

        }

      }

       

       

      It successfully adds the RDF into the oracle table but I realized it  gives the ID as null. How do I assign a ID via the code ? (the first ID 1 is given manually by me)

      Screenshot (47).png

        • 1. Re: How to add ID using Bulk Loader ?
          alwu-Oracle

          Hi,

           

          It is a good idea not to use an ID column in the application table. That additional column does not help query at all. It is cleaner (and also more robust) to remove that ID column.

           

          Note that when you give a new graph (model) name to Jena Adapter, we will create an application table for you automatically. And that application table has no ID column.

           

          Thanks,


          Zhe Wu