empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject empire-db git commit: EMPIREDB-235
Date Thu, 28 Jan 2016 10:37:42 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master e846070ef -> eef9350d5


EMPIREDB-235

Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/eef9350d
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/eef9350d
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/eef9350d

Branch: refs/heads/master
Commit: eef9350d5851ab8116acd8429be832932e01a79c
Parents: e846070
Author: Rainer Döbele <doebele@apache.org>
Authored: Thu Jan 28 11:37:35 2016 +0100
Committer: Rainer Döbele <doebele@apache.org>
Committed: Thu Jan 28 11:37:35 2016 +0100

----------------------------------------------------------------------
 .../jsf2/websample/web/SampleApplication.java   |  11 +-
 .../websample/web/SampleApplicationFactory.java |  33 --
 .../src/main/webapp/.gitignore                  |   1 +
 .../src/main/webapp/WEB-INF/faces-config.xml    |  23 +-
 .../main/webapp/pages/employeeDetailPage.xhtml  |   2 +-
 .../jsf2/app/AppRequestPhaseListener.java       |  87 ---
 .../empire/jsf2/app/AppStartupListener.java     |  73 ---
 .../empire/jsf2/app/FacesApplication.java       | 549 +++----------------
 .../jsf2/app/FacesApplicationFactory.java       | 119 ----
 .../empire/jsf2/app/FacesImplementation.java    |  13 -
 .../jsf2/app/FacesRequestPhaseListener.java     |  81 +++
 .../empire/jsf2/app/FacesStartupListener.java   |  95 ++++
 .../org/apache/empire/jsf2/app/FacesUtils.java  |   9 +-
 .../jsf2/app/impl/MojarraImplementation.java    |   4 +
 .../jsf2/app/impl/MyFacesImplementation.java    |   2 +
 .../empire/jsf2/utils/TagEncodingHelper.java    |   2 +-
 empire-db-spring/.gitignore                     |   1 +
 .../java/org/apache/empire/db/DBColumn.java     |   8 +-
 .../java/org/apache/empire/db/DBCommand.java    |  51 +-
 .../java/org/apache/empire/db/DBObject.java     |  19 +
 .../java/org/apache/empire/db/DBRecord.java     |  11 +
 .../java/org/apache/empire/db/DBRowSet.java     |   8 +-
 .../apache/empire/db/hsql/HSqlDDLGenerator.java |   2 -
 23 files changed, 375 insertions(+), 829 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java
index 02eb3af..bc13c50 100644
--- a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java
+++ b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java
@@ -26,6 +26,7 @@ import javax.servlet.ServletContext;
 import javax.sql.DataSource;
 
 import org.apache.empire.commons.StringUtils;
+import org.apache.empire.db.DBCmdType;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBDatabaseDriver;
@@ -49,8 +50,6 @@ public class SampleApplication extends FacesApplication {
 	private static final Logger log = LoggerFactory
 			.getLogger(SampleApplication.class);
 
-	private static SampleApplication sampleApplication = null;
-
 	protected static final String MANAGED_BEAN_NAME = "sampleApplication";
 	protected static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
 	// Non-Static
@@ -60,19 +59,13 @@ public class SampleApplication extends FacesApplication {
 	private Connection conn = null;
 
 	public static SampleApplication get() {
-		return SampleApplication.sampleApplication;
+		return (SampleApplication)FacesApplication.getInstance();
 	}
 
 	public SampleApplication() { 
 		
-		// Check for single instance
-		if (SampleApplication.sampleApplication != null) {
-			throw new RuntimeException(
-					"Attempt to create second instance of SampleApplication. SampleApplication is a singleton!");
-		}
 		// trace
 		SampleApplication.log.trace("SampleApplication created");
-		SampleApplication.sampleApplication = this;
 
 		// register custom control types
 		InputControlManager.registerControl(new FileInputControl());

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java
deleted file mode 100644
index 997fd09..0000000
--- a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.jsf2.websample.web;
-
-import org.apache.empire.jsf2.app.FacesApplicationFactory;
-
-/**
- * The Application factory for this application
- * @author doebele
- */
-public class SampleApplicationFactory extends FacesApplicationFactory
-{
-    public SampleApplicationFactory()
-    {
-    	super(SampleApplication.class);
-    }
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-examples/empire-db-example-jsf2/src/main/webapp/.gitignore
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/.gitignore b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/.gitignore
index 3d8e3f9..8db7f2e 100644
--- a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/.gitignore
+++ b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/.gitignore
@@ -1 +1,2 @@
 /.#webclasspath
+/hsqldb/

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml
index a826c72..c0a856f 100644
--- a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml
+++ b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml
@@ -13,16 +13,26 @@
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
 	version="2.0">
-	<factory>
-		<application-factory>org.apache.empire.jsf2.websample.web.SampleApplicationFactory</application-factory>
-	</factory>
+
 	<application>
+	    <!-- System event listener --> 
+	    <system-event-listener>
+			<system-event-listener-class>org.apache.empire.jsf2.app.FacesStartupListener</system-event-listener-class>
+			<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
+	    </system-event-listener>
+	    <!-- locales -->
 		<locale-config>
 			<default-locale>en</default-locale>
 			<supported-locale>en</supported-locale>
 			<supported-locale>de</supported-locale>
 		</locale-config>
 		<message-bundle>lang.messages</message-bundle>
+		<!-- messages -->
+		<message-bundle>lang.messages</message-bundle>
+		<resource-bundle>
+			<base-name>lang.messages</base-name>
+			<var>msg</var>
+		</resource-bundle>
 		<!-- EL resolver -->
 		<el-resolver>org.apache.empire.jsf2.app.DBELResolver</el-resolver>
 		<el-resolver>org.apache.empire.jsf2.pages.PagesELResolver</el-resolver>
@@ -32,19 +42,18 @@
 
 	<!-- Lifecycle -->
 	<lifecycle>
-		<phase-listener>org.apache.empire.jsf2.app.AppRequestPhaseListener</phase-listener>
+		<phase-listener>org.apache.empire.jsf2.app.FacesRequestPhaseListener</phase-listener>
 		<phase-listener>org.apache.empire.jsf2.pages.PagePhaseListener</phase-listener>
 		<phase-listener>org.apache.empire.jsf2.websample.web.AutheticationPhaseListener</phase-listener>
 	</lifecycle>
 
-	<!-- Application beans -->
+	<!-- Application bean (MUST be named 'facesApplication' for FacesStartupListener!) -->
 	<managed-bean>
-		<managed-bean-name>sampleApplication</managed-bean-name>
+		<managed-bean-name>facesApplication</managed-bean-name>
 		<managed-bean-class>org.apache.empire.jsf2.websample.web.SampleApplication</managed-bean-class>
 		<managed-bean-scope>application</managed-bean-scope>
 	</managed-bean>
 
-
 	<!-- Session beans -->
 	<managed-bean>
 		<managed-bean-name>sampleSession</managed-bean-name>

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeDetailPage.xhtml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeDetailPage.xhtml b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeDetailPage.xhtml
index 383fc6a..f6d163c 100644
--- a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeDetailPage.xhtml
+++ b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeDetailPage.xhtml
@@ -53,7 +53,7 @@
 				<!-- button bar -->
 				<h:panelGroup styleClass="buttonBar" layout="block">
 					<h:commandLink value="#{msg.employeeDetail_back}" action="#{page.doCancel}" immediate="true" />
-					<h:commandLink value="#{msg.employeeDetail_delete}" action="#{page.doDelete}" immediate="true" rendered="#{!page.employeeRecord.new}" />
+					<h:commandLink value="#{msg.employeeDetail_delete}" action="#{page.doDelete}" immediate="true" rendered="#{page.employeeRecord.exists}" />
 					<h:commandLink value="#{msg.employeeDetail_save}" action="#{page.doSave}" />
 				</h:panelGroup>
 			</h:form>

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppRequestPhaseListener.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppRequestPhaseListener.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppRequestPhaseListener.java
deleted file mode 100644
index c9017e7..0000000
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppRequestPhaseListener.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.jsf2.app;
-
-import javax.faces.application.Application;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-
-public class AppRequestPhaseListener implements PhaseListener
-{
-    private static final long   serialVersionUID = 1L;
-    final Logger                log              = LoggerFactory.getLogger(AppRequestPhaseListener.class);
-
-    /*
-    private static final String ACTION_PARAM     = "action";
-    private static final String REDIRECT_PARAM   = "redirect";
-    private static final String REDIRECT_RESULT  = "redirect:";
-    */
-
-    public AppRequestPhaseListener()
-    {
-        // foo
-    }
-
-    @Override
-    public PhaseId getPhaseId()
-    {
-        return PhaseId.ANY_PHASE;
-    }
-
-    @Override
-    public void beforePhase(PhaseEvent pe)
-    {
-        // Check for action param
-        /*
-        if (pe.getPhaseId().equals(PhaseId.RESTORE_VIEW))
-        {
-            beforeRestoreView(pe.getFacesContext());
-        }
-        */
-    }
-
-    /** 
-     * VERY VERY IMPORTANT FUNCTION: Release Connection on End of request! 
-     **/
-    @Override
-    public void afterPhase(PhaseEvent pe)
-    {
-        // Cleanup
-        FacesContext ctx = pe.getFacesContext();
-        if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE || ctx.getResponseComplete())
-        {
-            Application app = ctx.getApplication();
-            if (!(app instanceof FacesApplication))
-                throw new AbortProcessingException("Error: Application is not a JsfApplication instance. Please create a ApplicationFactory!");
-            // Cast and release 
-            FacesApplication jsfApp = (FacesApplication)app;
-            jsfApp.releaseAllConnections(ctx);
-        }
-            
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppStartupListener.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppStartupListener.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppStartupListener.java
deleted file mode 100644
index 271a7ac..0000000
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/AppStartupListener.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.jsf2.app;
-
-import javax.faces.application.Application;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.PostConstructApplicationEvent;
-import javax.faces.event.PreDestroyApplicationEvent;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
-import javax.servlet.ServletContext;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AppStartupListener implements SystemEventListener
-{
-    private static final Logger log = LoggerFactory.getLogger(AppStartupListener.class);
-
-    @Override
-    public boolean isListenerForSource(Object source)
-    {
-        return (source instanceof Application);
-    }
-
-    @Override
-    public void processEvent(SystemEvent event)
-        throws AbortProcessingException
-    {
-        log.info("ApplicationStartupListener:processEvent");
-        if (event instanceof PostConstructApplicationEvent)
-        {
-            Application app = ((PostConstructApplicationEvent) event).getApplication();
-            if (!(app instanceof FacesApplication))
-                throw new AbortProcessingException("Error: Application is not a "+FacesApplication.class.getName()+" instance. Please create a ApplicationFactory!");
-            // Create and Init application
-            ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
-            FacesApplication jsfApp = (FacesApplication)app;
-            jsfApp.init(servletContext);
-            // Set Servlet Attribute
-            if (servletContext.getAttribute(FacesApplication.APPLICATION_ATTRIBUTE)!=null)
-            {
-                log.warn("WARNING: Ambiguous application definition. An object of name '{}' already exists on application scope!", FacesApplication.APPLICATION_ATTRIBUTE);
-            }
-            servletContext.setAttribute(FacesApplication.APPLICATION_ATTRIBUTE, jsfApp);
-            // done
-            jsfApp.initComplete(servletContext);
-        }
-        else if (event instanceof PreDestroyApplicationEvent)
-        {
-            log.info("Processing PreDestroyApplicationEvent");
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
index 2085bc0..ec0e28f 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
@@ -20,43 +20,21 @@ package org.apache.empire.jsf2.app;
 
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
 
-import javax.el.ELContextListener;
-import javax.el.ELException;
-import javax.el.ELResolver;
-import javax.el.ExpressionFactory;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
 import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
 import javax.faces.application.FacesMessage;
 import javax.faces.application.FacesMessage.Severity;
-import javax.faces.application.NavigationHandler;
-import javax.faces.application.ProjectStage;
-import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
-import javax.faces.application.StateManager;
-import javax.faces.application.ViewHandler;
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
-import javax.faces.component.behavior.Behavior;
 import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.PropertyResolver;
-import javax.faces.el.ReferenceSyntaxException;
-import javax.faces.el.ValueBinding;
-import javax.faces.el.VariableResolver;
-import javax.faces.event.ActionListener;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
-import javax.faces.validator.Validator;
 import javax.servlet.ServletContext;
 import javax.sql.DataSource;
 
@@ -73,53 +51,84 @@ import org.slf4j.LoggerFactory;
 
 // import com.sun.faces.application.ApplicationImpl;
 
-@SuppressWarnings("deprecation")
-public abstract class FacesApplication extends Application
+public abstract class FacesApplication
 {
     private static final Logger log                   = LoggerFactory.getLogger(FacesApplication.class);
 
     private static final String CONNECTION_ATTRIBUTE  = "dbConnections";
 
-    public static String        APPLICATION_ATTRIBUTE = "app";
+    public static String        APPLICATION_BEAN_NAME = "facesApplication";
 
     protected TextResolver[]    textResolvers         = null;
 
     private String              webRoot               = null;
     
-    private Application			applImpl 			  = null;
-    
     private FacesImplementation facesImpl			  = null;
-
-    protected FacesApplication()
-    { 	// subscribe
-    	log.info("FacesApplication {0} created", getClass().getName());
-    }
     
-    public void setImplementation(FacesImplementation facesImpl, Application applImpl) 
+    private static FacesApplication appInstance       = null;
+    
+    public static FacesApplication getInstance()
     {
-    	this.facesImpl = facesImpl;
-    	this.applImpl  = applImpl; 
+        if (appInstance==null)
+            log.warn("No FacesApplication instance available. Please add a PostConstructApplicationEvent using FacesStartupListener in your faces-config.xml to create the FacesApplication object.");
+        // return instance
+        return appInstance;
     }
 
-	protected abstract DataSource getAppDataSource(DBDatabase db);
-
     protected abstract void init(ServletContext servletContext);
+    
+    protected abstract DataSource getAppDataSource(DBDatabase db);
+
+    protected FacesApplication()
+    {   // subscribe
+        log.info("FacesApplication {0} created", getClass().getName());
+        // Must be a singleton
+        if (appInstance!=null) {
+            throw new RuntimeException("An attempt was made to create second instance of FacesApplication. FacesApplication must be a singleton!");
+        }
+        // set Instance
+        appInstance = this;
+    }
 
-    protected void initComplete(ServletContext servletContext)
+    /**
+     * Init the Application
+     * @param servletContext
+     */
+    public final void init(FacesImplementation facesImpl, FacesContext startupContext)
     {
-        // Get Web Root
+        this.facesImpl = facesImpl;
+        // Only call once!
+        if (webRoot!=null)
+            throw new NotSupportedException(this, "init");
+        // webRoot
+        ServletContext servletContext = (ServletContext) startupContext.getExternalContext().getContext();
         webRoot = servletContext.getContextPath();
-
-        // Check Text resolvers
-        if (textResolvers == null)
-            initTextResolvers();
-
-        // done
-        log.info("FacesApplication initialization complete");
+        servletContext.setAttribute("webRoot", webRoot);
+        servletContext.setAttribute("app", this);
+        // Init
+        init(servletContext);
+        // text resolvers
+        ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+        Application app = appFactory.getApplication();
+        initTextResolvers(app);
     }
 
     /* Context handling */
+    
+    /**
+     * handle request cleanup
+     * @param ctx
+     */
+    public void onRequestComplete(final FacesContext ctx)
+    {
+        releaseAllConnections(ctx);
+    }
 
+    /**
+     * handle view change
+     * @param fc
+     * @param viewId
+     */
     public void onChangeView(final FacesContext fc, String viewId)
     {
         // allow custom view change logic
@@ -175,6 +184,26 @@ public abstract class FacesApplication extends Application
         return locale;
     }
 
+    public TextResolver getTextResolver(Locale locale)
+    {
+        // No text Resolvers provided
+        if (textResolvers == null || textResolvers.length == 0)
+        {
+            throw new NotSupportedException(this, "getTextResolver");
+        }
+        // Lookup resolver for locale
+        for (int i = 0; i < textResolvers.length; i++)
+            if (locale.equals(textResolvers[i].getLocale()))
+                return textResolvers[i];
+        // locale not found: return default
+        return textResolvers[0];
+    }
+
+    public TextResolver getTextResolver(FacesContext ctx)
+    {
+        return getTextResolver(getContextLocale(ctx));
+    }
+
     /**
      * checks if the current context contains an error
      * @param fc the FacesContext
@@ -320,19 +349,19 @@ public abstract class FacesApplication extends Application
 
     /* Message handling */
 
-    protected void initTextResolvers()
+    protected void initTextResolvers(Application app)
     {
         int count = 0;
-        Iterator<Locale> locales = getSupportedLocales();
+        Iterator<Locale> locales = app.getSupportedLocales();
         for (count = 0; locales.hasNext(); count++)
         {
             locales.next();
         }
 
         // get message bundles
-        String messageBundle = this.getMessageBundle();
+        String messageBundle = app.getMessageBundle();
         textResolvers = new TextResolver[count];
-        locales = getSupportedLocales();
+        locales = app.getSupportedLocales();
         for (int i = 0; locales.hasNext(); i++)
         {
             Locale locale = locales.next();
@@ -340,41 +369,6 @@ public abstract class FacesApplication extends Application
         }
     }
 
-    public TextResolver getTextResolver(Locale locale)
-    {
-        // No text Resolvers provided
-        if (textResolvers == null || textResolvers.length == 0)
-        {
-            throw new NotSupportedException(this, "getTextResolver");
-        }
-        // Lookup resolver for locale
-        for (int i = 0; i < textResolvers.length; i++)
-            if (locale.equals(textResolvers[i].getLocale()))
-                return textResolvers[i];
-        // locale not found: return default
-        return textResolvers[0];
-    }
-
-    public TextResolver getTextResolver(FacesContext ctx)
-    {
-        return getTextResolver(getContextLocale(ctx));
-    }
-
-    /**
-     * @see javax.faces.application.Application#getResourceBundle(javax.faces.context.FacesContext,
-     *      String)
-     */
-    @Override
-    public ResourceBundle getResourceBundle(final FacesContext fc, final String var)
-    {
-        if (var.equals("msg"))
-        {
-            TextResolver resolver = getTextResolver(fc);
-            return resolver.getResourceBundle();
-        }
-        return applImpl.getResourceBundle(fc, var);
-    }
-
     /**
      * returns a connection from the connection pool
      * 
@@ -502,386 +496,5 @@ public abstract class FacesApplication extends Application
         releaseConnection(fc, db, !hasError(fc));
     }
     
-    /************************************************************/
-
-	@Override
-	public void addBehavior(String behaviorId, String behaviorClass) {
-		// Forward to implementation
-		applImpl.addBehavior(behaviorId, behaviorClass);
-	}
-
-	@Override
-	public void addComponent(String componentType, String componentClass) {
-		// Forward to implementation
-		applImpl.addComponent(componentType, componentClass);
-	}
-
-	@Override
-	public void addConverter(Class<?> targetClass, String converterClass) {
-		// Forward to implementation
-		applImpl.addConverter(targetClass, converterClass);
-	}
-
-	@Override
-	public void addConverter(String converterId, String converterClass) {
-		// Forward to implementation
-		applImpl.addConverter(converterId, converterClass);
-	}
-
-	@Override
-	public void addDefaultValidatorId(String validatorId) {
-		// Forward to implementation
-		applImpl.addDefaultValidatorId(validatorId);
-	}
-
-	@Override
-	public void addELContextListener(ELContextListener listener) {
-		// Forward to implementation
-		applImpl.addELContextListener(listener);
-	}
-
-	@Override
-	public void addELResolver(ELResolver resolver) {
-		// Forward to implementation
-		applImpl.addELResolver(resolver);
-	}
-
-	@Override
-	public void addValidator(String validatorId, String validatorClass) {
-		// Forward to implementation
-		applImpl.addValidator(validatorId, validatorClass);
-	}
-
-	@Override
-	public Behavior createBehavior(String behaviorId) throws FacesException {
-		// Forward to implementation
-		return applImpl.createBehavior(behaviorId);
-	}
-
-	@Override
-	public UIComponent createComponent(FacesContext context,
-			Resource componentResource) {
-		// Forward to implementation
-		return applImpl.createComponent(context, componentResource);
-	}
-
-	@Override
-	public UIComponent createComponent(FacesContext context,
-			String componentType, String rendererType) {
-		// Forward to implementation
-		return applImpl.createComponent(context, componentType, rendererType);
-	}
-
-	@Override
-	public UIComponent createComponent(String componentType)
-			throws FacesException {
-		// Forward to implementation
-		return applImpl.createComponent(componentType);
-	}
-
-	@Override
-	public UIComponent createComponent(ValueBinding componentBinding,
-			FacesContext context, String componentType) throws FacesException {
-		// Forward to implementation
-		return applImpl.createComponent(componentBinding, context, componentType);
-	}
-
-	@Override
-	public UIComponent createComponent(ValueExpression componentExpression,
-			FacesContext context, String componentType) throws FacesException {
-		// Forward to implementation
-		return applImpl.createComponent(componentExpression, context, componentType);
-	}
-
-	@Override
-	public UIComponent createComponent(ValueExpression componentExpression,
-			FacesContext context, String componentType, String rendererType) {
-		// Forward to implementation
-		return applImpl.createComponent(componentExpression, context, componentType, rendererType);
-	}
-
-	@Override
-	public Converter createConverter(Class<?> targetClass) {
-		// Forward to implementation
-		return applImpl.createConverter(targetClass);
-	}
-
-	@Override
-	public Converter createConverter(String converterId) {
-		// Forward to implementation
-		return applImpl.createConverter(converterId);
-	}
-
-	@Override
-	public MethodBinding createMethodBinding(String ref, Class<?>[] params)
-			throws ReferenceSyntaxException {
-		// Forward to implementation
-		return applImpl.createMethodBinding(ref, params);
-	}
-
-	@Override
-	public Validator createValidator(String validatorId) throws FacesException {
-		// Forward to implementation
-		return applImpl.createValidator(validatorId);
-	}
-
-	@Override
-	public ValueBinding createValueBinding(String ref)
-			throws ReferenceSyntaxException {
-		// Forward to implementation
-		return applImpl.createValueBinding(ref);
-	}
-
-	@Override
-	public <T> T evaluateExpressionGet(FacesContext context, String expression,
-			Class<? extends T> expectedType) throws ELException {
-		// Forward to implementation
-		return applImpl.evaluateExpressionGet(context, expression, expectedType);
-	}
-
-	@Override
-	public ActionListener getActionListener() {
-		// Forward to implementation
-		return applImpl.getActionListener();
-	}
-
-	@Override
-	public Iterator<String> getBehaviorIds() {
-		// Forward to implementation
-		return applImpl.getBehaviorIds();
-	}
-
-	@Override
-	public Iterator<String> getComponentTypes() {
-		// Forward to implementation
-		return applImpl.getComponentTypes();
-	}
-
-	@Override
-	public Iterator<String> getConverterIds() {
-		// Forward to implementation
-		return applImpl.getConverterIds();
-	}
-
-	@Override
-	public Iterator<Class<?>> getConverterTypes() {
-		// Forward to implementation
-		return applImpl.getConverterTypes();
-	}
-
-	@Override
-	public Locale getDefaultLocale() {
-		// Forward to implementation
-		return applImpl.getDefaultLocale();
-	}
-
-	@Override
-	public String getDefaultRenderKitId() {
-		// Forward to implementation
-		return applImpl.getDefaultRenderKitId();
-	}
-
-	@Override
-	public Map<String, String> getDefaultValidatorInfo() {
-		// Forward to implementation
-		return applImpl.getDefaultValidatorInfo();
-	}
-
-	@Override
-	public ELContextListener[] getELContextListeners() {
-		// Forward to implementation
-		return applImpl.getELContextListeners();
-	}
-
-	@Override
-	public ELResolver getELResolver() {
-		// Forward to implementation
-		return applImpl.getELResolver();
-	}
-
-	@Override
-	public ExpressionFactory getExpressionFactory() {
-		// Forward to implementation
-		return applImpl.getExpressionFactory();
-	}
-
-	@Override
-	public String getMessageBundle() {
-		// Forward to implementation
-		return applImpl.getMessageBundle();
-	}
-
-	@Override
-	public NavigationHandler getNavigationHandler() {
-		// Forward to implementation
-		return applImpl.getNavigationHandler();
-	}
-
-	@Override
-	public ProjectStage getProjectStage() {
-		// Forward to implementation
-		return applImpl.getProjectStage();
-	}
-
-	@Override
-	public PropertyResolver getPropertyResolver() {
-		// Forward to implementation
-		return applImpl.getPropertyResolver();
-	}
-
-	@Override
-	public ResourceHandler getResourceHandler() {
-		// Forward to implementation
-		return applImpl.getResourceHandler();
-	}
-
-	@Override
-	public StateManager getStateManager() {
-		// Forward to implementation
-		return applImpl.getStateManager();
-	}
-
-	@Override
-	public Iterator<Locale> getSupportedLocales() {
-		// Forward to implementation
-		return applImpl.getSupportedLocales();
-	}
-
-	@Override
-	public Iterator<String> getValidatorIds() {
-		// Forward to implementation
-		return applImpl.getValidatorIds();
-	}
-
-	@Override
-	public VariableResolver getVariableResolver() {
-		// Forward to implementation
-		return applImpl.getVariableResolver();
-	}
-
-	@Override
-	public ViewHandler getViewHandler() {
-		// Forward to implementation
-		return applImpl.getViewHandler();
-	}
-
-	@Override
-	public void publishEvent(FacesContext facesContext,
-			Class<? extends SystemEvent> systemEventClass,
-			Class<?> sourceBaseType, Object source) {
-		// Forward to implementation
-		applImpl.publishEvent(facesContext, systemEventClass, sourceBaseType, source);
-	}
-
-	@Override
-	public void publishEvent(FacesContext facesContext,
-			Class<? extends SystemEvent> systemEventClass, Object source) {
-		// Forward to implementation
-		applImpl.publishEvent(facesContext, systemEventClass, source);
-	}
-
-	@Override
-	public void removeELContextListener(ELContextListener listener) {
-		// Forward to implementation
-		applImpl.removeELContextListener(listener);
-	}
-
-	@Override
-	public void setActionListener(ActionListener listener) {
-		// Forward to implementation
-		applImpl.setActionListener(listener);
-	}
-
-	@Override
-	public void setDefaultLocale(Locale locale) {
-		// Forward to implementation
-		applImpl.setDefaultLocale(locale);
-	}
-
-	@Override
-	public void setDefaultRenderKitId(String renderKitId) {
-		// Forward to implementation
-		applImpl.setDefaultRenderKitId(renderKitId);
-	}
-
-	@Override
-	public void setMessageBundle(String bundle) {
-		// Forward to implementation
-		applImpl.setMessageBundle(bundle);
-	}
-
-	@Override
-	public void setNavigationHandler(NavigationHandler handler) {
-		// Forward to implementation
-		applImpl.setNavigationHandler(handler);
-	}
-
-	@Override
-	public void setPropertyResolver(PropertyResolver resolver) {
-		// Forward to implementation
-		applImpl.setPropertyResolver(resolver);
-	}
-
-	@Override
-	public void setResourceHandler(ResourceHandler resourceHandler) {
-		// Forward to implementation
-		applImpl.setResourceHandler(resourceHandler);
-	}
-
-	@Override
-	public void setStateManager(StateManager manager) {
-		// Forward to implementation
-		applImpl.setStateManager(manager);
-	}
-
-	@Override
-	public void setSupportedLocales(Collection<Locale> locales) {
-		// Forward to implementation
-		applImpl.setSupportedLocales(locales);
-	}
-
-	@Override
-	public void setVariableResolver(VariableResolver resolver) {
-		// Forward to implementation
-		applImpl.setVariableResolver(resolver);
-	}
-
-	@Override
-	public void setViewHandler(ViewHandler handler) {
-		// Forward to implementation
-		applImpl.setViewHandler(handler);
-	}
-
-	@Override
-	public void subscribeToEvent(Class<? extends SystemEvent> systemEventClass,
-			Class<?> sourceClass, SystemEventListener listener) {
-		// Forward to implementation
-		applImpl.subscribeToEvent(systemEventClass, sourceClass, listener);
-	}
-
-	@Override
-	public void subscribeToEvent(Class<? extends SystemEvent> systemEventClass,
-			SystemEventListener listener) {
-		// Forward to implementation
-		applImpl.subscribeToEvent(systemEventClass, listener);
-	}
-
-	@Override
-	public void unsubscribeFromEvent(
-			Class<? extends SystemEvent> systemEventClass,
-			Class<?> sourceClass, SystemEventListener listener) {
-		// Forward to implementation
-		applImpl.unsubscribeFromEvent(systemEventClass, sourceClass, listener);
-	}
-
-	@Override
-	public void unsubscribeFromEvent(
-			Class<? extends SystemEvent> systemEventClass,
-			SystemEventListener listener) {
-		// Forward to implementation
-		applImpl.unsubscribeFromEvent(systemEventClass, listener);
-	}
-
-    /************************************************************/
     
 }

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplicationFactory.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplicationFactory.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplicationFactory.java
deleted file mode 100644
index 3fef72e..0000000
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplicationFactory.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.jsf2.app;
-
-import javax.faces.application.Application;
-import javax.faces.application.ApplicationFactory;
-
-import org.apache.empire.exceptions.InternalException;
-import org.apache.empire.exceptions.InvalidArgumentException;
-import org.apache.empire.exceptions.ItemExistsException;
-import org.apache.empire.jsf2.app.impl.MojarraImplementation;
-import org.apache.empire.jsf2.app.impl.MyFacesImplementation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class FacesApplicationFactory extends ApplicationFactory
-{
-    private static final Logger  log = LoggerFactory.getLogger(FacesApplicationFactory.class);
-    
-    private final Class<? extends FacesApplication> applicationClass;
-
-    private final FacesImplementation facesImplementation;
-
-    private final AppStartupListener startupListener;
-    
-    private volatile FacesApplication application;
-    
-	private static FacesImplementation detectFacesImplementation()
-	{
-		// Test for Sun Mojarra
-		try {
-			Class.forName("com.sun.faces.application.ApplicationFactoryImpl");
-			return new MojarraImplementation();
-		} catch (ClassNotFoundException e) {
-			// It's not Mojarra
-		}
-		// Test for Apache MyFaces
-		try {
-			Class.forName("org.apache.myfaces.application.ApplicationFactoryImpl");
-			return new MyFacesImplementation();
-		} catch (ClassNotFoundException e) {
-			// It's not MyFaces
-		}
-		// Not found
-		throw new UnsupportedOperationException(); 
-	}
-    
-    protected FacesApplicationFactory(Class<? extends FacesApplication> applicationClass, FacesImplementation facesImplementation, AppStartupListener startupListener)
-    {
-    	// FacesImplementation
-    	if (facesImplementation==null)
-    		facesImplementation= detectFacesImplementation();
-
-    	// FacesImplementation
-    	this.facesImplementation = facesImplementation;
-        this.applicationClass    = applicationClass;
-        this.startupListener     = startupListener;
-
-        // log
-        log.info("FacesApplicationFactory created for {0} using Implemenation {1}.", applicationClass, facesImplementation.getClass().getName());
-    }
-    
-    protected FacesApplicationFactory(Class<? extends FacesApplication> applicationClass)
-    {
-    	this(applicationClass, null, new AppStartupListener());
-    }
-
-    @Override
-    public Application getApplication()
-    {
-        if (application == null)
-        {   try
-            {	// Create FacesApplication
-                application = applicationClass.newInstance();
-        		// init
-        		facesImplementation.initApplication(application);
-                // subscribe
-                application.subscribeToEvent(javax.faces.event.PostConstructApplicationEvent.class, startupListener);
-            }
-            catch (InstantiationException e)
-            {
-                throw new InternalException(e);
-            }
-            catch (IllegalAccessException e)
-            {
-                throw new InternalException(e);
-            }
-            // log
-            log.info("Fin2Application Application instance created");
-        }
-        return application;
-    }
-
-    @Override
-    public void setApplication(Application application)
-    {
-        if (this.application != null)
-            throw new ItemExistsException(this.application);
-        if (!(application instanceof FacesApplication))
-            throw new InvalidArgumentException("application", application);
-        this.application = (FacesApplication)application;
-    }
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java
index 6f2bdb8..accd750 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java
@@ -25,19 +25,6 @@ import javax.faces.context.FacesContext;
 public interface FacesImplementation 
 {
 	/**
-	 * Init application
-	 * @param application the FacesApplication instance
-	 *	
-	 *	Implementation example:
-	 *	--------------------------- 
-	 *	ApplicationFactoryImpl applFactoryImpl = new ApplicationFactoryImpl();
-     *	// set implementation
-     *	application.setImplementation(this, applFactoryImpl.getApplication());
-     *	applFactoryImpl.setApplication(application);
-	 */
-	void initApplication(final FacesApplication application);
-
-	/**
 	 *	Registers a managed bean	
 	 *
 	 *	Implementation for Mojarra:

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java
new file mode 100644
index 0000000..700b6b3
--- /dev/null
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.app;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FacesRequestPhaseListener implements PhaseListener
+{
+    private static final long   serialVersionUID = 1L;
+    final Logger                log              = LoggerFactory.getLogger(FacesRequestPhaseListener.class);
+
+    public FacesRequestPhaseListener()
+    {
+        // foo
+    }
+
+    @Override
+    public PhaseId getPhaseId()
+    {
+        return PhaseId.ANY_PHASE;
+    }
+
+    @Override
+    public void beforePhase(PhaseEvent pe)
+    {
+        // Only when rendering the response
+        if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE)
+        {   
+            FacesContext facesContext = pe.getFacesContext();
+            HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
+            response.addHeader("Pragma", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+            response.addHeader("Cache-Control", "no-store");
+            response.addHeader("Cache-Control", "must-revalidate");
+        }
+        // default
+    }
+
+    /** 
+     * VERY VERY IMPORTANT FUNCTION: Release Connection on End of request! 
+     **/
+    @Override
+    public void afterPhase(PhaseEvent pe)
+    {
+        // Cleanup
+        FacesContext ctx = pe.getFacesContext();
+        if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE || ctx.getResponseComplete())
+        {
+            FacesApplication app = FacesApplication.getInstance();
+            if (app!=null)
+                app.onRequestComplete(ctx);
+            else
+                log.warn("No FacesApplication available to complete and cleanup request. Please create a managed bean of name "+FacesApplication.APPLICATION_BEAN_NAME);
+        }
+            
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java
new file mode 100644
index 0000000..a9044f3
--- /dev/null
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.app;
+
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.PreDestroyApplicationEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+import javax.servlet.ServletContext;
+
+import org.apache.empire.jsf2.app.impl.MojarraImplementation;
+import org.apache.empire.jsf2.app.impl.MyFacesImplementation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FacesStartupListener implements SystemEventListener
+{
+    private static final Logger log = LoggerFactory.getLogger(FacesStartupListener.class);
+
+    @Override
+    public boolean isListenerForSource(Object source)
+    {
+        return (source instanceof Application);
+    }
+
+    @Override
+    public void processEvent(SystemEvent event)
+        throws AbortProcessingException
+    {
+        log.info("ApplicationStartupListener:processEvent");
+        if (event instanceof PostConstructApplicationEvent)
+        {
+            FacesContext startupContext = FacesContext.getCurrentInstance();
+            // detect implementation
+            FacesImplementation facesImplementation = detectFacesImplementation();
+            Object app = facesImplementation.getManagedBean(FacesApplication.APPLICATION_BEAN_NAME, startupContext);
+            if (!(app instanceof FacesApplication))
+                throw new AbortProcessingException("Error: Application is not a "+FacesApplication.class.getName()+" instance. Please create a ApplicationFactory!");
+            // Create and Init application
+            FacesApplication facesApp = (FacesApplication)app;
+            facesApp.init(facesImplementation, startupContext);
+            // Set Servlet Attribute
+            ServletContext servletContext = (ServletContext) startupContext.getExternalContext().getContext();
+            if (servletContext.getAttribute(FacesApplication.APPLICATION_BEAN_NAME)!=facesApp)
+            {
+                log.warn("WARNING: Ambiguous application definition. An object of name '{}' already exists on application scope!", FacesApplication.APPLICATION_BEAN_NAME);
+            }
+        }
+        else if (event instanceof PreDestroyApplicationEvent)
+        {
+            log.info("Processing PreDestroyApplicationEvent");
+        }
+
+    }
+
+    private static FacesImplementation detectFacesImplementation()
+    {
+        // Test for Apache MyFaces
+        try {
+            Class.forName("org.apache.myfaces.application.ApplicationFactoryImpl");
+            return new MyFacesImplementation();
+        } catch (ClassNotFoundException e) {
+            // It's not MyFaces
+        }
+        // Test for Sun Mojarra
+        try {
+            Class.forName("com.sun.faces.application.ApplicationFactoryImpl");
+            return new MojarraImplementation();
+        } catch (ClassNotFoundException e) {
+            // It's not Mojarra
+        }
+        // Not found
+        throw new UnsupportedOperationException(); 
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
index 9a9af3a..dd0f373 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
@@ -24,9 +24,6 @@ import java.sql.Connection;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.application.ApplicationFactory;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
@@ -52,9 +49,7 @@ public class FacesUtils
 
     public static FacesApplication getFacesApplication()
     {
-        ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
-        Application app = appFactory.getApplication();
-        return (FacesApplication) app;
+        return FacesApplication.getInstance();
     }
     
     public static FacesContext getContext()
@@ -242,7 +237,7 @@ public class FacesUtils
     
     public static TextResolver getTextResolver(final FacesContext fc)
     {
-        return ((FacesApplication)fc.getApplication()).getTextResolver(fc);
+        return getFacesApplication().getTextResolver(fc);
     }
     
     public static String getMessage(final FacesContext fc, String key)

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java
index 4248b63..762ee7f 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java
@@ -40,6 +40,7 @@ public class MojarraImplementation implements FacesImplementation
 {
 	private BeanManager bm;
 
+	/*
 	@Override
 	public void initApplication(final FacesApplication application)
 	{
@@ -53,6 +54,7 @@ public class MojarraImplementation implements FacesImplementation
 		FacesContext fc = FacesContext.getCurrentInstance();
 		bm = ApplicationAssociate.getInstance(fc.getExternalContext()).getBeanManager();
 	}
+	*/
 
 	@Override
 	public void registerManagedBean(final String beanName,final String beanClass,final String scope) 
@@ -71,6 +73,8 @@ public class MojarraImplementation implements FacesImplementation
 	public Object getManagedBean(final String beanName, final FacesContext fc)
 	{
 		// Find Bean
+	    if (bm==null)
+            bm = ApplicationAssociate.getInstance(fc.getExternalContext()).getBeanManager();
 		Object mbean = bm.getBeanFromScope(beanName, fc);
 		if (mbean==null)
 			mbean= bm.create(beanName, fc);

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java
index 38b4a12..bbb2a63 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java
@@ -33,6 +33,7 @@ import org.apache.myfaces.config.impl.digester.elements.ManagedBean;
 
 public class MyFacesImplementation implements FacesImplementation 
 {
+    /*
 	@Override
 	public void initApplication(FacesApplication application)
 	{
@@ -41,6 +42,7 @@ public class MyFacesImplementation implements FacesImplementation
         application.setImplementation(this, applFactoryImpl.getApplication());
         applFactoryImpl.setApplication(application);
 	}
+	*/
 
 	@Override
 	public void registerManagedBean(final String beanName, final String beanClass, final String scope) {

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
index c5972b0..bf26e74 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
@@ -1098,7 +1098,7 @@ public class TagEncodingHelper implements NamingContainer
     public TextResolver getTextResolver(FacesContext context)
     {
         if (textResolver==null)
-            textResolver=((FacesApplication)context.getApplication()).getTextResolver(context);
+            textResolver=FacesApplication.getInstance().getTextResolver(context);
         return textResolver;
     }
     

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db-spring/.gitignore
----------------------------------------------------------------------
diff --git a/empire-db-spring/.gitignore b/empire-db-spring/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/empire-db-spring/.gitignore
@@ -0,0 +1 @@
+/bin/

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBColumn.java b/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
index 755033d..e2f2140 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBColumn.java
@@ -154,8 +154,8 @@ public abstract class DBColumn extends DBColumnExpr
         String rsname = rowset.getName(); 
         strm.writeObject(dbid);
         strm.writeObject(rsname);
-        if (log.isInfoEnabled())
-            log.info("Serialization: reading DBColumn "+dbid+"."+rsname);
+        if (log.isDebugEnabled())
+            log.debug("Serialization: writing DBColumn "+dbid+"."+rsname);
         strm.defaultWriteObject();
     }
 
@@ -169,8 +169,8 @@ public abstract class DBColumn extends DBColumnExpr
         if (StringUtils.isNotEmpty(dbid))
         {   // Find Rowset
             String rsname = String.valueOf(strm.readObject());
-            if (log.isInfoEnabled())
-                log.info("Serialization: reading DBColumn "+dbid+"."+rsname);
+            if (log.isDebugEnabled())
+                log.debug("Serialization: reading DBColumn "+dbid+"."+rsname);
             // find database
             DBDatabase db = DBDatabase.findById(dbid);
             if (db==null)

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
index 7c1fad9..9284a1b 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
@@ -18,6 +18,10 @@
  */
 package org.apache.empire.db;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -26,6 +30,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.Vector;
 
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.expr.compare.DBCompareColExpr;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
@@ -64,7 +69,7 @@ public abstract class DBCommand extends DBCommandExpr
     protected Vector<DBCmdParam>     cmdParams      = null;
     private int                      paramUsageCount= 0;
     // Database
-    private DBDatabase               db;
+    private transient DBDatabase     db;
 
     /**
      * Constructs a new DBCommand object and set the specified DBDatabase object.
@@ -77,6 +82,50 @@ public abstract class DBCommand extends DBCommandExpr
     }
 
     /**
+    * Custom serialization for transient database.
+    */
+    private void writeObject(ObjectOutputStream strm) throws IOException 
+    {
+        if (db==null)
+        {   // No database
+            strm.writeObject("");
+            strm.defaultWriteObject();
+            return;
+        }
+        String dbid = db.getId(); 
+        strm.writeObject(dbid);
+        if (log.isDebugEnabled())
+            log.debug("Serialization: writing DBCommand "+dbid);
+        // write the rest
+        strm.defaultWriteObject();
+    }
+
+    /**
+    * Custom deserialization for transient database.
+    */
+    private void readObject(ObjectInputStream strm) throws IOException, ClassNotFoundException,
+        SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
+    {
+        String dbid = String.valueOf(strm.readObject());
+        if (StringUtils.isNotEmpty(dbid))
+        {   // Find database
+            if (log.isDebugEnabled())
+                log.debug("Serialization: reading DBCommand "+dbid);
+            // find database
+            DBDatabase sdb = DBDatabase.findById(dbid);
+            if (sdb==null)
+                throw new ClassNotFoundException(dbid);
+            // set final field
+            Field f = DBCommand.class.getDeclaredField("db");
+            f.setAccessible(true);
+            f.set(this, sdb);
+            f.setAccessible(false);
+        }    
+        // read the rest
+        strm.defaultReadObject();
+    }
+    
+    /**
      * internally used to reset the command param usage count.
      * Note: Only one thread my generate an SQL statement 
      */

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db/src/main/java/org/apache/empire/db/DBObject.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBObject.java b/empire-db/src/main/java/org/apache/empire/db/DBObject.java
index 95c0de3..1d5bdf4 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBObject.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBObject.java
@@ -18,6 +18,9 @@
  */
 package org.apache.empire.db;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 // java.sql
 import java.io.Serializable;
 
@@ -41,4 +44,20 @@ public abstract class DBObject implements Serializable
      */
     public abstract DBDatabase getDatabase();
 
+    /*
+    private void readObject(ObjectInputStream strm) throws IOException, ClassNotFoundException,
+        SecurityException, IllegalArgumentException 
+    {
+        System.out.println("Serialization Reading Object "+getClass().getName());
+        //perform the default serialization for all non-transient, non-static fields
+        strm.defaultReadObject();
+    }
+
+    private void writeObject(ObjectOutputStream strm) throws IOException 
+    {
+        System.out.println("Serialization Writing Object "+getClass().getName());
+        //perform the default serialization for all non-transient, non-static fields
+        strm.defaultWriteObject();
+    }
+    */
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
index 01bdf57..5e2d8b7 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
@@ -281,6 +281,17 @@ public class DBRecord extends DBRecordData implements Record, Cloneable
     }
 
     /**
+     * Returns true if this record is a existing record (valid but not new).
+     * This may be used from expression language instead of the not allowed property "new" 
+     * 
+     * @return true if this record is a existing record (valid but not new).
+     */
+    public boolean isExists()
+    {
+        return (state == State.Valid || state == State.Modified);
+    }
+
+    /**
      * Returns the number of the columns.
      * 
      * @return the number of the columns

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
index f66c74b..0c46e12 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
@@ -149,8 +149,8 @@ public abstract class DBRowSet extends DBExpr
         }
         String dbid = db.getId(); 
         strm.writeObject(dbid);
-        if (log.isInfoEnabled())
-            log.info("Serialization: reading DBRowSet "+dbid);
+        if (log.isDebugEnabled())
+            log.debug("Serialization: writing DBRowSet "+dbid);
         // write the rest
         strm.defaultWriteObject();
     }
@@ -164,8 +164,8 @@ public abstract class DBRowSet extends DBExpr
         String dbid = String.valueOf(strm.readObject());
         if (StringUtils.isNotEmpty(dbid))
         {   // Find database
-            if (log.isInfoEnabled())
-                log.info("Serialization: reading DBRowSet "+dbid);
+            if (log.isDebugEnabled())
+                log.debug("Serialization: reading DBRowSet "+dbid);
             // find database
             DBDatabase sdb = DBDatabase.findById(dbid);
             if (sdb==null)

http://git-wip-us.apache.org/repos/asf/empire-db/blob/eef9350d/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java b/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java
index 931090d..34eb76f 100644
--- a/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java
+++ b/empire-db/src/main/java/org/apache/empire/db/hsql/HSqlDDLGenerator.java
@@ -18,8 +18,6 @@
  */
 package org.apache.empire.db.hsql;
 
-import java.util.Iterator;
-
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBDDLGenerator;


Mime
View raw message