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


Java ClientState类代码示例

本文整理汇总了Java中org.apache.cassandra.service.ClientState的典型用法代码示例。如果您正苦于以下问题:Java ClientState类的具体用法?Java ClientState怎么用?Java ClientState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: parseSchema

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
/**
 * Get the meta data (column definitions) for the target table.
 * 
 * @param query The CREATE TABLE statement for the table the Json data should be put into.
 * @return The table's meta data
 */
private static CFMetaData parseSchema(String query) {
    try {
        ClientState state = ClientState.forInternalCalls();
        ParsedStatement.Prepared prepared = QueryProcessor.getStatement(query, state);
        CQLStatement stmt = prepared.statement;
        stmt.validate(state);

        if (!stmt.getClass().equals(CreateTableStatement.class)) {
            throw new IllegalArgumentException("Invalid query, must be a CREATE TABLE statement");
        }

        return CreateTableStatement.class.cast(stmt).getCFMetaData();
    } catch (RequestValidationException | IllegalArgumentException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:PubGrade,项目名称:Json2SSTable,代码行数:23,代码来源:Json2SSTable.java

示例2: checkAccess

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void checkAccess(ClientState state) throws UnauthorizedException
{
    AuthenticatedUser user = state.getUser();

    boolean isSuper = user.isSuper();

    if (superuser != null && user.getName().equals(username))
        throw new UnauthorizedException("You aren't allowed to alter your own superuser status");

    if (superuser != null && !isSuper)
        throw new UnauthorizedException("Only superusers are allowed to alter superuser status");

    if (!user.isSuper() && !user.getName().equals(username))
        throw new UnauthorizedException("You aren't allowed to alter this user");

    if (!isSuper)
    {
        for (IAuthenticator.Option option : opts.getOptions().keySet())
        {
            if (!DatabaseDescriptor.getAuthenticator().alterableOptions().contains(option))
                throw new UnauthorizedException(String.format("You aren't allowed to alter %s option", option));
        }
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:25,代码来源:AlterUserStatement.java

示例3: system_add_column_family

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public String system_add_column_family(CfDef cf_def)
throws InvalidRequestException, SchemaDisagreementException, TException
{
    logger.debug("add_column_family");

    try
    {
        ClientState cState = state();
        String keyspace = cState.getKeyspace();
        cState.hasKeyspaceAccess(keyspace, Permission.CREATE);
        cf_def.unsetId(); // explicitly ignore any id set by client (Hector likes to set zero)
        CFMetaData cfm = CFMetaData.fromThrift(cf_def);
        CFMetaData.validateCompactionOptions(cfm.compactionStrategyClass, cfm.compactionStrategyOptions);
        cfm.addDefaultIndexNames();

        if (!cfm.getTriggers().isEmpty())
            state().ensureIsSuper("Only superusers are allowed to add triggers.");

        MigrationManager.announceNewColumnFamily(cfm);
        return Schema.instance.getVersion().toString();
    }
    catch (RequestValidationException e)
    {
        throw ThriftConversion.toThrift(e);
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:27,代码来源:CassandraServer.java

示例4: grantPermissionsToCreator

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
/**
 * Grant all applicable permissions on the newly created role to the user performing the request
 * see also: SchemaAlteringStatement#grantPermissionsToCreator and the overridden implementations
 * of it in subclasses CreateKeyspaceStatement & CreateTableStatement.
 * @param state
 */
private void grantPermissionsToCreator(ClientState state)
{
    // The creator of a Role automatically gets ALTER/DROP/AUTHORIZE permissions on it if:
    // * the user is not anonymous
    // * the configured IAuthorizer supports granting of permissions (not all do, AllowAllAuthorizer doesn't and
    //   custom external implementations may not)
    if (!state.getUser().isAnonymous())
    {
        try
        {
            DatabaseDescriptor.getAuthorizer().grant(AuthenticatedUser.SYSTEM_USER,
                                                     role.applicablePermissions(),
                                                     role,
                                                     RoleResource.role(state.getUser().getName()));
        }
        catch (UnsupportedOperationException e)
        {
            // not a problem, grant is an optional method on IAuthorizer
        }
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:28,代码来源:CreateRoleStatement.java

示例5: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
/**
 * The <code>CqlParser</code> only goes as far as extracting the keyword arguments
 * from these statements, so this method is responsible for processing and
 * validating.
 *
 * @throws InvalidRequestException if arguments are missing or unacceptable
 */
public void validate(ClientState state) throws RequestValidationException
{
    ThriftValidation.validateKeyspaceNotSystem(name);

    // keyspace name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace name", name));
    if (name.length() > Schema.NAME_LENGTH)
        throw new InvalidRequestException(String.format("Keyspace names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));

    attrs.validate();

    if (attrs.getReplicationStrategyClass() == null)
        throw new ConfigurationException("Missing mandatory replication strategy class");

    // The strategy is validated through KSMetaData.validate() in announceNewKeyspace below.
    // However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
    // so doing proper validation here.
    AbstractReplicationStrategy.validateReplicationStrategy(name,
                                                            AbstractReplicationStrategy.getClass(attrs.getReplicationStrategyClass()),
                                                            StorageService.instance.getTokenMetadata(),
                                                            DatabaseDescriptor.getEndpointSnitch(),
                                                            attrs.getReplicationOptions());
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:32,代码来源:CreateKeyspaceStatement.java

示例6: getStatement

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
private static <T extends CQLStatement> Pair<T, List<ColumnSpecification>> getStatement(String query, Class<T> klass, String type)
{
    try
    {
        ClientState state = ClientState.forInternalCalls();
        ParsedStatement.Prepared prepared = QueryProcessor.getStatement(query, state);
        CQLStatement stmt = prepared.statement;
        stmt.validate(state);

        if (!stmt.getClass().equals(klass))
            throw new IllegalArgumentException("Invalid query, must be a " + type + " statement");

        return Pair.create(klass.cast(stmt), prepared.boundNames);
    }
    catch (RequestValidationException e)
    {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:20,代码来源:CQLSSTableWriter.java

示例7: processStatement

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public ResultMessage processStatement(CQLStatement statement, QueryState queryState, QueryOptions options)
throws RequestExecutionException, RequestValidationException
{
    logger.trace("Process {} @CL.{}", statement, options.getConsistency());
    ClientState clientState = queryState.getClientState();
    statement.checkAccess(clientState);
    statement.validate(clientState);

    ResultMessage result = statement.execute(queryState, options);
    return result == null ? new ResultMessage.Void() : result;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:12,代码来源:QueryProcessor.java

示例8: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void validate(ClientState state)
{
    Collection<Function> olds = Schema.instance.getFunctions(functionName);

    if (!argsPresent && olds != null && olds.size() > 1)
        throw new InvalidRequestException(String.format("'DROP FUNCTION %s' matches multiple function definitions; " +
                                                        "specify the argument types by issuing a statement like " +
                                                        "'DROP FUNCTION %s (type, type, ...)'. Hint: use cqlsh " +
                                                        "'DESCRIBE FUNCTION %s' command to find all overloads",
                                                        functionName, functionName, functionName));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:12,代码来源:DropFunctionStatement.java

示例9: processBatch

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public ResultMessage processBatch(BatchStatement batch, QueryState queryState, BatchQueryOptions options)
throws RequestExecutionException, RequestValidationException
{
    ClientState clientState = queryState.getClientState();
    batch.checkAccess(clientState);
    batch.validate();
    batch.validate(clientState);
    return batch.execute(queryState, options);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:10,代码来源:QueryProcessor.java

示例10: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void validate(ClientState state) throws RequestValidationException
{
    state.ensureNotAnonymous();

    if (!DatabaseDescriptor.getRoleManager().isExistingRole(role))
        throw new InvalidRequestException(String.format("%s doesn't exist", role.getRoleName()));

    if (!DatabaseDescriptor.getRoleManager().isExistingRole(grantee))
        throw new InvalidRequestException(String.format("%s doesn't exist", grantee.getRoleName()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:11,代码来源:RoleManagementStatement.java

示例11: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void validate(ClientState state) throws InvalidRequestException
{
    if (hasConditions() && attrs.isTimestampSet())
        throw new InvalidRequestException("Cannot provide custom timestamp for conditional updates");

    if (isCounter() && attrs.isTimestampSet())
        throw new InvalidRequestException("Cannot provide custom timestamp for counter updates");

    if (isCounter() && attrs.isTimeToLiveSet())
        throw new InvalidRequestException("Cannot provide custom TTL for counter updates");
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:12,代码来源:ModificationStatement.java

示例12: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void validate(ClientState state) throws RequestValidationException
{
    ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
    try
    {
        TriggerExecutor.instance.loadTriggerInstance(triggerClass);
    }
    catch (Exception e)
    {
        throw new ConfigurationException(String.format("Trigger class '%s' doesn't exist", triggerClass));
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:13,代码来源:CreateTriggerStatement.java

示例13: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void validate(ClientState state) throws InvalidRequestException
{
    UDFunction.assertUdfsEnabled(language);

    if (ifNotExists && orReplace)
        throw new InvalidRequestException("Cannot use both 'OR REPLACE' and 'IF NOT EXISTS' directives");

    if (Schema.instance.getKSMetaData(functionName.keyspace) == null)
        throw new InvalidRequestException(String.format("Cannot add function '%s' to non existing keyspace '%s'.", functionName.name, functionName.keyspace));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:11,代码来源:CreateFunctionStatement.java

示例14: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void validate(ClientState state) throws RequestValidationException
{
    opts.validate();

    if (role.getRoleName().isEmpty())
        throw new InvalidRequestException("Role name can't be an empty string");

    // validate login here before checkAccess to avoid leaking role existence to anonymous users.
    state.ensureNotAnonymous();

    if (!ifNotExists && DatabaseDescriptor.getRoleManager().isExistingRole(role))
        throw new InvalidRequestException(String.format("%s already exists", role.getRoleName()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:14,代码来源:CreateRoleStatement.java

示例15: validate

import org.apache.cassandra.service.ClientState; //导入依赖的package包/类
public void validate(ClientState state) throws RequestValidationException
{
    opts.validate();

    if (superuser == null && opts.isEmpty())
        throw new InvalidRequestException("ALTER USER can't be empty");

    // validate login here before checkAccess to avoid leaking user existence to anonymous users.
    state.ensureNotAnonymous();

    if (!Auth.isExistingUser(username))
        throw new InvalidRequestException(String.format("User %s doesn't exist", username));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:14,代码来源:AlterUserStatement.java


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