From 2a7e74aabf79bbf813ca6450650742ce359ee7ca Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 15 Jul 2014 16:16:31 +0200 Subject: [PATCH 01/15] Add monitoring (events) to template rendering, JPQL queries and JPA operation --- framework/src/play/db/jpa/JPABase.java | 52 ++++++++++++++--------- framework/src/play/db/jpa/JPQL.java | 56 ++++++++++++++++++++----- framework/src/play/mvc/Controller.java | 58 +++++++++++++++----------- 3 files changed, 111 insertions(+), 55 deletions(-) diff --git a/framework/src/play/db/jpa/JPABase.java b/framework/src/play/db/jpa/JPABase.java index 8d83abf7ef..3f574d9b25 100644 --- a/framework/src/play/db/jpa/JPABase.java +++ b/framework/src/play/db/jpa/JPABase.java @@ -25,31 +25,42 @@ public class JPABase implements Serializable, play.db.Model { public void _save() { + boolean saving = false ; String dbName = JPA.getDBName(this.getClass()); if (!em(dbName).contains(this)) { + saving = true ; + PlayPlugin.postEvent("JPASupport.objectSaving", this); + PlayPlugin.postEvent("JPASupport.objectPersisting", this); em(dbName).persist(this); PlayPlugin.postEvent("JPASupport.objectPersisted", this); } - avoidCascadeSaveLoops.set(new HashSet()); - try { - saveAndCascade(true); - } finally { - avoidCascadeSaveLoops.get().clear(); - } - try { - em(dbName).flush(); - } catch (PersistenceException e) { - if (e.getCause() instanceof GenericJDBCException) { - throw new PersistenceException(((GenericJDBCException) e.getCause()).getSQL(), e); - } else { - throw e; - } - } - avoidCascadeSaveLoops.set(new HashSet()); - try { - saveAndCascade(false); - } finally { - avoidCascadeSaveLoops.get().clear(); + try{ + avoidCascadeSaveLoops.set(new HashSet()); + try { + saveAndCascade(true); + } finally { + avoidCascadeSaveLoops.get().clear(); + } + try { + em(dbName).flush(); + } catch (PersistenceException e) { + if (e.getCause() instanceof GenericJDBCException) { + throw new PersistenceException(((GenericJDBCException) e.getCause()).getSQL(), e); + } else { + throw e; + } + } + avoidCascadeSaveLoops.set(new HashSet()); + try { + saveAndCascade(false); + } finally { + avoidCascadeSaveLoops.get().clear(); + } + } + finally + { + if( saving ) + PlayPlugin.postEvent("JPASupport.objectSaved", this); } } @@ -57,6 +68,7 @@ public void _delete() { String dbName = JPA.getDBName(this.getClass()); try { + PlayPlugin.postEvent("JPASupport.objectDeleting", this); avoidCascadeSaveLoops.set(new HashSet()); try { saveAndCascade(true); diff --git a/framework/src/play/db/jpa/JPQL.java b/framework/src/play/db/jpa/JPQL.java index f69203e220..f294cd4865 100644 --- a/framework/src/play/db/jpa/JPQL.java +++ b/framework/src/play/db/jpa/JPQL.java @@ -7,6 +7,7 @@ import javax.persistence.Query; import play.Play; +import play.PlayPlugin; import play.data.binding.ParamNode; import play.data.binding.RootParamNode; import play.db.Configuration; @@ -28,7 +29,10 @@ public long count(String entity) { } public long count(String dbName, String entity) { - return Long.parseLong(em(dbName).createQuery("select count(*) from " + entity + " e").getSingleResult().toString()); + PlayPlugin.postEvent("JPQL.count.before", entity); + long result = Long.parseLong(em(dbName).createQuery("select count(*) from " + entity + " e").getSingleResult().toString()); + PlayPlugin.postEvent("JPQL.count.after", this); + return result ; } public long count(String entity, String query, Object[] params) { @@ -36,9 +40,12 @@ public long count(String entity, String query, Object[] params) { } public long count(String dbName, String entity, String query, Object[] params) { - return Long.parseLong( + PlayPlugin.postEvent("JPQL.count.before", entity); + long result = Long.parseLong( bindParameters(em(dbName).createQuery( createCountQuery(dbName, entity, entity, query, params)), params).getSingleResult().toString()); + PlayPlugin.postEvent("JPQL.count.after", this); + return result ; } public List findAll(String entity) { @@ -46,7 +53,10 @@ public List findAll(String entity) { } public List findAll(String dbName, String entity) { - return em(dbName).createQuery("select e from " + entity + " e").getResultList(); + PlayPlugin.postEvent("JPQL.findAll.before", entity); + List result = em(dbName).createQuery("select e from " + entity + " e").getResultList(); + PlayPlugin.postEvent("JPQL.findAll.after", this); + return result ; } public JPABase findById(String entity, Object id) throws Exception { @@ -62,9 +72,12 @@ public List findBy(String entity, String query, Object[] params) { } public List findBy(String dbName, String entity, String query, Object[] params) { + PlayPlugin.postEvent("JPQL.findBy.before", entity); Query q = em(dbName).createQuery( createFindByQuery(dbName, entity, entity, query, params)); - return bindParameters(q, params).getResultList(); + List result = bindParameters(q, params).getResultList(); + PlayPlugin.postEvent("JPQL.findBy.after", this); + return result ; } public JPAQuery find(String entity, String query, Object[] params) { @@ -73,10 +86,13 @@ public JPAQuery find(String entity, String query, Object[] params) { public JPAQuery find(String dbName, String entity, String query, Object[] params) { + PlayPlugin.postEvent("JPQL.find.before", entity); Query q = em(dbName).createQuery( createFindByQuery(dbName, entity, entity, query, params)); - return new JPAQuery( + JPAQuery result = new JPAQuery( createFindByQuery(dbName, entity, entity, query, params), bindParameters(q, params)); + PlayPlugin.postEvent("JPQL.find.after", this); + return result ; } public JPAQuery find(String entity) { @@ -84,10 +100,13 @@ public JPAQuery find(String entity) { } public JPAQuery find(String dbName, String entity) { + PlayPlugin.postEvent("JPQL.find.before", entity); Query q = em(dbName).createQuery( createFindByQuery(dbName, entity, entity, null)); - return new JPAQuery( + JPAQuery result = new JPAQuery( createFindByQuery(dbName, entity, entity, null), bindParameters(q)); + PlayPlugin.postEvent("JPQL.find.after", this); + return result ; } public JPAQuery all(String entity) { @@ -95,16 +114,22 @@ public JPAQuery all(String entity) { } public JPAQuery all(String dbName, String entity) { + PlayPlugin.postEvent("JPQL.all.before", entity); Query q = em(dbName).createQuery( createFindByQuery(dbName, entity, entity, null)); - return new JPAQuery( + JPAQuery result = new JPAQuery( createFindByQuery(dbName, entity, entity, null), bindParameters(q)); + PlayPlugin.postEvent("JPQL.all.after", this); + return result ; } public int delete(String dbName, String entity, String query, Object[] params) { + PlayPlugin.postEvent("JPQL.delete.before", entity); Query q = em(dbName).createQuery( createDeleteQuery(entity, entity, query, params)); - return bindParameters(q, params).executeUpdate(); + int result = bindParameters(q, params).executeUpdate(); + PlayPlugin.postEvent("JPQL.delete.after", this); + return result ; } public int delete(String entity, String query, Object[] params) { @@ -113,9 +138,12 @@ public int delete(String entity, String query, Object[] params) { public int deleteAll(String dbName, String entity) { + PlayPlugin.postEvent("JPQL.deleteAll.before", entity); Query q = em(dbName).createQuery( createDeleteQuery(entity, entity, null)); - return bindParameters(q).executeUpdate(); + int result = bindParameters(q).executeUpdate(); + PlayPlugin.postEvent("JPQL.deleteAll.after", this); + return result ; } public int deleteAll(String entity) { @@ -123,13 +151,16 @@ public int deleteAll(String entity) { } public JPABase findOneBy(String dbName, String entity, String query, Object[] params) { + PlayPlugin.postEvent("JPQL.findOneBy.before", entity); Query q = em(dbName).createQuery( createFindByQuery(dbName, entity, entity, query, params)); List results = bindParameters(q, params).getResultList(); if (results.size() == 0) { return null; } - return (JPABase) results.get(0); + JPABase result = (JPABase) results.get(0); + PlayPlugin.postEvent("JPQL.findOneBy.after", this); + return result ; } public JPABase findOneBy(String entity, String query, Object[] params) { @@ -141,11 +172,14 @@ public JPABase create(String entity, String name, Params params) throws Exceptio } public JPABase create(String dbName, String entity, String name, Params params) throws Exception { + PlayPlugin.postEvent("JPQL.create.before", entity); Object o = Play.classloader.loadClass(entity).newInstance(); RootParamNode rootParamNode = ParamNode.convert(params.all()); - return ((GenericModel) o).edit(rootParamNode, name); + JPABase result = ((GenericModel) o).edit(rootParamNode, name); + PlayPlugin.postEvent("JPQL.create.after", this); + return result ; } public String createFindByQuery(String dbName, String entityName, String entityClass, String query, Object... params) { diff --git a/framework/src/play/mvc/Controller.java b/framework/src/play/mvc/Controller.java index 7dc7cfb960..39a8b2e3b9 100644 --- a/framework/src/play/mvc/Controller.java +++ b/framework/src/play/mvc/Controller.java @@ -17,6 +17,7 @@ import play.Invoker.Suspend; import play.Logger; import play.Play; +import play.PlayPlugin; import play.classloading.ApplicationClasses.ApplicationClass; import play.classloading.enhancers.ContinuationEnhancer; import play.classloading.enhancers.ControllersEnhancer.ControllerInstrumentation; @@ -663,30 +664,39 @@ protected static void renderTemplate(String templateName, Object... args) { * @param args The template data. */ protected static void renderTemplate(String templateName, Map args) { - // Template datas - Scope.RenderArgs templateBinding = Scope.RenderArgs.current(); - templateBinding.data.putAll(args); - templateBinding.put("session", Scope.Session.current()); - templateBinding.put("request", Http.Request.current()); - templateBinding.put("flash", Scope.Flash.current()); - templateBinding.put("params", Scope.Params.current()); - templateBinding.put("errors", Validation.errors()); - try { - Template template = TemplateLoader.load(template(templateName)); - throw new RenderTemplate(template, templateBinding.data); - } catch (TemplateNotFoundException ex) { - if (ex.isSourceAvailable()) { - throw ex; - } - StackTraceElement element = PlayException.getInterestingStrackTraceElement(ex); - if (element != null) { - ApplicationClass applicationClass = Play.classes.getApplicationClass(element.getClassName()); - if (applicationClass != null) { - throw new TemplateNotFoundException(templateName, applicationClass, element.getLineNumber()); - } - } - throw ex; - } + PlayPlugin.postEvent("template.render.before", templateName); + Template template = null ; + try + { + // Template datas + Scope.RenderArgs templateBinding = Scope.RenderArgs.current(); + templateBinding.data.putAll(args); + templateBinding.put("session", Scope.Session.current()); + templateBinding.put("request", Http.Request.current()); + templateBinding.put("flash", Scope.Flash.current()); + templateBinding.put("params", Scope.Params.current()); + templateBinding.put("errors", Validation.errors()); + try { + template = TemplateLoader.load(template(templateName)); + throw new RenderTemplate(template, templateBinding.data); + } catch (TemplateNotFoundException ex) { + if (ex.isSourceAvailable()) { + throw ex; + } + StackTraceElement element = PlayException.getInterestingStrackTraceElement(ex); + if (element != null) { + ApplicationClass applicationClass = Play.classes.getApplicationClass(element.getClassName()); + if (applicationClass != null) { + throw new TemplateNotFoundException(templateName, applicationClass, element.getLineNumber()); + } + } + throw ex; + } + } + finally + { + PlayPlugin.postEvent("template.render.after", template); + } } /** From 1177629fb48fed612454833b0036a57b17cca728 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 12:16:59 +0200 Subject: [PATCH 02/15] Create monitoring.textile --- documentation/manual/monitoring.textile | 1 + 1 file changed, 1 insertion(+) create mode 100644 documentation/manual/monitoring.textile diff --git a/documentation/manual/monitoring.textile b/documentation/manual/monitoring.textile new file mode 100644 index 0000000000..a0990367ef --- /dev/null +++ b/documentation/manual/monitoring.textile @@ -0,0 +1 @@ +TBD From 97124ee0807c830cef7b039fd57b0dea327c7b5a Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 12:40:18 +0200 Subject: [PATCH 03/15] Update and rename monitoring.textile to events.textile --- documentation/manual/events.textile | 25 +++++++++++++++++++++++++ documentation/manual/monitoring.textile | 1 - 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 documentation/manual/events.textile delete mode 100644 documentation/manual/monitoring.textile diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile new file mode 100644 index 0000000000..845c98eff8 --- /dev/null +++ b/documentation/manual/events.textile @@ -0,0 +1,25 @@ +Play lets plugins send events to send notification the framework and other plugins. + +bc. +import play.PlayPlugin; + +... +PlayPlugin.postEvent("something happens", this); + +Plugins listen to these events in the the @@ method + +bc. + +public class My Plugin extends PlayPlugin { + + @Override + public void onEvent(String message, Object context) { + ... + } + +h2. Available events + +At the moment the following events are defined + +| event | message | object | description +| bla | xxxx | eee | diff --git a/documentation/manual/monitoring.textile b/documentation/manual/monitoring.textile deleted file mode 100644 index a0990367ef..0000000000 --- a/documentation/manual/monitoring.textile +++ /dev/null @@ -1 +0,0 @@ -TBD From 6ab3b6a194db765ce2472881e0433cb6736a7426 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:12:45 +0200 Subject: [PATCH 04/15] Update events.textile --- documentation/manual/events.textile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index 845c98eff8..f8e839abe8 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -1,16 +1,13 @@ Play lets plugins send events to send notification the framework and other plugins. -bc. -import play.PlayPlugin; +bc.import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); Plugins listen to these events in the the @@ method -bc. - -public class My Plugin extends PlayPlugin { +bc. public class My Plugin extends PlayPlugin { @Override public void onEvent(String message, Object context) { From 9e035e9128757ffab35cd11008cf9d618390fa57 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:13:05 +0200 Subject: [PATCH 05/15] Update events.textile --- documentation/manual/events.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index f8e839abe8..ba42c642f2 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -1,11 +1,11 @@ Play lets plugins send events to send notification the framework and other plugins. -bc.import play.PlayPlugin; +bc. import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); -Plugins listen to these events in the the @@ method +Plugins listen to these events in the the @onEvent@ method bc. public class My Plugin extends PlayPlugin { From d8fa2e8d02b2e37d5ab07a2cb2ed9a608c690bc8 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:13:30 +0200 Subject: [PATCH 06/15] Update events.textile --- documentation/manual/events.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index ba42c642f2..bf3058fe64 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -1,9 +1,10 @@ Play lets plugins send events to send notification the framework and other plugins. -bc. import play.PlayPlugin; +bc.. import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); +

Plugins listen to these events in the the @onEvent@ method From 33322b2ed738246fb1de23e80927e8833fe34d2d Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:13:40 +0200 Subject: [PATCH 07/15] Update events.textile --- documentation/manual/events.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index bf3058fe64..e912a3280f 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -4,7 +4,7 @@ bc.. import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); -

+

Plugins listen to these events in the the @onEvent@ method From b2b9baa9c40df0aaaeddef9e3d6e3316a5c44d36 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:14:30 +0200 Subject: [PATCH 08/15] Update events.textile --- documentation/manual/events.textile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index e912a3280f..aabbb91d3d 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -4,16 +4,17 @@ bc.. import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); -

+p. Plugins listen to these events in the the @onEvent@ method -bc. public class My Plugin extends PlayPlugin { +bc.. public class My Plugin extends PlayPlugin { @Override public void onEvent(String message, Object context) { ... } +p. h2. Available events From f5f86f914360e37b781291e7a42d6a7e187c0746 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:15:16 +0200 Subject: [PATCH 09/15] Update events.textile --- documentation/manual/events.textile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index aabbb91d3d..5eea666cb9 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -4,6 +4,7 @@ bc.. import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); + p. Plugins listen to these events in the the @onEvent@ method @@ -14,6 +15,7 @@ bc.. public class My Plugin extends PlayPlugin { public void onEvent(String message, Object context) { ... } + p. h2. Available events From 8bd50e3457018a0d94eec647e0d7c8dfe181cf8f Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:15:57 +0200 Subject: [PATCH 10/15] Update events.textile --- documentation/manual/events.textile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index 5eea666cb9..0d27075b21 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -5,9 +5,7 @@ bc.. import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); -p. - -Plugins listen to these events in the the @onEvent@ method +p. Plugins listen to these events in the the @onEvent@ method bc.. public class My Plugin extends PlayPlugin { @@ -16,7 +14,6 @@ bc.. public class My Plugin extends PlayPlugin { ... } -p. h2. Available events From c88574b409f3f3ec770493bd8a0bfedd3994b6f5 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:50:11 +0200 Subject: [PATCH 11/15] Update events.textile --- documentation/manual/events.textile | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index 0d27075b21..a32d5ef442 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -19,5 +19,31 @@ h2. Available events At the moment the following events are defined -| event | message | object | description -| bla | xxxx | eee | +| Class | Method | Event | Parameter | +|------------|----------------|----------------------------|-----------------------------| +| Controller | renderTemplate | template.render.before | @string@: the template name | +| | | template.render.after | idem | +| JPABase | _save | JPASupport.objectPersisted | @JPABase@: the object | +| | | JPASupport.objectSaved | idem | +| | _delete | JPASupport.objectDeleting | idem | +| | | JPASupport.objectDeleted | idem | +| BUG!! | saveAndCascade | JPASupport.objectUpdated | idem | +| | | JPASupport.objectUpdated | idem | +| JPQL | count | JPQL.count.before | @string@: the entity name | +| | | JPQL.count.after | @JPQL@: the object | +| | findAll | JPQL.findAll.before | idem | +| | | JPQL.findAll.after | idem | +| | findBy | JPQL.findBy.before | idem | +| | | JPQL.findBy.after | idem | +| | find | JPQL.find.before | idem | +| | | JPQL.find.after | idem | +| | all | JPQL.all.before | idem | +| | | JPQL.all.after | idem | +| | delete | JPQL.delete.before | idem | +| | | JPQL.delete.after | idem | +| | deleteAll | JPQL.deleteAll.before | idem | +| | | JPQL.deleteAll.after | idem | +| BUG | findOneBy | JPQL.findOneBy.before | idem | +| | | JPQL.findOneBy.after | idem | +| | create | JPQL.create.before | idem | +| | | JPQL.create.after | | From 37b9aee97ff9a750c2f2b5e9fe021b50160882e4 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 13:50:32 +0200 Subject: [PATCH 12/15] Update events.textile --- documentation/manual/events.textile | 1 - 1 file changed, 1 deletion(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index a32d5ef442..6d3487587c 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -20,7 +20,6 @@ h2. Available events At the moment the following events are defined | Class | Method | Event | Parameter | -|------------|----------------|----------------------------|-----------------------------| | Controller | renderTemplate | template.render.before | @string@: the template name | | | | template.render.after | idem | | JPABase | _save | JPASupport.objectPersisted | @JPABase@: the object | From cc3ab9acd905797d817edbe83101d459c6c57992 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Tue, 12 Aug 2014 16:08:31 +0200 Subject: [PATCH 13/15] Fix the botched merge --- framework/src/play/db/jpa/JPABase.java | 10 ++++------ framework/src/play/db/jpa/JPQL.java | 8 ++++---- framework/src/play/mvc/Controller.java | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/framework/src/play/db/jpa/JPABase.java b/framework/src/play/db/jpa/JPABase.java index 4f9acace8b..04fc7c9cf7 100644 --- a/framework/src/play/db/jpa/JPABase.java +++ b/framework/src/play/db/jpa/JPABase.java @@ -95,13 +95,14 @@ public void _delete() { saveAndCascade(false); } finally { avoidCascadeSaveLoops.get().clear(); - } - PlayPlugin.postEvent("JPASupport.objectDeleted", this); + } } catch (PersistenceException e) { throw e; } catch (Throwable e) { throw new RuntimeException(e); - } + } finally { + PlayPlugin.postEvent("JPASupport.objectDeleted", this); + } } public Object _key() { @@ -118,9 +119,6 @@ private void saveAndCascade(boolean willBeSaved) { return; } else { avoidCascadeSaveLoops.get().add(this); - if (willBeSaved) { - PlayPlugin.postEvent("JPASupport.objectUpdated", this); - } } // Cascade save try { diff --git a/framework/src/play/db/jpa/JPQL.java b/framework/src/play/db/jpa/JPQL.java index f294cd4865..abf7cb31ad 100644 --- a/framework/src/play/db/jpa/JPQL.java +++ b/framework/src/play/db/jpa/JPQL.java @@ -155,10 +155,10 @@ public JPABase findOneBy(String dbName, String entity, String query, Object[] pa Query q = em(dbName).createQuery( createFindByQuery(dbName, entity, entity, query, params)); List results = bindParameters(q, params).getResultList(); - if (results.size() == 0) { - return null; - } - JPABase result = (JPABase) results.get(0); + JPABase result = null ; + if (results.size() != 0) { + result = (JPABase) results.get(0); + } PlayPlugin.postEvent("JPQL.findOneBy.after", this); return result ; } diff --git a/framework/src/play/mvc/Controller.java b/framework/src/play/mvc/Controller.java index cb3e7196f5..3f6ce45565 100644 --- a/framework/src/play/mvc/Controller.java +++ b/framework/src/play/mvc/Controller.java @@ -677,7 +677,7 @@ protected static void renderTemplate(String templateName, Map arg templateBinding.put("params", Scope.Params.current()); templateBinding.put("errors", Validation.errors()); try { - Template template = TemplateLoader.load(template(templateName)); + template = TemplateLoader.load(template(templateName)); throw new RenderTemplate(template, templateBinding.data); } catch (TemplateNotFoundException ex) { if (ex.isSourceAvailable()) { @@ -693,7 +693,6 @@ protected static void renderTemplate(String templateName, Map arg throw ex; } } - } finally { PlayPlugin.postEvent("template.render.after", template); From 7e49e914fefc8effe4894389cafa4f75238bad30 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Mon, 18 Aug 2014 22:11:42 +0200 Subject: [PATCH 14/15] Update events.textile --- documentation/manual/events.textile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index 6d3487587c..6de2494545 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -1,11 +1,13 @@ -Play lets plugins send events to send notification the framework and other plugins. +Events are a + +The API to send event is pretty straightforward: an event is a `string` and an `Object`. bc.. import play.PlayPlugin; ... PlayPlugin.postEvent("something happens", this); -p. Plugins listen to these events in the the @onEvent@ method +p. Plugins can listen to these events in the the @onEvent@ method: bc.. public class My Plugin extends PlayPlugin { @@ -17,7 +19,10 @@ bc.. public class My Plugin extends PlayPlugin { h2. Available events -At the moment the following events are defined +At the moment the following events are sent by Play framework. The events go in pair signaling the beginning and the end of a framework operation. + +Usually the `context` provided before and after events are the same except for JPQL category. In this case, the before event gives the entity name while the after give the JPQL instance. + | Class | Method | Event | Parameter | | Controller | renderTemplate | template.render.before | @string@: the template name | @@ -26,8 +31,6 @@ At the moment the following events are defined | | | JPASupport.objectSaved | idem | | | _delete | JPASupport.objectDeleting | idem | | | | JPASupport.objectDeleted | idem | -| BUG!! | saveAndCascade | JPASupport.objectUpdated | idem | -| | | JPASupport.objectUpdated | idem | | JPQL | count | JPQL.count.before | @string@: the entity name | | | | JPQL.count.after | @JPQL@: the object | | | findAll | JPQL.findAll.before | idem | @@ -42,7 +45,7 @@ At the moment the following events are defined | | | JPQL.delete.after | idem | | | deleteAll | JPQL.deleteAll.before | idem | | | | JPQL.deleteAll.after | idem | -| BUG | findOneBy | JPQL.findOneBy.before | idem | +| | findOneBy | JPQL.findOneBy.before | idem | | | | JPQL.findOneBy.after | idem | | | create | JPQL.create.before | idem | | | | JPQL.create.after | | From 5dfde1ef7fcdbe22ccd074a41e5de4df0782d44e Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Mon, 18 Aug 2014 22:43:31 +0200 Subject: [PATCH 15/15] Update events.textile --- documentation/manual/events.textile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/documentation/manual/events.textile b/documentation/manual/events.textile index 6de2494545..5ff58556b2 100644 --- a/documentation/manual/events.textile +++ b/documentation/manual/events.textile @@ -1,6 +1,6 @@ -Events are a +Events are a way for plugins to receive notifications from the framework or other plugins. -The API to send event is pretty straightforward: an event is a `string` and an `Object`. +The API to send events is pretty straightforward: an event is a `string` and an `Object` (the context). bc.. import play.PlayPlugin; @@ -19,15 +19,20 @@ bc.. public class My Plugin extends PlayPlugin { h2. Available events -At the moment the following events are sent by Play framework. The events go in pair signaling the beginning and the end of a framework operation. +At the moment the following events are sent by Play framework. -Usually the `context` provided before and after events are the same except for JPQL category. In this case, the before event gives the entity name while the after give the JPQL instance. +Events go in pair signaling the beginning and the end of a framework operation. +Usually the context provided to the before and after events is the same except for JPQL category. +In this case, the before event gives the entity name while the after give the JPQL instance. -| Class | Method | Event | Parameter | + +| Class | Method | Event | Context | | Controller | renderTemplate | template.render.before | @string@: the template name | | | | template.render.after | idem | -| JPABase | _save | JPASupport.objectPersisted | @JPABase@: the object | +| JPABase | _save | JPASupport.objectSaving | @JPABase@: the object | +| | | JPASupport.objectPersisting| idem | +| | | JPASupport.objectPersisted | idem | | | | JPASupport.objectSaved | idem | | | _delete | JPASupport.objectDeleting | idem | | | | JPASupport.objectDeleted | idem |