当前位置: 首页>>代码示例>>Java>>正文


Java SailConnection.close方法代码示例

本文整理汇总了Java中org.openrdf.sail.SailConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java SailConnection.close方法的具体用法?Java SailConnection.close怎么用?Java SailConnection.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openrdf.sail.SailConnection的用法示例。


在下文中一共展示了SailConnection.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadTestStatements

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
private static void loadTestStatements() throws Exception {
    final ValueFactory vf = sail.getValueFactory();

    final SailConnection sailConn = sail.getConnection();
    sailConn.begin();
    sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
    sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
    sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
    sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
    sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
    sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
    sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
    sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));

    sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
    sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
    sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
    sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
    sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
    sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
    sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:green"));
    sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:brown"));
    sailConn.commit();
    sailConn.close();
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:26,代码来源:QueryBenchmarkRunIT.java

示例2: testGetStatements

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
@Test
public void testGetStatements() throws SailException {
    final SailConnection con = cas.getConnection();
    try {
        con.begin();

        Assert.assertTrue(hasStatement(con, u1, p1, l1));
        Assert.assertFalse(hasStatement(con, u2, p2, l2));

        con.commit();
    } catch (final Throwable t) {
        con.rollback();
        throw t;
    } finally {
        con.close();
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:18,代码来源:ContextAwareSailTest.java

示例3: testGetContextIDs

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
@Test
public void testGetContextIDs() throws SailException {
    final SailConnection con = cas.getConnection();
    try {
        con.begin();

        final CloseableIteration<? extends Resource, SailException> cid = con.getContextIDs();
        try {
            assertTrue(cid.hasNext());
            assertThat(cid.next(), CoreMatchers.is(c1));
            assertFalse(cid.hasNext());
        } finally {
            cid.close();
        }

        con.commit();
    } catch (final Throwable t) {
        con.rollback();
        throw t;
    } finally {
        con.close();
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:24,代码来源:ContextAwareSailTest.java

示例4: getEntry

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
/**
 * Return the cache entry for the given resource, or null if this entry does not exist.
 *
 *
 * @param resource the resource to retrieve the cache entry for
 * @return
 */
@Override
public CacheEntry getEntry(URI resource) {
    try {
        try(LDCachingKiWiPersistenceConnection dbcon = persistence.getConnection()) {

            // load cache entry from database
            CacheEntry ce = dbcon.getCacheEntry(resource.stringValue());

            // if entry exists, load triples for the resource from the cache context of the repository
            if(ce != null) {
                SailConnection con = store.getConnection();
                try {
                    con.begin();

                    Model triples = new TreeModel();
                    ModelCommons.add(triples,con.getStatements(resource,null,null,true,store.getValueFactory().createURI(cacheContext)));
                    ce.setTriples(triples);

                    con.commit();
                } catch(SailException ex) {
                    con.rollback();
                } finally {
                    con.close();
                }
            }
            return ce;

        }

    } catch (SailException | SQLException e) {
        log.error("could not retrieve cached triples from repository",e);
    }

    return null;
}
 
开发者ID:apache,项目名称:marmotta,代码行数:43,代码来源:LDCachingKiWiBackend.java

示例5: putEntry

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
/**
 * Update the cache entry for the given resource with the given entry.
 *
 * @param resource the resource to update
 * @param entry    the entry for the resource
 */
@Override
public void putEntry(URI resource, CacheEntry entry) {
    try {
        try(LDCachingKiWiPersistenceConnection dbcon = persistence.getConnection()) {

            // store cache entry in database
            dbcon.removeCacheEntry(resource.stringValue());

            // update triples in cache
            SailConnection con = store.getConnection();
            try {
                con.begin();

                con.removeStatements(resource, null, null, store.getValueFactory().createURI(cacheContext));
                for(Statement stmt : entry.getTriples()) {
                    con.addStatement(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), store.getValueFactory().createURI(cacheContext));
                }

                con.commit();

                entry.setResource(store.getValueFactory().createURI(resource.stringValue()));

                dbcon.storeCacheEntry(entry);
            } catch(SailException ex) {
                con.rollback();
            } finally {
                con.close();
            }

        }

    } catch (SailException | SQLException e) {
        log.error("could not retrieve cached triples from repository",e);
    }

}
 
开发者ID:apache,项目名称:marmotta,代码行数:43,代码来源:LDCachingKiWiBackend.java

示例6: removeEntry

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
/**
 * Remove the cache entry for the given resource if it exists. Does nothing otherwise.
 *
 * @param resource the resource to remove the entry for
 */
@Override
public void removeEntry(URI resource) {
    try {
        try(LDCachingKiWiPersistenceConnection dbcon = persistence.getConnection()) {

            // store cache entry in database
            dbcon.removeCacheEntry(resource.stringValue());

            // update triples in cache
            SailConnection con = store.getConnection();
            try {
                con.begin();

                con.removeStatements(resource, null, null, store.getValueFactory().createURI(cacheContext));

                con.commit();
            } catch(SailException ex) {
                con.rollback();
            } finally {
                con.close();
            }

        }

    } catch (SailException | SQLException e) {
        log.error("could not remove cached triples from repository",e);
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:34,代码来源:LDCachingKiWiBackend.java

示例7: clear

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
/**
 * Clear all entries in the cache backend.
 */
@Override
public void clear() {
    try {
        try(LDCachingKiWiPersistenceConnection dbcon = persistence.getConnection()) {

            // list all entries and remove them
            CloseableIteration<KiWiCacheEntry, SQLException> entries = dbcon.listAll();
            while (entries.hasNext()) {
                dbcon.removeCacheEntry(entries.next());
            }

            // update triples in cache
            SailConnection con = store.getConnection();
            try {
                con.begin();

                con.removeStatements((Resource) null, null, null, store.getValueFactory().createURI(cacheContext));

                con.commit();
            } catch(SailException ex) {
                con.rollback();
            } finally {
                con.close();
            }

        }

    } catch (SailException | SQLException e) {
        log.error("could not remove cached triples from repository",e);
    }

}
 
开发者ID:apache,项目名称:marmotta,代码行数:36,代码来源:LDCachingKiWiBackend.java

示例8: userNotAddedCanNotInsert

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
/**
 * Ensure a user that has not been added to the Rya instance can not interact with it.
 */
@Test
public void userNotAddedCanNotInsert() throws Exception {
    final String user = testInstance.createUniqueUser();
    final SecurityOperations secOps = super.getConnector().securityOperations();

    final RyaClient userAClient = AccumuloRyaClientFactory.build(
            new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()),
            super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));

    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());

    // Create the user that will not be added to the instance of Rya, but will try to scan it.
    secOps.createLocalUser(user, new PasswordToken(user));

    //Try to add a statement the Rya instance with the unauthorized user. This should fail.
    boolean securityExceptionThrown = false;

    Sail sail = null;
    SailConnection sailConn = null;
    try {
        final AccumuloRdfConfiguration userCConf = makeRyaConfig(getRyaInstanceName(), user, user, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userCConf);
        sailConn = sail.getConnection();

        final ValueFactory vf = sail.getValueFactory();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));

    } catch(final RuntimeException e) {
        final Throwable cause = e.getCause();
        if(cause instanceof AccumuloSecurityException) {
            securityExceptionThrown = true;
        }
    } finally {
        if(sailConn != null) {
            sailConn.close();
        }
        if(sail != null) {
            sail.shutDown();
        }
    }

    assertTrue(securityExceptionThrown);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:48,代码来源:AccumuloAddUserIT.java

示例9: userAddedCanInsert

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
/**
 * Ensure a user that has been added to the Rya instance can interact with it.
 */
@Test
public void userAddedCanInsert() throws Exception {
    final String user = testInstance.createUniqueUser();
    final SecurityOperations secOps = super.getConnector().securityOperations();

    final RyaClient userAClient = AccumuloRyaClientFactory.build(
            new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()),
            super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));

    // Create the user that will not be added to the instance of Rya, but will try to scan it.
    secOps.createLocalUser(user, new PasswordToken(user));

    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());

    // Add the user.
    userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);

    // Try to add a statement to the Rya instance. This should succeed.
    Sail sail = null;
    SailConnection sailConn = null;

    try {
        final AccumuloRdfConfiguration userDConf = makeRyaConfig(getRyaInstanceName(), user, user, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userDConf);
        sailConn = sail.getConnection();

        final ValueFactory vf = sail.getValueFactory();
        sailConn.begin();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
        sailConn.close();

    } finally {
        if(sailConn != null) {
            sailConn.close();
        }
        if(sail != null) {
            sail.shutDown();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:45,代码来源:AccumuloAddUserIT.java

示例10: removedUserCanNotInsert

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
/**
 * Ensure a user that has been removed from the Rya instance can not interact with it.
 */
@Test
public void removedUserCanNotInsert() throws Exception {
    final String adminUser = testInstance.createUniqueUser();
    final String user = testInstance.createUniqueUser();
    final SecurityOperations secOps = super.getConnector().securityOperations();

    // Create the user that will install the instance of Rya.
    secOps.createLocalUser(adminUser, new PasswordToken(adminUser));
    secOps.grantSystemPermission(adminUser, SystemPermission.CREATE_TABLE);

    final RyaClient userAClient = AccumuloRyaClientFactory.build(
            new AccumuloConnectionDetails(adminUser, adminUser.toCharArray(), getInstanceName(), getZookeepers()),
            super.getClusterInstance().getCluster().getConnector(adminUser, adminUser));

    // Create the user that will be added to the instance of Rya.
    secOps.createLocalUser(user, new PasswordToken(user));

    final RyaClient userCClient = AccumuloRyaClientFactory.build(
            new AccumuloConnectionDetails(user, user.toCharArray(), getInstanceName(), getZookeepers()),
            super.getClusterInstance().getCluster().getConnector(user, user));

    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());

    // Add userC.
    userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);

    // Remove userA.
    userCClient.getRemoveUser().get().removeUser(getRyaInstanceName(), adminUser);

    // Show that userA can not insert anything.
    boolean securityExceptionThrown = false;

    Sail sail = null;
    SailConnection sailConn = null;
    try {
        final AccumuloRdfConfiguration userAConf = makeRyaConfig(getRyaInstanceName(), adminUser, adminUser, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userAConf);
        sailConn = sail.getConnection();

        final ValueFactory vf = sail.getValueFactory();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));

    } catch(final RuntimeException e) {
        final Throwable cause = e.getCause();
        if(cause instanceof AccumuloSecurityException) {
            securityExceptionThrown = true;
        }
    } finally {
        if(sailConn != null) {
            sailConn.close();
        }
        if(sail != null) {
            sail.shutDown();
        }
    }

    assertTrue(securityExceptionThrown);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:63,代码来源:AccumuloRemoveUserIT.java

示例11: setUp

import org.openrdf.sail.SailConnection; //导入方法依赖的package包/类
@Before
public void setUp() throws SailException {
    sail = new MemoryStore();
    sail.initialize();

    final ValueFactory vf = sail.getValueFactory();
    u1 = vf.createURI(NS, UUID.randomUUID().toString());
    u2 = vf.createURI(NS, UUID.randomUUID().toString());
    u3 = vf.createURI(NS, UUID.randomUUID().toString());
    u4 = vf.createURI(NS, UUID.randomUUID().toString());
    
    p1 = vf.createURI(NS, UUID.randomUUID().toString());
    p2 = vf.createURI(NS, UUID.randomUUID().toString());
    p3 = vf.createURI(NS, UUID.randomUUID().toString());
    p4 = vf.createURI(NS, UUID.randomUUID().toString());
    
    c1 = vf.createURI(NS, UUID.randomUUID().toString());
    c2 = vf.createBNode();
    
    l1 = vf.createLiteral(UUID.randomUUID().toString());
    l2 = vf.createLiteral(UUID.randomUUID().toString());
    l3 = vf.createLiteral(UUID.randomUUID().toString());
    l4 = vf.createLiteral(UUID.randomUUID().toString());
    
    final SailConnection con = sail.getConnection();
    try {
        con.begin();
        
        con.addStatement(u1, p1, l1, c1);
        con.addStatement(u2, p2, l2, c2);
        con.addStatement(u3, p3, l3, c1);
        con.addStatement(u4, p4, l4, c2);
        
        con.commit();
    } catch (final Throwable t) {
        con.rollback();
        throw t;
    } finally {
        con.close();
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:42,代码来源:AbstractContextTest.java


注:本文中的org.openrdf.sail.SailConnection.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。