@Override public void postInit(AppContext context) throws Throwable { DataSource defaultDataSource = dsm.tryGetDefaultDataSource(); Map<String,DataSource> datasources = dsm.getAllDataSources(); boolean foundPrimary = false; for(Entry<String,DataSource> entry : datasources.entrySet()){ boolean primary = false; if(null != defaultDataSource && entry.getValue() == defaultDataSource){ primary = true; foundPrimary = true; } initBeans(entry.getKey(), entry.getValue(), primary); } if(!foundPrimary && null != defaultDataSource){ initBeans(DataSourceManager.DEFAULT_DATASOURCE_NAME, defaultDataSource, true); } }
@Override public Transactions beginTransactionsWith(String[] dataSourceNames, TransactionDefinition td) { List<Transaction> transactions = new ArrayList<>(); for(String name : dataSourceNames) { transactions.add(providers.get(dsm.getDataSource(name)).beginTransaction(td)); } return new SimpleTransactions(transactions.toArray(new Transaction[transactions.size()])); }
@Override public <T> T doTransaction(TransactionCallbackWithResult<T> callback) { return doTransaction(dsm.getDefaultDataSource(), callback); }
@Override public void init() { dsm.getAllDataSources().entrySet().forEach((entry) -> loadProvider(entry.getKey(), entry.getValue())); }
@Override public void postAppInit(App app) throws Throwable { if(enabled) { if(!sc.config().isEnabled()) { sc.enable(true); } this.hasDataSources = dsm.hasDataSources(); if(hasDataSources) { String dataSourceName = Strings.firstNotEmpty(jdbcDataSourceName, DataSourceManager.DEFAULT_DATASOURCE_NAME); if(getTokenStore() instanceof JdbcStore) { ((JdbcStore) getTokenStore()).setDataSourceName(dataSourceName); } if(getCodeStore() instanceof JdbcStore) { ((JdbcStore)getCodeStore()).setDataSourceName(dataSourceName); } if(getClientStore() instanceof JdbcStore) { ((JdbcStore)getClientStore()).setDataSourceName(dataSourceName); } if(getSSOStore() instanceof JdbcStore) { ((JdbcStore) getSSOStore()).setDataSourceName(dataSourceName); } } if(isCleanupEnabled()) { schedulerManager .newFixedThreadPoolScheduler("auth-cleanup") .scheduleAtFixedRate(() -> cleanup(), getCleanupInterval() * 1000l); } } }
@Override public void destroyDataSource(DataSource ds) { if(null != ds) { try { dataSourceManager.destroyDataSource(ds); } catch (Exception e) { log.error("Error destroying data source, {}", e.getMessage(), e); } } }
@Override protected void doInit(BeanFactory beanFactory) throws Exception { defaultDataSourceName = beanFactory.tryGetBean(DataSourceManager.class).getDefaultDataSourceBeanName(); if(this.modelsConfigs != null){ this.modelsConfigs.getModelsConfigMap().forEach((k,v)->{ if(Strings.isEmpty(v.getDataSource())){ v.setDataSource(defaultDataSourceName); } }); } super.doInit(beanFactory); }
protected DataSource newDataSource(MetaDataSource meta) throws SQLException { DataSourceProps props = new DataSourceProps.Builder(toMap(meta)).build(); log.debug("DataSource url '{}', username: {}", props.getJdbcUrl(), props.getUsername()); return dataSourceManager.createDataSource(props); }
if(dataSourceManager.tryGetDataSource(datasourceName)!=null){ rType=RemoteType.db; }else{
this.hasDataSources = dsm.hasDataSources();
DataSource defaultDataSource = dataSourceManager.tryGetDefaultDataSource(); Map<String,DataSource> dataSources = dataSourceManager.getAllDataSources();
@Override public <T> T doTransaction(TransactionCallbackWithResult<T> callback, boolean requiresNew) { return doTransaction(dsm.getDefaultDataSource(), callback, requiresNew); }
/** * Returns the cached {@link Db} instance for the {@link DataSource} managed by {@link DataSourceManager}. * * @see DataSourceManager#getDataSource(String) */ public static Db getInstance(String name) throws NestedSQLException,UnsupportedDbPlatformException,ObjectNotFoundException { DataSourceManager dsm = AppContext.factory().getBean(DataSourceManager.class); return getInstance(name, dsm.getDataSource(name)); }
@Override public <T> T executeWithResult(ConnectionCallbackWithResult<T> callback) { return executeWithResult(dsm.getDefaultDataSource(), callback); }
@Override public void doTransaction(TransactionCallback callback, boolean requiresNew) { doTransaction(dsm.getDefaultDataSource(), callback, requiresNew); }
@Override public void execute(ConnectionCallback callback) { execute(dsm.getDefaultDataSource(), callback); }
@Override public void doTransaction(TransactionCallback callback) { doTransaction(dsm.getDefaultDataSource(), callback); }
/** * Returns the cached {@link Db} instance for the default {@link DataSource} managed by {@link DataSourceManager}. * * @see DataSourceManager#getDefaultDataSource() */ public static Db getInstance() { DataSourceManager dsm = AppContext.factory().getBean(DataSourceManager.class); return getInstance(DataSourceManager.DEFAULT_DATASOURCE_NAME, dsm.getDefaultDataSource()); }