日期:2014-05-16  浏览次数:20418 次

Cassandra Database(3)Hector Scala Class

Cassandra Database(3)Hector Scala Class

Actually, I am using the latest cassandra from branch 1.2 and I build it myself.

1. Creating the Schema and Insert/Get
The case class object will be as follow
package com.sillyat.easycassandraserver.models

import org.joda.time.DateTime

case class Product(id: Option[Long], productName: String, create: DateTime, productPrice: BigDecimal, productCode: String, country: String)

The sample of the Schema and Insert/Get

package com.sillycat.easycassandraserver.apps

import me.prettyprint.hector.api.{Keyspace, Cluster}
import me.prettyprint.hector.api.factory.HFactory
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition
import me.prettyprint.hector.api.ddl.{KeyspaceDefinition, ColumnFamilyDefinition, ComparatorType}
import me.prettyprint.cassandra.service.ThriftCfDef
import java.util.Arrays
import me.prettyprint.hector.api.mutation.Mutator
import me.prettyprint.cassandra.serializers.{LongSerializer, StringSerializer, BigDecimalSerializer}
import com.sillyat.easycassandraserver.models.Product
import org.joda.time.DateTime
import me.prettyprint.hector.api.query.{QueryResult, ColumnQuery}
import me.prettyprint.hector.api.beans.HColumn

object CassandraShemaDataDemoApp extends App{
? val clusterName = "TestCluster"
? val host = "localhost"
? val port = 9160

? val keyspaceName = "sillycat"
? val columnFamilyName = "products"

? val cluster: Cluster = HFactory.getOrCreateCluster("TestCluster", host + ":" + 9160)