diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2015-01-17 07:33:37 +1100 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2015-01-17 07:33:37 +1100 |
commit | a30db47d03f48220553922422950273a14118160 (patch) | |
tree | 745e1c364a5610f6de3ed21cbef2f7e28f75324c /examples | |
parent | 76addf73581c53f24462ab5fd724048aec36eaf3 (diff) | |
parent | 38b6b25fb7e825b234a17ad1fb9269c5f48cb129 (diff) | |
download | mongo-a30db47d03f48220553922422950273a14118160.tar.gz |
Merge branch 'develop' into cursor-equal
Conflicts:
lang/python/wiredtiger.i
Diffstat (limited to 'examples')
7 files changed, 97 insertions, 66 deletions
diff --git a/examples/java/com/wiredtiger/examples/ex_async.java b/examples/java/com/wiredtiger/examples/ex_async.java index f99fe8af622..a822b5b8ea9 100644 --- a/examples/java/com/wiredtiger/examples/ex_async.java +++ b/examples/java/com/wiredtiger/examples/ex_async.java @@ -60,6 +60,7 @@ class AsyncKeys implements AsyncCallback { long id = op.getId(); /*! [async get identifier] */ + /* If doing a search, retrieve the key/value pair. */ if (optype == AsyncOpType.WT_AOP_SEARCH) { /*! [async get the operation's string key] */ String key = op.getKeyString(); @@ -73,10 +74,6 @@ class AsyncKeys implements AsyncCallback { System.out.println("Id " + id + " got record: " + key + " : " + value); } - else { - notifyError("unexpected optype"); - ret = 1; - } } catch (Exception e) { System.err.println("ERROR: exception in notify: " + e.toString() + @@ -209,15 +206,16 @@ public class ex_async { return (ret); } - public static int + public static void main(String[] argv) { try { - return (asyncExample()); + System.exit(asyncExample()); } catch (WiredTigerException wte) { System.err.println("Exception: " + wte); - return (-1); + wte.printStackTrace(); + System.exit(1); } } } diff --git a/examples/java/com/wiredtiger/examples/ex_call_center.java b/examples/java/com/wiredtiger/examples/ex_call_center.java index c0842410b80..c0fc018952e 100644 --- a/examples/java/com/wiredtiger/examples/ex_call_center.java +++ b/examples/java/com/wiredtiger/examples/ex_call_center.java @@ -126,10 +126,11 @@ public class ex_call_center { while(br.ready()) System.out.println(br.readLine()); br.close(); + proc.waitFor(); new File("WT_HOME").mkdir(); - } catch (IOException ioe) { - System.err.println("IOException: WT_HOME: " + ioe); - return(1); + } catch (Exception ex) { + System.err.println("Exception: " + ex); + return (1); } } else home = null; @@ -197,8 +198,8 @@ public class ex_call_center { cursor = session.open_cursor("table:calls", null, "append"); for (Call call : callSample) { cursor.putValueLong(call.call_date); - cursor.putValueLong(call.cust_id); - cursor.putValueLong(call.emp_id); + cursor.putValueRecord(call.cust_id); + cursor.putValueRecord(call.emp_id); cursor.putValueString(call.call_type); cursor.putValueString(call.notes); ret = cursor.insert(); @@ -224,7 +225,7 @@ public class ex_call_center { ret = cursor.search(); if (ret == 0) { Customer cust = new Customer(); - cust.id = cursor.getValueLong(); + cust.id = cursor.getValueRecord(); cust.name = cursor.getValueString(); System.out.println("Read customer record for " + cust.name + " (ID " + cust.id + ")"); @@ -254,7 +255,7 @@ public class ex_call_center { * backwards. */ long custid = 1; - cursor.putKeyLong(custid + 1); + cursor.putKeyRecord(custid + 1); cursor.putKeyLong(0); nearstatus = cursor.search_near(); @@ -269,7 +270,7 @@ public class ex_call_center { ret = cursor.prev(); for (count = 0; ret == 0 && count < 3; ++count) { Call call = new Call(); - call.cust_id = cursor.getValueLong(); + call.cust_id = cursor.getValueRecord(); call.call_type = cursor.getValueString(); call.notes = cursor.getValueString(); if (call.cust_id != custid) @@ -286,15 +287,16 @@ public class ex_call_center { return (ret); } - public static int + public static void main(String[] argv) { try { - return (callCenterExample()); + System.exit(callCenterExample()); } catch (WiredTigerException wte) { System.err.println("Exception: " + wte); - return (-1); + wte.printStackTrace(); + System.exit(1); } } } diff --git a/examples/java/com/wiredtiger/examples/ex_cursor.java b/examples/java/com/wiredtiger/examples/ex_cursor.java index 2a1de73ab81..38af04d5849 100644 --- a/examples/java/com/wiredtiger/examples/ex_cursor.java +++ b/examples/java/com/wiredtiger/examples/ex_cursor.java @@ -178,10 +178,11 @@ public class ex_cursor { while(br.ready()) System.out.println(br.readLine()); br.close(); + proc.waitFor(); new File("WT_HOME").mkdir(); - } catch (IOException ioe) { - System.err.println("IOException: WT_HOME: " + ioe); - return(1); + } catch (Exception ex) { + System.err.println("Exception: " + ex); + return (1); } } else home = null; @@ -226,15 +227,16 @@ public class ex_cursor { return (ret); } - public static int + public static void main(String[] argv) { try { - return (cursorExample()); + System.exit(cursorExample()); } catch (WiredTigerException wte) { System.err.println("Exception: " + wte); - return (-1); + wte.printStackTrace(); + System.exit(1); } } } diff --git a/examples/java/com/wiredtiger/examples/ex_log.java b/examples/java/com/wiredtiger/examples/ex_log.java index d77b2c92ec4..4a721d2a275 100644 --- a/examples/java/com/wiredtiger/examples/ex_log.java +++ b/examples/java/com/wiredtiger/examples/ex_log.java @@ -57,7 +57,7 @@ public class ex_log { conn = wiredtiger.open(home2, CONN_CONFIG); Session session = conn.open_session(null); - session.create(uri, "key_format=S,value_format=S"); + session.create(uri, "key_format=U,value_format=U"); return (session); } @@ -72,16 +72,17 @@ public class ex_log { while ((ret = cursor.next()) == 0) { ret = curs_copy.next(); - String key = cursor.getKeyString(); - String value = cursor.getValueString(); - String key_copy = curs_copy.getKeyString(); - String value_copy = curs_copy.getValueString(); - if (!key.equals(key_copy) || !value.equals(value_copy)) { + byte[] key = cursor.getKeyByteArray(); + byte[] value = cursor.getValueByteArray(); + byte[] key_copy = curs_copy.getKeyByteArray(); + byte[] value_copy = curs_copy.getValueByteArray(); + if (!Arrays.equals(key, key_copy) || + !Arrays.equals(value, value_copy)) { System.err.println( - "Mismatched: key " + key + - ", key_copy " + key_copy + - " value " + value + - " value_copy " + value_copy); + "Mismatched: key " + new String(key) + + ", key_copy " + new String(key_copy) + + ", value " + new String(value) + + ", value_copy " + new String(value_copy)); return (1); } } @@ -110,7 +111,7 @@ public class ex_log { ": record type " + rectype + " optype " + optype + " txnid " + txnid + " fileid " + fileid); System.out.println(" key size " + key.length + - "value size " + value.length); + " value size " + value.length); if (rectype == wiredtiger.WT_LOGREC_MESSAGE) System.out.println("Application Record: " + new String(value)); } @@ -302,10 +303,11 @@ public class ex_log { while(br.ready()) System.out.println(br.readLine()); br.close(); + proc.waitFor(); new File(home1).mkdir(); new File(home2).mkdir(); - } catch (IOException ioe) { - System.err.println("IOException: " + ioe); + } catch (Exception ex) { + System.err.println("Exception: " + ex); return (1); } if ((wt_conn = wiredtiger.open(home1, CONN_CONFIG)) == null) { @@ -345,6 +347,7 @@ public class ex_log { ret = session.log_printf("Wrote " + record_count + " records"); /*! [log cursor printf] */ + session.close(null); /* * Close and reopen the connection so that the log ends up with * a variety of records such as file sync and checkpoint. We @@ -359,19 +362,21 @@ public class ex_log { session = wt_conn.open_session(null); ret = simple_walk_log(session); ret = walk_log(session); + ret = session.close(null); ret = wt_conn.close(null); return (ret); } - public static int - main() + public static void + main(String[] args) { try { - return (logExample()); + System.exit(logExample()); } catch (WiredTigerException wte) { System.err.println("Exception: " + wte); - return (-1); + wte.printStackTrace(); + System.exit(1); } } } diff --git a/examples/java/com/wiredtiger/examples/ex_schema.java b/examples/java/com/wiredtiger/examples/ex_schema.java index cafa5e79f37..5b849ecf430 100644 --- a/examples/java/com/wiredtiger/examples/ex_schema.java +++ b/examples/java/com/wiredtiger/examples/ex_schema.java @@ -92,10 +92,11 @@ public class ex_schema { while(br.ready()) System.out.println(br.readLine()); br.close(); + proc.waitFor(); new File("WT_HOME").mkdir(); - } catch (IOException ioe) { - System.err.println("IOException: WT_HOME: " + ioe); - return(1); + } catch (Exception ex) { + System.err.println("Exception: " + ex); + return (1); } } else home = null; @@ -159,10 +160,23 @@ public class ex_schema { } ret = cursor.close(); + /* Update records in the table. */ + cursor = session.open_cursor("table:poptable", null, null); + while ((ret = cursor.next()) == 0) { + recno = cursor.getKeyRecord(); + country = cursor.getValueString(); + year = cursor.getValueShort(); + population = cursor.getValueLong(); + cursor.putValueString(country); + cursor.putValueShort(year); + cursor.putValueLong(population + 1); + } + ret = cursor.close(); + /* List the records in the table. */ cursor = session.open_cursor("table:poptable", null, null); while ((ret = cursor.next()) == 0) { - recno = cursor.getKeyLong(); + recno = cursor.getKeyRecord(); country = cursor.getValueString(); year = cursor.getValueShort(); population = cursor.getValueLong(); @@ -282,7 +296,7 @@ public class ex_schema { while ((ret = cursor.next()) == 0) { country = cursor.getKeyString(); year = cursor.getKeyShort(); - recno = cursor.getValueLong(); + recno = cursor.getValueRecord(); System.out.println("row ID " + recno + ": country " + country + ", year " + year); } @@ -326,15 +340,16 @@ public class ex_schema { return (ret); } - public static int + public static void main(String[] argv) { try { - return (schemaExample()); + System.exit(schemaExample()); } catch (WiredTigerException wte) { System.err.println("Exception: " + wte); - return (-1); + wte.printStackTrace(); + System.exit(1); } } } diff --git a/examples/java/com/wiredtiger/examples/ex_stat.java b/examples/java/com/wiredtiger/examples/ex_stat.java index 49ea7e5e0d8..2e932e1027f 100644 --- a/examples/java/com/wiredtiger/examples/ex_stat.java +++ b/examples/java/com/wiredtiger/examples/ex_stat.java @@ -201,16 +201,18 @@ public class ex_stat { if (System.getenv("WIREDTIGER_HOME") == null) { home = "WT_HOME"; try { - Process proc = Runtime.getRuntime().exec("/bin/rm -rf WT_HOME"); + Process proc = Runtime.getRuntime().exec("/bin/rm -rf " + home); BufferedReader br = new BufferedReader( new InputStreamReader(proc.getInputStream())); while(br.ready()) System.out.println(br.readLine()); br.close(); - new File("WT_HOME").mkdir(); - } catch (IOException ioe) { - System.err.println("IOException: WT_HOME: " + ioe); - return(1); + proc.waitFor(); + if (!(new File(home)).mkdir()) + System.err.println("mkdir: failed"); + } catch (Exception ex) { + System.err.println("Exception: " + home + ": " + ex); + System.exit(1); } } else home = null; @@ -239,15 +241,16 @@ public class ex_stat { return (conn.close(null) == 0 ? ret : -1); } - public static int + public static void main(String[] argv) { try { - return ((new ex_stat()).statExample()); + System.exit((new ex_stat()).statExample()); } catch (WiredTigerException wte) { System.err.println("Exception: " + wte); - return (-1); + wte.printStackTrace(); + System.exit(1); } } } diff --git a/examples/java/com/wiredtiger/examples/ex_thread.java b/examples/java/com/wiredtiger/examples/ex_thread.java index d5ff45e2611..59ab9c40b34 100644 --- a/examples/java/com/wiredtiger/examples/ex_thread.java +++ b/examples/java/com/wiredtiger/examples/ex_thread.java @@ -60,6 +60,8 @@ class ScanThread extends Thread { if (ret != wiredtiger.WT_NOTFOUND) System.err.println("Cursor.next: " + wiredtiger.wiredtiger_strerror(ret)); + cursor.close(); + session.close(null); } catch (WiredTigerException wte) { System.err.println("Exception " + wte); } @@ -74,7 +76,7 @@ public class ex_thread { public static final int NUM_THREADS = 10; /*! [thread main] */ - static int main(String[] argv) + public static void main(String[] argv) { try { Thread[] threads = new Thread[NUM_THREADS]; @@ -86,7 +88,7 @@ public class ex_thread { * environment variable isn't already set (as is done by make check). */ if (System.getenv("WIREDTIGER_HOME") == null) { - home = "WT_HOME"; + home = "WT_HOME"; try { Process proc = Runtime.getRuntime().exec("/bin/rm -rf " + home); BufferedReader br = new BufferedReader( @@ -94,17 +96,19 @@ public class ex_thread { while(br.ready()) System.out.println(br.readLine()); br.close(); - new File(home).mkdir(); - } catch (IOException ioe) { - System.err.println("IOException: " + home + ": " + ioe); - return(1); + proc.waitFor(); + if (!(new File(home)).mkdir()) + System.err.println("mkdir: failed"); + } catch (Exception ex) { + System.err.println("Exception: " + home + ": " + ex); + System.exit(1); } } else home = null; if ((conn = wiredtiger.open(home, "create")) == null) { System.err.println("Error connecting to " + home); - return(1); + System.exit(1); } /* Note: further error checking omitted for clarity. */ @@ -115,6 +119,7 @@ public class ex_thread { cursor.putKeyString("key1"); cursor.putValueString("value1"); ret = cursor.insert(); + cursor.close(); ret = session.close(null); for (i = 0; i < NUM_THREADS; i++) { @@ -131,11 +136,12 @@ public class ex_thread { } ret = conn.close(null); - return (ret); + System.exit(ret); } catch (WiredTigerException wte) { System.err.println("Exception: " + wte); - return (-1); + wte.printStackTrace(); + System.exit(1); } } /*! [thread main] */ |