From: <fg...@us...> - 2009-02-22 19:11:28
|
Revision: 1055 http://openutils.svn.sourceforge.net/openutils/?rev=1055&view=rev Author: fgrilli Date: 2009-02-22 19:11:23 +0000 (Sun, 22 Feb 2009) Log Message: ----------- usage doc Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/site/apt/index.apt trunk/openutils-mgnlcriteria/src/site/site.xml Added Paths: ----------- trunk/openutils-mgnlcriteria/src/site/changes/changes.xml Removed Paths: ------------- trunk/openutils-mgnlcriteria/src/site/apt/usage.apt Modified: trunk/openutils-mgnlcriteria/src/site/apt/index.apt =================================================================== --- trunk/openutils-mgnlcriteria/src/site/apt/index.apt 2009-02-21 17:53:48 UTC (rev 1054) +++ trunk/openutils-mgnlcriteria/src/site/apt/index.apt 2009-02-22 19:11:23 UTC (rev 1055) @@ -4,15 +4,75 @@ Fabrizio Giustina -------------------------- -openutils-mgnlcriteria +About openutils-mgnlcriteria -TODO write usage + <<<Criteria>>> is a simplified API for retrieving JCR Nodes by composing <<<Criterion>>> objects. This is a + very convenient approach for functionality like "search" screens where there is a variable number of conditions to be + placed upon the result set. + + The <<<JCRCriteriaFactory>>> is a factory for <<<Criteria>>>. <<<Criterion>>> instances are usually obtained + via the factory methods on <<<Restrictions>>>. eg. + + openutils-mgnlcriteria API is blatantly inspired by {{{http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html}} Hibernate's Criteria API}. + + <<openutils-mgnlcriteria requires JDK 1.5.x or superior>> - See {{{usage.html}usage}} for how to setup your DAOs and look at {{{apidocs/index.html}javadocs}} for - more details. +Usage + People already familiar with Hibernate's Criteria will find almost no difference (type names and methods have been kept the same on purpose, whenever possible): + you create a <<<Criteria>>> object with one of the static methods in <<<JCRCriteriaFactory>>> and start adding <<<Restrictions>>> and a final optional <<<Order>>>. + Then you call the <<<list()>>> method to get your <<<Collection>>> of results (basically instances of info.magnolia.cms.core.Content). As in Hibernate's Criteria, method chaining is supported. + Here is an example: + ++----------------------------------------------+ + Calendar begin = Calendar.getInstance(); + begin.set(2004, 0, 1); + Calendar end = Calendar.getInstance(); + end.set(2008, 11, 1); + + Collection pets = JCRCriteriaFactory.createMgnlCriteria("//dogs//*", MgnlContext.getQueryManager("website"), "mgnl:content").add( + Restrictions.contains("@name", "Nana")).add( + Restrictions.gt("@weight", new Float(10))).add( + Restrictions.between("@birthDate", begin, end).addOrder( + Order.desc("@jcr:score()")).list(); + + will be translated into the following xpath statement + + <<<//dogs//*[((jcr:contains(@name, 'Nana')) and (@weight>10.0) and (@birthDate >=xs:dateTime('2004-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2008-12-01T23:59:59.000+00:00')))] order by @jcr:score() descending>>> ++----------------------------------------------+ + Another handy feature is the possibility to specify a different type to be returned in the results Collection. eg. + ++----------------------------------------------+ + +Collection<Pet> pets = JCRCriteriaFactory.createMgnlCriteria("//dogs//*", MgnlContext.getQueryManager("website"), "mgnl:content", Pet.class).add( + Restrictions.contains("@name", "Nana")).add( + Restrictions.gt("@weight", new Float(10))).add( + Restrictions.between("@birthDate", begin, end).addOrder( + Order.desc("@jcr:score()")).list(); + + Internally, this will use <<<info.magnolia.content2bean.Content2BeanUtil.toBean()>>> to transform nodes into beans. + + So, for example, if you have a domain <<<Pet>>> class like this + + public class Pet +{ + private String name; + private Float weight; + private Calendar birthDate; + + [getters and setters here...] +} + +<<<Content>>> nodes returned by the above query will be automatically converted to and populate instances of the <<<Pet>>> type. + ++----------------------------------------------+ + + Finally, it is good to know that openutils-mgnlcriteria API catches all checked exceptions thrown by JCR and Magnolia and + wraps them into its own runtime <<<net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException>>>, leaving to + the API user the choice whether to catch it or not and, when needed, get to the original cause of error. + + Released versions Check it at {{{http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-mgnlcriteria}http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-mgnlcriteria}} - Deleted: trunk/openutils-mgnlcriteria/src/site/apt/usage.apt =================================================================== --- trunk/openutils-mgnlcriteria/src/site/apt/usage.apt 2009-02-21 17:53:48 UTC (rev 1054) +++ trunk/openutils-mgnlcriteria/src/site/apt/usage.apt 2009-02-22 19:11:23 UTC (rev 1055) @@ -1,67 +0,0 @@ - -------------------------- - O p e n u t i l s - -------------------------- - Fabrizio Giustina - -------------------------- - -Using annotations - - This is the preferred way of creating and configuring a new DAO using Spring 2.5 and annotations: - -+-----------------------------------------------+ - -public interface SampleDAO extends HibernateDAO<Sample, Integer> -{ - - @Repository(value = "sampleDAO") - public static class SampleDAOImpl extends HibernateDAOImpl<Sample, Integer> implements SampleDAO - { - - @Autowired - public SampleDAOImpl(SessionFactory factory) - { - setSessionFactory(factory); - setReferenceClass(Sample.class); - } - } -} - -+-----------------------------------------------+ - - Simple, isn't it? With those few lines you are: - - * Creating youd DAO interface, which allow you to manage <<<Sample>>> objects with a key of type <<<Integer>>> - - * Implementing your interface and setup your DAO - - * Registing you DAO in the Spring context using the <<<@Repository>>> annotation - - [] - - - -Using xml - - You need to write at least the DAO interface; the DAO implementation can be a subclass of HibernateDAOImpl or can - be created by Spring you you do not need to alter or add any method. - -+-----------------------------------------------+ - -public interface SampleDAO extends HibernateDAO<Sample, Integer> -{ - -} - <bean id="sampleDAO" class="org.springframework.aop.framework.ProxyFactoryBean"> - <property name="proxyInterfaces" value="com.myapp.SampleDAO"/> - <property name="target"> - <bean - class="it.openutils.dao.hibernate.HibernateDAOImpl"> - <property name="sessionFactory" ref="sessionFactory"/> - <property name="referenceClass" value="com.myapp.Sample"/> - </bean> - </property> - </bean> - -+-----------------------------------------------+ - - Added: trunk/openutils-mgnlcriteria/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnlcriteria/src/site/changes/changes.xml (rev 0) +++ trunk/openutils-mgnlcriteria/src/site/changes/changes.xml 2009-02-22 19:11:23 UTC (rev 1055) @@ -0,0 +1,15 @@ +<?xml version="1.0"?> +<!-- + "type" attribute can be: add, remove, update or fix. +--> +<document> + <properties> + <title>Changes</title> + <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> + </properties> + <body> + <release version="1.0" date="2009-02-28" description="first release"> + <action type="new" dev="fgiust">Initial public release.</action> + </release> + </body> +</document> \ No newline at end of file Property changes on: trunk/openutils-mgnlcriteria/src/site/changes/changes.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcriteria/src/site/site.xml =================================================================== --- trunk/openutils-mgnlcriteria/src/site/site.xml 2009-02-21 17:53:48 UTC (rev 1054) +++ trunk/openutils-mgnlcriteria/src/site/site.xml 2009-02-22 19:11:23 UTC (rev 1055) @@ -18,7 +18,7 @@ </head> <breadcrumbs> <item name="openutils" href="http://openutils.sourceforge.net/" /> - <item name="openutils-bshd5" href="http://openutils.sourceforge.net/openutils-mgnlcriteria" /> + <item name="openutils-mgnlcriteria" href="http://openutils.sourceforge.net/openutils-mgnlcriteria" /> </breadcrumbs> <menu name="openutils-mgnlcriteria"> <item name="Usage" href="index.html"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |