Pelops相传是cassandra的一个儿子,对于一个命途多舛的女人来说,儿子应该是她唯一的寄托,可见这个短小精悍的框架的强悍之处。
这个框架的优点:
1.基于thrift底层编写,速度快,实现优美,使用方便。
2.实现了连接池,支持集群配置。
3.对于集群的每个节点实现负载均衡。
4.增加了对错误的处理。
5.跟踪最新的cassandra版本,不会每次做很大的改动。
下面就来看看pelops是如何封装的。
1.建立连接池:
Pelops.addPool(
"Main",
new String[] { "cass1.database.com", "cass2.database.com", "cass3.database.com"},
9160,
new Policy());
2.插入删除数据:Mutator
Mutator mutator = Pelops.createMutator("Main", "SupportTickets");
/**
* Write multiple sub-column values to a super column...
* @param rowKey The key of the row to modify
* @param colFamily The name of the super column family to operate on
* @param colName The name of the super column
* @param subColumns A list of the sub-columns to write
*/
mutator. writeSubColumns(
userId,
"L1Tickets",
UuidHelper.newTimeUuidBytes(), // using a UUID value that sorts by time
mutator.newColumnList(
mutator.newColumn("category", "videoPhone"),
mutator.newColumn("reportType", "POOR_PICTURE"),
mutator.newColumn("createdDate", NumberHelper.toBytes(System.currentTimeMillis())),
mutator.newColumn("capture", jpegBytes),
mutator.newColumn("comment") ));
/**
* Delete a list of columns or super columns...
* @param rowKey The key of the row to modify
* @param colFamily The name of the column family to operate on
* @param colNames The column and/or super column names to delete
*/
mutator.deleteColumns(
userId,
"L1Tickets",
resolvedList);
mutator.execute(ConsistencyLevel.ONE);
3.读取数据 Selector
Selector selector = Pelops.createSelector("Main", "SupportTickets");
/**
* Retrieve a super column from a row...
* @param rowKey The key of the row
* @param columnFamily The name of the column family containing the super column
* @param superColName The name of the super column to retrieve
* @param cLevel The Cassandra consistency level with which to perform the operation
* @return The requested SuperColumn
*/
SuperColumn ticket = selector.getSuperColumnFromRow(
userId,
"L1Tickets",
ticketId,
ConsistencyLevel.ONE);
// enumerate sub-columns
for (Column data : ticket.columns) {
String name = data.name;
byte[] value = data.value;
}
/**
* Retrieve super columns from a row
* @param rowKey The key of the row
* @param columnFamily The name of the column family containing the super columns
* @param colPredicate The super column selector predicate
* @param cLevel The Cassandra consistency level with which to perform the operation
* @return A list of matching columns
*/
List<SuperColumn> allTickets = selector.getSuperColumnsFromRow(
userId,
"L1Tickets",
Selector.newColumnsPredicateAll(true, 10000),
ConsistencyLevel.ONE);
/**
* Retrieve super columns from a set of rows.
* @param rowKeys The keys of the rows
* @param columnFamily The name of the column family containing the super columns
* @param colPredicate The super column selector predicate
* @param cLevel The Cassandra consistency level with which to perform the operation
* @return A map from row keys to the matching lists of super columns
*/
Map<String, List<SuperColumn>> allTicketsForFriends = selector.getSuperColumnsFromRows(
Arrays.asList(new String[] { "matt", "james", "dom" }, // the friends
"L1Tickets",
Selector.newColumnsPredicateAll(true, 10000),
ConsistencyLevel.ONE);
/**
* Retrieve a page of super columns composed from a segment of the sequence of super columns in a row.
* @param rowKey The key of the row
* @param columnFamily The name of the column family containing the super columns
* @param startBeyondName The sequence of super columns must begin with the smallest super column name greater than this value. Pass null to start at the beginning of the sequence.
* @param orderType The scheme used to determine how the column names are ordered
* @param reversed Whether the scan should proceed in descending super column name order
* @param count The maximum number of super columns that can be retrieved by the scan
* @param cLevel The Cassandra consistency level with which to perform the operation
* @return A page of super columns
*/
List<SuperColumn> pageTickets = getPageOfSuperColumnsFromRow(
userId,
"L1Tickets",
lastIdOfPrevPage, // null for first page
Selector.OrderType.TimeUUIDType, // ordering defined in this super column family
true, // blog order
10, // count shown per page
ConsistencyLevel.ONE);
参考文章:
http://ria101.wordpress.com/2010/06/11/pelops-the-beautiful-cassandra-database-client-for-java/
Pelops源代码:http://pelops.googlecode.com/
分享到:
相关推荐
jocular-platform.zip,jocular的每个平台二进制文件(oculus sdk java access)oculus sdk c api的平台二进制文件
资源分类:Python库 所属语言:Python 资源全名:Pelops-0.1a23.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
pelops:--
scale7-pelops, 用于访问Cassandra数据库的Java库 简介Pelops已经创建成了与Cassandra一起工作的漂亮东西( 所以昵称很漂亮"Cassandra 。 使用Pelops开发人员可以以快速访问to的完全功能,同时编写清晰的代码,使基础...
nosql数据库cassandra入门的一个例子。包括简单的插入、查询、建立keyspace等