Search in sources :

Example 1 with CqlRows

use of me.prettyprint.cassandra.model.CqlRows in project sling by apache.

the class CassandraResourceProviderUtil method isResourceExists.

public static boolean isResourceExists(CassandraResourceProvider resourceProvider, Keyspace keyspace, String path) throws Exception {
    String cql = resourceProvider.getCassandraMapperMap().get(CassandraResourceProviderUtil.getColumnFamilySector(path)).getCQL(CassandraResourceProviderUtil.getColumnFamilySector(path), CassandraResourceProviderUtil.getRemainingPath(path));
    QueryResult<CqlRows<String, String, String>> result = CassandraResourceProviderUtil.executeQuery(cql, keyspace, new StringSerializer());
    return recordExists(result, "policy");
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 2 with CqlRows

use of me.prettyprint.cassandra.model.CqlRows in project sling by apache.

the class AccessControlUtil method addACE.

private void addACE(String path, String policy) throws Exception {
    String rid = getrowID(path);
    createColumnFamily(ACL_CF, provider.getKeyspace(), new StringSerializer());
    String getAllACEs = "select * from " + ACL_CF + " where KEY = '" + rid + "'";
    QueryResult<CqlRows<String, String, String>> results = CassandraResourceProviderUtil.executeQuery(getAllACEs, provider.getKeyspace(), new StringSerializer());
    if (CassandraResourceProviderUtil.recordExists(results, "policy")) {
        updateACL(rid, policy, new StringSerializer(), results);
    } else {
        addACL(rid, policy, new StringSerializer());
    }
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 3 with CqlRows

use of me.prettyprint.cassandra.model.CqlRows in project sling by apache.

the class CassandraResource method loadResourceData.

private void loadResourceData(ResourceProvider resourceProvider) {
    CassandraResourceProvider cassandraResourceProvider = (CassandraResourceProvider) resourceProvider;
    try {
        //          TODO ColumnFamilySector is NULL and hence this..
        String cql = cassandraResourceProvider.getCassandraMapperMap().get(columnFamilySector).getCQL(columnFamilySector, remainingPath);
        QueryResult<CqlRows<String, String, String>> results = CassandraResourceProviderUtil.executeQuery(cql, ((CassandraResourceProvider) resourceProvider).getKeyspace(), new StringSerializer());
        populateDataFromResult(results);
        dataLoaded = true;
    } catch (CassandraMapperException e) {
        System.out.println("Error occurred from resource at " + resourcePath + " : " + e.getMessage());
        LOGGER.error("Error occurred from resource at " + resourcePath + " : " + e.getMessage());
    }
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) CassandraMapperException(org.apache.sling.cassandra.resource.provider.mapper.CassandraMapperException) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 4 with CqlRows

use of me.prettyprint.cassandra.model.CqlRows in project sling by apache.

the class CassandraResourceProvider method deleteResource.

private boolean deleteResource(ResourceResolver resourceResolver, String path) throws PersistenceException {
    try {
        String key = getrowID(path);
        if (key == null) {
            return false;
        }
        String _cf = CassandraResourceProviderUtil.getColumnFamilySector(path);
        createColumnFamily(_cf, this.getKeyspace(), new StringSerializer());
        StringSerializer se = new StringSerializer();
        CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(keyspace, se, se, se);
        String query = "delete FROM " + _cf + " where KEY = '" + key + "';";
        cqlQuery.setQuery(query);
        QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();
    } catch (NoSuchAlgorithmException e) {
        throw new PersistenceException(e.getMessage());
    } catch (UnsupportedEncodingException e) {
        throw new PersistenceException(e.getMessage());
    }
    return true;
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CqlQuery(me.prettyprint.cassandra.model.CqlQuery) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 5 with CqlRows

use of me.prettyprint.cassandra.model.CqlRows in project sling by apache.

the class AccessControlUtil method updateACL.

private void updateACL(String rid, String policy, StringSerializer se, QueryResult<CqlRows<String, String, String>> results) {
    String oldACL = "";
    for (Row<String, String, String> row : ((CqlRows<String, String, String>) results.get()).getList()) {
        for (HColumn column : row.getColumnSlice().getColumns()) {
            if ("policy".equalsIgnoreCase(column.getName().toString()) && column.getValue() != null) {
                oldACL = column.getValue().toString();
            }
        }
    }
    if (!oldACL.isEmpty()) {
        oldACL = oldACL + ";" + policy;
    }
    addACL(rid, oldACL, new StringSerializer());
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) HColumn(me.prettyprint.hector.api.beans.HColumn) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Aggregations

CqlRows (me.prettyprint.cassandra.model.CqlRows)7 StringSerializer (me.prettyprint.cassandra.serializers.StringSerializer)6 HColumn (me.prettyprint.hector.api.beans.HColumn)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CqlQuery (me.prettyprint.cassandra.model.CqlQuery)1 CassandraMapperException (org.apache.sling.cassandra.resource.provider.mapper.CassandraMapperException)1