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");
}
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());
}
}
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());
}
}
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;
}
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());
}
Aggregations