Package org.castor.jdo.conf

Examples of org.castor.jdo.conf.DatabaseChoice


     * @see org.castor.jdo.engine.AbstractConnectionFactory#initializeFactory()
     */
    public void initializeFactory() throws MappingException {
        Object dataSource;
       
        DatabaseChoice dbChoice = getDatabase().getDatabaseChoice();
        String name = null;

        try {
            name = dbChoice.getJndi().getName();
            Context initialContext = new InitialContext();
            dataSource = initialContext.lookup(name);
        } catch (NameNotFoundException e) {
            String msg = Messages.format("jdo.jndiNameNotFound", name);
            LOG.error(msg, e);
View Full Code Here


     */
    public void initializeFactory() throws MappingException {
        Enumeration params;
        Param       param;
       
        DatabaseChoice dbChoice = getDatabase().getDatabaseChoice();
        String driverName = dbChoice.getDriver().getClassName();
        if (driverName != null) {
            try {
                Class.forName(driverName).newInstance();
            } catch (InstantiationException e) {
                String msg = Messages.format(
                        "jdo.engine.classNotInstantiable", driverName);
                LOG.error(msg, e);
                throw new MappingException(msg, e);
            } catch (IllegalAccessException e) {
                String msg = Messages.format(
                        "jdo.engine.classNotAccessable", driverName, "constructor");
                LOG.error(msg, e);
                throw new MappingException(msg, e);
            } catch (ClassNotFoundException e) {
                String msg = "Can not load class " + driverName;
                LOG.error(msg, e);
                throw new MappingException(msg, e);
            }
        }
       
        try {
            Driver driver = dbChoice.getDriver();
            if (DriverManager.getDriver(driver.getUrl()) == null) {
                String msg = Messages.format("jdo.missingDriver", driver.getUrl());
                LOG.error(msg);
                throw new MappingException(msg);
            }
        } catch (SQLException ex) {
            throw new MappingException(ex);
        }
       
        _url = dbChoice.getDriver().getUrl();
       
        _props = new Properties();
        params = dbChoice.getDriver().enumerateParam();
        while (params.hasMoreElements()) {
            param = (Param) params.nextElement();
            _props.put(param.getName(), param.getValue());
        }

View Full Code Here

                                            final ClassLoader loader)
    throws MappingException {
        DataSource dataSource;
        Param[] parameters;

        DatabaseChoice dbChoice = database.getDatabaseChoice();
        String className = dbChoice.getDataSource().getClassName();
        ClassLoader classLoader = loader;
        if (classLoader == null) {
            classLoader = Thread.currentThread().getContextClassLoader();
        }
View Full Code Here

     */
    public void initializeFactory() throws MappingException {
        _dataSource = loadDataSource(getDatabase(), getMapping().getClassLoader());

        if (LOG.isDebugEnabled()) {
            DatabaseChoice dbc = getDatabase().getDatabaseChoice();
            LOG.debug("Using DataSource: " + dbc.getDataSource().getClassName());
        }
    }
View Full Code Here

     * @return Database configuration.
     * @deprecated Pass mapping URL's to createDatabase() methods instead.
     */
    public static Database createDatabase(final String name, final String engine,
            final DataSource ds, final Mapping[] mappings) {
        DatabaseChoice dbChoice = new DatabaseChoice();
        dbChoice.setDataSource(ds);

        Database dbConf = createDatabase(name, engine);
        dbConf.setDatabaseChoice(dbChoice);
        dbConf.setMapping(mappings);
        return dbConf;
View Full Code Here

     * @param mappings Array of mapping URL's.
     * @return Database configuration.
     */
    public static Database createDatabase(final String name, final String engine,
            final DataSource ds, final String[] mappings) {
        DatabaseChoice dbChoice = new DatabaseChoice();
        dbChoice.setDataSource(ds);

        Database dbConf = createDatabase(name, engine);
        dbConf.setDatabaseChoice(dbChoice);
        dbConf.setMapping(createMappings(mappings));
        return dbConf;
View Full Code Here

     * @return Database configuration.
     * @deprecated Pass mapping URL's to createDatabase() methods instead.
     */
    public static Database createDatabase(final String name, final String engine,
            final Driver driver, final Mapping[] mappings) {
        DatabaseChoice dbChoise = new DatabaseChoice();
        dbChoise.setDriver(driver);

        Database dbConf = createDatabase(name, engine);
        dbConf.setDatabaseChoice(dbChoise);
        dbConf.setMapping(mappings);
        return dbConf;
View Full Code Here

     * @param mappings Array of mapping URL's.
     * @return Database configuration.
     */
    public static Database createDatabase(final String name, final String engine,
            final Driver driver, final String[] mappings) {
        DatabaseChoice dbChoise = new DatabaseChoice();
        dbChoise.setDriver(driver);

        Database dbConf = createDatabase(name, engine);
        dbConf.setDatabaseChoice(dbChoise);
        dbConf.setMapping(createMappings(mappings));
        return dbConf;
View Full Code Here

     * @param mappings Array of mapping URL's.
     * @return Database configuration.
     */
    public static Database createDatabase(final String name, final String engine,
            final Jndi jndi, final String[] mappings) {
        DatabaseChoice dbChoise = new DatabaseChoice();
        dbChoise.setJndi(jndi);

        Database dbConf = createDatabase(name, engine);
        dbConf.setDatabaseChoice(dbChoise);
        dbConf.setMapping(createMappings(mappings));
        return dbConf;
View Full Code Here

    private static AbstractConnectionFactory createFactory(
            final JdoConf jdoConf, final int index, final Mapping mapping)
    throws MappingException {
        AbstractConnectionFactory factory;
       
        DatabaseChoice choice = jdoConf.getDatabase(index).getDatabaseChoice();
        if (choice == null) {
            String name = jdoConf.getDatabase(index).getName();
            String msg = Messages.format("jdo.missingDataSource", name);
            LOG.error(msg);
            throw new MappingException(msg);
        }
       
        if (choice.getDriver() != null) {
            // JDO configuration file specifies a driver, use the driver
            // properties to create a new registry object.
            factory = new DriverConnectionFactory(jdoConf, index, mapping);
        } else if (choice.getDataSource() != null) {
            // JDO configuration file specifies a DataSource object, use the
            // DataSource which was configured from the JDO configuration file
            // to create a new registry object.
            factory = new DataSourceConnectionFactory(jdoConf, index, mapping);
        } else if (choice.getJndi() != null) {
            // JDO configuration file specifies a DataSource lookup through JNDI,
            // locate the DataSource object frome the JNDI namespace and use it.
            factory = new JNDIConnectionFactory(jdoConf, index, mapping);
        } else {
            String name = jdoConf.getDatabase(index).getName();
View Full Code Here

TOP

Related Classes of org.castor.jdo.conf.DatabaseChoice

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.