Cassandra Hector edition Dao

Source: Internet
Author: User
Tags cassandra datastax

Cassandra all clients: http://wiki.apache.org/cassandra/ClientOptions

Astyanax claims to be the son of Hector, And the API looks quite attractive. Unfortunately, there is no full-package download, and the project is Maven (not like Maven ). Hector looks good. If you are not familiar with other things, just grab a Hector.

Reference Hector example: Me. prettyprint. Cassandra. Examples. exampledaov2

Package ***; import Java. util. arraylist; import Java. util. date; import Java. util. hashmap; import Java. util. iterator; import Java. util. list; import Java. util. map; import me. prettyprint. cassandra. serializers. abstractserializer; import me. prettyprint. cassandra. serializers. stringserializer; import me. prettyprint. cassandra. service. cassandrahostconfigurator; import me. prettyprint. cassandra. service. keyiterator; impo RT me. prettyprint. hector. API. cluster; import me. prettyprint. hector. API. keyspace; import me. prettyprint. hector. API. serializer; import me. prettyprint. hector. API. beans. hcolumn; import me. prettyprint. hector. API. beans. rows; import me. prettyprint. hector. API. DDL. columnfamilydefinition; import me. prettyprint. hector. API. DDL. keyspacedefinition; import me. prettyprint. hector. API. exceptions. hectorexception; import me. Prettyprint. hector. API. factory. hfactory; import me. prettyprint. hector. API. mutation. mutator; import me. prettyprint. hector. API. query. columnquery; import me. prettyprint. hector. API. query. multigetslicequery; import me. prettyprint. hector. API. query. queryresult;/***** @ author zzf ***/public class cassandrahectorgateway {private final string name; private final cluster; private final string keyspace; P Rivate final keyspace keyspaceobj; private serializer nameserializer = stringserializer. get (); Public cassandrahectorgateway (string keyspace, string hostips) {This (keyspace, hostips, null);} public cassandrahectorgateway (string keyspace, string hostips, Map <string, string> credentials) {name = "cluster-" + hostips. hashcode (); cluster = getorcreatecluster (name, hostips, credentials); this. keyspace = keys Pace; keyspaceobj = getorcreatekeyspace (keyspace);} public serializer getnameserializer () {return nameserializer;} public void setnameserializer (serializer nameserializer) {This. nameserializer = nameserializer;}/*** obtain the Cluster Object (if the Cluster Object does not exist) ** @ Param clustername * to get the cluster name (only on the client, give the obtained cluster Instance name, which has nothing to do with the cluster server name on the server side.) * @ Param hostips * Cluster machine set. Multiple Cluster machines are separated by commas (,) in the format of {IP: port, IP: Port ,...} * @ Param credentials * permission verification {user Name: XXX, password: XXX} */private cluster getorcreatecluster (string clustername, string hostips, Map <string, string> credentials) {// note, here, create is to create the "phantom" (equivalent to the RPC Interface) of the client, and then name the cluster. Return hfactory. getorcreatecluster (clustername, new cassandrahostator ator (hostips), credentials);} private keyspace getorcreatekeyspace (string keyspace) {Boolean exists = false; List <keyspacedefinition> kslist = cluster. describekeyspaces (); For (keyspacedefinition KS: kslist) {If (keyspace. equals (KS. getname () {exists = true; break ;}} if (! Exists) {// The server creates a real keyspace // cluster. addkeyspace (New thriftksdef (keyspace, // "org. apache. cassandra. locator. simplestrategy ", 1, // new arraylist <columnfamilydefinition> (); // replicationfactor = number of available cluster nodes. Keyspacedefinition ks_def = hfactory. createkeyspacedefinition (keyspace, "org. apache. cassandra. locator. simplestrategy ", cluster. getconnectionmanager (). getactivepools (). size (), new arraylist <columnfamilydefinition> (); cluster. addkeyspace (ks_def, true);} // client phantom return hfactory. createkeyspace (keyspace, cluster);} public void ensurecolumnfamily (string family) {list <columnfamilydefinition> List = cluster.de Scribekeyspace (keyspace ). getcfdefs (); Boolean exists = false; For (columnfamilydefinition Col: List) {If (family. equals (Col. getname () {exists = true; break ;}} if (! Exists) {columnfamilydefinition cfdef = hfactory. createcolumnfamilydefinition (keyspace, family); cluster. addcolumnfamily (cfdef, true) ;}} Public <k> void insert (K key, object value, string column, string family, serializer <k> keyserializer, serializer valueserializer) {hfactory. createmutator (keyspaceobj, keyserializer ). insert (Key, family, hfactory. createcolumn (column, value, nameserializer, valueserialize R);} Public <k> void insertmulti (Map <K, Object> keyvalues, string column, string family, serializer <k> keyserializer, serializer valueserializer) {mutator <k> M = hfactory. createmutator (keyspaceobj, keyserializer); For (map. entry <K, Object> keyValue: keyvalues. entryset () {M. addinsertion (keyValue. getkey (), family, hfactory. createcolumn (column, keyValue. getvalue (), keyspaceobj. createclock (), nameserializ Er,valueserializer=;m.exe cute ();} Public <k> Object get (final K key, string column, string family, serializer <k> keyserializer, serializer valueserializer) throws hectorexception {columnquery <K, string, Object> q = hfactory. createcolumnquery (keyspaceobj, keyserializer, nameserializer, valueserializer); queryresult 

It is troublesome to query.

The common practice is to query some attributes stored in the relational data table, and the partitions stored in Cassandra. The custom key maintains the association logic.


[Resource]
Apache-Cassandra-1.0.7
Bin

Http://mirror.bit.edu.cn/apache//cassandra/1.0.7/apache-cassandra-1.0.7-bin.tar.gz

SRC

Http://labs.mop.com/apache-mirror//cassandra/1.0.7/apache-cassandra-1.0.7-src.tar.gz

Configuration parameter description
Http://www.cnblogs.com/gpcuster/archive/2010/11/12/1875388.html

Hector1.03
Bin

Https://github.com/rantav/hector/downloads

SRC

Https://nodeload.github.com/rantav/hector/zipball/master

Doc
Http://www.datastax.com/sites/default/files/hector-v2-client-doc.pdf

Cassandra Cluster Manager: datastax-community

Http://downloads.datastax.com/community/datastax-community-64bit.msi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.