private DataSource getDataSource() throws Exception { if (getDataSourceName() == null || "".equals(getDataSourceName())) { return connectionFactory.getDataSource(getDriver(), getUrl(), getUser(), getPassword()); } else { return connectionFactory.getDataSource(dataSourceName); } }
/** * Completes initialization of this database journal. Base implementation checks whether the * required bean properties <code>driver</code> and <code>url</code> have been specified and * optionally deduces a valid database type. Should be overridden by subclasses that use a * different way to create a connection and therefore require other arguments. * * @see #getConnection() * @throws JournalException if initialization fails */ protected void init() throws JournalException { if (driver == null && dataSourceName == null) { String msg = "Driver not specified."; throw new JournalException(msg); } if (url == null && dataSourceName == null) { String msg = "Connection URL not specified."; throw new JournalException(msg); } if (dataSourceName != null) { try { String configuredDatabaseType = connectionFactory.getDataBaseType(dataSourceName); if (DatabaseJournal.class.getResourceAsStream(configuredDatabaseType + ".ddl") != null) { setDatabaseType(configuredDatabaseType); } } catch (RepositoryException e) { throw new JournalException("failed to get database type", e); } } if (databaseType == null) { try { databaseType = getDatabaseTypeFromURL(url); } catch (IllegalArgumentException e) { String msg = "Unable to derive database type from URL: " + e.getMessage(); throw new JournalException(msg); } } }