summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase
diff options
context:
space:
mode:
Diffstat (limited to 'collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase')
-rw-r--r--collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseDatatabase.java92
-rw-r--r--collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseGroup.java81
-rw-r--r--collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseSession.java68
3 files changed, 241 insertions, 0 deletions
diff --git a/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseDatatabase.java b/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseDatatabase.java
new file mode 100644
index 0000000000..5d49fd76da
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseDatatabase.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.nosqldatastore.hbase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.tuscany.nosqldatastore.Database;
+import org.apache.tuscany.nosqldatastore.Group;
+
+import java.io.IOException;
+
+public class HBaseDatatabase implements Database{
+
+ private HTable table;
+ private HBaseAdmin admin;
+
+ HBaseDatatabase(String dbname, HBaseAdmin admin){
+ Configuration conf = HBaseConfiguration.create();
+ try {
+ try{
+ HTableDescriptor descriptor = new HTableDescriptor(dbname);
+ admin.createTable(descriptor);
+ } catch (MasterNotRunningException e) {
+ e.printStackTrace();
+ } catch (ZooKeeperConnectionException e) {
+ e.printStackTrace();
+ } catch (TableExistsException e){
+ System.out.println("connected to existing database....");
+ } finally {
+ table = new HTable(conf,dbname);
+ System.out.println(new String(table.getTableName()));
+ this.admin = admin;
+ table.flushCommits();
+ }
+ }catch (IOException ex) {
+ ex.printStackTrace();
+ }
+
+ }
+
+ public Group createGroup(String groupId) {
+
+ HColumnDescriptor cf= new HColumnDescriptor(groupId.getBytes());
+
+ try {
+ admin.disableTable(table.getTableName());
+ admin.addColumn(table.getTableName(),cf);
+ admin.enableTable(table.getTableName());
+ } catch (IOException e) {
+ System.out.println("Error: Creating the group "+groupId);
+ e.printStackTrace();
+ }
+
+ Group group = new HBaseGroup(table, groupId);
+ return group;
+ }
+
+ public Group getGroup(String groupId) {
+ Group group = new HBaseGroup(table, groupId);
+ return group;
+ }
+
+ public void deleteGroup(String groupId) {
+ try {
+ admin.disableTable(table.getTableName());
+ admin.deleteColumn(table.getTableName(),groupId.getBytes());
+ admin.enableTable(table.getTableName());
+ } catch (IOException e) {
+ System.out.println("Error: Deleting the group "+groupId);
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+}
diff --git a/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseGroup.java b/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseGroup.java
new file mode 100644
index 0000000000..f57b70ee60
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseGroup.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.nosqldatastore.hbase;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.*;
+import org.apache.tuscany.nosqldatastore.Group;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class HBaseGroup implements Group {
+
+ private HTable table;
+ private String cf;
+
+ HBaseGroup(HTable table, String cf){
+ this.table = table;
+ this.cf = cf;
+ }
+
+ public void addEntry(String key, Object value) {
+ Put put = new Put(key.getBytes());
+ put.add(cf.getBytes(),key.getBytes(),((String)value).getBytes());
+ try {
+ table.put(put);
+ table.flushCommits();
+ } catch (IOException e) {
+ System.out.println("Error: Adding the entry for the Key "+key);
+ e.printStackTrace();
+ }
+
+ }
+
+ public void updateEntry(String key, Object value) {
+ addEntry(key,value);
+ }
+
+ public void deleteEntry(String key) {
+ Delete delete = new Delete(key.getBytes());
+ delete.deleteColumn(cf.getBytes(), key.getBytes());
+ try {
+ table.delete(delete);
+ table.flushCommits();
+ } catch (IOException e) {
+ System.out.println("Error: Deleting the entry for the Key "+key);
+ e.printStackTrace();
+ }
+ }
+
+ public Object getValue(String key) {
+ Result result = null;
+ Get get = new Get(key.getBytes());
+ try {
+ result = table.get(get);
+ } catch (IOException e) {
+ System.out.println("Error: Retrieving the value or the Key "+key);
+ e.printStackTrace();
+ }
+ return new String(result.getValue(cf.getBytes(),key.getBytes()));
+ }
+}
diff --git a/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseSession.java b/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseSession.java
new file mode 100644
index 0000000000..83648eadc0
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/hbase/src/main/java/org/apache/tuscany/nosqldatastore/hbase/HBaseSession.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.nosqldatastore.hbase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.MasterNotRunningException;
+import org.apache.hadoop.hbase.ZooKeeperConnectionException;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.tuscany.nosqldatastore.Database;
+import org.apache.tuscany.nosqldatastore.Session;
+
+import java.io.IOException;
+
+public class HBaseSession implements Session{
+
+ private String session;
+ private HBaseAdmin admin;
+
+ public HBaseSession(String session){
+ this.session = session;
+ Configuration conf = HBaseConfiguration.create();
+ try {
+ admin = new HBaseAdmin(conf);
+ } catch (MasterNotRunningException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ } catch (ZooKeeperConnectionException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ public Database createDatabase(String databaseName) {
+ Database database = new HBaseDatatabase(databaseName, admin);
+ return database;
+ }
+
+ public Database getDatabase(String databaseName) {
+ Database database = new HBaseDatatabase(databaseName, admin);
+ return database;
+ }
+
+ public void deleteDatabase(String databaseName) {
+ try {
+ admin.disableTable(databaseName);
+ admin.deleteTable(databaseName);
+ } catch (IOException e) {
+ System.out.println("Error: Creating the database "+databaseName);
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+}