table

BangDB 1.5 supports multiple types of tables. Namely they are 'Normal Table', Primitive Table' and 'Wide Table'. Let's discuss the Normal Table first. This is the default table and has been existing in BangDB since earlier version

Normal Table

Now we will create table object. Note that we can have multiple tables within a db and each table can have different sub set of config parameters. There are few config parameters which can be overriden and defined separately for different tables as defined in the API section

we will show different ways of creating table object

API is as follows, we get it through database object;

table* gettable(const char *tblName, bangdb_open_type openFlag = OPENCREATE, table_env *tenv=NULL);

To create table;

	//create table with default values, which is apply the bangdb.config values 
	//by putting NULL for table_env* and open or create the table
	
	table *tbl1 = db->gettable("mytable1");
		
	//override few config values using table_env to create second table
	
	table_env tenv;
	te.set_persist_type(INMEM_ONLY);
	te.set_idx_type(EXTHASH);
	te.set_log_state(false);
	
	table *tbl2 = db->gettable("mytable2", OPENCREATE, &tenv);
	
	//and other table with different set of values
	
	table_env tenv2;
	te.set_persist_type(INMEM_PERSIST);
	te.set_idx_type(BTREE);
	te.set_log_state(true);
	te.set_log_size_mb(32);
	te.set_autocommit_state(true);
	te.set_key_size_byte(12);
	
	table *tbl3 = db->gettable("mytable3", OPENCREATE, &tenv2);
	
	//etc...
	//note that you shouldn't create table using the constructor, behaviour is not defined
	

to close table

	int retval = tbl1->closetable();
	delete tbl1;
	
	//note that it's good practice to close table and delete the handle when done as
	//it clears up resources for db
	

API

Table GetTable(string tableName, DBOpenType flag = DBOpenType.Opencreate, TableEnv tblEnv = null)

To create table;

	//create table with default values, which is use the config values as defined 
	//in bangdb.config for some of the configuration which can be overridden
	
	Table tbl1 = db.GetTable("mytable1");
		
	//override few config values using table_env to create second table
	
	TableEnv tenv = new TableEnv();
	tenv.persistType = PersistType.InmemOnly;
	tenv.indexType = IndexType.ExtHash;
	tenv.walState = WALState.Disabled;
	
	Table tbl2 = db.GetTable("mytable2", DBOpenType.OpenCreate, tenv);
		
	//and other table with different set of values
	
	TableEnv tenv2 = new TableEnv();
	tenv2.persistType = PersistType.InmemPersist;
	tenv2.IndexType = IndexType.Btree;
	tenv2.walState = WALState.Enabled;
	tenv2.logSizeMB = 32;
	tenv2.autoCommitState = AutoCommitState.Enabled;
	tenv2.keySize = 12;
		
	Table tbl3 = db.GetTable("mytable3", DBOpenType.OpenCreate, tenv2);
	
	//etc...
	

to close table

	int retval = tbl1.CloseTable();

	

API

Table getTable(String name, DBAccess openflag, TableEnv tenv)

To create table;

	//create table with default values, which is use the config values as defined 
	//in bangdb.config for some of the configuration which can be overridden
	
	Table tbl1 = db.getTable("mytable1", DBAccess.OPENCREATE, null);
		
	//override few config values using table_env to create second table
	
	tenv = new TableEnv();
	tenv.setPersistType(PersistType.INMEM_ONLY);
	tenv.setIndexType(IndexType.EXTHASH);
	tenv.setLogState(false);
	
	Table tbl2 = db.getTable("mytable2", DBAccess.OPENCREATE, tenv);
		
	//and other table with different set of values
	
	TableEnv tenv2 = new TableEnv();
	tenv2.setPersistType(PersistType.INMEM_PERSIST);
	tenv2.setIndexType(IndexType.BTREE);
	tenv2.setLogState(true);
	tenv2.setAutocommitState(true);
	tenv2.setLogSizeMB(128);
	tenv2.setKeySizeByte(32);
		
	Table tbl3 = db.getTable("mytable3", DBAccess.OPENCREATE, tenv2);
	
	//etc...
	

to close table

	int retval = tbl1.closeTable(DBClose.DEFAULT);
	
	//Note that to clean up while closing the app all you need to do is to 
	//close the databasee, which cleansup all tables and connections resources. Therefore
	//separate close for all open tables and connections are not required 
	//if you wish to close db, only closing db is enough
	//But for closing a table whenever needed, this API should be used 
	

Primitive Table

Now we will create primitive table object. The API is similar to that of Normal Table except that user has to pass extra parameter to tell for which data type the db should create table. The options can be selected from the enum defined by the db.

we will show different ways of creating primitive table object

API is as follows, we get it through database object;

table* getPrimitiveTable(const char *name, bangdb_primitive_data_type dataType = PRIMITIVE_LONG, bangdb_open_type openflag = OPENCREATE, table_env *tenv=NULL);

To create table;

	//create table with default values, which is apply the bangdb.config values 
	//by putting NULL for table_env* and open or create the table, 
	//also the bangdb_primitive_data_type is PRIMITIVE_LONG by default
	
	table *tbl1 = db->getPrimitiveTable("mytable1");
		
	//note that it returns the table object only	
	
	//override few config values using table_env to create second table
	
	table_env tenv;
	tenv.set_persist_type(INMEM_ONLY);
	tenv.set_idx_type(EXTHASH);
	tenv.set_log_state(false);
	
	table *tbl2 = db->getPrimitiveTable("mytable2", PRIMITIVE_INT, OPENCREATE, &tenv);
	
	//and other table with different set of values
	
	tenv.reset();
	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);
	
	table *tbl3 = db->getPrimitiveTable("mytable3", PRIMITIVE_STRING, OPENCREATE, &tenv);
	
	//etc...
	//note that you can't create table using the constructor, behaviour is not defined
	
	//Also note that key_type in table_env doesn't affect primitive table as 
	//the primitive type is passed directly to the get table API. The key_type is only
	//for normal table and wide table
	
	

to close table

	int retval = tbl1->closetable();
	delete tbl1;
	
	//note that it's good practice to close table and delete the handle when done as
	//it clears up resources for db
	

API is as follows, we get it through database object;

Table GetPrimitiveTable(string tableName, BangDBPrimitiveDataType dataType = BangDBPrimitiveDataType.PrimitiveLong, DBOpenType flag = DBOpenType.Opencreate, TableEnv tblEnv = null);

To create table;

	//create table with default values, which is apply the bangdb.config values 
	//by putting NULL for TableEnv and open or create the table, 
	//also the BangDBPrimitiveDataType is PrimitiveLong by default
	
	Table tbl1 = db.GetPrimitiveTable("mytable1");
		
	//note that it returns the table object only	
	
	//override few config values using table_env to create second table
	
	TableEnv tenv = new TableEnv();
	tenv.persistType = PersistType.InmemOnly;
	tenv.indexType = IndexType.ExtHash;
	tenv.walState = WALState.Disabled;
	
	Table tbl2 = db.GetPrimitiveTable("mytable2", BangDBPrimitiveDataType.PrimitiveInt, DBOpenType.Opencreate, tenv);
	
	//and other table with different set of values
	
	tenv.Reset();
	tenv.persistType = PersistType.InmemPersist;
	tenv.indexType = IndexType.Btree;
	tenv.walState = WALState.Enabled;
	tenv.keySize = 12;
	tenv.keyType = BangDBKeyType.CompositeKey;
	tenv.sortDirection = BangDBKeySortDirection.SortDescending;
	
	Table tbl3 = db.GetPrimitiveTable("mytable3", BangDBPrimitiveDataType.PrimitiveString, DBOpenType.Opencreate, tenv);
	
	//etc...
	//note that you can't create table using the constructor, behaviour is not defined
	
	//Also note that keyType in TableEnv doesn't affect primitive table as 
	//the primitive type is passed directly to the get table API. The keyType is only
	//for normal table and wide table
	
	

to close table

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

API is as follows, we get it through database object;

Table getPrimitiveTable(String name, BangDBPrimitiveDataType dataType, DBAccess openflag, TableEnv tenv);

To create table;

	//create table with default values, which is apply the bangdb.config values 
	//by putting NULL for table_env* and open or create the table, 
	//also the BangDBPrimitiveDataType is PrimitiveLong by default
	
	Table tbl1 = db.getPrimitiveTable("mytable1", BangDBPrimitiveDataType.PRIMITIVE_LONG, DBAccess.OPENCREATE, null);
		
	//note that it returns the table object only	
	
	//override few config values using table_env to create second table
	
	TableEnv tenv = new TableEnv();
	tenv.setPersistType(PersistType.INMEM_ONLY);
	tenv.setIndexType(IndexType.EXTHASH);
	tenv.setLogState(false);
	
	Table tbl2 = db.getPrimitiveTable("mytable2", BangDBPrimitiveDataType.PRIMITIVE_INT, DBAccess.OPENCREATE, tenv);
	
	//and other table with different set of values
	tenv.reset();
	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 tbl3 = db.getPrimitiveTable("mytable3", BangDBPrimitiveDataType.PRIMITIVE_STRING, DBAccess.OPENCREATE, tenv);
	
	//etc...
	//note that you can't create table using the constructor, behaviour is not defined
	
	//Also note that key_type in table_env doesn't affect primitive table as 
	//the primitive type is passed directly to the get table API. The key_type is only
	//for normal table and wide table
	
	

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

Now we will create wide table object. The API is very similar to that of Normal Table except that it returns Wide Table

we will show different ways of creating wide table object

API is as follows, we get it through database object;

wideTable* getWideTable(const char *name, bangdb_open_type openflag = OPENCREATE, table_env *tenv=NULL);

To create table;

	//create table with default values, which is apply the bangdb.config values 
	//by putting NULL for table_env* and open or create the table, 
	
	wideTable *tbl1 = db->getWideTable((char*)"mytable1");
		
	//note that it returns the wideTable object	
	
	//override few config values using table_env to create second table
	
	table_env tenv;
	tenv.set_persist_type(INMEM_ONLY);
	tenv.set_idx_type(EXTHASH);
	tenv.set_log_state(false);
	
	wideTable *tbl2 = db->getWideTable((char*)"mytable2", OPENCREATE, &tenv);
	
	//and other table with different set of values
	
	tenv.reset();
	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 *tbl3 = db->getWideTable((char*)"mytable3", OPENCREATE, &tenv);
	
	//etc...
	//note that you can't create table using the constructor, behaviour is not defined
	
	

to close table

	int retval = tbl1->closetable();
	delete tbl1;
	
	//note that it's good practice to close table and delete the handle when done as
	//it clears up resources for db
	

API is as follows, we get it through database object;

WideTable GetWideTable(string tableName, DBOpenType flag = DBOpenType.Opencreate, TableEnv tblEnv = null);

To create table;

	//create table with default values, which is apply the bangdb.config values 
	//by putting NULL for TableEnv and open or create the table, 
	
	WideTable tbl1 = db.GetWideTable("mytable1");
		
	//note that it returns the WideTable object	
	
	//override few config values using table_env to create second table
	
	TableEnv tenv = new TableEnv();
	tenv.persistType = PersistType.InmemOnly;
	tenv.indexType = IndexType.ExtHash;
	tenv.walState = WALState.Disabled;
	
	WideTable tbl2 = db.GetWideTable("mytable2", DBOpenType.Opencreate, tenv);
	
	//and other table with different set of values
	
	tenv.Reset();
	tenv.persistType = PersistType.InmemPersist;
	tenv.indexType = IndexType.Btree;
	tenv.walState = WALState.Enabled;
	tenv.keySize = 12;
	tenv.keyType = BangDBKeyType.CompositeKey;
	tenv.sortDirection = BangDBKeySortDirection.SortDescending;
	
	WideTable tbl3 = db.GetWideTable("mytable3", DBOpenType.Opencreate, tenv);
	
	//etc...
	//note that you can't create table using the constructor, behaviour is not defined
	
	

to close table

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

API is as follows, we get it through database object;

WideTable getWideTable(String name, DBAccess openflag, TableEnv tenv);

To create table;

	//create table with default values, which is apply the bangdb.config values 
	//by putting NULL for table_env* and open or create the table, 
	
	WideTable tbl1 = db.getWideTable("mytable1", DBAccess.OPENCREATE, null);
		
	//note that it returns the table object only	
	
	//override few config values using table_env to create second table
	
	TableEnv tenv = new TableEnv();
	tenv.setPersistType(PersistType.INMEM_ONLY);
	tenv.setIndexType(IndexType.EXTHASH);
	tenv.setLogState(false);
	
	WideTable tbl2 = db.getWideTable("mytable2", DBAccess.OPENCREATE, tenv);
	
	//and other table with different set of values
	
	tenv.reset();
	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 tbl3 = db.getWideTable("mytable3", DBAccess.OPENCREATE, tenv);
	
	//etc...
	//note that you can't create table using the constructor, behaviour is not defined
	
	

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