Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.vrspace.server.db
Class SQLDB  view SQLDB download SQLDB.java

java.lang.Object
  extended byorg.vrspace.server.DB
      extended byorg.vrspace.server.db.SQLDB
Direct Known Subclasses:
InformixDB, MySQLDB

public abstract class SQLDB
extends org.vrspace.server.DB

DB store objects by storing all public fields: all primitive types and primitive arrays (java.lang.String, java.net.URL and java.util.Date are considered as primitive) all objects and object arrays that are contained inside object (recursive) Requirements and restrictions: every object that will be stored in DB must have defined "public long db_id" field (or must inherit from class that have db_id field) objects that have encapsulated data - private fields and get/set methods for retrieving/storing that fields can't be stored correctly! This is common for JDK classes - that classes can be stored by manually coding (it's already done for String, Date, URL and Float) Description of DB structure: DB has "repository" tables and "object" tables. "repository" tables stores information about classes, objects and packages; "object" tables store objects. "repository" tables: mysql> describe classes; +--------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | classID | bigint(20) | | PRI | 0 | | | superClassID | bigint(20) | YES | | NULL | | | packageID | bigint(20) | YES | | NULL | | | className | varchar(255) | YES | | NULL | | +--------------+--------------+------+-----+---------+-------+ mysql> describe packages; +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | packageID | bigint(20) | | PRI | 0 | | | packageName | varchar(255) | YES | | NULL | | +-------------+--------------+------+-----+---------+-------+ mysql> describe objects; +----------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+------------+------+-----+---------+-------+ | objectID | bigint(20) | | PRI | 0 | | | classID | bigint(20) | YES | | NULL | | +----------+------------+------+-----+---------+-------+ details about "repository" tables: relations in repository tables (these are just logical relations - not explicitly created): - superClassID in one classes record must exist as classID in another classes record (except for java.lang.Object when superClassID is null) - classID in objects table must exist in classes table - packageID in classes table must exist in packages table className is full class name with dots replaced by optional char example: when optional char is '_', org.vrspace.server.File is stored as org_vrspace_server_File. This is done because some db's can't have points in table names details about "object" tables: - names are full class names as stored in "classes" repository table - names of columns in tables are names of object fields - every table has "db_id" column that contains object ID stored in "objects" repository table - tables are divided into five groups: object: - for storing "main" object (the one that is referenced in put/get method) - if object consist of several inherited classes, every class is stored in separated table - primary key is "db_id" - object fields are stored as follows: if field is primitive, its value is stored. The type of a column is a type of that primitive mapped to matching database type if field is a primitive array, object or object array, than that column has integer type and stores a unique reference inside object for that primitive array, object or object array; primitive array, object or object array itself are stored in another table (described below), if they are null, column has null value and there's no recods in another table - if class has "db_id" field it isn't explicitly stored because it's already stored as primary key object_array: - for storing "main" object array (the one that is referenced in put/get method) - table name has suffix "_arr" - has column "arr_id" that stores index of object in array - primary key is "db_id" + "arr_id" - has column "isNull" which is true if object is null - fields are stored according to rules from object tables object_contained: - for storing objects that are contained inside "main" object - table name has suffix "_cnt" - has column "cnt_id" that stores reference described in object table - primary key is "db_id" + "cnt_id" - fields are stored according to rules from object tables object_array_contained: - for storing object arrays that are contained inside "main" object - table name has suffix "_arr_cnt" - has column "cnt_id" that stores reference described in object table - has column "arr_id" that stores index of object in array - primary key is "db_id" + "cnt_id" + "arr_id" - has column "isNull" which is true if object is null - fields are stored according to rules from object tables primitive_array_contained: - for storing primitive arrays that are contained inside "main" object - table name is primitive name + "_arr" - has column "cnt_id" that stores reference described in object table - has column "arr_id" that stores index of object in array - primary key is "db_id" + "cnt_id" + "arr_id" - in column "value" is stored value of that primitive How objects are stored: - "repository" tables are created automatically first time when db starts - when storing object of class that is inherited from other class(es), every field is stored in table of class that declare that field. - if some class in hierarchy has no public fields, table for that class will not be created, but class itself will be added to classes table. example class is java.lang.Object - if object contains another object(s), than contained object(s) is stored in object_contained table(s) with above rules - if object contains object array(s) than contained array(s) is stored in object_array table(s) with above rules - if object has primitive array(s) than contained array(s) is stored in primitive array table Example - storing object of class D: // A.java package org.vrspace; public class A { public long db_id; public int a1 = 6; public char a2 = 'a'; } // B.java package org.vrspace; public class B extends A { public String b1 = "Hawkwind"; } // C.java package org.vrspace; public class C extends B { } // D.java package org.vrspace; import java.net.URL; import org.vrspace.test.*; public class D extends C { public long d1 = 666; public float d2 = 6.66f; public URL d3 = new URL("http://vrspace.org"); public E d4 = new E(); public int[] d5 = new int[10]; } // E.java package org.vrspace.test; public class E { public String e1 = "Ozrics"; public int e2 = 6; } contens of "repository": ------------------------ mysql> select * from classes; +---------+--------------+-----------+--------------------+ | classID | superClassID | packageID | className | +---------+--------------+-----------+--------------------+ | 1 | 0 | 1 | java_lang_Object | | 2 | 1 | 2 | org_vrspace_A | | 3 | 2 | 2 | org_vrspace_B | | 4 | 3 | 2 | org_vrspace_C | | 5 | 4 | 2 | org_vrspace_D | | 6 | 1 | 3 | org_vrspace_test_E | +---------+--------------+-----------+--------------------+ mysql> select * from packages; +-----------+------------------+ | packageID | packageName | +-----------+------------------+ | 1 | java_lang | | 2 | org_vrspace | | 3 | org_vrspace_test | +-----------+------------------+ mysql> select * from objects; +----------+---------+ | objectID | classID | +----------+---------+ | 1 | 5 | +----------+---------+ created "object" tables: ------------------------ mysql> describe org_vrspace_a; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | db_id | bigint(20) | | PRI | 0 | | | a1 | mediumint(9) | YES | | NULL | | | a2 | char(1) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ mysql> describe org_vrspace_b; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | db_id | bigint(20) | | PRI | 0 | | | b1 | varchar(255) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ mysql> describe org_vrspace_d; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | db_id | bigint(20) | | PRI | 0 | | | d1 | bigint(20) | YES | | NULL | | | d2 | float(10,2) | YES | | NULL | | | d3 | varchar(255) | YES | | NULL | | | d4 | bigint(20) | YES | | NULL | | | d5 | bigint(20) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ mysql> describe int_array; +--------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+-------+ | db_id | bigint(20) | | PRI | 0 | | | arr_id | bigint(20) | | PRI | 0 | | | nr_id | bigint(20) | | PRI | 0 | | | value | mediumint(9) | YES | | NULL | | +--------+--------------+------+-----+---------+-------+ mysql> describe org_vrspace_test_e_array; +--------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+-------+ | db_id | bigint(20) | | PRI | 0 | | | arr_id | bigint(20) | | PRI | 0 | | | nr_id | bigint(20) | | PRI | 0 | | | e1 | varchar(255) | YES | | NULL | | | e2 | mediumint(9) | YES | | NULL | | +--------+--------------+------+-----+---------+-------+ contens of "object" tables: --------------------------- mysql> select * from org_vrspace_a; +-------+------+------+ | db_id | a1 | a2 | +-------+------+------+ | 1 | 6 | a | +-------+------+------+ mysql> select * from org_vrspace_b; +-------+----------+ | db_id | b1 | +-------+----------+ | 1 | Hawkwind | +-------+----------+ mysql> select * from org_vrspace_d; +-------+------+------+--------------------+------+------+ | db_id | d1 | d2 | d3 | d4 | d5 | +-------+------+------+--------------------+------+------+ | 1 | 666 | 6.66 | http://vrspace.org | 0 | 1 | +-------+------+------+--------------------+------+------+ mysql> select * from org_vrspace_test_e_array; +-------+--------+-------+--------+------+ | db_id | arr_id | nr_id | e1 | e2 | +-------+--------+-------+--------+------+ | 1 | 0 | 0 | Ozrics | 6 | +-------+--------+-------+--------+------+ mysql> select * from int_array; +-------+--------+-------+-------+ | db_id | arr_id | nr_id | value | +-------+--------+-------+-------+ | 1 | 0 | 1 | 0 | | 1 | 1 | 1 | 0 | | 1 | 2 | 1 | 0 | | 1 | 3 | 1 | 0 | | 1 | 4 | 1 | 0 | | 1 | 5 | 1 | 0 | | 1 | 6 | 1 | 0 | | 1 | 7 | 1 | 0 | | 1 | 8 | 1 | 0 | | 1 | 9 | 1 | 0 | +-------+--------+-------+-------+


Field Summary
protected static int BOOLEAN
           
protected static int BOOLEAN_ARR
           
protected static int BYTE
           
protected static int BYTE_ARR
           
protected  java.lang.String BYTE_TYPE
           
protected static int CHAR
           
protected static int CHAR_ARR
           
protected  java.lang.String CHAR_TYPE
           
(package private) static long clsID
           
(package private) static java.util.HashMap clsRepository
          in-memory repository that contains information about classes key: class name value: SQLClass object
(package private)  java.sql.Connection conn
           
protected static int DATE_OBJ
           
protected static int DATE_OBJ_ARR
           
protected  java.lang.String DATE_TYPE
           
protected static int DOUBLE
           
protected static int DOUBLE_ARR
           
protected  java.lang.String DOUBLE_TYPE
           
protected static int FLOAT
           
protected static int FLOAT_ARR
           
protected static int FLOAT_OBJ
           
protected static int FLOAT_OBJ_ARR
           
protected  java.lang.String FLOAT_TYPE
           
protected static int INT
           
protected static int INT_ARR
           
protected  java.lang.String INT_TYPE
           
(package private)  org.vrspace.util.Logger logger
           
protected static int LONG
           
protected static int LONG_ARR
           
protected  java.lang.String LONG_TYPE
           
protected static int OBJECT
           
protected static int OBJECT_ARR
           
(package private) static long objID
           
(package private) static long pkgID
           
(package private)  java.sql.ResultSet rs
           
protected static int SHORT
           
protected static int SHORT_ARR
           
protected  java.lang.String SHORT_TYPE
           
protected  java.lang.String SQL_CHECK_CLASS
           
protected  java.lang.String SQL_CHECK_PACKAGE
           
protected  java.lang.String SQL_COUNT_CLASSES
           
protected  java.lang.String SQL_COUNT_OBJECTS
           
protected  java.lang.String SQL_COUNT_PACKAGES
           
protected  java.lang.String SQL_CREATE_CLASSES_TABLE
           
protected  java.lang.String SQL_CREATE_OBJ_TABLE_1
           
protected  java.lang.String SQL_CREATE_OBJ_TABLE_2
           
protected  java.lang.String SQL_CREATE_OBJECTS_TABLE
           
protected  java.lang.String SQL_CREATE_PACKAGES_TABLE
           
protected  java.lang.String SQL_CREATE_PRIM_TABLE_1
           
protected  java.lang.String SQL_CREATE_PRIM_TABLE_2
           
protected  java.lang.String SQL_CREATE_PRIM_TABLE_3
           
protected  java.lang.String SQL_DEL_OBJECT
           
protected  java.lang.String SQL_DELETE_OBJECT
           
protected  java.lang.String SQL_GET_ALL
           
protected  java.lang.String SQL_GET_ARR_1
           
protected  java.lang.String SQL_GET_ARR_2
           
protected  java.lang.String SQL_GET_ARR_3
           
protected  java.lang.String SQL_GET_ARR_4
           
protected  java.lang.String SQL_GET_CLASSES
           
protected  java.lang.String SQL_GET_OBJ_ARR_1
           
protected  java.lang.String SQL_GET_OBJ_ARR_2
           
protected  java.lang.String SQL_GET_OBJ_ARR_3
           
protected  java.lang.String SQL_GET_OBJECT_1
           
protected  java.lang.String SQL_GET_OBJECT_2
           
protected  java.lang.String SQL_GET_OBJECT_3
           
protected  java.lang.String SQL_GET_OBJECT_4
           
protected  java.lang.String SQL_GET_PRIM_ARR_1
           
protected  java.lang.String SQL_GET_PRIM_ARR_2
           
protected  java.lang.String SQL_GET_PRIM_ARR_3
           
protected  java.lang.String SQL_GET_RANGE_1
           
protected  java.lang.String SQL_GET_RANGE_2
           
protected  java.lang.String SQL_GET_RANGE_3
           
protected  java.lang.String SQL_INSERT_CLASS
           
protected  java.lang.String SQL_INSERT_OBJECT
           
protected  java.lang.String SQL_INSERT_PACKAGE
           
protected  java.lang.String SQL_INSERT_PRIM_1
           
protected  java.lang.String SQL_INSERT_PRIM_2
           
protected  java.lang.String SQL_SHOW_TABLES
           
(package private)  java.sql.Statement stmt
           
(package private)  java.sql.PreparedStatement stmtCheckClass
           
(package private)  java.sql.PreparedStatement stmtCheckPackage
           
(package private)  java.sql.PreparedStatement stmtDeleteObject
           
(package private)  java.sql.PreparedStatement stmtDelObject
           
(package private)  java.sql.PreparedStatement stmtGetObject
           
(package private)  java.sql.PreparedStatement stmtInsertClass
           
(package private)  java.sql.PreparedStatement stmtInsertObject
           
(package private)  java.sql.PreparedStatement stmtInsertPackage
           
(package private)  java.sql.PreparedStatement stmtInsertPrim
           
protected static int STRING_OBJ
           
protected static int STRING_OBJ_ARR
           
protected  java.lang.String STRING_TYPE
           
protected static int URL_OBJ
           
protected static int URL_OBJ_ARR
           
 
Fields inherited from class org.vrspace.server.DB
cache
 
Constructor Summary
SQLDB()
           
 
Method Summary
protected  SQLClass analizeClass(java.lang.Class cls)
          Internal
 void commit()
          Not implemented
 void connect(java.lang.String name)
          Connect to the database
abstract  java.lang.String create(java.lang.String name)
          create a new database if does not exist
protected  void createPrimTable(java.lang.Class primitive)
          Creates table to store primitives
 void delete(java.lang.Object obj)
          Delete object from database.
 void disconnect()
          Close connection to the database
 java.lang.Object get(java.lang.Object obj)
          Retreives an object from the database
 java.lang.Object get(java.lang.String className, long id)
          Retreives an object from the database
 java.lang.Object get(java.lang.String className, java.lang.String field, java.lang.Object value)
          Get first object of class className, whose field field have value value
 java.lang.Object[] getAll(java.lang.String className)
          Get all objects of className from db
protected  SQLClass getClass(java.lang.Class cls)
          Internal, try to get class from repository return SQLClass if class exits in repository, else return null
protected  java.lang.Object getObject(java.lang.Object obj, long id, long cntID, long arrID)
          Retreives an object from the database, internal
protected  java.lang.Object getObjectArray(java.lang.String className, long id, long cntID)
          Internal
protected  long getObjectID(long classID)
          returns object ID
protected  long getPackageID(java.lang.Package objPackage)
          Retreives package ID from the repository
protected  java.lang.Object getPrimitiveArray(java.lang.String className, int type, long id, long cntID)
          Internal
 java.lang.Object[] getRange(java.lang.Object o1, java.lang.Object o2)
          Get all objects that are "between" object o1 and o2.
 java.lang.Object[] getRange(java.lang.String className, java.lang.String field, java.lang.Object value)
          Get all objects of class className, whose field field have value value
protected  java.sql.ResultSet getRangeDb_id(java.lang.String className, java.lang.String field, java.lang.Object value)
          unfinished, work only for primitive fields not objects Internal
protected  java.lang.String getSQLText(java.lang.String className, java.util.ArrayList fieldName, java.util.ArrayList fieldType)
          Internal
protected  void insertObject(java.lang.Object obj, long objectID, SQLClass cls, long cntID, long arrID)
          Internal, called from put(Object obj) and put(Object[] obj)
protected abstract  boolean loadDriver()
          Override this in actual implementations.
protected  java.lang.String mapJava2SQL(java.lang.String type)
          Internal
protected  java.lang.String mapTypes(int intType)
          Internal
 void put(java.lang.Object obj)
          Stores obj to the database.
 void put(java.lang.Object[] obj)
          Stores object array to the database.
protected  void putPrimitiveArray(java.lang.Object obj, long objectID, long cntID)
          Internal
protected  java.sql.ResultSet query(java.lang.String sqlQuery)
          Internal
private static java.lang.String replacePoints(java.lang.String s)
          Internal
 void update(org.vrspace.server.Request r)
          Update field in object.
protected  int update(java.lang.String sqlQuery)
          Internal
 
Methods inherited from class org.vrspace.server.DB
load, load, load
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN

protected static final int BOOLEAN
See Also:
Constant Field Values

BYTE

protected static final int BYTE
See Also:
Constant Field Values

SHORT

protected static final int SHORT
See Also:
Constant Field Values

INT

protected static final int INT
See Also:
Constant Field Values

LONG

protected static final int LONG
See Also:
Constant Field Values

FLOAT

protected static final int FLOAT
See Also:
Constant Field Values

DOUBLE

protected static final int DOUBLE
See Also:
Constant Field Values

CHAR

protected static final int CHAR
See Also:
Constant Field Values

FLOAT_OBJ

protected static final int FLOAT_OBJ
See Also:
Constant Field Values

STRING_OBJ

protected static final int STRING_OBJ
See Also:
Constant Field Values

DATE_OBJ

protected static final int DATE_OBJ
See Also:
Constant Field Values

URL_OBJ

protected static final int URL_OBJ
See Also:
Constant Field Values

OBJECT

protected static final int OBJECT
See Also:
Constant Field Values

BOOLEAN_ARR

protected static final int BOOLEAN_ARR
See Also:
Constant Field Values

BYTE_ARR

protected static final int BYTE_ARR
See Also:
Constant Field Values

SHORT_ARR

protected static final int SHORT_ARR
See Also:
Constant Field Values

INT_ARR

protected static final int INT_ARR
See Also:
Constant Field Values

LONG_ARR

protected static final int LONG_ARR
See Also:
Constant Field Values

FLOAT_ARR

protected static final int FLOAT_ARR
See Also:
Constant Field Values

DOUBLE_ARR

protected static final int DOUBLE_ARR
See Also:
Constant Field Values

CHAR_ARR

protected static final int CHAR_ARR
See Also:
Constant Field Values

FLOAT_OBJ_ARR

protected static final int FLOAT_OBJ_ARR
See Also:
Constant Field Values

STRING_OBJ_ARR

protected static final int STRING_OBJ_ARR
See Also:
Constant Field Values

DATE_OBJ_ARR

protected static final int DATE_OBJ_ARR
See Also:
Constant Field Values

URL_OBJ_ARR

protected static final int URL_OBJ_ARR
See Also:
Constant Field Values

OBJECT_ARR

protected static final int OBJECT_ARR
See Also:
Constant Field Values

BYTE_TYPE

protected java.lang.String BYTE_TYPE

SHORT_TYPE

protected java.lang.String SHORT_TYPE

INT_TYPE

protected java.lang.String INT_TYPE

LONG_TYPE

protected java.lang.String LONG_TYPE

FLOAT_TYPE

protected java.lang.String FLOAT_TYPE

DOUBLE_TYPE

protected java.lang.String DOUBLE_TYPE

CHAR_TYPE

protected java.lang.String CHAR_TYPE

STRING_TYPE

protected java.lang.String STRING_TYPE

DATE_TYPE

protected java.lang.String DATE_TYPE

SQL_SHOW_TABLES

protected java.lang.String SQL_SHOW_TABLES

SQL_CREATE_OBJECTS_TABLE

protected java.lang.String SQL_CREATE_OBJECTS_TABLE

SQL_CREATE_CLASSES_TABLE

protected java.lang.String SQL_CREATE_CLASSES_TABLE

SQL_CREATE_PACKAGES_TABLE

protected java.lang.String SQL_CREATE_PACKAGES_TABLE

SQL_COUNT_OBJECTS

protected java.lang.String SQL_COUNT_OBJECTS

SQL_COUNT_CLASSES

protected java.lang.String SQL_COUNT_CLASSES

SQL_COUNT_PACKAGES

protected java.lang.String SQL_COUNT_PACKAGES

SQL_GET_CLASSES

protected java.lang.String SQL_GET_CLASSES

SQL_CHECK_CLASS

protected java.lang.String SQL_CHECK_CLASS

SQL_CHECK_PACKAGE

protected java.lang.String SQL_CHECK_PACKAGE

SQL_INSERT_CLASS

protected java.lang.String SQL_INSERT_CLASS

SQL_INSERT_PACKAGE

protected java.lang.String SQL_INSERT_PACKAGE

SQL_INSERT_OBJECT

protected java.lang.String SQL_INSERT_OBJECT

SQL_DELETE_OBJECT

protected java.lang.String SQL_DELETE_OBJECT

SQL_DEL_OBJECT

protected java.lang.String SQL_DEL_OBJECT

SQL_GET_OBJECT_1

protected java.lang.String SQL_GET_OBJECT_1

SQL_GET_OBJECT_2

protected java.lang.String SQL_GET_OBJECT_2

SQL_GET_OBJECT_3

protected java.lang.String SQL_GET_OBJECT_3

SQL_GET_OBJECT_4

protected java.lang.String SQL_GET_OBJECT_4

SQL_CREATE_OBJ_TABLE_1

protected java.lang.String SQL_CREATE_OBJ_TABLE_1

SQL_CREATE_OBJ_TABLE_2

protected java.lang.String SQL_CREATE_OBJ_TABLE_2

SQL_INSERT_PRIM_1

protected java.lang.String SQL_INSERT_PRIM_1

SQL_INSERT_PRIM_2

protected java.lang.String SQL_INSERT_PRIM_2

SQL_CREATE_PRIM_TABLE_1

protected java.lang.String SQL_CREATE_PRIM_TABLE_1

SQL_CREATE_PRIM_TABLE_2

protected java.lang.String SQL_CREATE_PRIM_TABLE_2

SQL_CREATE_PRIM_TABLE_3

protected java.lang.String SQL_CREATE_PRIM_TABLE_3

SQL_GET_ARR_1

protected java.lang.String SQL_GET_ARR_1

SQL_GET_ARR_2

protected java.lang.String SQL_GET_ARR_2

SQL_GET_ARR_3

protected java.lang.String SQL_GET_ARR_3

SQL_GET_ARR_4

protected java.lang.String SQL_GET_ARR_4

SQL_GET_PRIM_ARR_1

protected java.lang.String SQL_GET_PRIM_ARR_1

SQL_GET_PRIM_ARR_2

protected java.lang.String SQL_GET_PRIM_ARR_2

SQL_GET_PRIM_ARR_3

protected java.lang.String SQL_GET_PRIM_ARR_3

SQL_GET_OBJ_ARR_1

protected java.lang.String SQL_GET_OBJ_ARR_1

SQL_GET_OBJ_ARR_2

protected java.lang.String SQL_GET_OBJ_ARR_2

SQL_GET_OBJ_ARR_3

protected java.lang.String SQL_GET_OBJ_ARR_3

SQL_GET_RANGE_1

protected java.lang.String SQL_GET_RANGE_1

SQL_GET_RANGE_2

protected java.lang.String SQL_GET_RANGE_2

SQL_GET_RANGE_3

protected java.lang.String SQL_GET_RANGE_3

SQL_GET_ALL

protected java.lang.String SQL_GET_ALL

stmtCheckClass

java.sql.PreparedStatement stmtCheckClass

stmtCheckPackage

java.sql.PreparedStatement stmtCheckPackage

stmtInsertClass

java.sql.PreparedStatement stmtInsertClass

stmtInsertPackage

java.sql.PreparedStatement stmtInsertPackage

stmtInsertObject

java.sql.PreparedStatement stmtInsertObject

stmtDeleteObject

java.sql.PreparedStatement stmtDeleteObject

stmtDelObject

java.sql.PreparedStatement stmtDelObject

stmtGetObject

java.sql.PreparedStatement stmtGetObject

stmtInsertPrim

java.sql.PreparedStatement stmtInsertPrim

conn

java.sql.Connection conn

stmt

java.sql.Statement stmt

rs

java.sql.ResultSet rs

objID

static long objID

pkgID

static long pkgID

clsID

static long clsID

clsRepository

static java.util.HashMap clsRepository
in-memory repository that contains information about classes key: class name value: SQLClass object


logger

org.vrspace.util.Logger logger
Constructor Detail

SQLDB

public SQLDB()
Method Detail

loadDriver

protected abstract boolean loadDriver()
Override this in actual implementations. Called from connect( String )


create

public abstract java.lang.String create(java.lang.String name)
Description copied from class: org.vrspace.server.DB
create a new database if does not exist


connect

public void connect(java.lang.String name)
             throws java.lang.Exception
Connect to the database


put

public void put(java.lang.Object obj)
         throws java.lang.Exception
Stores obj to the database.


put

public void put(java.lang.Object[] obj)
         throws java.lang.Exception
Stores object array to the database.


insertObject

protected void insertObject(java.lang.Object obj,
                            long objectID,
                            SQLClass cls,
                            long cntID,
                            long arrID)
                     throws java.lang.Exception
Internal, called from put(Object obj) and put(Object[] obj)


putPrimitiveArray

protected void putPrimitiveArray(java.lang.Object obj,
                                 long objectID,
                                 long cntID)
                          throws java.lang.Exception
Internal


get

public java.lang.Object get(java.lang.Object obj)
                     throws java.lang.Exception
Retreives an object from the database


get

public java.lang.Object get(java.lang.String className,
                            long id)
                     throws java.lang.Exception
Retreives an object from the database


getObject

protected java.lang.Object getObject(java.lang.Object obj,
                                     long id,
                                     long cntID,
                                     long arrID)
                              throws java.lang.Exception
Retreives an object from the database, internal


getPrimitiveArray

protected java.lang.Object getPrimitiveArray(java.lang.String className,
                                             int type,
                                             long id,
                                             long cntID)
                                      throws java.lang.Exception
Internal


getObjectArray

protected java.lang.Object getObjectArray(java.lang.String className,
                                          long id,
                                          long cntID)
                                   throws java.lang.Exception
Internal


get

public java.lang.Object get(java.lang.String className,
                            java.lang.String field,
                            java.lang.Object value)
                     throws java.lang.Exception
Get first object of class className, whose field field have value value


getRange

public java.lang.Object[] getRange(java.lang.String className,
                                   java.lang.String field,
                                   java.lang.Object value)
                            throws java.lang.Exception
Get all objects of class className, whose field field have value value


getRangeDb_id

protected java.sql.ResultSet getRangeDb_id(java.lang.String className,
                                           java.lang.String field,
                                           java.lang.Object value)
unfinished, work only for primitive fields not objects Internal


getRange

public java.lang.Object[] getRange(java.lang.Object o1,
                                   java.lang.Object o2)
                            throws java.lang.Exception
Get all objects that are "between" object o1 and o2. Object o1 and o2 must be of same class, and must have implement method compareTo(obj) (interface Comparable), else null is returned.


getAll

public java.lang.Object[] getAll(java.lang.String className)
                          throws java.lang.Exception
Get all objects of className from db


update

public void update(org.vrspace.server.Request r)
Update field in object. Field and object are encapsulated inside request object.


delete

public void delete(java.lang.Object obj)
            throws java.lang.Exception
Delete object from database. This implementation works but is just temporary, needs complete rewrite


commit

public void commit()
Not implemented


disconnect

public void disconnect()
Close connection to the database


getObjectID

protected long getObjectID(long classID)
                    throws java.lang.Exception
returns object ID


query

protected java.sql.ResultSet query(java.lang.String sqlQuery)
Internal


update

protected int update(java.lang.String sqlQuery)
              throws java.sql.SQLException
Internal


replacePoints

private static java.lang.String replacePoints(java.lang.String s)
Internal


createPrimTable

protected void createPrimTable(java.lang.Class primitive)
                        throws java.sql.SQLException
Creates table to store primitives


mapJava2SQL

protected java.lang.String mapJava2SQL(java.lang.String type)
Internal


getSQLText

protected java.lang.String getSQLText(java.lang.String className,
                                      java.util.ArrayList fieldName,
                                      java.util.ArrayList fieldType)
Internal


mapTypes

protected java.lang.String mapTypes(int intType)
Internal


getPackageID

protected long getPackageID(java.lang.Package objPackage)
                     throws java.sql.SQLException
Retreives package ID from the repository


getClass

protected SQLClass getClass(java.lang.Class cls)
Internal, try to get class from repository return SQLClass if class exits in repository, else return null


analizeClass

protected SQLClass analizeClass(java.lang.Class cls)
Internal