Author: dlanglais Date: 2010-02-17 22:56:07 +0100 (Wed, 17 Feb 2010) New Revision: 96 Modified: trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java trunk/msm-hbase/src/site/todo.rst Log: Avancement plugin HBaseNewBigTable Toujours autant ?\195?\160 tester... Modified: trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java =================================================================== --- trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java 2010-02-17 20:44:44 UTC (rev 95) +++ trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java 2010-02-17 21:56:07 UTC (rev 96) @@ -1,6 +1,7 @@ package org.nuiton.mapstoragemanager.plugins.hbase; import java.io.IOException; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -14,7 +15,6 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; @@ -34,7 +34,7 @@ private HBaseAdmin hBaseAdmin; private HBaseConfiguration config; - private HTable hTable; + private HTable selectedTable; // private HTable table; // private String familyName = "mylittlecolumnfamily"; // private String rowName = "myLittleRow"; @@ -49,7 +49,6 @@ new org.apache.hadoop.conf.Configuration(); config = new HBaseConfiguration(conf); hBaseAdmin = new HBaseAdmin(config); - LOG.info("test"); } /** @@ -170,9 +169,10 @@ Put put = new Put(key.getBytes()); put.add(column.getBytes(), key.getBytes(), content.getBytes()); - HTable hTable = new HTable(config, table); - hTable.put(put); - + //HTable hTable = new HTable(config, table); + this.selectTable(table); + this.selectedTable.put(put); + LOG.trace("put " + table + " " + column + " " + key + " " + content); } catch (IOException ex) { LOG.error(ex, ex); @@ -188,8 +188,9 @@ Get get = new Get(key.getBytes()); get = get.addColumn(column.getBytes()); - HTable hTable = new HTable(config, table); - Result result = hTable.get(get); + //HTable hTable = new HTable(config, table); + this.selectTable(table); + Result result = this.selectedTable.get(get); ret = result.getCellValue().toString(); @@ -204,27 +205,82 @@ * {@inheritDoc} */ public String get(String table, String column, String key, int version) { - throw new UnsupportedOperationException("Not supported yet."); + String ret = ""; + try { + Get get = new Get(key.getBytes()); + get = get.addColumn(column.getBytes()); + get = get.setTimeStamp(version); + + //HTable hTable = new HTable(config, table); + this.selectTable(table); + Result result = this.selectedTable.get(get); + + ret = result.getCellValue().toString(); + + LOG.trace("put " + table + " " + column + " " + key + " " + ret + + " " + version); + } catch (IOException ex) { + LOG.error(ex, ex); + } + return ret; } /** * {@inheritDoc} */ public Map<String, String> getRow(String table, String key) { - throw new UnsupportedOperationException("Not supported yet."); + Map<String, String> ret = new HashMap<String, String>(); + try { + for (String column : this.getColumnsNames(table)) { + Get get = new Get(key.getBytes()); + get = get.addColumn(column.getBytes()); + + //HTable hTable = new HTable(config, table); + this.selectTable(table); + Result result = this.selectedTable.get(get); + + String columnContent = result.getCellValue().toString(); + + ret.put(column, columnContent); + } + + + LOG.trace("row " + key + " " + ret.toString()); + } catch (IOException ex) { + LOG.error(ex, ex); + } + return ret; } /** * {@inheritDoc} */ public Set<String> getKeys(String table) { - throw new UnsupportedOperationException("Not supported yet."); + Set<String> ret = new HashSet<String>(); + try { + //HTable hTable = new HTable(config, table); + this.selectTable(table); + Set<byte[]> familiesKeys; + familiesKeys = + this.selectedTable.getTableDescriptor().getFamiliesKeys(); + for (byte[] key : familiesKeys) { + ret.add(key.toString()); + } + + } catch (IOException ex) { + LOG.error(ex, ex); + } + return ret; } /** * {@inheritDoc} */ public void selectTable(String table) { - throw new UnsupportedOperationException("Not supported yet."); + try { + selectedTable = new HTable(config, table); + } catch (IOException ex) { + LOG.error(ex, ex); + } } } Modified: trunk/msm-hbase/src/site/todo.rst =================================================================== --- trunk/msm-hbase/src/site/todo.rst 2010-02-17 20:44:44 UTC (rev 95) +++ trunk/msm-hbase/src/site/todo.rst 2010-02-17 21:56:07 UTC (rev 96) @@ -11,7 +11,7 @@ - getColumnsNames [to test] - put [to test] - get [to test] - - get (version) [pending] - - getRow [pending] - - getKeys [pending] - - selectTable [pending] \ No newline at end of file + - get (version) [to test] + - getRow [to test] + - getKeys [to test] + - selectTable [to test] \ No newline at end of file