Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titlePrzykład z wykorzystaniem filtrów
linenumberstrue
SubstitutionFinder sf = FinderFactory.getSubstitutionFinder();
 
//definiujemy filtry wyszukiwania
List<HibernateFilter> filters = new ArrayList<HibernateFilter>();
//Łączenie kryteriów za pomocą operatora logicznego OR
GroupHibernateFilter groupFilter = new GroupHibernateFilter();
groupFilter.setLogicOperator( LogicOperator.OR );
 
//Warunek - processDefId = "test"
SimpleHibernateFilter filter1 = new SimpleHibernateFilter( "processDefId", "test" );
groupFilter.addFilter( filter1 );
//Warunek - lStartDate (data rozpoczęcia) > obecna data
SimpleHibernateFilter filter2 = new SimpleHibernateFilter( "lStartDate", ( new Date() ).getTime() );
filter2.setOperator( FilterOperator.GT );
groupFilter.addFilter( filter2 );
 
filters.add( groupFilter );
 
//Sortowanie malejąco po id z bazy
Sorter sorter = new Sorter( "id", SortDirection.DESC );

int start = 0;
int limit = 10;
 
CountedResult<Substitution>Pagination substitutionspagination = sfPagination.findByFilterscreate( filters, sorter, start, limit );
 
CountedResult<Substitution> substitutions = sf.findByFilters( filters, pagination );

Zdefiniowane powyżej wyszukiwanie znajdzie zastępstwa, które zdefiniowane są dla procesu "test" lub ich data rozpoczęcia jest późniejsza niż aktualna data. Wyniki zostaną zawężone do 10 pozycji i posortowane malejąco po "id" z bazy danych.

...

Code Block
titlePrzykład z wykorzystaniem DetachedCriteria
linenumberstrue
SubstitutionFinder sf = FinderFactory.getSubstitutionFinder();

DetachedCriteria dc = DetachedCriteria.forClass( Substitution.class );

//Łączenie kryteriów za pomocą operatora logicznego OR
Disjunction or = Restrictions.disjunction();
or.add( Restrictions.eq( "processDefId", "test" ) );
or.add( Restrictions.gt( "lStartDate", ( new Date() ).getTime() ) );

dc.add( or );

int start = 0;
int limit = 10;

/*Można wybrac jeden z dwóch poniższych wariantów:*/
 
//Pobieranie listy zastępstw za pomocą metody findByCriteria (musimy dodać order do DetachedCriteria.
dc.addOrder( Order.desc( "id" ) );
List<Substitution> substitutions = sf.findByCriteria( dc, start, limit );

//LUB
 
//pobieranie zastępstw wraz z całkowitą liczbą za pomocą getCountedResult (musimy utworzyć obiekt Sorter do sortowania)
Sorter sorter = new Sorter( "id", SortDirection.DESC );
CountedResult<Substitution>Pagination substitutionspagination = sfPagination.getCountedResultcreate( dc, sorter, start, limit );
CountedResult<Substitution> substitutions = sf.getCountedResult( dc, pagination );