module HxCorba { exception DatabaseException { long dbCode; string dbMessage; string message; // maybe more friendly }; struct SegmentQueryResult { string videoName; string segmentationName; VxSegment segment; VxTimeSpan time; }; typedef sequence<SegmentQueryResult> SegmentQueryResultSeq; interface DatabaseSession { StringSeq listVideos(); StringSeq listSegmentations(in string videoName); VxSegmentation getSegmentation(in string videoName, in string segName); StringSeq queryStrings(in string sqlQuery) raises(DatabaseException); VxSegmentSeq querySegments(in string sqlQuery) raises(DatabaseException); SegmentQueryResultSeq queryMultipleSegments(in string sqlQuery) raises(DatabaseException); void close(); }; interface Database { DatabaseSession openSession(in string username, in string password) raises(DatabaseException); }; };
The Database
interface is the entry point. It allows to initiate a database session, providing identification.
The DatabaseSession
interface offers funtions to perform easy queries on video segmentations : listVideos
, listSegmentations
and getSegmentation
.
queryStrings
, querySegments
and queryMultipleSegments
can be used to query the database with SQL, although each function determines the result type of the query. Only SQL queries that return that type are allowed.
Subclasses of DatabaseSession
have been defined to offer other functionality: adding and modifying video segmentations, more powerful query mechanisms and accessing other type of data.
Here is the definition of other database sessions (file HxCorbaDatabaseSessions.idl):
module HxCorba { //////////////////////////////////////////////////////////////// // // StoreSession // //////////////////////////////////////////////////////////////// interface VxSegmentBuilder { void addInt(in string id, in long value) raises(DatabaseException); void addDouble(in string id, in double value) raises(DatabaseException); void addString(in string id, in string value) raises(DatabaseException); }; interface VxSegmentationBuilder { void setDescription(in string description); VxSegmentBuilder buildSegment(in long start, in long end) raises(DatabaseException); }; interface StoreSession : DatabaseSession { void addSegmentation(in VxSegmentation seg, in string videoName, in string segName, in string description) raises(DatabaseException); VxSegmentationBuilder buildSegmentation(in string videoName, in string segName) raises(DatabaseException); }; //////////////////////////////////////////////////////////////// // // UpdateSession // //////////////////////////////////////////////////////////////// interface VxMutableSegment : VxSegmentBuilder, VxSegment { void setStart(in long start); void setEnd(in long end); void removeInt(in string id) raises(DatabaseException); void removeDouble(in string id) raises(DatabaseException); void removeString(in string id) raises(DatabaseException); void changeInt(in string id, in long newValue) raises(DatabaseException); void changeDouble(in string id, in double newValue) raises(DatabaseException); void changeString(in string id, in string newValue) raises(DatabaseException); }; interface VxMutableSegmentation : VxSegmentationBuilder, VxSegmentation { void removeSegment(in long index) raises(DatabaseException); }; interface UpdateSession : StoreSession { void removeVideo(in string videoName) raises(DatabaseException); void removeSegmentation(in VxSegmentation seg) raises(DatabaseException); void removeSegment(in VxSegment segment) raises(DatabaseException); }; //////////////////////////////////////////////////////////////// // // XMLSession // //////////////////////////////////////////////////////////////// enum DBDataTag { DBINT, DBDOUBLE, DBSTRING, DBSEGMENTATION, DBSEGMENT }; union DBData switch (DBDataTag) { case DBINT: long intData; case DBDOUBLE: double doubleData; case DBSTRING: string stringData; case DBSEGMENTATION: VxSegmentation segmentation; case DBSEGMENT: VxSegment segment; }; typedef sequence<DBDataTag> DBDataTagSeq; typedef sequence<DBData> DBDataRow; typedef sequence<DBDataRow> DBDataRowSeq; interface XMLSession : DatabaseSession { string queryXML(in string sqlQuery) raises(DatabaseException); DBDataRowSeq queryDBData(in string sqlQuery, in DBDataTagSeq resultType) raises(DatabaseException); }; //////////////////////////////////////////////////////////////// // // HistogramSession // //////////////////////////////////////////////////////////////// interface HistogramSession : DatabaseSession { void addHistogram(in string imageName, in string setName, in FloatSeq histoData) raises(DatabaseException); FloatSeq getHistogram(in string imageName, in string setName) raises(DatabaseException); StringSeq nearest(in string imageName, in string setName, in long count) raises(DatabaseException); StringSeq random(in string setName, in long count) raises(DatabaseException); StringSeq search(in long count, in FloatSeq sample) raises(DatabaseException); }; //////////////////////////////////////////////////////////////// // // VxSimilaritySession // //////////////////////////////////////////////////////////////// interface VxSimilarityBuilder { void addSimilarity(in long index1, in long index2, in double value, in long keyFrame1, in long keyFrame2) raises(DatabaseException); }; interface VxSimilaritySession : DatabaseSession { VxSimilarityBuilder addSimilarities(in string videoName, in string segName, in string featureName) raises(DatabaseException); }; //////////////////////////////////////////////////////////////// // // FullSession // //////////////////////////////////////////////////////////////// interface FullSession : UpdateSession, XMLSession, HistogramSession, VxSimilaritySession { }; };
Functionality of DatabaseSession
has been splitted in different subclasses to structure it a little and to allow different database servers implement different functionality. That way, existing servers doesn't have to be modified when new functionality is added.
Users have to check which interfaces are supported by the DatabaseSession
object returned by Database.openSession
operation to see which functionality is supported by the server.
The server can even decide to return different subclasses of DatabaseSessions
depending on the identification provided by the user: normal users can receive only a basic DatabaseSession
, but advanced users can get instead an UpdateSession
because they are allowed to modify the contents of the database.
Here is a small description of each session type:
StoreSession:
It allows to add new video segmentations to the database, but not modify existing ones.
UpdateSession:
It offers all the functionality of StoreSession
and also allows to modify existing segmentations.
To modify a segmentation, first obtain one with DatabaseSession.getSegmentation
and downcast it to VxMutableSegmentation
.
XMLSession:
These session has a function to test the retrieval of query results through XML, and also offers a mechanism to perform SQL queries that return any type. "any type" is not really true: only rows of int, double, strings, VxSegmentations and VxSegments can be retrieved (in any order and any amount) but it can be easily be extended to any other type if required.
XMLSession.queryDBData
takes an SQL query and a description of the rows returned by the query (as a sequence of DBDataTag)
, and returns a sequence of rows. A row is a sequence of unions that encapsulate the allowed types. Section Tools and Examples contains an example of using queryDBData
.
HistogramSession:
This is an example of how to access other data than video segmentations. The functionality to access this other data is moved out from the base DatabaseSession
and that way not all CORBA servers that implement the Database
interface are forced to support histogram sessions.
The server can even decide to return a HistogramSession
object only if the user scheema contains the tables required to handle histograms. (This is not implemented yet by any server, but it's not a bad idea).
VxSimilaritySession:
Another example of storing other kind of data. To retrieve similarities, use the querying functions of XMLSession
.
FullSession:
This interface has been defined to access servers that support all the interfaces, so all the functionality can be accessed through just one interface