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


Java Sail.getConnection方法代码示例

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


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

示例1: userNotAddedCanNotInsert

import org.openrdf.sail.Sail; //导入方法依赖的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

示例2: userAddedCanInsert

import org.openrdf.sail.Sail; //导入方法依赖的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

示例3: removedUserCanNotInsert

import org.openrdf.sail.Sail; //导入方法依赖的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


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