Package com.complexible.stardog.api

Examples of com.complexible.stardog.api.Connection


  /**
   * Test method for validating connection configured correctly
   */
  @Test
  public void testBasicSnarl() {
    Connection con = dataSource.getConnection();
    assertNotNull(con);
  }
View Full Code Here


   * @param action callback to run
   * @param <T> type of callback to run
   * @return generic type
   */
  public <T> T execute(ConnectionCallback<T> action) {
    Connection connection = dataSource.getConnection();
   
    try {
      connection.begin();
      T t =  action.doWithConnection(connection);
      connection.commit();
      return t;
    } catch (StardogException e) {
      log.error("Error executing ConnectionCallback", e);
      throw new RuntimeException(e);
    } finally {
View Full Code Here

      dataSource.releaseConnection(connection);
    }
  }
 
  public void remove(String subject, String predicate, Object object, String graphUri) {
    Connection connection = dataSource.getConnection();
    URIImpl subjectResource = null;
    URIImpl predicateResource = null;
    Resource context = null;
   
    if (subject != null) {
      subjectResource = new URIImpl(subject);
    }
    if (predicate != null) {
      predicateResource = new URIImpl(predicate);
    }
   
    if (graphUri != null) {
      context = ValueFactoryImpl.getInstance().createURI(graphUri);
    }
   
    Value objectValue = null;
    if (object != null) {
      objectValue = TypeConverter.asLiteral(object);
    }
   
    try {
      connection.begin();
      connection.remove().statements(subjectResource, predicateResource, objectValue, context);
      connection.commit();
    } catch (StardogException e) {
      log.error("Error with remove statement", e);
      throw new RuntimeException(e);
    } finally {
      dataSource.releaseConnection(connection);
View Full Code Here

   * <code>remove</code>
   * @param graphUri - the context of the graph to remove.  If the context is
     * {@link Contexts#DEFAULT}, this will remove the default graph (no context).
   */
  public void remove(String graphUri) {
    Connection connection = dataSource.getConnection();
   
    try {
      connection.begin();
      connection.remove().context(ValueFactoryImpl.getInstance().createURI(graphUri));
      connection.commit();
    } catch (StardogException e) {
      log.error("Error removing graph from Stardog", e);
      throw new RuntimeException(e);
    } finally {
      dataSource.releaseConnection(connection);
View Full Code Here

      dataSource.releaseConnection(connection);
    }
  }
 
  public void singleton(String subject, String predicate, Object object, String graphUri) {
    Connection connection = dataSource.getConnection();
   
    URIImpl subjectResource = null;
    URIImpl predicateResource = null;
    Resource context = null;
   
    if (subject != null) {
      subjectResource = new URIImpl(subject);
    }
    if (predicate != null) {
      predicateResource = new URIImpl(predicate);
    }
   
    if (graphUri != null) {
      context = ValueFactoryImpl.getInstance().createURI(graphUri);
    }
   
    Value objectValue = TypeConverter.asLiteral(object);
   
    try {
      connection.begin();
      connection.remove().statements(subjectResource, predicateResource, null, context);
      connection.add().statement(subjectResource, predicateResource, objectValue, context);
      connection.commit();
    } catch (StardogException e) {
      log.error("Error with remove statement", e);
      throw new RuntimeException(e);
    } finally {
      dataSource.releaseConnection(connection);
View Full Code Here

    ArrayList<T> list = new ArrayList<T>();
    if (subject == null && predicate == null) {
      return list;
    }
   
    Connection connection = dataSource.getConnection();
    Getter getter = null;
    try {
      getter = connection.get();
     
      if (subject != null) {
        getter.subject(new URIImpl(subject));
      }
     
View Full Code Here

   * @param action AdderCallBack, generic type
   * @param <T> generic type of AdderCallback
   * @return generic type T
   */
  public <T> T doWithAdder(AdderCallback<T> action) {
    Connection connection = dataSource.getConnection();
    Adder adder = null;
    try {
      connection.begin();
      adder = connection.add();
      T t = action.add(adder);
      connection.commit();
      return t;
    } catch (StardogException e) {
      log.error("Error with adder ", e);
      throw new RuntimeException(e);
    } finally {
View Full Code Here

   * @param action RemoverCallback, generic type
   * @param <T> Generic type of RemoverCallback
   * @return generic type T
   */
  public <T> T doWithRemover(RemoverCallback<T> action) {
    Connection connection = dataSource.getConnection();
    Remover remover = null;
    try {
      connection.begin();
      remover = connection.remove();
      T t = action.remove(remover);
      connection.commit();
      return t;
    } catch (StardogException e) {
      log.error("Error with remover ", e);
      throw new RuntimeException(e);
    } finally {
View Full Code Here

  public <T> List<T> construct(String sparql, GraphMapper<T> mapper) {
    return construct(sparql, null, mapper);
  }
 
  public <T> List<T> construct(String sparql,  Map<String, Object> args, GraphMapper<T> mapper) {
    Connection connection = dataSource.getConnection();
    GraphQueryResult result = null;
    try {
      GraphQuery query = connection.graph(sparql);
     
      if (args != null) {
        for (Entry<String, Object> arg : args.entrySet()) {          
          query.parameter(arg.getKey(), arg.getValue());
        }
View Full Code Here

   * @param mapper implementation of the RowMapper interface
   * @param <T> generic type of RowMapper
   * @return List of results from the RowMapper calls
   */
  public <T> List<T> query(String sparql, Map<String, Object> args, RowMapper<T> mapper) {
    Connection connection = dataSource.getConnection();
    TupleQueryResult result = null;
    try {
      SelectQuery query = connection.select(sparql);
     
      if (args != null) {
        for (Entry<String, Object> arg : args.entrySet()) {          
          query.parameter(arg.getKey(), arg.getValue());
        }
View Full Code Here

TOP

Related Classes of com.complexible.stardog.api.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.