use of com.mysql.cj.log.Log in project JavaSegundasQuintas by ecteruel.
the class NativeSession method createConfigCacheIfNeeded.
private void createConfigCacheIfNeeded(Object syncMutex) {
synchronized (syncMutex) {
if (this.serverConfigCache != null) {
return;
}
try {
Class<?> factoryClass = Class.forName(getPropertySet().getStringProperty(PropertyKey.serverConfigCacheFactory).getStringValue());
@SuppressWarnings("unchecked") CacheAdapterFactory<String, Map<String, String>> cacheFactory = ((CacheAdapterFactory<String, Map<String, String>>) factoryClass.newInstance());
this.serverConfigCache = cacheFactory.getInstance(syncMutex, this.hostInfo.getDatabaseUrl(), Integer.MAX_VALUE, Integer.MAX_VALUE);
ExceptionInterceptor evictOnCommsError = new ExceptionInterceptor() {
public ExceptionInterceptor init(Properties config, Log log1) {
return this;
}
public void destroy() {
}
@SuppressWarnings("synthetic-access")
public Exception interceptException(Exception sqlEx) {
if (sqlEx instanceof SQLException && ((SQLException) sqlEx).getSQLState() != null && ((SQLException) sqlEx).getSQLState().startsWith("08")) {
NativeSession.this.serverConfigCache.invalidate(NativeSession.this.hostInfo.getDatabaseUrl());
}
return null;
}
};
if (this.exceptionInterceptor == null) {
this.exceptionInterceptor = evictOnCommsError;
} else {
((ExceptionInterceptorChain) this.exceptionInterceptor).addRingZero(evictOnCommsError);
}
} catch (ClassNotFoundException e) {
throw ExceptionFactory.createException(Messages.getString("Connection.CantFindCacheFactory", new Object[] { getPropertySet().getStringProperty(PropertyKey.parseInfoCacheFactory).getValue(), PropertyKey.parseInfoCacheFactory }), e, getExceptionInterceptor());
} catch (InstantiationException | IllegalAccessException | CJException e) {
throw ExceptionFactory.createException(Messages.getString("Connection.CantLoadCacheFactory", new Object[] { getPropertySet().getStringProperty(PropertyKey.parseInfoCacheFactory).getValue(), PropertyKey.parseInfoCacheFactory }), e, getExceptionInterceptor());
}
}
}
use of com.mysql.cj.log.Log in project aws-mysql-jdbc by awslabs.
the class NodeMonitoringConnectionPluginTest method generateNullArguments.
/**
* Generate different sets of method arguments where one argument is null to ensure
* {@link NodeMonitoringConnectionPlugin#NodeMonitoringConnectionPlugin(ICurrentConnectionProvider, PropertySet, IConnectionPlugin, Log)}
* can handle null arguments correctly.
*
* @return different sets of arguments.
*/
private static Stream<Arguments> generateNullArguments() {
final ConnectionProxy proxy = mock(ConnectionProxy.class);
final ICurrentConnectionProvider currentConnectionProvider = mock(ICurrentConnectionProvider.class);
final PropertySet set = new DefaultPropertySet();
final Log log = new NullLogger("NodeMonitoringConnectionPluginTest");
final IConnectionPlugin connectionPlugin = new DefaultConnectionPlugin(currentConnectionProvider, log);
return Stream.of(Arguments.of(null, set, connectionPlugin, log), Arguments.of(proxy, null, connectionPlugin, log), Arguments.of(proxy, set, null, log), Arguments.of(proxy, set, connectionPlugin, null));
}
use of com.mysql.cj.log.Log in project aws-mysql-jdbc by awslabs.
the class UtilsRegressionTest method testBug82115.
/**
* Tests fix for Bug#82115 - Some exceptions are intercepted twice or fail to set the init cause.
*
* @throws Exception
*/
@Test
public void testBug82115() throws Exception {
Exception ex = SQLError.createSQLException("ORIGINAL_EXCEPTION", "0", new Exception("ORIGINAL_CAUSE"), null);
assertEquals("ORIGINAL_EXCEPTION", ex.getMessage());
assertEquals("ORIGINAL_CAUSE", ex.getCause().getMessage());
ex = SQLError.createSQLException("ORIGINAL_EXCEPTION", "0", new Exception("ORIGINAL_CAUSE"), new ExceptionInterceptor() {
boolean alreadyIntercepted = false;
@Override
public ExceptionInterceptor init(Properties props, Log log) {
this.alreadyIntercepted = false;
return this;
}
public void destroy() {
}
@Override
public Exception interceptException(Exception sqlEx) {
assertFalse(this.alreadyIntercepted);
this.alreadyIntercepted = true;
assertEquals("ORIGINAL_EXCEPTION", sqlEx.getMessage());
assertEquals("ORIGINAL_CAUSE", sqlEx.getCause().getMessage());
SQLException newSqlEx = new SQLException("INTERCEPT_EXCEPTION");
return newSqlEx;
}
});
assertEquals("INTERCEPT_EXCEPTION", ex.getMessage());
assertNull(ex.getCause());
ex = SQLError.createSQLException("ORIGINAL_EXCEPTION", "0", new Exception("ORIGINAL_CAUSE"), new ExceptionInterceptor() {
boolean alreadyIntercepted = false;
@Override
public ExceptionInterceptor init(Properties props, Log log) {
this.alreadyIntercepted = false;
return this;
}
public void destroy() {
}
@Override
public Exception interceptException(Exception sqlEx) {
assertFalse(this.alreadyIntercepted);
this.alreadyIntercepted = true;
assertEquals("ORIGINAL_EXCEPTION", sqlEx.getMessage());
assertEquals("ORIGINAL_CAUSE", sqlEx.getCause().getMessage());
SQLException newSqlEx = new SQLException("INTERCEPT_EXCEPTION");
newSqlEx.initCause(new Exception("INTERCEPT_CAUSE"));
return newSqlEx;
}
});
assertEquals("INTERCEPT_EXCEPTION", ex.getMessage());
assertEquals("INTERCEPT_CAUSE", ex.getCause().getMessage());
}
use of com.mysql.cj.log.Log in project aws-mysql-jdbc by awslabs.
the class NativeSession method createConfigCacheIfNeeded.
private void createConfigCacheIfNeeded(Object syncMutex) {
synchronized (syncMutex) {
if (this.serverConfigCache != null) {
return;
}
try {
Class<?> factoryClass = Class.forName(getPropertySet().getStringProperty(PropertyKey.serverConfigCacheFactory).getStringValue());
@SuppressWarnings("unchecked") CacheAdapterFactory<String, Map<String, String>> cacheFactory = ((CacheAdapterFactory<String, Map<String, String>>) factoryClass.newInstance());
this.serverConfigCache = cacheFactory.getInstance(syncMutex, this.hostInfo.getDatabaseUrl(), Integer.MAX_VALUE, Integer.MAX_VALUE);
ExceptionInterceptor evictOnCommsError = new ExceptionInterceptor() {
public ExceptionInterceptor init(Properties config, Log log1) {
return this;
}
public void destroy() {
}
@SuppressWarnings("synthetic-access")
public Exception interceptException(Exception sqlEx) {
if (sqlEx instanceof SQLException && ((SQLException) sqlEx).getSQLState() != null && ((SQLException) sqlEx).getSQLState().startsWith("08")) {
NativeSession.this.serverConfigCache.invalidate(NativeSession.this.hostInfo.getDatabaseUrl());
}
return null;
}
};
if (this.exceptionInterceptor == null) {
this.exceptionInterceptor = evictOnCommsError;
} else {
((ExceptionInterceptorChain) this.exceptionInterceptor).addRingZero(evictOnCommsError);
}
} catch (ClassNotFoundException e) {
throw ExceptionFactory.createException(Messages.getString("Connection.CantFindCacheFactory", new Object[] { getPropertySet().getStringProperty(PropertyKey.parseInfoCacheFactory).getValue(), PropertyKey.parseInfoCacheFactory }), e, getExceptionInterceptor());
} catch (InstantiationException | IllegalAccessException | CJException e) {
throw ExceptionFactory.createException(Messages.getString("Connection.CantLoadCacheFactory", new Object[] { getPropertySet().getStringProperty(PropertyKey.parseInfoCacheFactory).getValue(), PropertyKey.parseInfoCacheFactory }), e, getExceptionInterceptor());
}
}
}
use of com.mysql.cj.log.Log in project JavaSegundasQuintas by ecteruel.
the class UtilsRegressionTest method testBug82115.
/**
* Tests fix for Bug#82115 - Some exceptions are intercepted twice or fail to set the init cause.
*
* @throws Exception
*/
@Test
public void testBug82115() throws Exception {
Exception ex = SQLError.createSQLException("ORIGINAL_EXCEPTION", "0", new Exception("ORIGINAL_CAUSE"), null);
assertEquals("ORIGINAL_EXCEPTION", ex.getMessage());
assertEquals("ORIGINAL_CAUSE", ex.getCause().getMessage());
ex = SQLError.createSQLException("ORIGINAL_EXCEPTION", "0", new Exception("ORIGINAL_CAUSE"), new ExceptionInterceptor() {
boolean alreadyIntercepted = false;
@Override
public ExceptionInterceptor init(Properties props, Log log) {
this.alreadyIntercepted = false;
return this;
}
public void destroy() {
}
@Override
public Exception interceptException(Exception sqlEx) {
assertFalse(this.alreadyIntercepted);
this.alreadyIntercepted = true;
assertEquals("ORIGINAL_EXCEPTION", sqlEx.getMessage());
assertEquals("ORIGINAL_CAUSE", sqlEx.getCause().getMessage());
SQLException newSqlEx = new SQLException("INTERCEPT_EXCEPTION");
return newSqlEx;
}
});
assertEquals("INTERCEPT_EXCEPTION", ex.getMessage());
assertNull(ex.getCause());
ex = SQLError.createSQLException("ORIGINAL_EXCEPTION", "0", new Exception("ORIGINAL_CAUSE"), new ExceptionInterceptor() {
boolean alreadyIntercepted = false;
@Override
public ExceptionInterceptor init(Properties props, Log log) {
this.alreadyIntercepted = false;
return this;
}
public void destroy() {
}
@Override
public Exception interceptException(Exception sqlEx) {
assertFalse(this.alreadyIntercepted);
this.alreadyIntercepted = true;
assertEquals("ORIGINAL_EXCEPTION", sqlEx.getMessage());
assertEquals("ORIGINAL_CAUSE", sqlEx.getCause().getMessage());
SQLException newSqlEx = new SQLException("INTERCEPT_EXCEPTION");
newSqlEx.initCause(new Exception("INTERCEPT_CAUSE"));
return newSqlEx;
}
});
assertEquals("INTERCEPT_EXCEPTION", ex.getMessage());
assertEquals("INTERCEPT_CAUSE", ex.getCause().getMessage());
}
Aggregations