Project

General

Profile

Actions

Developer's Guide Version v2.x

This page describes how to develop a Java program with OntoQL library. This guide is based on the Eclipse IDE.

We suppose that an OntoDB schema is correctly installed. If it is not the case, please refer to this page.

Create a new Java project

  • Start Eclipse
  • Create a new Java project (File => New => Java Project) and from the Project name field, input OntoQLSample value, and click on finish

Configure your Java project

  • From your operating system explorer, create a lib directory
  • Copy from the OntoQL distribution (lib) all jar files into the new lib directory
  • From the properties of the OntoQLSample project, add the previous Jar into the classpath (Add JARs option)

Create a main class

  • Create a new class called OntoQLSampleTest with a specific package (at your convenance).
  • Copy this code
public class OntoQLSampleTest {
    public static void main(String[] args) throws SQLException {
        Properties props = new Properties();

        props.setProperty("server.host", "localhost");
        props.setProperty("server.port", "5433");
        props.setProperty("server.user", "postgres");
        props.setProperty("server.password", "psql");
        props.setProperty("server.sid", "mariusqltest");
        props.setProperty("driver.class", "fr.ensma.lias.mariusql.driver.postgresql.MariusQLDriverImpl");

        // Create session
        MariusQLSession currentMariusSession = new MariusQLSessionImpl(props);
        currentMariusSession.getMetaModelCache().setEnabled(true);
        currentMariusSession.getModelCache().setEnabled(true);
        currentMariusSession.getQueryCache().setEnabled(true);

        currentMariusSession.setReferenceLanguage(MariusQLConstants.FRENCH);
        currentMariusSession.setDefaultNameSpace("http://www.lias.fr/");

        MariusQLStatement statement = currentMariusSession.createMariusQLStatement();
        statement.executeUpdate("CREATE #CLASS myFirstClass (DESCRIPTOR (#code = 'myFirstClassCode'))");

        final MariusQLResultSet executeQuery = statement.executeQuery("select #code from #class where #code='myFirstClassCode'");
        executeQuery.next();
        System.out.println(executeQuery.getString(1));

        currentMariusSession.rollback();
    }
}
  • Execute your program

Updated by Mickael BARON almost 7 years ago ยท 5 revisions