|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.InitializingBean; |
|
|
|
import org.springframework.beans.factory.InitializingBean; |
|
|
|
|
|
|
|
import org.springframework.core.SpringProperties; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
@ -34,11 +35,19 @@ import org.springframework.util.Assert; |
|
|
|
* See {@link org.springframework.jdbc.core.JdbcTemplate}. |
|
|
|
* See {@link org.springframework.jdbc.core.JdbcTemplate}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
|
|
|
|
* @author Sebastien Deleuze |
|
|
|
* @since 28.11.2003 |
|
|
|
* @since 28.11.2003 |
|
|
|
* @see org.springframework.jdbc.core.JdbcTemplate |
|
|
|
* @see org.springframework.jdbc.core.JdbcTemplate |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public abstract class JdbcAccessor implements InitializingBean { |
|
|
|
public abstract class JdbcAccessor implements InitializingBean { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Boolean flag controlled by a {@code spring.xml.ignore} system property that instructs Spring to |
|
|
|
|
|
|
|
* ignore XML, i.e. to not initialize the XML-related infrastructure. |
|
|
|
|
|
|
|
* <p>The default is "false". |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore"); |
|
|
|
|
|
|
|
|
|
|
|
/** Logger available to subclasses. */ |
|
|
|
/** Logger available to subclasses. */ |
|
|
|
protected final Log logger = LogFactory.getLog(getClass()); |
|
|
|
protected final Log logger = LogFactory.getLog(getClass()); |
|
|
|
|
|
|
|
|
|
|
|
@ -87,8 +96,10 @@ public abstract class JdbcAccessor implements InitializingBean { |
|
|
|
* @see java.sql.DatabaseMetaData#getDatabaseProductName() |
|
|
|
* @see java.sql.DatabaseMetaData#getDatabaseProductName() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setDatabaseProductName(String dbName) { |
|
|
|
public void setDatabaseProductName(String dbName) { |
|
|
|
|
|
|
|
if (!shouldIgnoreXml) { |
|
|
|
this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dbName); |
|
|
|
this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dbName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the exception translator for this instance. |
|
|
|
* Set the exception translator for this instance. |
|
|
|
@ -118,7 +129,10 @@ public abstract class JdbcAccessor implements InitializingBean { |
|
|
|
exceptionTranslator = this.exceptionTranslator; |
|
|
|
exceptionTranslator = this.exceptionTranslator; |
|
|
|
if (exceptionTranslator == null) { |
|
|
|
if (exceptionTranslator == null) { |
|
|
|
DataSource dataSource = getDataSource(); |
|
|
|
DataSource dataSource = getDataSource(); |
|
|
|
if (dataSource != null) { |
|
|
|
if (shouldIgnoreXml) { |
|
|
|
|
|
|
|
exceptionTranslator = new SQLExceptionSubclassTranslator(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (dataSource != null) { |
|
|
|
exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource); |
|
|
|
exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
|