Created
April 12, 2012 08:12
-
-
Save groundwater/2365569 to your computer and use it in GitHub Desktop.
Play with HBase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import play.api._ | |
import play.api.mvc._ | |
import com.googlecode.protobuf.format._ | |
import org.apache.hadoop.hbase.HBaseConfiguration | |
import org.apache.hadoop.hbase.client.{ HTable, Put, Scan, Get } | |
import org.apache.hadoop.hbase.util.Bytes | |
import models.Auth.User | |
import play.api.templates.Html | |
object Application extends Controller { | |
// HBase Constants | |
val d = Bytes.toBytes("d") | |
val buf = Bytes.toBytes("buf") | |
val rid = Bytes.toBytes("row1") | |
val conf = HBaseConfiguration.create() | |
val table = new HTable(conf, "demo") | |
def index = Action { | |
val put = new Put(rid) | |
val protobuf = User.newBuilder(). | |
setUid("bob"). | |
setEmail("[email protected]"). | |
setPwdhash("0293fj09ajdfasdf"). | |
build() | |
put.add( | |
d, | |
buf, | |
protobuf.toByteArray()) | |
table.put(put) | |
val row = table.get(new Get(rid)) | |
val user = models.Auth.User.parseFrom(row.getValue( | |
d, | |
buf)) | |
Ok(Html(HtmlFormat.printToString(user))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment