Permalink
Browse files

Added OSIV and fix to HibernateFilter.

Upgrade spring xmls to 2.5 schemas

git-svn-id: file:///a/svnrepos/hippo/code/trunk/HippoTest@487 b8d5060c-ad15-0410-9d10-96fc93d4f2a4
  • Loading branch information...
1 parent f262690 commit 1b89f63f5ddb083ab6a8fb1b47cab24d7f5f931d Jeff Dwyer committed Dec 14, 2007
View
174 src/main/java/com/aavu/server/util/gwt/HibernateFilter.java
@@ -11,95 +11,105 @@
import org.hibernate.collection.PersistentList;
import org.hibernate.collection.PersistentMap;
import org.hibernate.collection.PersistentSet;
-import org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.proxy.LazyInitializer;
public class HibernateFilter {
- private static final Logger log = Logger
- .getLogger(HibernateFilter.class);
+ private static final Logger log = Logger.getLogger(HibernateFilter.class);
- public static Object filter(Object instance) {
- if (instance == null) {
- return instance;
- }
- if (instance instanceof Date) {
- return new java.util.Date(((java.util.Date) instance)
- .getTime());
- }
+ public static Object filter(Object instance) {
+ if (instance == null) {
+ return instance;
+ }
+ if (instance instanceof Date) {
+ return new java.util.Date(((java.util.Date) instance).getTime());
+ }
- if (instance instanceof PersistentSet) {
- HashSet<Object> hashSet = new HashSet<Object>();
- PersistentSet persSet = (PersistentSet) instance;
- if (persSet.wasInitialized()) {
- hashSet.addAll(persSet);
- }
- return hashSet;
- }
- if (instance instanceof PersistentList) {
- ArrayList<Object> arrayList = new ArrayList<Object>();
- PersistentList persList = (PersistentList) instance;
- if (persList.wasInitialized()) {
- arrayList.addAll(persList);
- }
- return arrayList;
- }
- if (instance instanceof PersistentBag) {
- ArrayList<Object> arrayList = new ArrayList<Object>();
- PersistentBag persBag = (PersistentBag) instance;
- if (persBag.wasInitialized()) {
- arrayList.addAll(persBag);
- }
- return arrayList;
- }
- if (instance instanceof PersistentMap) {
- HashMap<Object, Object> hashMap = new HashMap<Object, Object>();
- PersistentMap persMap = (PersistentMap) instance;
- if (persMap.wasInitialized()) {
- hashMap.putAll(persMap);
- }
- return hashMap;
- }
- if (instance.getClass().getName().contains("CGLIB")) {
+ if (instance instanceof PersistentSet) {
+ HashSet<Object> hashSet = new HashSet<Object>();
+ PersistentSet persSet = (PersistentSet) instance;
+ if (persSet.wasInitialized()) {
+ hashSet.addAll(persSet);
+ }
+ return hashSet;
+ }
+ if (instance instanceof PersistentList) {
+ ArrayList<Object> arrayList = new ArrayList<Object>();
+ PersistentList persList = (PersistentList) instance;
+ if (persList.wasInitialized()) {
+ arrayList.addAll(persList);
+ }
+ return arrayList;
+ }
+ if (instance instanceof PersistentBag) {
+ ArrayList<Object> arrayList = new ArrayList<Object>();
+ PersistentBag persBag = (PersistentBag) instance;
+ if (persBag.wasInitialized()) {
+ arrayList.addAll(persBag);
+ }
+ return arrayList;
+ }
+ if (instance instanceof PersistentMap) {
+ HashMap<Object, Object> hashMap = new HashMap<Object, Object>();
+ PersistentMap persMap = (PersistentMap) instance;
+ if (persMap.wasInitialized()) {
+ hashMap.putAll(persMap);
+ }
+ return hashMap;
+ }
+ if (instance.getClass().getName().contains("CGLIB")) {
- if (Hibernate.isInitialized(instance)) {
+ if (Hibernate.isInitialized(instance)) {
- CGLIBLazyInitializer cg = (CGLIBLazyInitializer) instance;
- log.warn("On The Fly initialization: "
- + cg.getEntityName());
- return cg.getImplementation();
+ try {
+ HibernateProxy hp = (HibernateProxy) instance;
+ LazyInitializer li = hp.getHibernateLazyInitializer();
+ log.warn("On The Fly initialization: " + li.getEntityName());
+ return li.getImplementation();
- // Hibernate.initialize(instance);
- //
- //
- // log.warn("\nentity: " + cg.getEntityName()
- // + "\nidentifier" + cg.getIdentifier()
- // + "\nimplemenation " + cg.getImplementation());
- //
- // log.warn("On The Fly initialization: " + instance
- // + " now: " + instance.getClass().getName());
- //
- // if (instance instanceof ReallyCloneable) {
- // log.debug(instance.getClass().getName()
- // + " CGLIB Cloning " + instance);
- // return ((ReallyCloneable) instance).clone();
- // } else {
- // log
- // .warn("Initialized, but doesn't implement
- // ReallyCloneable"
- // + instance.getClass()
- // + " "
- // + instance.getClass().getName());
- // throw new CouldntFixCGLIBException(
- // instance.getClass()
- // + " must implement ReallyCloneable if we're to fix
- // it.");
- // }
- } else {
- log.debug("Uninitialized CGLIB");
- return null;
- }
- }
+ } catch (ClassCastException c) {
+ log.error("error casting to HibernateProxy " + instance);
+ return null;
+ }
- return instance;
- }
+
+
+ // CGLIBLazyInitializer cg = (CGLIBLazyInitializer) instance;
+ // return cg.getImplementation();
+
+ // Hibernate.initialize(instance);
+ //
+ //
+ // log.warn("\nentity: " + cg.getEntityName()
+ // + "\nidentifier" + cg.getIdentifier()
+ // + "\nimplemenation " + cg.getImplementation());
+ //
+ // log.warn("On The Fly initialization: " + instance
+ // + " now: " + instance.getClass().getName());
+ //
+ // if (instance instanceof ReallyCloneable) {
+ // log.debug(instance.getClass().getName()
+ // + " CGLIB Cloning " + instance);
+ // return ((ReallyCloneable) instance).clone();
+ // } else {
+ // log
+ // .warn("Initialized, but doesn't implement
+ // ReallyCloneable"
+ // + instance.getClass()
+ // + " "
+ // + instance.getClass().getName());
+ // throw new CouldntFixCGLIBException(
+ // instance.getClass()
+ // + " must implement ReallyCloneable if we're to fix
+ // it.");
+ // }
+ } else {
+ log.debug("Uninitialized CGLIB");
+ return null;
+ }
+ }
+
+ return instance;
+ }
}
View
4 src/main/webapp/WEB-INF/applicationContext-acegi-security.xml
@@ -3,8 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!--
- A simple "base bones" Acegi Security configuration.
-
View
24 src/main/webapp/WEB-INF/applicationContext-hibernate.xml
@@ -4,9 +4,9 @@
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClass}" />
@@ -17,7 +17,7 @@
</bean>
- <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
+ <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
@@ -90,33 +90,33 @@
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory" ref="mySessionFactory" />
+ <property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="selectDAO" class="com.aavu.server.dao.hibernate.SelectDAOHibernateImpl">
- <property name="sessionFactory" ref="mySessionFactory" />
+ <property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="browseDAO" class="com.aavu.server.dao.hibernate.BrowseDAOHibernateImpl">
- <property name="sessionFactory" ref="mySessionFactory" />
+ <property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="editDAO" class="com.aavu.server.dao.hibernate.EditDAOHibernateImpl">
- <property name="sessionFactory" ref="mySessionFactory" />
+ <property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="userDAO" class="com.aavu.server.dao.hibernate.UserDAOHibernateImpl">
- <property name="sessionFactory" ref="mySessionFactory" />
+ <property name="sessionFactory" ref="sessionFactory" />
<property name="initDAO" ref="initDAO"/>
<property name="init" value="false"/>
</bean>
<bean id="initDAO" class="com.aavu.server.dao.hibernate.InitDAOHibernateImpl">
- <property name="sessionFactory" ref="mySessionFactory" />
+ <property name="sessionFactory" ref="sessionFactory" />
<property name="userService" ref="userService"/>
<property name="editDAO" ref="editDAO" />
<property name="selectDAO" ref="selectDAO" />
</bean>
<bean id="mailingListDAO" class="com.aavu.server.dao.hibernate.MailingListDAOHibernateImpl">
- <property name="sessionFactory" ref="mySessionFactory"/>
+ <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- COMPASS START -->
@@ -164,7 +164,7 @@
<value>hibernateDevice</value>
</property>
<property name="sessionFactory">
- <ref local="mySessionFactory" />
+ <ref local="sessionFactory" />
</property>
</bean>
<bean id="compassGPS" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop" abstract="false"
View
6 src/main/webapp/WEB-INF/applicationContext.xml
@@ -2,9 +2,9 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- Turn on HostPrecedingPropertyPlaceholderConfigurer -->
<!-- http://jdwyah.blogspot.com/2006/12/updated-spring-configuration.html -->
View
6 src/main/webapp/WEB-INF/dispatcher-servlet.xml
@@ -2,9 +2,9 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- Turn on @Required -->
View
13 src/main/webapp/WEB-INF/web.xml
@@ -43,7 +43,18 @@
</filter-mapping>
-
+ <filter>
+ <filter-name>osivFilter</filter-name>
+ <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>osivFilter</filter-name>
+ <url-pattern>/site/*</url-pattern>
+ </filter-mapping>
+ <filter-mapping>
+ <filter-name>osivFilter</filter-name>
+ <url-pattern>/service/*</url-pattern>
+ </filter-mapping>
<filter>
<filter-name>sitemesh</filter-name>

0 comments on commit 1b89f63

Please sign in to comment.