all operations on YaCy in a database that should make it possible 1) to re-create a setting on fresh peers 2) to transmit a setting from one peer to another 3) to re-create crawl starts after a complete deletion of the index This functionality will also support 4) scheduled re-crawls (new implementation) To implement this, a new database structure has been crated that stores maps into blob heaps. to encode maps the b-encoding technique was used (this is the same encoding that torrent files use) - added a b-encoder - enhanced the b-decoder - added a b-encoded map heap data structure - added a table organisation based on b-encoded heaps - added a servlet to maintain such tables (see Tables_p.html) - integrated the servlet into the Advanced Settings menu - added an api recording based on the new tables git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6606 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
8df1694288
commit
8ce936bcdd
@ -0,0 +1,86 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>YaCy '#[clientname]#': Table Viewer</title>
|
||||
#(showtable)#::
|
||||
<link rel="alternate" type="application/xml" title="Tables" href="Tables.rss?table=#[table]#" />
|
||||
#(/showtable)#
|
||||
#%env/templates/metas.template%#
|
||||
</head>
|
||||
<body id="Tables">
|
||||
#%env/templates/header.template%#
|
||||
#%env/templates/submenuConfig.template%#
|
||||
|
||||
<h2>Table Administration</h2>
|
||||
<form action="Tables_p.html" method="get">
|
||||
<fieldset><legend>Table Selection</legend>
|
||||
<dl>
|
||||
<dt class="TableCellDark">Select Table:
|
||||
<select name="table" size="1">
|
||||
#{tables}#
|
||||
<option value="#[name]#" #(selected)#::selected="selected"#(/selected)#>#[name]#</option>
|
||||
#{/tables}#
|
||||
</select></dt>
|
||||
<dd>
|
||||
<input type="submit" name="edittable" value="Show Table" />
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
</form>
|
||||
#(showtable)#::
|
||||
<form action="Tables_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
|
||||
<fieldset>
|
||||
<legend><label for="table">Table Editor: showing table '#[table]#'</label></legend>
|
||||
<table border="0" cellpadding="2" cellspacing="1">
|
||||
<tr class="TableHeader" valign="bottom">
|
||||
<td> </td>
|
||||
<td>PK</td>
|
||||
#{columns}#
|
||||
<td>#[header]#</td>
|
||||
#{/columns}#
|
||||
</tr>
|
||||
#{list}#
|
||||
<tr class="TableCell#(dark)#Light::Dark::Summary#(/dark)#">
|
||||
<td align="left"><input type="checkbox" name="mark_#[pk]#" /></td>
|
||||
<td>#[pk]#</td>
|
||||
#{columns}#
|
||||
<td align="left">#[cell]#</td>
|
||||
#{/columns}#
|
||||
</tr>
|
||||
#{/list}#
|
||||
</table>
|
||||
<p>
|
||||
<input type="hidden" name="table" value="#[table]#" />
|
||||
<input type="submit" name="editrow" value="Edit Selected Row" />
|
||||
<input type="submit" name="addrow" value="Add a new Row" />
|
||||
<input type="submit" name="deleterows" value="Delete Selected Rows" />
|
||||
<input type="submit" name="deletetable" value="Delete Table" />
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
#(/showtable)#
|
||||
#(showedit)#::
|
||||
<form action="Tables_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
|
||||
<fieldset><legend>Row Editor</legend>
|
||||
<dl>
|
||||
<dt class="TableCellLight">Primary Key</dt>
|
||||
<dd>#[pk]#</dd>
|
||||
#{list}#
|
||||
<dt class="TableCellLight">#[key]#</dt>
|
||||
<dd>
|
||||
<input type="text" name="col_#[key]#" value="#[value]#" size="80"/>
|
||||
</dd>
|
||||
#{/list}#
|
||||
<dt class="TableCellDark"></dt>
|
||||
<dd>
|
||||
<input type="hidden" name="table" value="#[table]#" />
|
||||
<input type="hidden" name="pk" value="#[pk]#" />
|
||||
<input type="submit" name="commitrow" value="Commit" />
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
</form>
|
||||
#(/showedit)#
|
||||
#%env/templates/footer.template%#
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,194 @@
|
||||
// News.java
|
||||
// -----------------------
|
||||
// part of YaCy
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2005
|
||||
// last major change: 29.07.2005
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// You must compile this file with
|
||||
// javac -classpath .:../classes Network.java
|
||||
// if the shell's current path is HTROOT
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.yacy.kelondro.index.RowSpaceExceededException;
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
|
||||
import de.anomic.http.server.RequestHeader;
|
||||
import de.anomic.search.Switchboard;
|
||||
import de.anomic.server.serverObjects;
|
||||
import de.anomic.server.serverSwitch;
|
||||
|
||||
public class Tables_p {
|
||||
|
||||
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
final Switchboard sb = (Switchboard) env;
|
||||
final serverObjects prop = new serverObjects();
|
||||
String table = (post == null) ? null : post.get("table", null);
|
||||
if (table != null && !sb.tables.hasHeap(table)) table = null;
|
||||
|
||||
// show table selection
|
||||
int count = 0;
|
||||
Iterator<String> ti = sb.tables.tables();
|
||||
String tablename;
|
||||
while (ti.hasNext()) {
|
||||
tablename = ti.next();
|
||||
prop.put("tables_" + count + "_name", tablename);
|
||||
prop.put("tables_" + count + "_selected", (table != null && table.equals(tablename)) ? 1 : 0);
|
||||
count++;
|
||||
}
|
||||
prop.put("tables", count);
|
||||
|
||||
List<String> columns = null;
|
||||
if (table != null) try {
|
||||
columns = sb.tables.columns(table);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
|
||||
// apply deletion requests
|
||||
if (post != null && post.get("deletetable", "").length() > 0) {
|
||||
try {
|
||||
sb.tables.clear(table);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (post != null && post.get("deleterows", "").length() > 0) {
|
||||
try {
|
||||
for (Map.Entry<String, String> entry: post.entrySet()) {
|
||||
if (entry.getKey().startsWith("mark_") && entry.getValue().equals("on")) {
|
||||
sb.tables.delete(table, entry.getKey().substring(5).getBytes());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (post != null && post.get("commitrow", "").length() > 0) {
|
||||
String pk = post.get("pk");
|
||||
Map<String, byte[]> map = new HashMap<String, byte[]>();
|
||||
for (Map.Entry<String, String> entry: post.entrySet()) {
|
||||
if (entry.getKey().startsWith("col_")) {
|
||||
map.put(entry.getKey().substring(4), entry.getValue().getBytes());
|
||||
}
|
||||
}
|
||||
try {
|
||||
sb.tables.insert(table, pk.getBytes(), map);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// generate table
|
||||
prop.put("showtable", 0);
|
||||
prop.put("showedit", 0);
|
||||
|
||||
if (table != null && !post.containsKey("editrow") && !post.containsKey("addrow")) try {
|
||||
prop.put("showtable", 1);
|
||||
prop.put("showtable_table", table);
|
||||
|
||||
// insert the columns
|
||||
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
prop.putHTML("showtable_columns_" + i + "_header", columns.get(i));
|
||||
}
|
||||
prop.put("showtable_columns", columns.size());
|
||||
|
||||
// insert all rows
|
||||
final int maxCount = Math.min(1000, sb.tables.size(table));
|
||||
final Iterator<Map.Entry<byte[], Map<String, byte[]>>> mapIterator = sb.tables.iterator(table);
|
||||
Map.Entry<byte[], Map<String, byte[]>> record;
|
||||
Map<String, byte[]> map;
|
||||
byte[] pk;
|
||||
count = 0;
|
||||
boolean dark = true;
|
||||
byte[] cell;
|
||||
while ((mapIterator.hasNext()) && (count < maxCount)) {
|
||||
record = mapIterator.next();
|
||||
if (record == null) continue;
|
||||
pk = record.getKey();
|
||||
map = record.getValue();
|
||||
prop.put("showtable_list_" + count + "_dark", ((dark) ? 1 : 0) ); dark=!dark;
|
||||
prop.put("showtable_list_" + count + "_pk", new String(pk));
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
cell = map.get(columns.get(i));
|
||||
prop.putHTML("showtable_list_" + count + "_columns_" + i + "_cell", cell == null ? "" : new String(cell));
|
||||
}
|
||||
prop.put("showtable_list_" + count + "_columns", columns.size());
|
||||
|
||||
count++;
|
||||
}
|
||||
prop.put("showtable_list", count);
|
||||
} catch (IOException e) {}
|
||||
|
||||
if (post != null && table != null && post.containsKey("editrow")) try {
|
||||
// check if we can find a key
|
||||
String pk = null;
|
||||
for (Map.Entry<String, String> entry: post.entrySet()) {
|
||||
if (entry.getKey().startsWith("mark_") && entry.getValue().equals("on")) {
|
||||
pk = entry.getKey().substring(5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pk != null && sb.tables.has(table, pk.getBytes())) {
|
||||
setEdit(sb, prop, table, pk, columns);
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
|
||||
if (post != null && table != null && post.containsKey("addrow")) try {
|
||||
// get a new key
|
||||
String pk = new String(sb.tables.insert(table, new HashMap<String, byte[]>()));
|
||||
setEdit(sb, prop, table, pk, columns);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
|
||||
// adding the peer address
|
||||
prop.put("address", sb.peers.mySeed().getPublicAddress());
|
||||
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
}
|
||||
|
||||
private static void setEdit(final Switchboard sb, final serverObjects prop, final String table, final String pk, List<String> columns) throws IOException {
|
||||
prop.put("showedit", 1);
|
||||
prop.put("showedit_table", table);
|
||||
prop.put("showedit_pk", pk);
|
||||
Map<String, byte[]> map = sb.tables.select(table, pk.getBytes());
|
||||
int count = 0;
|
||||
byte[] cell;
|
||||
for (String col: columns) {
|
||||
cell = map.get(col);
|
||||
prop.put("showedit_list_" + count + "_key", col);
|
||||
prop.put("showedit_list_" + count + "_value", cell == null ? "" : new String(cell));
|
||||
count++;
|
||||
}
|
||||
prop.put("showedit_list", count);
|
||||
}
|
||||
}
|
@ -0,0 +1,333 @@
|
||||
// BEncodedHeapArray.java
|
||||
// (C) 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 14.01.2010 on http://yacy.net
|
||||
//
|
||||
// This is a part of YaCy, a peer-to-peer based web search engine
|
||||
//
|
||||
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
|
||||
// $LastChangedRevision: 6539 $
|
||||
// $LastChangedBy: low012 $
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
package net.yacy.kelondro.blob;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.yacy.kelondro.index.RowSpaceExceededException;
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
import net.yacy.kelondro.util.FileUtils;
|
||||
|
||||
|
||||
public class BEncodedHeapArray {
|
||||
|
||||
private static final String suffix = ".bheap";
|
||||
private static final String system_table_pkcounter = "pkcounter";
|
||||
private static final String system_table_pkcounter_counterName = "pk";
|
||||
|
||||
private File location;
|
||||
private ConcurrentHashMap<String, BEncodedHeap> tables;
|
||||
private int keymaxlen;
|
||||
|
||||
public BEncodedHeapArray(final File location, final int keymaxlen) {
|
||||
this.location = location;
|
||||
this.keymaxlen = keymaxlen;
|
||||
this.tables = new ConcurrentHashMap<String, BEncodedHeap>();
|
||||
String[] files = this.location.list();
|
||||
String tablename;
|
||||
File file;
|
||||
for (String f: files) {
|
||||
if (f.endsWith(suffix)) {
|
||||
file = new File(this.location, f);
|
||||
if (file.length() == 0) {
|
||||
file.delete();
|
||||
continue;
|
||||
}
|
||||
tablename = f.substring(0, f.length() - suffix.length());
|
||||
try {
|
||||
getHeap(tablename);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<String> tables() {
|
||||
return this.tables.keySet().iterator();
|
||||
}
|
||||
|
||||
public void close(final String tablename) {
|
||||
final BEncodedHeap heap = this.tables.remove(tablename);
|
||||
if (heap == null) return;
|
||||
heap.close();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
for (BEncodedHeap heap: this.tables.values()) heap.close();
|
||||
this.tables.clear();
|
||||
}
|
||||
|
||||
public void clear(final String tablename) throws IOException {
|
||||
BEncodedHeap heap = getHeap(tablename);
|
||||
if (heap == null) return;
|
||||
heap.clear();
|
||||
File f = heap.getFile();
|
||||
heap.close();
|
||||
heap = null;
|
||||
this.tables.remove(tablename);
|
||||
FileUtils.deletedelete(f);
|
||||
}
|
||||
|
||||
public boolean hasHeap(final String tablename) {
|
||||
try {
|
||||
return getHeap(tablename) != null;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private BEncodedHeap getHeap(final String tablename) throws IOException {
|
||||
final String table = tablename + suffix;
|
||||
BEncodedHeap heap = this.tables.get(tablename);
|
||||
if (heap != null) return heap;
|
||||
|
||||
// open a new heap and register it in the tables
|
||||
final File heapf = new File(this.location, table);
|
||||
heap = new BEncodedHeap(heapf, this.keymaxlen);
|
||||
this.tables.put(tablename, heap);
|
||||
return heap;
|
||||
}
|
||||
|
||||
public int size(String table) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
return heap.size();
|
||||
}
|
||||
|
||||
private byte[] ukey(String tablename) throws IOException {
|
||||
byte[] pk = select(system_table_pkcounter, tablename.getBytes(), system_table_pkcounter_counterName);
|
||||
int pki;
|
||||
if (pk == null) {
|
||||
pki = size(tablename);
|
||||
} else {
|
||||
pki = Integer.parseInt(new String(pk)) + 1;
|
||||
}
|
||||
while (true) {
|
||||
pk = int2key(pki).getBytes();
|
||||
if (!has(tablename, pk)) break;
|
||||
pki++;
|
||||
}
|
||||
return pk;
|
||||
}
|
||||
|
||||
private String int2key(int i) {
|
||||
StringBuilder sb = new StringBuilder(this.keymaxlen);
|
||||
String is = Integer.toString(i);
|
||||
for (int j = 0; j < this.keymaxlen - is.length(); j++) sb.append('0');
|
||||
sb.append(is);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* insert a map into a table using a new unique key
|
||||
* @param tablename
|
||||
* @param map
|
||||
* @throws RowSpaceExceededException
|
||||
* @throws IOException
|
||||
*/
|
||||
public byte[] insert(final String tablename, Map<String, byte[]> map) throws RowSpaceExceededException, IOException {
|
||||
byte[] uk = ukey(tablename);
|
||||
insert(tablename, uk, map);
|
||||
insert(system_table_pkcounter, tablename.getBytes(), system_table_pkcounter_counterName, uk);
|
||||
return uk;
|
||||
}
|
||||
|
||||
public byte[] insert(final String tablename, String key, byte[] value) throws RowSpaceExceededException, IOException {
|
||||
byte[] uk = ukey(tablename);
|
||||
insert(tablename, uk, key, value);
|
||||
insert(system_table_pkcounter, tablename.getBytes(), system_table_pkcounter_counterName, uk);
|
||||
return uk;
|
||||
}
|
||||
|
||||
public byte[] insert(final String tablename,
|
||||
String key0, byte[] value0,
|
||||
String key1, byte[] value1
|
||||
) throws RowSpaceExceededException, IOException {
|
||||
byte[] uk = ukey(tablename);
|
||||
insert(tablename, uk,
|
||||
key0, value0,
|
||||
key1, value1
|
||||
);
|
||||
insert(system_table_pkcounter, tablename.getBytes(), system_table_pkcounter_counterName, uk);
|
||||
return uk;
|
||||
}
|
||||
|
||||
public byte[] insert(final String tablename,
|
||||
String key0, byte[] value0,
|
||||
String key1, byte[] value1,
|
||||
String key2, byte[] value2
|
||||
) throws RowSpaceExceededException, IOException {
|
||||
byte[] uk = ukey(tablename);
|
||||
insert(tablename, uk,
|
||||
key0, value0,
|
||||
key1, value1,
|
||||
key2, value2
|
||||
);
|
||||
insert(system_table_pkcounter, tablename.getBytes(), system_table_pkcounter_counterName, uk);
|
||||
return uk;
|
||||
}
|
||||
|
||||
public byte[] insert(final String tablename,
|
||||
String key0, byte[] value0,
|
||||
String key1, byte[] value1,
|
||||
String key2, byte[] value2,
|
||||
String key3, byte[] value3
|
||||
) throws RowSpaceExceededException, IOException {
|
||||
byte[] uk = ukey(tablename);
|
||||
insert(tablename, uk,
|
||||
key0, value0,
|
||||
key1, value1,
|
||||
key2, value2,
|
||||
key3, value3
|
||||
);
|
||||
insert(system_table_pkcounter, tablename.getBytes(), system_table_pkcounter_counterName, uk);
|
||||
return uk;
|
||||
}
|
||||
|
||||
public void insert(final String table, byte[] pk,
|
||||
String key, byte[] value
|
||||
) throws RowSpaceExceededException, IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
heap.put(pk, key, value);
|
||||
}
|
||||
|
||||
public void insert(final String table, byte[] pk,
|
||||
String key0, byte[] value0,
|
||||
String key1, byte[] value1
|
||||
) throws RowSpaceExceededException, IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
heap.put(pk,
|
||||
key0, value0,
|
||||
key1, value1
|
||||
);
|
||||
}
|
||||
|
||||
public void insert(final String table, byte[] pk,
|
||||
String key0, byte[] value0,
|
||||
String key1, byte[] value1,
|
||||
String key2, byte[] value2
|
||||
) throws RowSpaceExceededException, IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
heap.put(pk,
|
||||
key0, value0,
|
||||
key1, value1,
|
||||
key2, value2
|
||||
);
|
||||
}
|
||||
|
||||
public void insert(final String table, byte[] pk,
|
||||
String key0, byte[] value0,
|
||||
String key1, byte[] value1,
|
||||
String key2, byte[] value2,
|
||||
String key3, byte[] value3
|
||||
) throws RowSpaceExceededException, IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
heap.put(pk,
|
||||
key0, value0,
|
||||
key1, value1,
|
||||
key2, value2,
|
||||
key3, value3
|
||||
);
|
||||
}
|
||||
|
||||
public void insert(final String table, byte[] pk, Map<String, byte[]> map) throws RowSpaceExceededException, IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
heap.put(pk, map);
|
||||
}
|
||||
|
||||
public Map<String, byte[]> select(final String table, byte[] pk) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
return heap.get(pk);
|
||||
}
|
||||
|
||||
public byte[] select(final String table, byte[] pk, String key) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
return heap.getProp(pk, key);
|
||||
}
|
||||
|
||||
public void delete(final String table, byte[] pk) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
heap.delete(pk);
|
||||
}
|
||||
|
||||
public boolean has(String table, byte[] key) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
return heap.has(key);
|
||||
}
|
||||
|
||||
public Iterator<byte[]> keys(String table) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
return heap.keys();
|
||||
}
|
||||
|
||||
public Iterator<Map.Entry<byte[], Map<String, byte[]>>> iterator(String table) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
return heap.iterator();
|
||||
}
|
||||
|
||||
public List<String> columns(String table) throws IOException {
|
||||
BEncodedHeap heap = getHeap(table);
|
||||
return heap.columns();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// test the class
|
||||
File f = new File(new File("maptest").getAbsolutePath());
|
||||
// System.out.println(f.getAbsolutePath());
|
||||
// System.out.println(f.getParent());
|
||||
try {
|
||||
BEncodedHeapArray map = new BEncodedHeapArray(f.getParentFile(), 4);
|
||||
// put some values into the map
|
||||
Map<String, byte[]> m = new HashMap<String, byte[]>();
|
||||
m.put("k", "000".getBytes());
|
||||
map.insert("testdao", "123".getBytes(), m);
|
||||
m.put("k", "111".getBytes());
|
||||
map.insert("testdao", "456".getBytes(), m);
|
||||
m.put("k", "222".getBytes());
|
||||
map.insert("testdao", "789".getBytes(), m);
|
||||
// iterate over keys
|
||||
Iterator<Map.Entry<byte[], Map<String, byte[]>>> i = map.iterator("testdao");
|
||||
while (i.hasNext()) {
|
||||
Map.Entry<byte[], Map<String, byte[]>> entry = i.next();
|
||||
System.out.println(new String(entry.getKey(), "UTF-8") + ": "
|
||||
+ entry.getValue());
|
||||
}
|
||||
// clean up
|
||||
map.close();
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue