org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup Java Examples
The following examples show how to use
org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.
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: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testMetaInfCase() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #2
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testExample3() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example3.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement3", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals(0, info[0].getProperties().keySet().size()); assertNull(info[0].getJtaDataSource()); assertNull(info[0].getNonJtaDataSource()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #3
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testExample2() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example2.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement2", info[0].getPersistenceUnitName()); assertEquals(1, info[0].getMappingFileNames().size()); assertEquals("mappings.xml", info[0].getMappingFileNames().get(0)); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #4
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testExample3() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example3.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement3", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals(0, info[0].getProperties().keySet().size()); assertNull(info[0].getJtaDataSource()); assertNull(info[0].getNonJtaDataSource()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #5
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testMetaInfCase() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #6
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testExample2() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example2.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement2", info[0].getPersistenceUnitName()); assertEquals(1, info[0].getMappingFileNames().size()); assertEquals("mappings.xml", info[0].getMappingFileNames().get(0)); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #7
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testExample5() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example5.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement5", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getMappingFileNames().size()); assertEquals("order1.xml", info[0].getMappingFileNames().get(0)); assertEquals("order2.xml", info[0].getMappingFileNames().get(1)); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals("com.acme.AcmePersistence", info[0].getPersistenceProviderClassName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #8
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testExample5() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example5.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement5", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getMappingFileNames().size()); assertEquals("order1.xml", info[0].getMappingFileNames().get(0)); assertEquals("order2.xml", info[0].getMappingFileNames().get(1)); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals("com.acme.AcmePersistence", info[0].getPersistenceProviderClassName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #9
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testExample5() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example5.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement5", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getMappingFileNames().size()); assertEquals("order1.xml", info[0].getMappingFileNames().get(0)); assertEquals("order2.xml", info[0].getMappingFileNames().get(1)); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals("com.acme.AcmePersistence", info[0].getPersistenceProviderClassName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #10
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testExample3() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example3.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement3", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals(0, info[0].getProperties().keySet().size()); assertNull(info[0].getJtaDataSource()); assertNull(info[0].getNonJtaDataSource()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #11
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testExample2() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example2.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement2", info[0].getPersistenceUnitName()); assertEquals(1, info[0].getMappingFileNames().size()); assertEquals("mappings.xml", info[0].getMappingFileNames().get(0)); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #12
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testMetaInfCase() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #13
Source File: NeoConfig.java From cloud-spring-boot-sample with Apache License 2.0 | 5 votes |
@Bean(destroyMethod="") public DataSource jndiDataSource() throws IllegalArgumentException, NamingException, SQLException { JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); DataSource ds = dataSourceLookup.getDataSource("java:comp/env/jdbc/DefaultDB"); DBInformation dbInfo = new DBInformation(ds.getConnection().getMetaData()); log.info(dbInfo.toString()); return ds; }
Example #14
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testExample1() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example1.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #15
Source File: SpringBootWebApplication.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private static DataSource getDataSource(DataSourceProperties dataSourceProperties) { if (!Strings.isNullOrEmpty(dataSourceProperties.getJndiName())) { // Use JNDI provided datasource, which is already configured with pooling JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); return dataSourceLookup.getDataSource(dataSourceProperties.getJndiName()); } else { return dataSourceProperties.initializeDataSourceBuilder().build(); } }
Example #16
Source File: DataSourceServiceImpl.java From multitenant with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public DataSource createDataSource(Organization organization) { return MultitenantUtils.doQuery(() -> { DataSource dataSouce = null; DataSourceInfo dataSourceInfo = dataSourceInfoService.get(organization); if (StringUtils.isEmpty(dataSourceInfo.getJndiName())) { String master = Constants.MASTER; if (EmbeddedDatabaseConnection.isEmbedded(dataSourceInfo.getDriverClassName())) { master = properties.determineDatabaseName(); } DataSourceBuilder<?> factory = this.properties.initializeDataSourceBuilder(); factory.url(dataSourceInfo.getUrl().replace(databaseNameService.getDatabaseName(master), databaseNameService.getDatabaseName(organization.getId()))) .username(dataSourceInfo.getUsername()) .password(dataSourceInfo.getPassword()); if (!StringUtils.isEmpty(dataSourceInfo.getDriverClassName())) { factory.driverClassName(dataSourceInfo.getDriverClassName()); } if (!StringUtils.isEmpty(dataSourceInfo.getType())) { try { factory.type((Class<? extends DataSource>) Class.forName(dataSourceInfo.getType())); } catch (ClassNotFoundException e) { throw new RuntimeException(e.getMessage()); } } publishEvent(organization, dataSourceInfo, factory); dataSouce = factory.build(); } else { JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); dataSouce = dataSourceLookup.getDataSource(dataSourceInfo.getJndiName()); } dataSourceMap.put(organization.getId(), dataSouce); this.applicationContext.publishEvent(new OrgDataSourceCreateEvent(dataSouce)); return dataSouce; }); }
Example #17
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testJpa2ExcludeUnlisted() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-exclude-2.0.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals("The number of persistence units is incorrect.", 4, info.length); PersistenceUnitInfo noExclude = info[0]; assertNotNull("noExclude should not be null.", noExclude); assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName()); assertFalse("Exclude unlisted still defaults to false in 2.0.", noExclude.excludeUnlistedClasses()); PersistenceUnitInfo emptyExclude = info[1]; assertNotNull("emptyExclude should not be null.", emptyExclude); assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName()); assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses()); PersistenceUnitInfo trueExclude = info[2]; assertNotNull("trueExclude should not be null.", trueExclude); assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName()); assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses()); PersistenceUnitInfo falseExclude = info[3]; assertNotNull("falseExclude should not be null.", falseExclude); assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName()); assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses()); }
Example #18
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testExample4() throws Exception { SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); DataSource ds = new DriverManagerDataSource(); builder.bind("java:comp/env/jdbc/MyDB", ds); PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example4.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement4", info[0].getPersistenceUnitName()); assertEquals(1, info[0].getMappingFileNames().size()); assertEquals("order-mappings.xml", info[0].getMappingFileNames().get(0)); assertEquals(3, info[0].getManagedClassNames().size()); assertEquals("com.acme.Order", info[0].getManagedClassNames().get(0)); assertEquals("com.acme.Customer", info[0].getManagedClassNames().get(1)); assertEquals("com.acme.Item", info[0].getManagedClassNames().get(2)); assertTrue("Exclude unlisted should be true when no value.", info[0].excludeUnlistedClasses()); assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info[0].getTransactionType()); assertEquals(0, info[0].getProperties().keySet().size()); builder.clear(); }
Example #19
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testExample6() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example6.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertEquals(1, info.length); assertEquals("pu", info[0].getPersistenceUnitName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #20
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility @Test public void testInvalidPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-invalid.xml"; try { reader.readPersistenceUnitInfos(resource); fail("expected invalid document exception"); } catch (RuntimeException expected) { } }
Example #21
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility @Test public void testNoSchemaPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-no-schema.xml"; try { reader.readPersistenceUnitInfos(resource); fail("expected invalid document exception"); } catch (RuntimeException expected) { } }
Example #22
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testPersistenceUnitRootUrl() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); URL url = reader.determinePersistenceUnitRootUrl(new ClassPathResource( "/org/springframework/orm/jpa/persistence-no-schema.xml")); assertNull(url); url = reader.determinePersistenceUnitRootUrl(new ClassPathResource("/org/springframework/orm/jpa/META-INF/persistence.xml")); assertTrue("the containing folder should have been returned", url.toString().endsWith("/org/springframework/orm/jpa")); }
Example #23
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testPersistenceUnitRootUrlWithJar() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); ClassPathResource archive = new ClassPathResource("/org/springframework/orm/jpa/jpa-archive.jar"); String newRoot = "jar:" + archive.getURL().toExternalForm() + "!/META-INF/persist.xml"; Resource insideArchive = new UrlResource(newRoot); // make sure the location actually exists assertTrue(insideArchive.exists()); URL url = reader.determinePersistenceUnitRootUrl(insideArchive); assertTrue("the archive location should have been returned", archive.getURL().sameFile(url)); }
Example #24
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testJpa1ExcludeUnlisted() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-exclude-1.0.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals("The number of persistence units is incorrect.", 4, info.length); PersistenceUnitInfo noExclude = info[0]; assertNotNull("noExclude should not be null.", noExclude); assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName()); assertFalse("Exclude unlisted should default false in 1.0.", noExclude.excludeUnlistedClasses()); PersistenceUnitInfo emptyExclude = info[1]; assertNotNull("emptyExclude should not be null.", emptyExclude); assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName()); assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses()); PersistenceUnitInfo trueExclude = info[2]; assertNotNull("trueExclude should not be null.", trueExclude); assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName()); assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses()); PersistenceUnitInfo falseExclude = info[3]; assertNotNull("falseExclude should not be null.", falseExclude); assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName()); assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses()); }
Example #25
Source File: DaoEnvSpringModuleConfig.java From herd with Apache License 2.0 | 5 votes |
/** * The data source for the application. * * @return the data source. */ @Bean public static DataSource herdDataSource() { // Access the environment using the application context holder since we're in a static method that doesn't have access to the environment in any // other way. Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment(); // Get the configuration property for the data source JNDI name. String dataSourceJndiName = ConfigurationHelper.getProperty(ConfigurationValue.HERD_DATA_SOURCE_JNDI_NAME, environment); // Return a new JNDI data source. return new JndiDataSourceLookup().getDataSource(dataSourceJndiName); }
Example #26
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testJpa2ExcludeUnlisted() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-exclude-2.0.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals("The number of persistence units is incorrect.", 4, info.length); PersistenceUnitInfo noExclude = info[0]; assertNotNull("noExclude should not be null.", noExclude); assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName()); assertFalse("Exclude unlisted still defaults to false in 2.0.", noExclude.excludeUnlistedClasses()); PersistenceUnitInfo emptyExclude = info[1]; assertNotNull("emptyExclude should not be null.", emptyExclude); assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName()); assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses()); PersistenceUnitInfo trueExclude = info[2]; assertNotNull("trueExclude should not be null.", trueExclude); assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName()); assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses()); PersistenceUnitInfo falseExclude = info[3]; assertNotNull("falseExclude should not be null.", falseExclude); assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName()); assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses()); }
Example #27
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testJpa1ExcludeUnlisted() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-exclude-1.0.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals("The number of persistence units is incorrect.", 4, info.length); PersistenceUnitInfo noExclude = info[0]; assertNotNull("noExclude should not be null.", noExclude); assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName()); assertFalse("Exclude unlisted should default false in 1.0.", noExclude.excludeUnlistedClasses()); PersistenceUnitInfo emptyExclude = info[1]; assertNotNull("emptyExclude should not be null.", emptyExclude); assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName()); assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses()); PersistenceUnitInfo trueExclude = info[2]; assertNotNull("trueExclude should not be null.", trueExclude); assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName()); assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses()); PersistenceUnitInfo falseExclude = info[3]; assertNotNull("falseExclude should not be null.", falseExclude); assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName()); assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses()); }
Example #28
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility @Test public void testNoSchemaPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-no-schema.xml"; try { reader.readPersistenceUnitInfos(resource); fail("expected invalid document exception"); } catch (RuntimeException expected) { } }
Example #29
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testExample1() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example1.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
Example #30
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility @Test public void testInvalidPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-invalid.xml"; try { reader.readPersistenceUnitInfos(resource); fail("expected invalid document exception"); } catch (RuntimeException expected) { } }