diff options
Diffstat (limited to 'examples/java/com/wiredtiger/examples/ex_schema.java')
-rw-r--r-- | examples/java/com/wiredtiger/examples/ex_schema.java | 76 |
1 files changed, 65 insertions, 11 deletions
diff --git a/examples/java/com/wiredtiger/examples/ex_schema.java b/examples/java/com/wiredtiger/examples/ex_schema.java index 7cc26acb479..76bff66a688 100644 --- a/examples/java/com/wiredtiger/examples/ex_schema.java +++ b/examples/java/com/wiredtiger/examples/ex_schema.java @@ -76,7 +76,8 @@ public class ex_schema { throws WiredTigerException { Connection conn; - Cursor cursor, cursor2, join_cursor, stat_cursor; + Cursor country_cursor, country_cursor2, cursor, join_cursor, + stat_cursor, subjoin_cursor, year_cursor; Session session; String country; long recno, population; @@ -343,18 +344,18 @@ public class ex_schema { /* Open cursors needed by the join. */ join_cursor = session.open_cursor( "join:table:poptable", null, null); - cursor = session.open_cursor( + country_cursor = session.open_cursor( "index:poptable:country", null, null); - cursor2 = session.open_cursor( + year_cursor = session.open_cursor( "index:poptable:immutable_year", null, null); /* select values WHERE country == "AU" AND year > 1900 */ - cursor.putKeyString("AU"); - ret = cursor.search(); - session.join(join_cursor, cursor, "compare=eq,count=10"); - cursor2.putKeyShort((short)1900); - ret = cursor2.search(); - session.join(join_cursor, cursor2, + country_cursor.putKeyString("AU"); + ret = country_cursor.search(); + session.join(join_cursor, country_cursor, "compare=eq,count=10"); + year_cursor.putKeyShort((short)1900); + ret = year_cursor.search(); + session.join(join_cursor, year_cursor, "compare=gt,count=10,strategy=bloom"); /* List the values that are joined */ @@ -376,8 +377,61 @@ public class ex_schema { ret = stat_cursor.close(); ret = join_cursor.close(); - ret = cursor2.close(); - ret = cursor.close(); + ret = year_cursor.close(); + ret = country_cursor.close(); + + /*! [Complex join cursors] */ + /* Open cursors needed by the join. */ + join_cursor = session.open_cursor( + "join:table:poptable", null, null); + subjoin_cursor = session.open_cursor( + "join:table:poptable", null, null); + country_cursor = session.open_cursor( + "index:poptable:country", null, null); + country_cursor2 = session.open_cursor( + "index:poptable:country", null, null); + year_cursor = session.open_cursor( + "index:poptable:immutable_year", null, null); + + /* + * select values WHERE (country == "AU" OR country == "UK") + * AND year > 1900 + * + * First, set up the join representing the country clause. + */ + country_cursor.putKeyString("AU"); + ret = country_cursor.search(); + ret = session.join(subjoin_cursor, country_cursor, + "operation=or,compare=eq,count=10"); + country_cursor2.putKeyString("UK"); + ret = country_cursor2.search(); + ret = session.join(subjoin_cursor, country_cursor2, + "operation=or,compare=eq,count=10"); + + /* Join that to the top join, and add the year clause */ + ret = session.join(join_cursor, subjoin_cursor, null); + year_cursor.putKeyShort((short)1900); + ret = year_cursor.search(); + ret = session.join(join_cursor, year_cursor, + "compare=gt,count=10,strategy=bloom"); + + /* List the values that are joined */ + while ((ret = join_cursor.next()) == 0) { + recno = join_cursor.getKeyRecord(); + country = join_cursor.getValueString(); + year = join_cursor.getValueShort(); + population = join_cursor.getValueLong(); + System.out.print("ID " + recno); + System.out.println( ": country " + country + ", year " + year + + ", population " + population); + } + /*! [Complex join cursors] */ + + ret = join_cursor.close(); + ret = subjoin_cursor.close(); + ret = year_cursor.close(); + ret = country_cursor.close(); + ret = country_cursor2.close(); ret = conn.close(null); |