1 package org.apache.torque; 2 3 21 22 import org.apache.torque.adapter.DB; 23 import org.apache.torque.dsfactory.DataSourceFactory; 24 import org.apache.torque.map.DatabaseMap; 25 import org.apache.torque.oid.IDBroker; 26 import org.apache.torque.oid.IdGenerator; 27 28 32 public class Database 33 { 34 38 private String name; 39 40 43 private DB adapter; 44 45 48 private DatabaseMap databaseMap; 49 50 53 private DataSourceFactory dataSourceFactory; 54 55 60 Database(String aName) 61 { 62 this.name = aName; 63 } 64 65 70 public String getName() 71 { 72 return name; 73 } 74 75 80 public DB getAdapter() 81 { 82 return adapter; 83 } 84 85 91 public void setAdapter(DB anAdapter) 92 { 93 this.adapter = anAdapter; 94 } 95 96 100 public synchronized DatabaseMap getDatabaseMap() 101 { 102 if (databaseMap == null) 103 { 104 databaseMap = new DatabaseMap(name); 105 } 106 return databaseMap; 107 } 108 109 117 public DataSourceFactory getDataSourceFactory() 118 { 119 return dataSourceFactory; 120 } 121 122 130 public void setDataSourceFactory(DataSourceFactory aDataSourceFactory) 131 { 132 this.dataSourceFactory = aDataSourceFactory; 133 } 134 135 141 public IDBroker getIDBroker() 142 { 143 if (databaseMap == null) 144 { 145 return null; 146 } 147 return databaseMap.getIDBroker(); 148 } 149 150 159 public synchronized boolean startIDBroker() 160 { 161 DatabaseMap dbMap = getDatabaseMap(); 162 if (dbMap.getIDBroker() != null) 163 { 164 return false; 165 } 166 return dbMap.startIdBroker(); 167 } 168 169 175 public IdGenerator getIdGenerator(String type) 176 { 177 if (databaseMap == null) 178 { 179 return null; 180 } 181 return databaseMap.getIdGenerator(type); 182 } 183 184 190 public void addIdGenerator(String type, IdGenerator idGen) 191 { 192 getDatabaseMap().addIdGenerator(type, idGen); 193 } 194 195 200 public String getSchema() 201 { 202 DataSourceFactory dsf = getDataSourceFactory(); 203 if (dsf == null) 204 { 205 return null; 206 } 207 return dsf.getSchema(); 208 } 209 210 217 public void setSchema(String schema) 218 { 219 getDataSourceFactory().setSchema(schema); 220 } 221 } 222 | Popular Tags |