UpdateAPI: How to use it


RDF Suite      RSSDB      RDF Update API      Download UpdateAPI      Installation      API specification      Usage      Error Handling     



In the following, we supose that UpdateAPI has been succesfuly installed, by following the installation instructions in this document. UpdateAPI is designed to be used be other applications that are connected to a postgres database. In these examples we demonstrate two ways of using the API: through a command line interactive db interface, and through java programs using JDBC.

In the following we consider UpdateAPI as compiled and the resulting library file (rql-spi-api.so) is installed in a location known by the user. We will refer to this location as UpdateApiPath and we will use it as a variable (so we can say that the library file is located at UpdateApiPath/rql-spi-api.so ). In your applications and tests you must replace UpdateApiPath with the actuall location of the library file. By default, the library is located at the BIN directory inside the UpdateAPI source directory.


1. Using UpdateAPI through postgres interactive command line client (psql)

1.1 Loading UpdateAPI


Run the command line client to connect to a database you have access to. From the command line interface, type:

   
> create function create_instance(text,text,text) returns int4 as
'UpdateApiPath/rql-spi-api.so' language 'c';
CREATE FUNCTION
> create function delete_object(text, text, text, int4) returns int4 as
'UpdateApiPath/rql-spi-api.so' language 'c';

CREATE FUNCTION
> create function add_property(text, text, text, text) returns int4 as
'UpdateApiPath/rql-spi-api.so' language 'c';

CREATE FUNCTION
> create function delete_property(text, text, text, text, int4) returns int4 as
'UpdateApiPath/rql-spi-api.so' language 'c';

CREATE FUNCTION
> create function update_property(text, text, text, text, text, int4) returns int4 as
'UpdateApiPath/rql-spi-api.so' language 'c';

CREATE FUNCTION
>



This will load all methods in UpdateAPI. If you want to load only some of them, type the create function expresions for only the methods you want to use.

1.2 Using UpdateAPI methods


In order to use UpdateAPI methods, you should first check the method specifications . In the following example, updates are occuring on the schema and data examples used in the API specification in this document.
   
> select create_instance('#davinci','','artist');
1
> select delete_object('#guernica', '', 'painting', 0);
1
> select add_property(
'', 'title', '#guernica', 'Guernica');
1
> select delete_property(
'#guernica', '', 'painting', 0);
1
> select update_property(
'#guernica', '', 'painting', 0);
1
>


If you haven't load (succesfully) any of the above methods, psql will reply with an error message. The above example shows a succesfull execution of the methods. If, for any reason, the requested action cannot be applied, -1 will be returned for each method that cannot act as requested. For example, if #guernica is not a painting, delete_object cannot perform the deletion, therefore -1 will be returned.

1.3 Removing UpdateAPi methods


After using UpdateAPIs, users might want to remove the methods from the database. This may be nessecary especialy if new versions of UpdateAPI must be loaded. In that case, the old methods must be removed in order to load the new ones.

In the following example, all UpdateAPI methods are removed succesfully:
   
> drop function create_instance(text,text,text);
DROP FUNCTION
> drop function delete_object(text, text, text, int4);
DROP FUNCTION
>
drop function add_property(text, text, text, text);
DROP FUNCTION
>
drop function delete_property(text, text, text, text, int4);
DROP FUNCTION
>
drop function update_property(text, text, text, text, text, int4);
DROP FUNCTION
>

2 Using UpdateAPI with java and JDBC


Users may load, use and/or drop UpdateAPI methods through their own applications. For this matter there are three example files that demonstrate this functionality. In order to run and use the examples, users must download them (see bellow) and change the values of a few variables. These are programs that are for demonstration purposes only. They all use JDBC to communicate with the database. In fact, these programs execute the same queries that where presented in the previous section (UpdateAPI through psql). Users should make their own applications instead of using the examples that follow.

In order to make these examples run, you need the jdbc driver.

2.1 Loading UpdateAPI


download

This a java program that loads updateAPI. In order to make it actually run, users must modify the
following variables in the source code:

   apiLocation is the location where the UpdateAPI library file (rql-spi-api.so) is located
   dblocation is the the location:port string for connecting to the database
   dbname is the name of the database where data is stored
   username is needed for accessing a database (the username of the database account)
   password the password for accessing the database account "username". If the account is passwordless, use the empty string here.

2.2 Using UpdateAPI


download

This is a java program that tests the updateAPI methods, using a specific ontology. We suppose that this ontology is allready loaded in the database by RSSDB. Users should not actully run this program, but they can check it to see how to make their own. If, nevertheless, a user insists on running the example, the following variables must be modified in the source code:

   dblocation is the the location:port string for connecting to the database
   dbname is the name of the database where data is stored
   username is needed for accessing a database (the username of the database account)
   password the password for accessing the database account "username". If the account is passwordless, use the empty string here.

2.3 Removing UpdateAPI


download

This is a java program that drops all updateAPI methods from the database. Users can use this example but it is strongly recomended to create their own loader and unloader. In order to run the example, the following variables must be modified in the source code:

   dblocation is the the location:port string for connecting to the database
   dbname is the name of the database where data is stored
   username is needed for accessing a database (the username of the database account)
   password the password for accessing the database account "username". If the account is passwordless, use the empty string here.