From: <tri...@us...> - 2008-08-11 22:46:40
|
Revision: 663 http://equanda.svn.sourceforge.net/equanda/?rev=663&view=rev Author: triathlon98 Date: 2008-08-11 22:46:35 +0000 (Mon, 11 Aug 2008) Log Message: ----------- EQ-210 make sure filters always use the SelectorsState which were valid at time of query creation Modified Paths: -------------- trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/SelectorsFiltersTest.java Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java 2008-08-07 23:18:48 UTC (rev 662) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java 2008-08-11 22:46:35 UTC (rev 663) @@ -68,17 +68,26 @@ protected EJB getOneObject( int index ) throws NamingException, EquandaPersistenceException { - SEL sel = getSelector(); - int saveFirstResult = query.getFirstResult(); - int saveMaxResult = query.getMaxResults(); - query.setFirstResult( index ); - query.setMaxResults( 1 ); - List<EJB> res = sel.equandaRunQueryEJB( query ); - query.setFirstResult( saveFirstResult ); - query.setMaxResults( saveMaxResult ); - sel.remove(); - if ( res.size() == 0 ) return null; - return res.get( 0 ); + SelectorsStateType keepSelectorsState = SelectorsState.getSelectorsState(); + try + { + SelectorsState.setSelectorsState( selectorsState ); + SEL sel = getSelector(); + int saveFirstResult = query.getFirstResult(); + int saveMaxResult = query.getMaxResults(); + query.setFirstResult( index ); + query.setMaxResults( 1 ); + List<EJB> res = sel.equandaRunQueryEJB( query ); + query.setFirstResult( saveFirstResult ); + query.setMaxResults( saveMaxResult ); + sel.remove(); + if ( res.size() == 0 ) return null; + return res.get( 0 ); + } + finally + { + SelectorsState.setSelectorsState( keepSelectorsState ); + } } protected EJB refreshObject( EJB obj ) @@ -100,17 +109,26 @@ protected EJB[] getMultipleObjects( int first, int size ) throws NamingException, EquandaPersistenceException { - SEL sel = getSelector(); - int saveFirstResult = query.getFirstResult(); - int saveMaxResult = query.getMaxResults(); - query.setFirstResult( first ); - query.setMaxResults( size ); - List<EJB> col = sel.equandaRunQueryEJB( query ); - EJB[] res = (EJB[]) new EquandaEJB[col.size()]; - for ( int i = 0; i < col.size() ; i++ ) res[ i ] = col.get( i ); - query.setFirstResult( saveFirstResult ); - query.setMaxResults( saveMaxResult ); - sel.remove(); - return res; + SelectorsStateType keepSelectorsState = SelectorsState.getSelectorsState(); + try + { + SelectorsState.setSelectorsState( selectorsState ); + SEL sel = getSelector(); + int saveFirstResult = query.getFirstResult(); + int saveMaxResult = query.getMaxResults(); + query.setFirstResult( first ); + query.setMaxResults( size ); + List<EJB> col = sel.equandaRunQueryEJB( query ); + EJB[] res = (EJB[]) new EquandaEJB[col.size()]; + for ( int i = 0; i < col.size() ; i++ ) res[ i ] = col.get( i ); + query.setFirstResult( saveFirstResult ); + query.setMaxResults( saveMaxResult ); + sel.remove(); + return res; + } + finally + { + SelectorsState.setSelectorsState( keepSelectorsState ); + } } } Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java 2008-08-07 23:18:48 UTC (rev 662) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java 2008-08-11 22:46:35 UTC (rev 663) @@ -24,9 +24,9 @@ package org.equanda.persistence; +import org.apache.log4j.Logger; import org.equanda.persistence.query.EquandaQuery; import org.equanda.util.MockObject; -import org.apache.log4j.Logger; import javax.naming.NamingException; import java.io.Serializable; @@ -153,6 +153,8 @@ private List<ID> data; // possible list with data for complex queries + protected SelectorsStateType selectorsState; + public LazyList( EquandaQuery query ) { if ( query == null ) throw new IllegalArgumentException(); @@ -161,6 +163,7 @@ this.hasSubselects = false; originalFirst = query.getFirstResult(); originalMax = query.getMaxResults(); + selectorsState = SelectorsState.getSelectorsState(); } public LazyList( List<EquandaQuery> queries, boolean addOperator, int equandaLimit ) @@ -171,6 +174,7 @@ this.hasSubselects = true; originalFirst = -1; originalMax = equandaLimit; + selectorsState = SelectorsState.getSelectorsState(); } public void setMockObject( MockObject m ) { mock = m; } @@ -391,8 +395,10 @@ { if ( size != -1 ) return size; EquandaSelector sel = null; + SelectorsStateType keepSelectorsState = SelectorsState.getSelectorsState(); try { + SelectorsState.setSelectorsState( selectorsState ); sel = getSelector(); if ( !hasSubselects ) { @@ -430,6 +436,7 @@ finally { if ( sel != null ) sel.remove(); + SelectorsState.setSelectorsState( keepSelectorsState ); } } Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java 2008-08-07 23:18:48 UTC (rev 662) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java 2008-08-11 22:46:35 UTC (rev 663) @@ -68,17 +68,26 @@ protected PROXY getOneObject( int index ) throws NamingException, EquandaPersistenceException { - SEL sel = getSelector(); - int saveFirstResult = query.getFirstResult(); - int saveMaxResult = query.getMaxResults(); - query.setFirstResult( index ); - query.setMaxResults( 1 ); - List<PROXY> res = sel.equandaRunQuery( query ); - query.setFirstResult( saveFirstResult ); - query.setMaxResults( saveMaxResult ); - sel.remove(); - if ( res.size() == 0 ) return null; - return res.get( 0 ); + SelectorsStateType keepSelectorsState = SelectorsState.getSelectorsState(); + try + { + SelectorsState.setSelectorsState( selectorsState ); + SEL sel = getSelector(); + int saveFirstResult = query.getFirstResult(); + int saveMaxResult = query.getMaxResults(); + query.setFirstResult( index ); + query.setMaxResults( 1 ); + List<PROXY> res = sel.equandaRunQuery( query ); + query.setFirstResult( saveFirstResult ); + query.setMaxResults( saveMaxResult ); + sel.remove(); + if ( res.size() == 0 ) return null; + return res.get( 0 ); + } + finally + { + SelectorsState.setSelectorsState( keepSelectorsState ); + } } protected PROXY refreshObject( PROXY obj ) @@ -100,18 +109,26 @@ protected PROXY[] getMultipleObjects( int first, int size ) throws NamingException, EquandaPersistenceException { - SEL sel = getSelector(); - int saveFirstResult = query.getFirstResult(); - int saveMaxResult = query.getMaxResults(); - query.setFirstResult( first ); - query.setMaxResults( size ); - List<PROXY> col = sel.equandaRunQuery( query ); - PROXY[] res = (PROXY[]) new EquandaProxy[col.size()]; - for ( int i = 0; i < col.size() ; i++ ) res[ i ] = col.get( i ); - query.setFirstResult( saveFirstResult ); - query.setMaxResults( saveMaxResult ); - sel.remove(); - return res; + SelectorsStateType keepSelectorsState = SelectorsState.getSelectorsState(); + try + { + SelectorsState.setSelectorsState( selectorsState ); + SEL sel = getSelector(); + int saveFirstResult = query.getFirstResult(); + int saveMaxResult = query.getMaxResults(); + query.setFirstResult( first ); + query.setMaxResults( size ); + List<PROXY> col = sel.equandaRunQuery( query ); + PROXY[] res = (PROXY[]) new EquandaProxy[col.size()]; + for ( int i = 0; i < col.size() ; i++ ) res[ i ] = col.get( i ); + query.setFirstResult( saveFirstResult ); + query.setMaxResults( saveMaxResult ); + sel.remove(); + return res; + } + finally + { + SelectorsState.setSelectorsState( keepSelectorsState ); + } } - } Modified: trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/SelectorsFiltersTest.java =================================================================== --- trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/SelectorsFiltersTest.java 2008-08-07 23:18:48 UTC (rev 662) +++ trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/SelectorsFiltersTest.java 2008-08-11 22:46:35 UTC (rev 663) @@ -27,8 +27,9 @@ import org.equanda.test.dm.client.EquandaGlobal; import org.equanda.test.dm.client.FootballPlayer; import org.equanda.test.dm.client.FootballPlayerSelectorEJB; + +import java.util.ArrayList; import java.util.List; -import java.util.ArrayList; /** * Tests for the selectors filters (setting/unsetting the variable should affect the order of the results) @@ -133,6 +134,58 @@ playerS.removeEntityBean(); } + public void testParameterFilterKeepState() + throws Exception + { + FootballPlayer playerG = new FootballPlayer(); + playerG.setGoalkeeper( true ); + playerG.setName( "G" ); + playerG.setTeam( "Anderlecht" ); + playerG.equandaUpdate(); + + FootballPlayer playerD = new FootballPlayer(); + playerD.setDefender( true ); + playerD.setName( "D" ); + playerD.setTeam( "Anderlecht" ); + playerD.equandaUpdate(); + + FootballPlayer playerM = new FootballPlayer(); + playerM.setMidfielder( true ); + playerM.setName( "M" ); + playerM.setTeam( "Standard" ); + playerM.equandaUpdate(); + + FootballPlayer playerS = new FootballPlayer(); + playerS.setMidfielder( true ); + playerS.setName( "S" ); + playerS.setTeam( "Standard" ); + playerS.equandaUpdate(); + + FootballPlayerSelectorEJB sel = EquandaGlobal.getFootballPlayerSelector(); + List<FootballPlayer> results = sel.selectAll(); + assertEquals( 4, results.size() ); + + SelectorsState.setFilter( "Team", "Standard" ); + results = sel.selectAll(); + SelectorsState.setFilter( "Team", null ); + assertEquals( 2, results.size() ); + assertEquals( "M", results.get( 0 ).getName() ); + assertEquals( "S", results.get( 1 ).getName() ); + + Thread.sleep( 1500 ); // assure data is requeried + SelectorsState.setFilter( "Team", null ); + assertEquals( 2, results.size() ); + assertEquals( "M", results.get( 0 ).getName() ); + assertEquals( "S", results.get( 1 ).getName() ); + + sel.remove(); + + playerG.removeEntityBean(); + playerD.removeEntityBean(); + playerM.removeEntityBean(); + playerS.removeEntityBean(); + } + public void testFromFilter() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |