Lithron.LDatabase
[ class tree: Lithron.LDatabase ] [ index: Lithron.LDatabase ] [ all elements ]

Source for file LDatabase.php

Documentation is available at LDatabase.php

  1. <?php
  2.  
  3.  
  4. /**
  5. * LDatabase class file.
  6. *
  7. * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  8. * @copyright 2005, diemeisterei GmbH. All rights reserved.
  9. * @author $Author: schmunk $
  10. * @version $Revision: 246 $ $Date: 2006-06-01 17:11:24 +0200 (Do, 01 Jun 2006) $
  11. * @package Lithron.LDatabase
  12. * @subpackage Modules
  13. */
  14.  
  15. /**
  16. * Provides database intialization and access.
  17. *
  18. * @package Lithron.LDatabase
  19. * @subpackage Modules
  20. */
  21. Prado :: using("Library.propel.*");
  22.  
  23. Prado :: using("Library.propel.runtime.classes.propel.util.*");
  24. Prado :: using("Library.propel.runtime.classes.propel.adapter.*");
  25. Prado :: using("Library.propel.runtime.classes.propel.*");
  26. Prado :: using("Library.propel.runtime.classes.*");
  27.  
  28. Prado :: using("Library.creole.classes.creole.common.*");
  29. Prado :: using("Library.creole.classes.creole.drivers.sqlite.*");
  30. Prado :: using("Library.creole.classes.creole.drivers.mysql.*");
  31. Prado :: using("Library.creole.classes.creole.*");
  32. Prado :: using("Library.creole.classes.*");
  33.  
  34. Prado :: using("Library.log.*");
  35. Prado :: using("Library.log.Log.*");
  36.  
  37. class LDatabase extends TModule
  38. {
  39. /**
  40. * Location of master config file
  41. */
  42. private $_masterConfigFile;
  43.  
  44. /**
  45. * Config handler
  46. */
  47. public $DatabaseConfig;
  48.  
  49. /**
  50. * Returns location of config file (within package dir)
  51. */
  52. public function getMasterConfigFile()
  53. {
  54. return $this->_masterConfigFile;
  55. }
  56.  
  57. /**
  58. * Sets location of config file (within package dir)
  59. */
  60. public function setMasterConfigFile($value)
  61. {
  62. $this->_masterConfigFile= $value;
  63. }
  64.  
  65. /**
  66. * Inits database configutation
  67. */
  68. public function init($config)
  69. {
  70. $this->DatabaseConfig= new LDatabaseConfiguration();
  71. $this->DatabaseConfig->init($config);
  72. Prado :: trace("LDatabase initialized ", 'Lithron.LDatabase');
  73. parent :: init($config);
  74. }
  75.  
  76. /**
  77. * Returns a propel or creole (which is faster) connection
  78. */
  79. public function getConnection($name, $layer= "creole")
  80. {
  81. static $connections;
  82. if (isset ($connections[$layer . ":" . $name]))
  83. {
  84. #Prado :: trace("Returning pooled connection ($name) with $layer ... ", 'Lithron.LDatabase');
  85. return $connections[$layer . ":" . $name];
  86. }
  87.  
  88. if (!is_array($this->DatabaseConfig->_config['propel']['datasources'][$name]))
  89. $this->DatabaseConfig->_config['propel']['datasources'][$name]= $this->DatabaseConfig->_config['propel']['datasources']["development"]; // TODO
  90.  
  91. switch ($layer)
  92. {
  93. case 'propel' :
  94. $conn= LPropel :: getConnection($name);
  95. break;
  96. default :
  97. $dsn= $this->DatabaseConfig->getDsn($name); // not implem. TODO
  98. $conn= LCreole :: getConnection($dsn, Creole :: PERSISTENT);
  99. break;
  100. }
  101. Prado :: trace("Returning connection ($name) with $layer ... ", 'Lithron.LDatabase');
  102. $connections[$layer . ":" . $name]= $conn;
  103. return $conn;
  104.  
  105. }
  106. }
  107. ?>

Documentation generated on Tue, 20 Jun 2006 05:15:08 +0200 by phpDocumentor 1.3.0RC4