Table Examples

Normal Table

Sample example for creating normal table and connections then closing them after use

	//create the db
	database *db = new database("mydb");
	
	//set the table config
	table_env tenv;
	tenv.set_persist_type(INMEM_PERSIST);//if you wish to override bangdb.config setting
	tenv.set_idx_type(BTREE);	//if you wish to override bangdb.config setting
	tenv.set_log_state(true);	//if you wish to override bangdb.config setting
	tenv.set_log_size_mb(64);	//set this if log state is true and you wish to override the bangdb.config setting
	tenv.set_key_size_byte(24); //if you wish to override bangdb.config setting
	tenv.set_table_type(NORMAL_TABLE); //this is not reqd as NORMAL_TABLE is default
	//can do more overridding here, but let's say this enough for our requirement as of now
	
	table *tbl = db->gettable("mytbl", OPENCREATE, &tenv);
	
	connection *conn = tbl->getconnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	conn->closeconnection();
	delete conn;
	tbl->closetable();
	delete tbl
	db->closedatabase();
	delete db;
	
	//all closeXXX API takes bangdb_close_type, which has following values;
	/*
	DEFAULT,
	CONSERVATIVE,
	OPTIMISTIC,
	CLEANCLOSE,
	SIMPLECLOSE,
	*/
	
	//default value for the API is 'DEFAULT'. If you wish to clean the db once it is closed, call CLEANCLOSE
	//CLEANCLOSE deletes all files and folders for the db after it is closed. This is useful during development
	//phase as many a times after correcting stuff in app, we need to delete the db files in order to start test again
	
	//create the db, path is where the bangdb.config file is kept (one can keep all DLLs also here)
	Database db = new Database((string)"userdb", path);
	
	//set the table config
	TableEnv tenv = new TableEnv();
	tenv.persistType = PersistType.InmemPersist;//if you wish to override bangdb.config setting
	tenv.indexType = IndexType.Btree;	//if you wish to override bangdb.config setting
	tenv.walState = WALState.Enabled;	//if you wish to override bangdb.config setting
	tenv2.logSizeMB = 64;	//set this if log state is true and you wish to override the bangdb.config setting
	tenv2.keySize = 12; //if you wish to override bangdb.config setting
	tenv.tableType = BangDBTableType.NormalTable; //this is not reqd as NORMAL_TABLE is default
	//can do more overridding here, but let's say this enough for our requirement as of now
	
	Table tbl = db.GetTable("mytbl", DBOpenType.Opencreate, tenv);
	
	Connection conn = tbl.GetConnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	conn.CloseConnection();
	tbl.CloseTable();
	db.CloseDatabase();
	
	//all closeXXX API takes bangdb_close_type, which has following values;
	/*
	Default,
	Conservative,
	Optimistic,
	CleanClose,
	*/
	
	//default value for the API is 'Default'. If you wish to clean the db once it is closed, call CleanClose
	//CleanClose deletes all files and folders for the db after it is closed. This is useful during development
	//phase as many a times after correcting stuff in app, we need to delete the db files in order to start test again
	
	//create the db, path is where the bangdb.config file is kept (one can keep all DLLs also here)
	System.loadLibrary("bangdbjava");
	Database db = new DatabaseImpl("mydb", null, TransactionType.DB_MULTIOPS_TRANSACTION_NONE, null);
	
	//set the table config
	TableEnv tenv = new TableEnv();
	tenv.setPersistType(PersistType.INMEM_PERSIST);//if you wish to override bangdb.config setting
	tenv.setIndexType(IndexType.BTREE);	//if you wish to override bangdb.config setting
	tenv.setLogState(true);	//if you wish to override bangdb.config setting
	tenv2.setLogSizeMB(64);	//set this if log state is true and you wish to override the bangdb.config setting
	tenv2.setKeySizeByte(12); //if you wish to override bangdb.config setting
	tenv.setTableType(BangDBTableType.NORMAL_TABLE); //this is not reqd as NORMAL_TABLE is default
	//can do more overridding here, but let's say this enough for our requirement as of now
	
	Table tbl = db.getTable(table_name, DBAccess.OPENCREATE, tenv);
	
	Connection conn = tbl.getConnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	conn.closeConnection(DBClose.DEFAULT);
	tbl.closeTable(DBClose.DEFAULT);
	db.closeDatabase(DBClose.DEFAULT);
	
	//all closeXXX API takes bangdb_close_type, which has following values;
	/*
	DEFAULT,
	CONSERVATIVE,
	OPTIMISTIC,
	CLEANCLOSE,
	SIMPLECLOSE,
	*/
	
	//If you wish to clean the db once it is closed, call CLEANCLOSE
	//CLEANCLOSE deletes all files and folders for the db after it is closed. This is useful during development
	//phase as many a times after correcting stuff in app, we need to delete the db files in order to start test again
		

Primitive Table

Sample example for creating primitive table and connections then closing them after use

	//create the db
	database *db = new database("mydb");
	
	//create table with different set of values
	
	table_env tenv;
	tenv.set_persist_type(INMEM_PERSIST);
	tenv.set_idx_type(BTREE);
	tenv.set_log_state(true);
	tenv.set_log_size_mb(32);
	tenv.set_autocommit_state(true);
	tenv.set_key_size_byte(12);
	
	table *tbl = db->getPrimitiveTable("mytable", PRIMITIVE_LONG, OPENCREATE, &tenv);
	
	primConnection *pconn = tbl->getPrimConnection();

	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	pconn->closeconnection();
	delete pconn;
	tbl->closetable();
	delete tbl;
	db->closedatabase();
	delete db;
	
	//create the db, path is where the bangdb.config file is kept (one can keep all DLLs also here)
	Database db = new Database((string)"userdb", path);
	
	//create table with different set of values
	
	table_env tenv = new TableEnv();
	tenv.persistType = PersistType.InmemPersist;
	tenv.indexType = IndexType.Btree;
	tenv.walState = WALState.Enabled;
	tenv.keySize = 12;
	tenv.keyType = BangDBKeyType.CompositeKey;
	tenv.sortDirection = BangDBKeySortDirection.SortDescending;
	
	Table ptbl = db.GetPrimitiveTable("mytable", BangDBPrimitiveDataType.PrimitiveString, DBOpenType.Opencreate, tenv);
	
	PrimConnection pconn = ptbl.GetPrimConnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	pconn.CloseConnection();
	ptbl.CloseTable();
	tb.CloseDatabase();
	
	//create the db, path is where the bangdb.config file is kept (one can keep all DLLs also here)
	System.loadLibrary("bangdbjava");
	Database db = new DatabaseImpl("mydb", null, TransactionType.DB_MULTIOPS_TRANSACTION_NONE, null);
	
	//create table with different set of values
	
	table_env tenv = new TableEnv();
	tenv.setPersistType(PersistType.INMEM_ONLY);
	tenv.setIndexType(IndexType.EXTHASH);
	tenv.setLogState(false);
	tenv.setKeySizeByte(12);
	tenv.setKeyType(BangDBKeyType.COMPOSITE_KEY);
	tenv.setSortDirection(BangDBSortDirection.SORT_DESCENDING);
	
	Table ptbl = db.getPrimitiveTable("mytable", BangDBPrimitiveDataType.PRIMITIVE_STRING, DBAccess.OPENCREATE, tenv);
	
	PrimConnection pconn = ptbl.getPrimConnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	pconn.closeConnection(DBClose.DEFAULT);
	ptbl.CloseTable(DBClose.DEFAULT);
	db.CloseDatabase(DBClose.DEFAULT);
	
	

to close table

	int retval = tbl1.closeTable(DBClose.DEFAULT);
	
	//note that it's good practice to close table as
	//it clears up resources for db
	

Wide Table

Sample example for creating wide table and connections then closing them after use

	//create the db
	database *db = new database("mydb");
	
	//create table with different set of values
	
	table_env tenv;
	tenv.set_persist_type(INMEM_PERSIST);
	tenv.set_idx_type(BTREE);
	tenv.set_log_state(true);
	tenv.set_key_size_byte(12);
	tenv.set_key_type(COMPOSITE_KEY);
	tenv.set_sort_dirction(SORT_DESCENDING);
	
	wideTable *wtbl = db->getWideTable("mytable", OPENCREATE, &tenv);
	
	wideConnection *wconn = wtbl->getconnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	wconn->closeconnection();
	delete wconn;
	wtbl->closetable();
	delete wtbl;
	db->closedatabase();
	delete db;
	
	//create the db, path is where the bangdb.config file is kept (one can keep all DLLs also here)
	Database db = new Database((string)"userdb", path);
	
	//create table with different set of values
	
	table_env tenv = new TableEnv();
	tenv.persistType = PersistType.InmemPersist;
	tenv.indexType = IndexType.Btree;
	tenv.walState = WALState.Enabled;
	tenv.keySize = 12;
	tenv.keyType = BangDBKeyType.CompositeKey;
	tenv.sortDirection = BangDBKeySortDirection.SortDescending;
	
	WideTable wtbl = db.GetWideTable("mytable", DBOpenType.Opencreate, tenv);
	
	WideConnection wconn = wtbl.GetConnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	wconn.CloseConnection();
	wtbl.CloseTable();
	db.CloseDatabase();
	
	
	
	//create the db, path is where the bangdb.config file is kept (one can keep all DLLs also here)
	System.loadLibrary("bangdbjava");
	Database db = new DatabaseImpl("mydb", null, TransactionType.DB_MULTIOPS_TRANSACTION_NONE, null);
	
	//create table with different set of values
	
	table_env tenv = new TableEnv();
	tenv.setPersistType(PersistType.INMEM_ONLY);
	tenv.setIndexType(IndexType.EXTHASH);
	tenv.setLogState(false);
	tenv.setKeySizeByte(12);
	tenv.setKeyType(BangDBKeyType.COMPOSITE_KEY);
	tenv.setSortDirection(BangDBSortDirection.SORT_DESCENDING);
	
	WideTable wtbl = db.getWideTable("mytable", DBAccess.OPENCREATE, tenv);
	
	WideConnection wconn = wtbl.getConnection();
	
	//you must check for null for tbl and conn above
	
	//do some operations
	
	//close the resources
	wconn.closeConnection(DBClose.DEFAULT);
	wtbl.CloseTable(DBClose.DEFAULT);
	db.CloseDatabase(DBClose.DEFAULT);