| Home >> All >> org >> fencedb >> [ base Javadoc ] |
Source code: org/fencedb/base/DBAccess.java
1 2 package org.fencedb.base; 3 4 import org.odmg.Implementation; 5 import org.odmg.Database; 6 import org.odmg.ODMGException; 7 import org.odmg.OQLQuery; 8 import org.odmg.Transaction; 9 import org.odmg.DList; 10 import org.odmg.QueryException; 11 12 import java.util.Vector; 13 import java.util.List; 14 15 import org.apache.ojb.odmg.OJB; 16 17 /** 18 * Description of the Class 19 * 20 * @author vico 21 * @created June 7, 2003 22 */ 23 public class DBAccess 24 { 25 26 private static DBAccess self = null; 27 28 private Implementation odmg; 29 private Database db; 30 31 32 /** 33 *Constructor for the DBAccess object 34 */ 35 public DBAccess() 36 { 37 if (self == null) { 38 // get odmg facade instance 39 odmg = OJB.getInstance(); 40 db = odmg.newDatabase(); 41 //open database 42 try { 43 db.open("default", Database.OPEN_READ_WRITE); 44 } 45 catch (ODMGException ex) { 46 ex.printStackTrace(); 47 } 48 self = this; 49 } 50 } 51 52 53 /** 54 * Gets the instance attribute of the DBAccess object 55 * 56 * @return The instance value 57 */ 58 public static DBAccess getInstance() 59 { 60 if (self != null) { 61 return self; 62 } 63 else { 64 return new DBAccess(); 65 } 66 } 67 68 69 /** 70 * Gets the odmg attribute of the DBAccess object 71 * 72 * @return The odmg value 73 */ 74 public Implementation getOdmg() 75 { 76 return odmg; 77 } 78 79 80 /** 81 * Description of the Method 82 * 83 * @param oqlQuery Description of the Parameter 84 * @param args Description of the Parameter 85 * @return Description of the Return Value 86 * @exception QueryException Description of the Exception 87 */ 88 public List runOQL(String oqlQuery, Vector args) 89 throws QueryException 90 { 91 92 Transaction tx = getInstance().getOdmg().newTransaction(); 93 tx.begin(); 94 OQLQuery query = getInstance().getOdmg().newOQLQuery(); 95 query.create(oqlQuery); 96 if (args != null) { 97 for (int i = 0, size = args.size(); i < size; i++) { 98 query.bind(args.elementAt(i)); 99 } 100 } 101 DList result = (DList)query.execute(); 102 tx.commit(); 103 return result; 104 } 105 106 107 /** 108 * Description of the Method 109 * 110 * @param oqlQuery Description of the Parameter 111 * @return Description of the Return Value 112 * @exception QueryException Description of the Exception 113 */ 114 public List runOQL(String oqlQuery) 115 throws QueryException 116 { 117 return runOQL(oqlQuery, null); 118 } 119 120 } 121