For a beginner these are big assumptions; none of these technologies are simple. However we simply cannot conver these topics in a brief guide. In addition, these subjects are covered well elsewhere.
For an absolute beginner in using these technologies, we recommend taking a look at the Faces-Goodies project - a perfect way of kickstarting you in the world of JSF, Spring and JPA and then return back to include Apache Orchestra.
The installation guide will show you how to setup a JPA entity manager for Orchestra (so you are working with the new JavaPersistence API standard). Later we hope to add chapters on integrating directly with Hibernate and Toplink.
Apache MyFaces Orchestra uses the powerful Spring framework to provide its conversation scope. Spring is a dependency injection framework - just like the JSF managed-bean facility which is configured in the faces-config files of traditional JSF applications. However Spring offers many very nice additional features, including some that are essential for Apache Orchestra. In particular it allows us to create a new scope-type.
Lets start with the Spring configuration for the conversation scope and the JPA entity-manager factory. This configuration file has to be placed into the WEB-INF directory of your web application using the name applicationContext.xml. This can be configured with a context-parameter in your web.xml; for more information, take a look at the Spring documentation.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" 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/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"> <!-- 1. initialization of all orchestra modules (required for core15 module) --> <import resource="classpath*:/META-INF/spring-orchestra-init.xml" /> <!-- 2. the conversation scopes --> <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer"> <property name="scopes"> <map> <entry key="conversation.manual"> <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope"> <property name="timeout" value="30" /> <property name="advices"> <list> <ref bean="persistentContextConversationInterceptor"/> </list> </property> </bean> </entry> <entry key="conversation.flash"> <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope"> <property name="timeout" value="30" /> <property name="advices"> <list> <ref bean="persistentContextConversationInterceptor"/> </list> </property> <property name="lifetime" value="flash"/> </bean> </entry> </map> </property> </bean> <!-- 3. the "entity manager" manager --> <bean id="persistentContextConversationInterceptor" class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor"> <property name="persistenceContextFactory" ref="persistentContextFactory"/> </bean> <!-- 4. conversation - persistence adapter --> <bean id="persistentContextFactory" class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <!-- 5. persistence --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <tx:annotation-driven /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="jpaProperties"> <props> <prop key="toplink.logging.level">FINE</prop> <prop key="toplink.jdbc.driver">org.apache.derby.jdbc.EmbeddedDriver</prop> <prop key="toplink.jdbc.url">jdbc:derby:myfacesOrchestraDB;create=true</prop> <prop key="toplink.jdbc.user">sa</prop> <prop key="toplink.jdbc.password">foobar</prop> <prop key="toplink.target-database">oracle.toplink.essentials.platform.database.DerbyPlatform</prop> <prop key="toplink.ddl-generation">create-tables</prop> </props> </property> <property name="persistenceUnitName" value="default"/> </bean> </beans>
Basically, all you need to do is copy this configuration segment and paste it into your Spring configuration file. Then you'll need to adapt the settings in the element entityManagerFactory - namely the jpaProperties. For a more detailed explanation, we have included the following instructions - it is not necessary to read through them.
spring-orchestra-init.xml
files are processed. Orchestra sets up some defaults in these init files that are
necessary for the correct functioning of Orchestra.
timeout
property accepts a numeric value which means a timespan
in minutes.
.
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <listener> <listener-class>org.apache.myfaces.orchestra.conversation.servlet.ConversationManagerSessionListener</listener-class> </listener>and
<filter> <filter-name>orchestraFilter</filter-name> <filter-class>org.apache.myfaces.orchestra.conversation.jsf.filter.OrchestraServletFilter</filter-class> </filter> <filter-mapping> <filter-name>orchestraFilter</filter-name> <url-pattern>*.faces</url-pattern> </filter-mapping>
Notice: Replace the *.faces
url-pattern by the one used by your application.
If your application has only JSF pages then no further configuration is required.
However if your application includes jsp, plain servlets, or anything else that does not pass through the FacesServlet then two additional filters must be defined:
<filter> <filter-name>frameworkAdapterFilter</filter-name> <filter-class>org.apache.myfaces.orchestra.frameworkAdapter.basic.BasicFrameworkAdapterFilter</filter-class> </filter> <filter> <filter-name>requestParameterFilter</filter-name> <filter-class>org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterServletFilter</filter-class> </filter> <filter-mapping> <filter-name>frameworkAdapterFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>requestParameterFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>