use of cn.taketoday.core.io.EncodedResource in project today-infrastructure by TAKETODAY.
the class ResourceDatabasePopulator method populate.
/**
* {@inheritDoc}
*
* @see #execute(DataSource)
*/
@Override
public void populate(Connection connection) throws ScriptException {
Assert.notNull(connection, "'connection' must not be null");
for (Resource script : this.scripts) {
EncodedResource encodedScript = new EncodedResource(script, this.sqlScriptEncoding);
ScriptUtils.executeSqlScript(connection, encodedScript, this.continueOnError, this.ignoreFailedDrops, this.commentPrefixes, this.separator, this.blockCommentStartDelimiter, this.blockCommentEndDelimiter);
}
}
use of cn.taketoday.core.io.EncodedResource in project today-infrastructure by TAKETODAY.
the class XmlBeanDefinitionReader method loadBeanDefinitions.
/**
* Load bean definitions from the specified XML file.
*
* @param encodedResource the resource descriptor for the XML file,
* allowing to specify an encoding to use for parsing the file
* @return the number of bean definitions found
* @throws BeanDefinitionStoreException in case of loading or parsing errors
*/
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
Assert.notNull(encodedResource, "EncodedResource must not be null");
if (logger.isTraceEnabled()) {
logger.trace("Loading XML bean definitions from {}", encodedResource);
}
Set<EncodedResource> currentResources = this.resourcesCurrentlyBeingLoaded.get();
if (!currentResources.add(encodedResource)) {
throw new BeanDefinitionStoreException("Detected cyclic loading of " + encodedResource + " - check your import definitions!");
}
try (InputStream inputStream = encodedResource.getResource().getInputStream()) {
InputSource inputSource = new InputSource(inputStream);
if (encodedResource.getEncoding() != null) {
inputSource.setEncoding(encodedResource.getEncoding());
}
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
} catch (IOException ex) {
throw new BeanDefinitionStoreException("IOException parsing XML document from " + encodedResource.getResource(), ex);
} finally {
currentResources.remove(encodedResource);
if (currentResources.isEmpty()) {
this.resourcesCurrentlyBeingLoaded.remove();
}
}
}
use of cn.taketoday.core.io.EncodedResource in project today-infrastructure by TAKETODAY.
the class XmlBeanFactoryTests method refToSingleton.
@Test
void refToSingleton() {
StandardBeanFactory xbf = new StandardBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(new EncodedResource(REFTYPES_CONTEXT, "ISO-8859-1"));
TestBean jen = (TestBean) xbf.getBean("jenny");
TestBean dave = (TestBean) xbf.getBean("david");
TestBean jenks = (TestBean) xbf.getBean("jenks");
ITestBean davesJen = dave.getSpouse();
ITestBean jenksJen = jenks.getSpouse();
assertThat(davesJen == jenksJen).as("1 jen instance").isTrue();
assertThat(davesJen == jen).as("1 jen instance").isTrue();
}
use of cn.taketoday.core.io.EncodedResource in project today-framework by TAKETODAY.
the class ResourceDatabasePopulator method populate.
/**
* {@inheritDoc}
*
* @see #execute(DataSource)
*/
@Override
public void populate(Connection connection) throws ScriptException {
Assert.notNull(connection, "'connection' must not be null");
for (Resource script : this.scripts) {
EncodedResource encodedScript = new EncodedResource(script, this.sqlScriptEncoding);
ScriptUtils.executeSqlScript(connection, encodedScript, this.continueOnError, this.ignoreFailedDrops, this.commentPrefixes, this.separator, this.blockCommentStartDelimiter, this.blockCommentEndDelimiter);
}
}
use of cn.taketoday.core.io.EncodedResource in project today-framework by TAKETODAY.
the class XmlBeanFactoryTests method refToSingleton.
@Test
void refToSingleton() {
StandardBeanFactory xbf = new StandardBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(new EncodedResource(REFTYPES_CONTEXT, "ISO-8859-1"));
TestBean jen = (TestBean) xbf.getBean("jenny");
TestBean dave = (TestBean) xbf.getBean("david");
TestBean jenks = (TestBean) xbf.getBean("jenks");
ITestBean davesJen = dave.getSpouse();
ITestBean jenksJen = jenks.getSpouse();
assertThat(davesJen == jenksJen).as("1 jen instance").isTrue();
assertThat(davesJen == jen).as("1 jen instance").isTrue();
}
Aggregations