telosys
Blame | Last modification | View Log | RSS feed
package org.objectweb.telosys.dal;
import java.io.InputStream;
import org.objectweb.telosys.common.Telosys;
import org.objectweb.telosys.dal.dao.DAOProvider;
import org.objectweb.telosys.dal.dao.DAOProviderImpl;
import org.objectweb.telosys.dal.dao.DAORegistries;
import org.objectweb.telosys.dal.sql.ConnectionManager;
import org.objectweb.telosys.util.FileUtil;
/**
* Telosys Data Access Layer ( DAL ) manager <br>
*
* Static methods to initialize the D.A. Layer and retrieve the DAO provider
*
* @author Laurent GUERIN
*
*/
public final class TelosysDAL
{
//--- Fichier de configuration des bases de données
private static String $sDbConfigFileName = null ;
private static DAOProvider $daoProvider = null ; // v 1.0.0
//-----------------------------------------------------------------------------
// PUBLIC METHODS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/**
* Telosys DAL initialization with the Telosys properties <br>
* @return
*/
public static boolean init()
{
Telosys.info("TelosysDAL : INIT from telosys properties ..." );
boolean bRet = false;
InputStream is = Telosys.getDbConfigInputStream();
if ( is != null )
{
//--- Connection Manager initialization ( use the DbConfFile )
bRet = ConnectionManager.init(is);
if ( bRet )
{
//--- Keep the file name used for init
$sDbConfigFileName = Telosys.getDbConfigFileName() ;
Telosys.info ( "Connection Manager initialized (conf. file = " + $sDbConfigFileName + ")" ) ;
}
else
{
Telosys.error ( "Cannot initialize Connection Manager !" ) ;
}
}
else
{
Telosys.error("TelosysDAL.init() : Cannot get DBCONFIG InputStream ! ");
}
afterInit(); // v 1.0.0
return bRet ;
}
//-----------------------------------------------------------------------------
/**
* Telosys-DAL initialization from the given config file name<br>
* (method to init Telosys-DAL without full Telosys environment)
* @param sDbConfigFileName the full path for the configuration file ( 'dbconfig.xml' )
* @return
*/
public static boolean init(String sDbConfigFileName)
{
Telosys.info("TelosysDAL : INIT from file '" + sDbConfigFileName + "'" );
boolean bRet = false;
if (sDbConfigFileName == null)
{
Telosys.error("TelosysDAL.init(ConfigFile) : file parameter is null ");
}
else
{
String sFileName = sDbConfigFileName.trim() ;
//--- Build full path from relative path (if any)
//if ( Tool.fileExists( sFileName ) )
if ( FileUtil.exists( sFileName ) ) // v 1.1.0
{
//--- Connection Manager initialization ( use the DbConfFile )
bRet = ConnectionManager.init(sFileName);
if ( bRet )
{
//--- Keep the file name used for init
$sDbConfigFileName = sFileName ;
Telosys.info ( "Connection Manager initialized (config file = " + sFileName + ")" ) ;
}
else
{
Telosys.error ( "Cannot initialize Connection Manager !" ) ;
}
}
else
{
Telosys.error("TelosysDAL.init(ConfigFile) : file " + sFileName + " not found !");
}
}
afterInit(); // v 1.0.0
return bRet;
}
//-----------------------------------------------------------------------------
private static void afterInit() // v 1.0.0
{
Telosys.info("TelosysDAL : DAO registries initialization ..." );
//--- Init all the DAO registries ( one for each database )
DAORegistries reg = new DAORegistries();
Telosys.info("TelosysDAL : " + reg.getNumberOfRegistries() + " DAO registries initialized." );
//--- Init the DAO provider
$daoProvider = new DAOProviderImpl(reg);
Telosys.info("TelosysDAL : DAO provider ready." );
}
//-----------------------------------------------------------------------------
/**
* Returns the config file name used for initialization
* @return
*/
public static String getDbConfig()
{
return $sDbConfigFileName ;
}
//-----------------------------------------------------------------------------
/**
* Return the DAO provider
* @return
* @since 1.0.0
*/
public static DAOProvider getDAOProvider() // v 1.0.0
{
return $daoProvider;
}
}
Generated by GNU enscript 1.6.4.