You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "Dimov, Stefan" <st...@sap.com> on 2017/06/24 00:46:38 UTC

Enable update with Java

Hello,
I have Fuseki/Jena and I configure it thru Java code (no config files).
Does anybody know, how I can enable Fuseki update (e.g. – allow SPARQL INSERT/DELETE requests) thru Java code?

S.

Re: Enable update with Java

Posted by Andy Seaborne <an...@apache.org>.
Stefan,

Thanks for let me know.
Using the embedded server does look better from your description of the 
requirement. It is possible to setup the full server in code but it is 
messy and still ends up with an on-disk "run" area.

FYI:

There is now a way to run the embedded server (better called the "basic" 
server) from the command line.

A new module "jena-fuseki-basic" adds a command line program and creates 
a combined jar for it : "jena-fuseki-basic-VER-server.jar"

In the development build as of yesterday (!).

The basic server is the core Fuseki SPARQL engine, no security, no 
runtime area, no admin UI, not as a war file; just datasets and SPARQL, 
together with being about to serve static pages. It is entirely setup 
from the command line.

sparql.org is now running it.

     Andy

On 25/06/17 01:23, Dimov, Stefan wrote:
> Hi Andy,
> 
> Seems so, the updating was already enabled. It didn’t work for me, because I omitted something else.
> 
> Now it works.
> 
> On your questions. I’m configuring, starting and loading data into Fuseki, completely thru Java:
> 
> This is a configurarion code snippet:
> 
>      public static Dataset createEmptyDataset() {
>          Dataset ds;
>          if (inMemory) {
>              ds = DatasetFactory.createTxnMem();
>              LOGGER.info("Store type - in memory");
>          } else {
>              Location location = Location.create("tdb");
>              ds = TDBFactory.createDataset(location);
>              LOGGER.info("Store type - TDB");
>          }
>          return ds;
>      }
> 
> this is how I load the data:
> 
>      private static boolean loadGraphT(Dataset ds, String sourceFileName) {
>          String fileName = GRAPH_RES_FOLDER + sourceFileName;
>          File f = new File(fileName);
>          if (!f.exists()) return false;
>          String graphName = FILE_TO_GRAPH_NAME.get(sourceFileName.split("\\.")[0]);
>          ds.begin(ReadWrite.WRITE);
>          Model model = ds.getNamedModel(graphName);
>          FileManager.get().readModel(model, fileName);
>          ds.commit();
>          ds.end();
>          LOGGER.info("Graph file " + sourceFileName + " - loaded");
>          return true;
>      }
> 
> and this is how I start the server:
> 
>      private static void startFuseki(Dataset ds) {
>          FusekiEmbeddedServer server = FusekiEmbeddedServer.create()
>                  .add("/ds", ds)
>                  .build();
>          server.start() ;
>      }
> 
> Like I said, the INSERT/DELETE requests are working now (without changing the configuration), but anyway thanks for the response …
> 
> Regards,
> Stefan
> 
> 
> 
> 
> On 6/24/17, 1:43 AM, "Andy Seaborne" <an...@apache.org> wrote:
> 
>      
>      
>      On 24/06/17 01:46, Dimov, Stefan wrote:
>      > Hello,
>      > I have Fuseki/Jena and I configure it thru Java code (no config files).
>      > Does anybody know, how I can enable Fuseki update (e.g. – allow SPARQL INSERT/DELETE requests) thru Java code?
>      >
>      > S.
>      >
>      
>      Hi Stefan,
>      
>      It needs to have the right services added to the DataAccessPointRegistry
>      though the best way to do that is probably not directly (it is an
>      internal API really though quite stable).
>      
>      How are you configuring it in code and also which form of Fuseki?
>      
>      The embedded server has a builder and one option is whether a dataset is
>      updatable or not:
>      
>      http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html
>      
>      which has no required disk footprint.
>      
>      or are you launching it by calling FusekiCmd.main (make sure "--update"
>      is used)
>      
>      or directly manipulating the DataAccessPointRegistry?
>      (the command line
>      
>      (There'll be a command line for the embedded server soon - for running
>      Fuseki without admin.)
>      
>           Andy
>      
> 

Re: Enable update with Java

Posted by "Dimov, Stefan" <st...@sap.com>.
Hi Andy,

Seems so, the updating was already enabled. It didn’t work for me, because I omitted something else.

Now it works.

On your questions. I’m configuring, starting and loading data into Fuseki, completely thru Java:

This is a configurarion code snippet:

    public static Dataset createEmptyDataset() {
        Dataset ds;
        if (inMemory) {
            ds = DatasetFactory.createTxnMem();
            LOGGER.info("Store type - in memory");
        } else {
            Location location = Location.create("tdb");
            ds = TDBFactory.createDataset(location);
            LOGGER.info("Store type - TDB");
        }
        return ds;
    }

this is how I load the data:

    private static boolean loadGraphT(Dataset ds, String sourceFileName) {
        String fileName = GRAPH_RES_FOLDER + sourceFileName;
        File f = new File(fileName);
        if (!f.exists()) return false;
        String graphName = FILE_TO_GRAPH_NAME.get(sourceFileName.split("\\.")[0]);
        ds.begin(ReadWrite.WRITE);
        Model model = ds.getNamedModel(graphName);
        FileManager.get().readModel(model, fileName);
        ds.commit();
        ds.end();
        LOGGER.info("Graph file " + sourceFileName + " - loaded");
        return true;
    }

and this is how I start the server:

    private static void startFuseki(Dataset ds) {
        FusekiEmbeddedServer server = FusekiEmbeddedServer.create()
                .add("/ds", ds)
                .build();
        server.start() ;
    }

Like I said, the INSERT/DELETE requests are working now (without changing the configuration), but anyway thanks for the response …

Regards,
Stefan




On 6/24/17, 1:43 AM, "Andy Seaborne" <an...@apache.org> wrote:

    
    
    On 24/06/17 01:46, Dimov, Stefan wrote:
    > Hello,
    > I have Fuseki/Jena and I configure it thru Java code (no config files).
    > Does anybody know, how I can enable Fuseki update (e.g. – allow SPARQL INSERT/DELETE requests) thru Java code?
    > 
    > S.
    > 
    
    Hi Stefan,
    
    It needs to have the right services added to the DataAccessPointRegistry 
    though the best way to do that is probably not directly (it is an 
    internal API really though quite stable).
    
    How are you configuring it in code and also which form of Fuseki?
    
    The embedded server has a builder and one option is whether a dataset is 
    updatable or not:
    
    http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html
    
    which has no required disk footprint.
    
    or are you launching it by calling FusekiCmd.main (make sure "--update" 
    is used)
    
    or directly manipulating the DataAccessPointRegistry?
    (the command line
    
    (There'll be a command line for the embedded server soon - for running 
    Fuseki without admin.)
    
         Andy
    


Re: Enable update with Java

Posted by Andy Seaborne <an...@apache.org>.

On 24/06/17 01:46, Dimov, Stefan wrote:
> Hello,
> I have Fuseki/Jena and I configure it thru Java code (no config files).
> Does anybody know, how I can enable Fuseki update (e.g. – allow SPARQL INSERT/DELETE requests) thru Java code?
> 
> S.
> 

Hi Stefan,

It needs to have the right services added to the DataAccessPointRegistry 
though the best way to do that is probably not directly (it is an 
internal API really though quite stable).

How are you configuring it in code and also which form of Fuseki?

The embedded server has a builder and one option is whether a dataset is 
updatable or not:

http://jena.apache.org/documentation/fuseki2/fuseki-embedded.html

which has no required disk footprint.

or are you launching it by calling FusekiCmd.main (make sure "--update" 
is used)

or directly manipulating the DataAccessPointRegistry?
(the command line

(There'll be a command line for the embedded server soon - for running 
Fuseki without admin.)

     Andy