1 module deepmagic.orm.models.configuration.db_config; 2 3 import deepmagic.orm; 4 5 class DBConfig(DriverTemplate, DialectTemplate){ 6 @Transient{ 7 DriverTemplate driver = null; 8 EntityMetaData schema = null; 9 string uri = ""; 10 string[string] params = null; 11 Dialect dialect = null; 12 } 13 14 this(){ 15 this.driver = new DriverTemplate(); 16 this.dialect = new DialectTemplate(); 17 } 18 19 @Transient{ 20 @property{ 21 private Session _session = null; 22 ref Session session(){ 23 if(_session is null){ 24 this._session = this.factory.openSession(); 25 } 26 return this._session; 27 } 28 } 29 30 @property{ 31 private DataSource _datasource = null; 32 ref DataSource datasource(){ 33 if(this._datasource is null){ 34 this._datasource = new ConnectionPoolDataSourceImpl(this.driver, this.uri, this.params); 35 } 36 return this._datasource; 37 } 38 } 39 40 @property{ 41 private DBInfo _db = null; 42 ref DBInfo db(){ 43 if(this._db is null){ 44 this._db = this.factory.getDBMetaData(); 45 } 46 return this._db; 47 } 48 } 49 50 @property{ 51 private SessionFactory _factory = null; 52 ref SessionFactory factory(){ 53 if(this._factory is null){ 54 this._factory = new SessionFactoryImpl(this.schema, this.dialect, this.datasource); 55 } 56 return this._factory; 57 } 58 } 59 60 @property{ 61 private Connection _connection = null; 62 ref Connection connection(){ 63 if(this._connection is null){ 64 this._connection = this.datasource.getConnection(); 65 scope(exit) this._connection.close(); 66 } 67 return this._connection; 68 } 69 } 70 } 71 72 void update(){ 73 bool drop_tables = true; 74 bool create_tables = true; 75 this.db.updateDBSchema(this.connection, drop_tables, create_tables); 76 } 77 }