Menu

OODBI

ENGITEX

Overview

OODBI (object-oriented database interface) is the client for OODBC described here: [OODBC - OODB as service]
OODBI itself as well as code examples using OODBI are contained in OODB_example_as_service.zip
The file ExampleServiceOODB.cs shows how to use OODBI from C# code and ExampleServiceOODB.ps1 shows how to use it from PowerShell.

As described in [Data types], arrays/lists of simple value types, OODBobjects, lists of OODBobjects, Hashtables and arrays or Hashtables can be stored in the database via OODBI. However there are some differences when using OODBI from C# code and from PowerShell. OODBobjects are "strong-typed" structures that do not give much flexibility and should be used from code only. On the other hand Hashtables do take some extra disk space and lead to processing overhead but they are flexible and supported by PowerShell.

First step is always to create an object of OODBI class.
In C#:
OODBI.OODBI dbi = new OODBI.OODBI("192.168.0.1");
In PShell:
$dbi = (new-object OODBI.OODBI([string]"192.168.0.1"))

Then a password for the database server must be set. GUESTs can only read data, USERs can read and write but cannot delete anything and initiate defragmentation.
dbi.setPassword("my-guest-pass");

Put methods

dbi.putList(floatList, floatListName);
dbi.putList(int16List, int16ListName);
...
dbi.putString(str, stringName); 
dbi.putObject(o); // o is OODBobject which has its name and will be written under its name in the database
dbi.putList(objList, objListName); // objList is List<OODBobject>
dbi.putHashtable(ht, htName);
dbi.putHashtableArray(htarr, htArrName); // htarr is Hashtable[]

Get methods

Getting single element from lists - saves time and traffic volume:

float f = dbi.getSingleFloatFromList(floatListName, index);
Int16 i = dbi.getSingleInt16FromList(shortListName, index);
...

Getting entire lists:

List<float> l = dbi.getFloatList(floatListName);  
List<Int16> l = dbi.getInt16List(int16ListName);  
...

Objects, Hashtables and their arrays/lists:

OODBobject o = dbi.getSingleOodbobjFromList(objList, dummy, index); / dummy is an object of the respective class extending OODBobject
List<OODBobject> objListRead = dbi.getObjectList(objList, dummy); // reads entire obj. list
OODBobject o = dbi.getSingleOodbobj(objName, dummy); // gets a single object stored outside of any arrays
dbi.getString(strName);
Hashtable t = dbi.loadHashtable(htName);
Hashtable[] htArrNew = dbi.loadHashtableArray(htArrName);

Other methods and PowerShell

In ExampleServiceOODB.cs all other methods are shown such as those for getting database info, its list of contents, for modifying and deleting items. ExampleServiceOODB.ps1 contains an example of how OODBI can be used from PowerShell.
The two main classes that are "native" to PowerShell and are supported by OODB are:

1 - Hashtables that are initialized like this:

$myStruct = @{
'volume' = [int]2
'width' = [float]1.111
'height' = [float]100.0
'comment' = [string]"no comment"
}  

Hashtables in PowerShell are read/written from/to the database with the same methods that are shown above for C# code.

2 - Arrays
[float[]]$myFloatArray = @(1.1, 0.1, 122.2)
There are extra methods in OODBI made for convenience when using arrays in PowerShell. They simply let the user work with arrays instead of lists.
Most of these methods internally call put/get methods for list.

$dbi.putArray($myFloatArray, [string]"myFloatArray")
$myFloatArrFromDb = $dbi.getFloatArray("myFloatArray")

Even though it is allowed to put "weakly-typed" array (i.e. an array of Objects, Object[]), the user has to know exactly what casting will take place internally and under which type the array will be stored in the database in the end.
For example, this will result in the array being stored as Int32 array (and not as Int16 as some might guess):

$testArray = @(13, 41, 122)
$dbi.putArray($testArray, [string]"myArray")

Related

Wiki: Data types
Wiki: Home
Wiki: OODBC - OODB as service

MongoDB Logo MongoDB