Sample app using index for both structured (json) and unstructured data

		database *db = new database ((char * )"userdb");

		//create table with key type as long
		table_env tenv;
		tenv.set_persist_type(INMEM_PERSIST);
		tenv.set_idx_type(BTREE);
		tenv.set_key_type(NORMAL_KEY_LONG);
		tenv.set_log_state(false);
		wideTable *wtbl1 = db->getWideTable("mytbl_long", OPENCREATE, &tenv);

		//create another table with key type as string, default key type is string
		tenv.set_persist_type(INMEM_PERSIST);
		tenv.set_idx_type(BTREE);
		tenv.set_log_state(false);
		tenv.set_allow_duplicate(true);
		wideTable *wtbl2 = db->getWideTable("mytbl_str", OPENCREATE, &tenv);

		//create indexes on table 1
		//assumes that table 1 will store json data and table 2 will store simple string
		wtbl1->addIndex_num("views", true);
		wtbl1->addIndex_str("name.first", 32, true);

		wtbl2->addIndex_str("errmsg", 24, true);

		wideConnection *wconn1 = wtbl1->getconnection();
		wideConnection *wconn2 = wtbl2->getconnection();

		char * jstr1 = "{\"_id\": \"5099803df3f4948bd2f98391\", "
						"\"name\": { \"first\": \"Alan\", \"last\": \"Turing\" },  "
						"\"achievement\": {\"education\" : {\"school\":\"sherborne school\", "
						"\"college\":\"Cambridge\"}}, "
						"\"birth\": \"Jun 23, 1912\", \"death\": \"Jun 07, 1954\", "
						"\"contribs\": [ \"Turing machine\", \"Turing test\", \"Turingery\" ],\"views\" : 1250000}";

		char * jstr2 = "{\"_id\": \"7919803df3f4948bd2f98760\", "
						"\"name\": { \"first\": \"Thomas\", \"last\": \"Edison\" },  "
						"\"achievement\": {\"education\" : {\"school\":\"self educated\", "
						"\"college\":\"Cooper Union\"}, \"occupation\":[\"inventor\",\"businessman\"]}, "
						"\"birth\": \"Feb 11, 1847\", \"death\": \"Oct 18, 1931\", "
						"\"contribs\": [ \"Incandescent light\", \"Fluoroscopy\", \"Media inventions\" ],\"views\" : 3190000}";

		char * str1 = "The errmsg is 'unable to ping machine 192.168.100.23'";

		char * str2 = "the errmsg is 'network unavialble'";

		char * str3 = "The errmsg is 'unable to ping machine 192.168.87.32'";

		long pk;
		bool flag = true;

		//put with no pk, let db create one, remember table is created with long key type
		if((pk = wconn1->put_doc(jstr1)) < 0)
		{
			bangdb_logger("error in put");
			flag = false;
		}

		//provide our own pk now
		if(wconn1->put_doc(100, jstr2, INSERT_UNIQUE) < 0)
		{
			bangdb_logger("error in put");
			flag = false;
		}

		FDT k, v, iv;

		k.data = (void*)"key1"; k.length = 4;
		v.data = str1; v.length = strlen(str1);
		iv.data = (void*)"ping"; iv.length = 4;
		//now for table 2, we put unstructred data but specify index explictly
		if(wconn2->put(&k, &v, "errmsg", &iv) < 0)
		{
			bangdb_logger("error in put");
			flag = false;
		}

		k.data = (void*)"key2"; k.length = 4;
		v.data = str2; v.length = strlen(str2);
		iv.data = (void*)"network"; iv.length = 7;
		if(wconn2->put(&k, &v, "errmsg", &iv) < 0)
		{
			bangdb_logger("error in put");
			flag = false;
		}

		k.data = (void*)"key3"; k.length = 4;
		v.data = str3; v.length = strlen(str3);
		iv.data = (void*)"ping"; iv.length = 4;
		if(wconn2->put(&k, &v, "errmsg", &iv) < 0)
		{
			bangdb_logger("error in put");
			flag = false;
		}

		//now scan the table
		scan_filter sf;
		resultset * rs1 = wconn1->scan_doc("views", 100000, 50000000, &sf);

		if(rs1->count() != 2)
			flag = false;

		while(rs1->hasNext())
		{
			printf("Document Retrieved = %s\n", rs1->getNextValStr());
			rs1->moveNext();
		}

		rs1->clear();

		resultset * rs2 = wconn1->scan_doc("name.first", "Adam", "Vallerie", &sf);

		if(rs2->count() != 2)
			flag = false;

		while(rs2->hasNext())
		{
			printf("Document Retrieved = %s\n", rs2->getNextValStr());
			rs2->moveNext();
		}

		rs2->clear();

		long nc = wconn2->count();
		printf("Total num or items in table 2 = %d\n", nc);

		//scan table 2 now
		resultset * rs3 = wconn2->scan("errmsg", "ping", "pings", &sf);

		if(rs3->count() != 2)
			flag = false;

		while(rs3->hasNext())
		{
			printf("Document Retrieved = %s\n", rs3->getNextValStr());
			rs3->moveNext();
		}
		rs3->clear();

		wconn1->closeconnection();
		wconn2->closeconnection();
		wtbl1->closetable();
		wtbl2->closetable();
		db->closedatabase();

		if(!flag)
			printf("Test Failed\n");
		else
			printf("Test Passed!\n");
	
		Database db = new Database((string)"userdb", path, TransactionType.DBTransactionNone);
		
		//create table with key type as long
		TableEnv tenv = new TableEnv();
		tenv.persistType = PersistType.InmemPersist;
		tenv.indexType = IndexType.Btree;
		tenv.keyType = BangDBKeyType.NormalKeyLong;
		tenv.walState = WALState.Disabled;
		WideTable wtbl1 = db.GetWideTable("mytbl_long", DBOpenType.Opencreate, tenv);
		
		//create another table with key type as string, default key type is string
		tenv.Reset();
		tenv.persistType = PersistType.InmemPersist;
		tenv.indexType = IndexType.Btree;
		tenv.walState = WALState.Disabled;
		tenv.allowDuplicate = true;
		WideTable wtbl2 = db.GetWideTable("mytbl_str", DBOpenType.Opencreate, tenv);
		
		//create indexes on table 1
		//assumes that table 1 will store json data and table 2 will store simple string
		wtbl1.AddIndex_Num("views", true);
		wtbl1.AddIndex_Str("name.first", 32, true);
		
		wtbl2.AddIndex_Str("errmsg", 24, true);
		
		WideConnection wconn1 = wtbl1.GetConnection();
		WideConnection wconn2 = wtbl2.GetConnection();
		
		String jstr1 = "{\"_id\": \"5099803df3f4948bd2f98391\", "+
						"\"name\": { \"first\": \"Alan\", \"last\": \"Turing\" },  "+
						"\"achievement\": {\"education\" : {\"school\":\"sherborne school\", "+
						"\"college\":\"Cambridge\"}}, "+
						"\"birth\": \"Jun 23, 1912\", \"death\": \"Jun 07, 1954\", "+
						"\"contribs\": [ \"Turing machine\", \"Turing test\", \"Turingery\" ],\"views\" : 1250000}";
		
		String jstr2 = "{\"_id\": \"7919803df3f4948bd2f98760\", "+
						"\"name\": { \"first\": \"Thomas\", \"last\": \"Edison\" },  "+
						"\"achievement\": {\"education\" : {\"school\":\"self educated\", "+
						"\"college\":\"Cooper Union\"}, \"occupation\":[\"inventor\",\"businessman\"]}, "+
						"\"birth\": \"Feb 11, 1847\", \"death\": \"Oct 18, 1931\", "+
						"\"contribs\": [ \"Incandescent light\", \"Fluoroscopy\", \"Media inventions\" ],\"views\" : 3190000}";
		
		String str1 = "The errmsg is 'unable to ping machine 192.168.100.23'";
		
		String str2 = "the errmsg is 'network unavialble'";
		
		String str3 = "The errmsg is 'unable to ping machine 192.168.87.32'";
		
		long pk;
		bool flag = true;
		
		//put with no pk, let db create one, remember table is created with long key type
		if((pk = wconn1.PutDoc(jstr1)) < 0)
		{
			Common.BangDBLogger("error in put");
			flag = false;
		}
		
		//provide our own pk now
		if(wconn1.PutDoc(100, jstr2, InsertOptions.InsertUnique) < 0)
		{
			Common.BangDBLogger("error in put");
			flag = false;
		}
		
		//now for table 2, we put unstructred data but specify index explictly
		if(wconn2.Put("key1", str1, "errmsg", "ping") < 0)
		{
			Common.BangDBLogger("error in put");
			flag = false;
		}
		
		if(wconn2.Put("key2", str2, "errmsg", "network") < 0)
		{
			Common.BangDBLogger("error in put");
			flag = false;
		}
		
		if(wconn2.Put("key3", str3, "errmsg", "ping") < 0)
		{
			Common.BangDBLogger("error in put");
			flag = false;
		}
		
		//now scan the table
		ScanFilter sf = new ScanFilter();
		ResultSet rs1 = wconn1.ScanDoc("views", 100000, 50000000, sf);
		
		if(rs1.Count() != 2)
			flag = false;
		
		while(rs1.HasNext())
		{
			Console.Out.WriteLine("Document Retrieved = " + rs1.GetNextValStr());
			rs1.MoveNext();
		}
		
		rs1.Clear();
		
		ResultSet rs2 = wconn1.ScanDoc("name.first", "Adam", "Vallerie", sf);
		
		if(rs2.Count() != 2)
			flag = false;
		
		while(rs2.HasNext())
		{
			Console.Out.WriteLine("Document Retrieved = " + rs2.GetNextValStr());
			rs2.MoveNext();
		}
		
		rs2.Clear();
		
		long nc = wconn2.Count();
		Console.Out.WriteLine("Total num or items in table 2 = " + nc);
		
		//scan table 2 now
		ResultSet rs3 = wconn2.Scan("errmsg", "ping", "pings", sf);
		
		if(rs3.Count() != 2)
			flag = false;
		
		while(rs3.HasNext())
		{
			Console.Out.WriteLine("Document Retrieved = " + rs3.GetNextValStr());
			rs3.MoveNext();
		}
		rs3.Clear();
		
		wconn1.CloseConnection();
		wconn2.CloseConnection();
		wtbl1.CloseTable();
		wtbl2.CloseTable();
		db.CloseDatabase();
		
		if(!flag)
			Console.Out.WriteLine("Test Failed");
		else
            Console.Out.WriteLine("Test Passed!");
	
		System.loadLibrary("bangdbjava");
		Database db = new DatabaseImpl ((String )"userdb", null, TransactionType.DB_MULTIOPS_TRANSACTION_NONE, null);
		
		//create table with key type as long
		TableEnv tenv = new TableEnv();
		tenv.setPersistType(PersistType.INMEM_PERSIST);
		tenv.setIndexType(IndexType.BTREE);
		tenv.setKeyType(BangDBKeyType.NORMAL_KEY_LONG);
		tenv.setLogState(false);
		WideTable wtbl1 = db.getWideTable("mytbl_long", DBAccess.OPENCREATE, tenv);
		
		//create another table with key type as string, default key type is string
		tenv.reset();
		tenv.setPersistType(PersistType.INMEM_PERSIST);
		tenv.setIndexType(IndexType.BTREE);
		tenv.setLogState(false);
		tenv.setAllowDuplicates(true);
		WideTable wtbl2 = db.getWideTable("mytbl_str", DBAccess.OPENCREATE, tenv);
		
		//create indexes on table 1
		//assumes that table 1 will store json data and table 2 will store simple string
		wtbl1.addIndex_num("views", true);
		wtbl1.addIndex_str("name.first", 32, true);
		
		wtbl2.addIndex_str("errmsg", 24, true);
		
		WideConnection wconn1 = wtbl1.getConnection();
		WideConnection wconn2 = wtbl2.getConnection();
		
		String jstr1 = "{\"_id\": \"5099803df3f4948bd2f98391\", "+
						"\"name\": { \"first\": \"Alan\", \"last\": \"Turing\" },  "+
						"\"achievement\": {\"education\" : {\"school\":\"sherborne school\", "+
						"\"college\":\"Cambridge\"}}, "+
						"\"birth\": \"Jun 23, 1912\", \"death\": \"Jun 07, 1954\", "+
						"\"contribs\": [ \"Turing machine\", \"Turing test\", \"Turingery\" ],\"views\" : 1250000}";
		
		String jstr2 = "{\"_id\": \"7919803df3f4948bd2f98760\", "+
						"\"name\": { \"first\": \"Thomas\", \"last\": \"Edison\" },  "+
						"\"achievement\": {\"education\" : {\"school\":\"self educated\", "+
						"\"college\":\"Cooper Union\"}, \"occupation\":[\"inventor\",\"businessman\"]}, "+
						"\"birth\": \"Feb 11, 1847\", \"death\": \"Oct 18, 1931\", "+
						"\"contribs\": [ \"Incandescent light\", \"Fluoroscopy\", \"Media inventions\" ],\"views\" : 3190000}";
		
		String str1 = "The errmsg is 'unable to ping machine 192.168.100.23'";
		
		String str2 = "the errmsg is 'network unavialble'";
		
		String str3 = "The errmsg is 'unable to ping machine 192.168.87.32'";
		
		long pk;
		boolean flag = true;
		
		//put with no pk, let db create one, remember table is created with long key type
		if((pk = wconn1.putDoc(jstr1)) < 0)
		{
			BangDBCommon.bangdbLogger("error in put");
			flag = false;
		}
		
		//provide our own pk now
		if(wconn1.putDoc(100, jstr2, InsertOptions.INSERT_UNIQUE) < 0)
		{
			BangDBCommon.bangdbLogger("error in put");
			flag = false;
		}
		
		//now for table 2, we put unstructred data but specify index explictly
		if(wconn2.put("key1", str1, "errmsg", "ping") < 0)
		{
			BangDBCommon.bangdbLogger("error in put");
			flag = false;
		}
		
		if(wconn2.put("key2", str2, "errmsg", "network") < 0)
		{
			BangDBCommon.bangdbLogger("error in put");
			flag = false;
		}
		
		if(wconn2.put("key3", str3, "errmsg", "ping") < 0)
		{
			BangDBCommon.bangdbLogger("error in put");
			flag = false;
		}
		
		//now scan the table
		ScanFilter sf = new ScanFilter();
		ResultSet rs1 = wconn1.scanDoc("views", 100000, 50000000, sf);
		
		if(rs1.count() != 2)
			flag = false;
		
		while(rs1.hasNext())
		{
			System.out.println("Document Retrieved = " + rs1.getNextValStr());
			rs1.moveNext();
		}
		
		rs1.clear();
		
		ResultSet rs2 = wconn1.scanDoc("name.first", "Adam", "Vallerie", sf);
		
		if(rs2.count() != 2)
			flag = false;
		
		while(rs2.hasNext())
		{
			System.out.println("Document Retrieved = " + rs2.getNextValStr());
			rs2.moveNext();
		}
		
		rs2.clear();
		
		long nc = wconn2.count();
		System.out.println("Total num or items in table 2 = " + nc);
		
		//scan table 2 now
		ResultSet rs3 = wconn2.scan("errmsg", "ping", "pings", sf);
		
		if(rs3.count() != 2)
			flag = false;
		
		while(rs3.hasNext())
		{
			System.out.println("Document Retrieved = " + rs3.getNextValStr());
			rs3.moveNext();
		}
		rs3.clear();
		
		wconn1.closeConnection();
		wconn2.closeConnection();
		wtbl1.closeTable(DBClose.DEFAULT);
		wtbl2.closeTable(DBClose.DEFAULT);
		db.closeDatabase(DBClose.DEFAULT);
		
		if(!flag)
			System.out.println("Test Failed");
		else
			System.out.println("Test Passed!");