29 changed files with 86 additions and 760 deletions
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.hibernate3; |
||||
|
||||
import java.util.Properties; |
||||
|
||||
import org.hibernate.cache.Cache; |
||||
import org.hibernate.cache.CacheException; |
||||
import org.hibernate.cache.CacheProvider; |
||||
|
||||
/** |
||||
* Proxy for a Hibernate CacheProvider, delegating to a Spring-managed |
||||
* CacheProvider instance, determined by LocalSessionFactoryBean's |
||||
* "cacheProvider" property. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 2.5.1 |
||||
* @see LocalSessionFactoryBean#setCacheProvider |
||||
* @deprecated as of Spring 3.0, following Hibernate 3.3's deprecation |
||||
* of the CacheProvider SPI |
||||
*/ |
||||
@Deprecated |
||||
public class LocalCacheProviderProxy implements CacheProvider { |
||||
|
||||
private final CacheProvider cacheProvider; |
||||
|
||||
|
||||
public LocalCacheProviderProxy() { |
||||
CacheProvider cp = LocalSessionFactoryBean.getConfigTimeCacheProvider(); |
||||
// absolutely needs thread-bound CacheProvider to initialize
|
||||
if (cp == null) { |
||||
throw new IllegalStateException("No Hibernate CacheProvider found - " + |
||||
"'cacheProvider' property must be set on LocalSessionFactoryBean"); |
||||
} |
||||
this.cacheProvider = cp; |
||||
} |
||||
|
||||
|
||||
public Cache buildCache(String regionName, Properties properties) throws CacheException { |
||||
return this.cacheProvider.buildCache(regionName, properties); |
||||
} |
||||
|
||||
public long nextTimestamp() { |
||||
return this.cacheProvider.nextTimestamp(); |
||||
} |
||||
|
||||
public void start(Properties properties) throws CacheException { |
||||
this.cacheProvider.start(properties); |
||||
} |
||||
|
||||
public void stop() { |
||||
this.cacheProvider.stop(); |
||||
} |
||||
|
||||
public boolean isMinimalPutsEnabledByDefault() { |
||||
return this.cacheProvider.isMinimalPutsEnabledByDefault(); |
||||
} |
||||
|
||||
} |
||||
@ -1,114 +0,0 @@
@@ -1,114 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.vendor; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.SQLException; |
||||
import javax.persistence.EntityManager; |
||||
import javax.persistence.PersistenceException; |
||||
|
||||
import oracle.toplink.essentials.internal.sessions.AbstractSession; |
||||
import oracle.toplink.essentials.sessions.Session; |
||||
import oracle.toplink.essentials.sessions.UnitOfWork; |
||||
|
||||
import org.springframework.jdbc.datasource.ConnectionHandle; |
||||
import org.springframework.jdbc.datasource.SimpleConnectionHandle; |
||||
import org.springframework.orm.jpa.DefaultJpaDialect; |
||||
import org.springframework.transaction.TransactionDefinition; |
||||
import org.springframework.transaction.TransactionException; |
||||
|
||||
/** |
||||
* {@link org.springframework.orm.jpa.JpaDialect} implementation for |
||||
* Oracle TopLink Essentials. Developed and tested against TopLink Essentials v2. |
||||
* |
||||
* <p>By default, this class acquires a TopLink transaction to get the JDBC Connection |
||||
* early. This allows mixing JDBC and JPA/TopLink operations in the same transaction. |
||||
* In some cases, this eager acquisition of a transaction/connection may impact |
||||
* scalability. In that case, set the "lazyDatabaseTransaction" flag to true if you |
||||
* do not require mixing JDBC and JPA operations in the same transaction. Otherwise, |
||||
* use a {@link org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy} |
||||
* to ensure that the cost of connection acquisition is near zero until code actually |
||||
* needs a JDBC Connection. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
* @since 2.0 |
||||
* @see #setLazyDatabaseTransaction |
||||
* @see org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy |
||||
* @deprecated as of Spring 3.1, in favor of the EclipseLink project and |
||||
* Spring's corresponding {@link EclipseLinkJpaDialect} |
||||
*/ |
||||
@Deprecated |
||||
@SuppressWarnings("serial") |
||||
public class TopLinkJpaDialect extends DefaultJpaDialect { |
||||
|
||||
private boolean lazyDatabaseTransaction = false; |
||||
|
||||
|
||||
/** |
||||
* Set whether to lazily start a database transaction within a TopLink |
||||
* transaction. |
||||
* <p>By default, database transactions are started early. This allows |
||||
* for reusing the same JDBC Connection throughout an entire transaction, |
||||
* including read operations, and also for exposing TopLink transactions |
||||
* to JDBC access code (working on the same DataSource). |
||||
* <p>It is only recommended to switch this flag to "true" when no JDBC access |
||||
* code is involved in any of the transactions, and when it is acceptable to |
||||
* perform read operations outside of the transactional JDBC Connection. |
||||
* @see oracle.toplink.essentials.sessions.UnitOfWork#beginEarlyTransaction() |
||||
*/ |
||||
public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) { |
||||
this.lazyDatabaseTransaction = lazyDatabaseTransaction; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) |
||||
throws PersistenceException, SQLException, TransactionException { |
||||
|
||||
super.beginTransaction(entityManager, definition); |
||||
if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) { |
||||
// This is the magic bit. As with the existing Spring TopLink integration,
|
||||
// begin an early transaction to force TopLink to get a JDBC Connection
|
||||
// so that Spring can manage transactions with JDBC as well as TopLink.
|
||||
UnitOfWork uow = (UnitOfWork) getSession(entityManager); |
||||
uow.beginEarlyTransaction(); |
||||
} |
||||
// Could return the UOW, if there were any advantage in having it later.
|
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public ConnectionHandle getJdbcConnection(EntityManager em, boolean readOnly) |
||||
throws PersistenceException, SQLException { |
||||
|
||||
AbstractSession session = (AbstractSession) getSession(em); |
||||
// The connection was already acquired eagerly in beginTransaction,
|
||||
// unless lazyDatabaseTransaction was set to true.
|
||||
Connection con = session.getAccessor().getConnection(); |
||||
return (con != null ? new SimpleConnectionHandle(con) : null); |
||||
} |
||||
|
||||
/** |
||||
* Get a traditional TopLink Session from the given EntityManager. |
||||
*/ |
||||
protected Session getSession(EntityManager em) { |
||||
oracle.toplink.essentials.ejb.cmp3.EntityManager emi = (oracle.toplink.essentials.ejb.cmp3.EntityManager) em; |
||||
return emi.getActiveSession(); |
||||
} |
||||
|
||||
} |
||||
@ -1,120 +0,0 @@
@@ -1,120 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.vendor; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.logging.Level; |
||||
import javax.persistence.EntityManager; |
||||
import javax.persistence.spi.PersistenceProvider; |
||||
|
||||
import oracle.toplink.essentials.config.TargetDatabase; |
||||
import oracle.toplink.essentials.config.TopLinkProperties; |
||||
import oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider; |
||||
|
||||
import org.springframework.orm.jpa.JpaDialect; |
||||
|
||||
/** |
||||
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for |
||||
* Oracle TopLink Essentials. Developed and tested against TopLink Essentials v2. |
||||
* |
||||
* <p>Exposes TopLink's persistence provider and EntityManager extension interface, |
||||
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
* @since 2.0 |
||||
* @see oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider |
||||
* @see oracle.toplink.essentials.ejb.cmp3.EntityManager |
||||
* @deprecated as of Spring 3.1, in favor of the EclipseLink project and |
||||
* Spring's corresponding {@link EclipseLinkJpaVendorAdapter} |
||||
*/ |
||||
@Deprecated |
||||
public class TopLinkJpaVendorAdapter extends AbstractJpaVendorAdapter { |
||||
|
||||
private final PersistenceProvider persistenceProvider = new EntityManagerFactoryProvider(); |
||||
|
||||
private final JpaDialect jpaDialect = new TopLinkJpaDialect(); |
||||
|
||||
|
||||
public PersistenceProvider getPersistenceProvider() { |
||||
return this.persistenceProvider; |
||||
} |
||||
|
||||
@Override |
||||
public String getPersistenceProviderRootPackage() { |
||||
return "oracle.toplink.essentials"; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, Object> getJpaPropertyMap() { |
||||
Map<String, Object> jpaProperties = new HashMap<String, Object>(); |
||||
|
||||
if (getDatabasePlatform() != null) { |
||||
jpaProperties.put(TopLinkProperties.TARGET_DATABASE, getDatabasePlatform()); |
||||
} |
||||
else if (getDatabase() != null) { |
||||
String targetDatabase = determineTargetDatabaseName(getDatabase()); |
||||
if (targetDatabase != null) { |
||||
jpaProperties.put(TopLinkProperties.TARGET_DATABASE, targetDatabase); |
||||
} |
||||
} |
||||
|
||||
if (isGenerateDdl()) { |
||||
jpaProperties.put(EntityManagerFactoryProvider.DDL_GENERATION, |
||||
EntityManagerFactoryProvider.CREATE_ONLY); |
||||
jpaProperties.put(EntityManagerFactoryProvider.DDL_GENERATION_MODE, |
||||
EntityManagerFactoryProvider.DDL_DATABASE_GENERATION); |
||||
} |
||||
if (isShowSql()) { |
||||
jpaProperties.put(TopLinkProperties.LOGGING_LEVEL, Level.FINE.toString()); |
||||
} |
||||
|
||||
return jpaProperties; |
||||
} |
||||
|
||||
/** |
||||
* Determine the TopLink target database name for the given database. |
||||
* @param database the specified database |
||||
* @return the TopLink target database name, or {@code null} if none found |
||||
*/ |
||||
protected String determineTargetDatabaseName(Database database) { |
||||
switch (database) { |
||||
case DB2: return TargetDatabase.DB2; |
||||
case DERBY: return TargetDatabase.Derby; |
||||
case HSQL: return TargetDatabase.HSQL; |
||||
case INFORMIX: return TargetDatabase.Informix; |
||||
case MYSQL: return TargetDatabase.MySQL4; |
||||
case ORACLE: return TargetDatabase.Oracle; |
||||
case POSTGRESQL: return TargetDatabase.PostgreSQL; |
||||
case SQL_SERVER: return TargetDatabase.SQLServer; |
||||
case SYBASE: return TargetDatabase.Sybase; |
||||
default: return null; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public JpaDialect getJpaDialect() { |
||||
return this.jpaDialect; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends EntityManager> getEntityManagerInterface() { |
||||
return oracle.toplink.essentials.ejb.cmp3.EntityManager.class; |
||||
} |
||||
|
||||
} |
||||
@ -1,49 +0,0 @@
@@ -1,49 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.toplink; |
||||
|
||||
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; |
||||
import org.springframework.orm.jpa.EntityManagerFactoryInfo; |
||||
|
||||
/** |
||||
* TopLink-specific JPA tests. |
||||
* |
||||
* @author Costin Leau |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class TopLinkEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests { |
||||
|
||||
@Override |
||||
protected String[] getConfigLocations() { |
||||
return TOPLINK_CONFIG_LOCATIONS; |
||||
} |
||||
|
||||
|
||||
public void testCanCastNativeEntityManagerFactoryToTopLinkEntityManagerFactoryImpl() { |
||||
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; |
||||
assertTrue(emfi.getNativeEntityManagerFactory().getClass().getName().endsWith("EntityManagerFactoryImpl")); |
||||
} |
||||
|
||||
public void testCanCastSharedEntityManagerProxyToTopLinkEntityManager() { |
||||
assertTrue(sharedEntityManager instanceof oracle.toplink.essentials.ejb.cmp3.EntityManager); |
||||
oracle.toplink.essentials.ejb.cmp3.EntityManager toplinkEntityManager = |
||||
(oracle.toplink.essentials.ejb.cmp3.EntityManager) sharedEntityManager; |
||||
assertNotNull(toplinkEntityManager.getActiveSession()); |
||||
} |
||||
|
||||
} |
||||
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.toplink; |
||||
|
||||
import javax.persistence.EntityManager; |
||||
import javax.persistence.EntityManagerFactory; |
||||
|
||||
import org.junit.Ignore; |
||||
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; |
||||
|
||||
/** |
||||
* Toplink-specific JPA tests with multiple EntityManagerFactory instances. |
||||
* |
||||
* @author Costin Leau |
||||
* @author Chris Beams |
||||
*/ |
||||
@Ignore("This test causes gradle to hang. See SPR-10333.") |
||||
public class TopLinkMultiEntityManagerFactoryIntegrationTests extends |
||||
AbstractContainerEntityManagerFactoryIntegrationTests { |
||||
|
||||
private EntityManagerFactory entityManagerFactory2; |
||||
|
||||
|
||||
@SuppressWarnings("deprecation") |
||||
public TopLinkMultiEntityManagerFactoryIntegrationTests() { |
||||
setAutowireMode(AUTOWIRE_BY_NAME); |
||||
} |
||||
|
||||
public void setEntityManagerFactory2(EntityManagerFactory entityManagerFactory2) { |
||||
this.entityManagerFactory2 = entityManagerFactory2; |
||||
} |
||||
|
||||
@Override |
||||
protected String[] getConfigLocations() { |
||||
return new String[] { |
||||
"/org/springframework/orm/jpa/toplink/toplink-manager-multi.xml", |
||||
"/org/springframework/orm/jpa/memdb.xml" |
||||
}; |
||||
} |
||||
|
||||
|
||||
public void testEntityManagerFactory2() { |
||||
EntityManager em = this.entityManagerFactory2.createEntityManager(); |
||||
try { |
||||
em.createQuery("select tb from TestBean"); |
||||
fail("Should have thrown IllegalArgumentException"); |
||||
} |
||||
catch (IllegalArgumentException ex) { |
||||
// expected
|
||||
} |
||||
finally { |
||||
em.close(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,16 +0,0 @@
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> |
||||
|
||||
<beans> |
||||
|
||||
<import resource="classpath:/org/springframework/orm/jpa/multi-jpa-emf.xml"/> |
||||
|
||||
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"> |
||||
<property name="database" value="HSQL"/> |
||||
<property name="showSql" value="true"/> |
||||
<property name="generateDdl" value="true"/> |
||||
</bean> |
||||
|
||||
<bean id="jpaProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"/> |
||||
|
||||
</beans> |
||||
@ -1,18 +0,0 @@
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> |
||||
|
||||
<beans> |
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> |
||||
<property name="persistenceXmlLocation" value="org/springframework/orm/jpa/domain/persistence.xml"/> |
||||
<property name="dataSource" ref="dataSource"/> |
||||
<property name="jpaVendorAdapter"> |
||||
<bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"> |
||||
<property name="database" value="HSQL"/> |
||||
<property name="showSql" value="true"/> |
||||
<property name="generateDdl" value="true"/> |
||||
</bean> |
||||
</property> |
||||
</bean> |
||||
|
||||
</beans> |
||||
Loading…
Reference in new issue