當前位置: 首頁>>代碼示例>>Java>>正文


Java MapDataSourceLookup類代碼示例

本文整理匯總了Java中org.springframework.jdbc.datasource.lookup.MapDataSourceLookup的典型用法代碼示例。如果您正苦於以下問題:Java MapDataSourceLookup類的具體用法?Java MapDataSourceLookup怎麽用?Java MapDataSourceLookup使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MapDataSourceLookup類屬於org.springframework.jdbc.datasource.lookup包,在下文中一共展示了MapDataSourceLookup類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testExampleComplex

import org.springframework.jdbc.datasource.lookup.MapDataSourceLookup; //導入依賴的package包/類
@Test
public void testExampleComplex() throws Exception {
	DataSource ds = new DriverManagerDataSource();

	String resource = "/org/springframework/orm/jpa/persistence-complex.xml";
	MapDataSourceLookup dataSourceLookup = new MapDataSourceLookup();
	Map<String, DataSource> dataSources = new HashMap<String, DataSource>();
	dataSources.put("jdbc/MyPartDB", ds);
	dataSources.put("jdbc/MyDB", ds);
	dataSourceLookup.setDataSources(dataSources);
	PersistenceUnitReader reader = new PersistenceUnitReader(
			new PathMatchingResourcePatternResolver(), dataSourceLookup);
	PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

	assertEquals(2, info.length);

	PersistenceUnitInfo pu1 = info[0];

	assertEquals("pu1", pu1.getPersistenceUnitName());

	assertEquals("com.acme.AcmePersistence", pu1.getPersistenceProviderClassName());

	assertEquals(1, pu1.getMappingFileNames().size());
	assertEquals("ormap2.xml", pu1.getMappingFileNames().get(0));

	assertEquals(1, pu1.getJarFileUrls().size());
	assertEquals(new ClassPathResource("order.jar").getURL(), pu1.getJarFileUrls().get(0));

	assertFalse(pu1.excludeUnlistedClasses());

	assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, pu1.getTransactionType());

	Properties props = pu1.getProperties();
	assertEquals(2, props.keySet().size());
	assertEquals("on", props.getProperty("com.acme.persistence.sql-logging"));
	assertEquals("bar", props.getProperty("foo"));

	assertNull(pu1.getNonJtaDataSource());

	assertSame(ds, pu1.getJtaDataSource());

	assertFalse("Exclude unlisted should default false in 1.0.", pu1.excludeUnlistedClasses());

	PersistenceUnitInfo pu2 = info[1];

	assertSame(PersistenceUnitTransactionType.JTA, pu2.getTransactionType());
	assertEquals("com.acme.AcmePersistence", pu2.getPersistenceProviderClassName());

	assertEquals(1, pu2.getMappingFileNames().size());
	assertEquals("order2.xml", pu2.getMappingFileNames().get(0));

	// the following assertions fail only during coverage runs
	// assertEquals(1, pu2.getJarFileUrls().size());
	// assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), pu2.getJarFileUrls().get(0));

	assertTrue(pu2.excludeUnlistedClasses());

	assertNull(pu2.getJtaDataSource());
	assertEquals(ds, pu2.getNonJtaDataSource());

	assertTrue("Exclude unlisted should be true when no value.", pu2.excludeUnlistedClasses());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:63,代碼來源:PersistenceXmlParsingTests.java

示例2: setDataSources

import org.springframework.jdbc.datasource.lookup.MapDataSourceLookup; //導入依賴的package包/類
/**
 * Specify the JDBC DataSources that the JPA persistence provider is supposed
 * to use for accessing the database, resolving data source names in
 * {@code persistence.xml} against Spring-managed DataSources.
 * <p>The specified Map needs to define data source names for specific DataSource
 * objects, matching the data source names used in {@code persistence.xml}.
 * If not specified, data source names will be resolved as JNDI names instead
 * (as defined by standard JPA).
 * @see org.springframework.jdbc.datasource.lookup.MapDataSourceLookup
 */
public void setDataSources(Map<String, DataSource> dataSources) {
	this.dataSourceLookup = new MapDataSourceLookup(dataSources);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:DefaultPersistenceUnitManager.java


注:本文中的org.springframework.jdbc.datasource.lookup.MapDataSourceLookup類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。