org.apache.ibatis.datasource.DataSourceException Java Examples
The following examples show how to use
org.apache.ibatis.datasource.DataSourceException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeneralExceptionsTest.java From mybaties with Apache License 2.0 | 6 votes |
@Test public void shouldInstantiateAndThrowAllCustomExceptions() throws Exception { Class<?>[] exceptionTypes = { BindingException.class, CacheException.class, DataSourceException.class, ExecutorException.class, LogException.class, ParsingException.class, BuilderException.class, PluginException.class, ReflectionException.class, PersistenceException.class, SqlSessionException.class, TransactionException.class, TypeException.class, ScriptingException.class }; for (Class<?> exceptionType : exceptionTypes) { testExceptionConstructors(exceptionType); } }
Example #2
Source File: AbstractDataSourceFactory.java From nano-framework with Apache License 2.0 | 6 votes |
@Override public void setProperties(final Properties properties) { final Properties driverProperties = new Properties(); final MetaObject metaDataSource = SystemMetaObject.forObject(dataSource); for (final Object key : properties.keySet()) { final String propertyName = (String) key; if (metaDataSource.hasSetter(propertyName)) { final String value = (String) properties.get(propertyName); /** 对没有设置值的属性跳过设置 */ if (StringUtils.isNotEmpty(value) && value.startsWith("${") && value.endsWith("}")) { continue; } final Object convertedValue = convertValue(metaDataSource, propertyName, value); metaDataSource.setValue(propertyName, convertedValue); } else { throw new DataSourceException("Unknown DataSource property: " + propertyName); } } if (driverProperties.size() > 0) { metaDataSource.setValue("driverProperties", driverProperties); } }
Example #3
Source File: GeneralExceptionsTest.java From mybatis with Apache License 2.0 | 6 votes |
@Test public void shouldInstantiateAndThrowAllCustomExceptions() throws Exception { Class<?>[] exceptionTypes = { BindingException.class, CacheException.class, DataSourceException.class, ExecutorException.class, LogException.class, ParsingException.class, BuilderException.class, PluginException.class, ReflectionException.class, PersistenceException.class, SqlSessionException.class, TransactionException.class, TypeException.class, ScriptingException.class }; for (Class<?> exceptionType : exceptionTypes) { testExceptionConstructors(exceptionType); } }
Example #4
Source File: JndiDataSourceFactoryTest.java From mybaties with Apache License 2.0 | 5 votes |
private void createJndiDataSource() throws Exception { try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, TEST_INITIAL_CONTEXT_FACTORY); MockContext ctx = new MockContext(false); ctx.bind(TEST_DATA_SOURCE, expectedDataSource); InitialContext initCtx = new InitialContext(env); initCtx.bind(TEST_INITIAL_CONTEXT, ctx); } catch (NamingException e) { throw new DataSourceException("There was an error configuring JndiDataSourceTransactionPool. Cause: " + e, e); } }
Example #5
Source File: C3P0DataSourceFactory.java From nano-framework with Apache License 2.0 | 5 votes |
public C3P0DataSourceFactory() { try { Class<?> comboPooledDataSource = Class.forName("com.mchange.v2.c3p0.ComboPooledDataSource"); this.dataSource = (DataSource) comboPooledDataSource.newInstance(); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new DataSourceException(e.getMessage(), e); } }
Example #6
Source File: TomcatJdbcPoolDataSourceFactory.java From nano-framework with Apache License 2.0 | 5 votes |
public TomcatJdbcPoolDataSourceFactory() { try { tomcatJdbcDataSource = Class.forName("org.apache.tomcat.jdbc.pool.DataSource"); this.dataSource = (DataSource) tomcatJdbcDataSource.newInstance(); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new DataSourceException(e.getMessage(), e); } }
Example #7
Source File: DruidDataSourceFactory.java From nano-framework with Apache License 2.0 | 5 votes |
public DruidDataSourceFactory() { try { Class<?> druidDataSource = Class.forName("com.alibaba.druid.pool.DruidDataSource"); this.dataSource = (DataSource) druidDataSource.newInstance(); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new DataSourceException(e.getMessage(), e); } }
Example #8
Source File: JndiDataSourceFactoryTest.java From mybatis with Apache License 2.0 | 5 votes |
private void createJndiDataSource() throws Exception { try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, TEST_INITIAL_CONTEXT_FACTORY); MockContext ctx = new MockContext(false); ctx.bind(TEST_DATA_SOURCE, expectedDataSource); InitialContext initCtx = new InitialContext(env); initCtx.bind(TEST_INITIAL_CONTEXT, ctx); } catch (NamingException e) { throw new DataSourceException("There was an error configuring JndiDataSourceTransactionPool. Cause: " + e, e); } }
Example #9
Source File: TomcatJdbcPoolDataSourceFactory.java From nano-framework with Apache License 2.0 | 4 votes |
@Override public void setProperties(final Properties properties) { try { final Map<String, Object> map = Maps.newHashMap(); properties.forEach((key, value) -> { if (StringUtils.isNotEmpty((String) value) && ((String) value).startsWith("${") && ((String) value).endsWith("}")) { return; } map.put((String) key, value); }); final TomcatJdbcConfig config = TomcatJdbcConfig.mapToBean(map, TomcatJdbcConfig.class); if (tomcatJdbcDataSource != null) { tomcatJdbcDataSource.getMethod("setDriverClassName", String.class).invoke(dataSource, config.getDriver()); tomcatJdbcDataSource.getMethod("setUrl", String.class).invoke(dataSource, config.getUrl()); tomcatJdbcDataSource.getMethod("setUsername", String.class).invoke(dataSource, config.getUserName()); tomcatJdbcDataSource.getMethod("setPassword", String.class).invoke(dataSource, config.getPasswd()); if (config.getInitialSize() != null) { tomcatJdbcDataSource.getMethod("setInitialSize", int.class).invoke(dataSource, config.getInitialSize()); } if (config.getMinIdle() != null) { tomcatJdbcDataSource.getMethod("setMinIdle", int.class).invoke(dataSource, config.getMinIdle()); } if (config.getMaxWait() != null) { tomcatJdbcDataSource.getMethod("setMaxWait", int.class).invoke(dataSource, config.getMaxWait()); } if (config.getMaxActive() != null) { tomcatJdbcDataSource.getMethod("setMaxActive", int.class).invoke(dataSource, config.getMaxActive()); } if (config.getTestWhileIdle() != null) { tomcatJdbcDataSource.getMethod("setTestWhileIdle", boolean.class).invoke(dataSource, config.getTestWhileIdle()); } if (config.getTestOnBorrow() != null) { tomcatJdbcDataSource.getMethod("setTestOnBorrow", boolean.class).invoke(dataSource, config.getTestOnBorrow()); } if (config.getValidationInterval() != null) { tomcatJdbcDataSource.getMethod("setValidationInterval", long.class).invoke(dataSource, config.getValidationInterval()); } if (config.getTimeBetweenEvictionRunsMillis() != null) { tomcatJdbcDataSource.getMethod("setTimeBetweenEvictionRunsMillis", int.class).invoke(dataSource, config.getTimeBetweenEvictionRunsMillis()); } if (config.getLogAbandoned() != null) { tomcatJdbcDataSource.getMethod("setLogAbandoned", boolean.class).invoke(dataSource, config.getLogAbandoned()); } if (config.getRemoveAbandoned() != null) { tomcatJdbcDataSource.getMethod("setRemoveAbandoned", boolean.class).invoke(dataSource, config.getRemoveAbandoned()); } if (config.getRemoveAbandonedTimeout() != null) { tomcatJdbcDataSource.getMethod("setRemoveAbandonedTimeout", int.class).invoke(dataSource, config.getRemoveAbandonedTimeout()); } if (config.getMinEvictableIdleTimeMillis() != null) { tomcatJdbcDataSource.getMethod("setMinEvictableIdleTimeMillis", int.class).invoke(dataSource, config.getMinEvictableIdleTimeMillis()); } if (config.getJdbcInterceptors() != null) { tomcatJdbcDataSource.getMethod("setJdbcInterceptors", String.class).invoke(dataSource, config.getJdbcInterceptors()); } if (config.getJmxEnabled() != null) { tomcatJdbcDataSource.getMethod("setJmxEnabled", boolean.class).invoke(dataSource, config.getJmxEnabled()); } } else { throw new DataSourceException("Unknown class [ org.apache.tomcat.jdbc.pool.DataSource ]"); } } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new DataSourceException(e.getMessage(), e); } }