|
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jdbc; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource; |
|
|
|
import javax.sql.DataSource; |
|
|
|
|
|
|
|
|
|
|
|
@ -57,6 +58,11 @@ public class DataSourceProperties |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String name = "testdb"; |
|
|
|
private String name = "testdb"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generate a random datasource name. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean generateUniqueName; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Fully qualified name of the connection pool implementation to use. By default, it |
|
|
|
* Fully qualified name of the connection pool implementation to use. By default, it |
|
|
|
* is auto-detected from the classpath. |
|
|
|
* is auto-detected from the classpath. |
|
|
|
@ -148,6 +154,8 @@ public class DataSourceProperties |
|
|
|
|
|
|
|
|
|
|
|
private Xa xa = new Xa(); |
|
|
|
private Xa xa = new Xa(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String uniqueName; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
this.classLoader = classLoader; |
|
|
|
this.classLoader = classLoader; |
|
|
|
@ -183,6 +191,14 @@ public class DataSourceProperties |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isGenerateUniqueName() { |
|
|
|
|
|
|
|
return this.generateUniqueName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setGenerateUniqueName(boolean generateUniqueName) { |
|
|
|
|
|
|
|
this.generateUniqueName = generateUniqueName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Class<? extends DataSource> getType() { |
|
|
|
public Class<? extends DataSource> getType() { |
|
|
|
return this.type; |
|
|
|
return this.type; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -268,7 +284,7 @@ public class DataSourceProperties |
|
|
|
if (StringUtils.hasText(this.url)) { |
|
|
|
if (StringUtils.hasText(this.url)) { |
|
|
|
return this.url; |
|
|
|
return this.url; |
|
|
|
} |
|
|
|
} |
|
|
|
String url = this.embeddedDatabaseConnection.getUrl(this.name); |
|
|
|
String url = this.embeddedDatabaseConnection.getUrl(determineDatabaseName()); |
|
|
|
if (!StringUtils.hasText(url)) { |
|
|
|
if (!StringUtils.hasText(url)) { |
|
|
|
throw new DataSourceBeanCreationException(this.embeddedDatabaseConnection, |
|
|
|
throw new DataSourceBeanCreationException(this.embeddedDatabaseConnection, |
|
|
|
this.environment, "url"); |
|
|
|
this.environment, "url"); |
|
|
|
@ -276,6 +292,16 @@ public class DataSourceProperties |
|
|
|
return url; |
|
|
|
return url; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String determineDatabaseName() { |
|
|
|
|
|
|
|
if (this.generateUniqueName) { |
|
|
|
|
|
|
|
if (this.uniqueName == null) { |
|
|
|
|
|
|
|
this.uniqueName = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.uniqueName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the configured username or {@code null} if none was configured. |
|
|
|
* Return the configured username or {@code null} if none was configured. |
|
|
|
* @return the configured username |
|
|
|
* @return the configured username |
|
|
|
|