@@ -691,11 +691,13 @@ private ServiceResponse save(Class c, ServiceRequest request, Database database)
691691 Object obj ;
692692 if (id !=null ){
693693 obj = newInstance (c , id );
694+ beforeUpdate (obj , request );
694695 Method update = c .getDeclaredMethod ("update" , JSONObject .class );
695696 update .invoke (obj , new Object []{json });
696697 }
697698 else {
698699 obj = newInstance (c , json );
700+ beforeCreate (obj , request );
699701 isNew = true ;
700702 }
701703
@@ -729,8 +731,8 @@ private ServiceResponse save(Class c, ServiceRequest request, Database database)
729731 //**************************************************************************
730732 //** delete
731733 //**************************************************************************
732- /** Used to delete an object in the database. Returns a 200 status code if
733- * the object was successfully deleted.
734+ /** Used to delete an object in the database. Returns a JSON representation
735+ * of the object that was deleted.
734736 */
735737 private ServiceResponse delete (Class c , ServiceRequest request , Database database ) {
736738 try (Connection conn = database .getConnection ()){
@@ -754,24 +756,94 @@ private ServiceResponse delete(Class c, ServiceRequest request, Database databas
754756 //Create new instance of the class
755757 Object obj = newInstance (c , id );
756758
759+
760+ //Fire event
761+ beforeDelete (obj , request );
762+
763+
757764 //Delete object
758765 Method delete = getMethod ("delete" , c );
759766 delete .invoke (obj );
760767
768+
761769 //Fire event
762770 onDelete (obj , request );
763771
772+
764773 //Return response
765- return new ServiceResponse (200 );
774+ Method toJson = getMethod ("toJson" , c );
775+ JSONObject json = (JSONObject ) toJson .invoke (obj );
776+ return new ServiceResponse (json );
766777 }
767778 catch (Exception e ){
768779 return getServiceResponse (e );
769780 }
770781 }
771782
772783
784+ //**************************************************************************
785+ //** beforeCreate
786+ //**************************************************************************
787+ /** This method is called immediately before a record is inserted into the
788+ * database. Override this method to process the event.
789+ * @param obj Object. If this method is called by this class, the Object
790+ * will correspond to an instance of a javaxt.sql.Model
791+ */
792+ public void beforeCreate (Object obj , ServiceRequest request ){};
793+
794+
795+ //**************************************************************************
796+ //** onCreate
797+ //**************************************************************************
798+ /** This method is called immediately after a record is inserted into the
799+ * database. Override this method to process the event.
800+ * @param obj Object. If this method is called by this class, the Object
801+ * will correspond to an instance of a javaxt.sql.Model
802+ */
773803 public void onCreate (Object obj , ServiceRequest request ){};
804+
805+
806+ //**************************************************************************
807+ //** beforeUpdate
808+ //**************************************************************************
809+ /** This method is called immediately before a record is updated in the
810+ * database. Override this method to process the event.
811+ * @param obj Object. If this method is called by this class, the Object
812+ * will correspond to an instance of a javaxt.sql.Model
813+ */
814+ public void beforeUpdate (Object obj , ServiceRequest request ){};
815+
816+
817+ //**************************************************************************
818+ //** onUpdate
819+ //**************************************************************************
820+ /** This method is called immediately after a record is updated in the
821+ * database. Override this method to process the event.
822+ * @param obj Object. If this method is called by this class, the Object
823+ * will correspond to an instance of a javaxt.sql.Model
824+ */
774825 public void onUpdate (Object obj , ServiceRequest request ){};
826+
827+
828+ //**************************************************************************
829+ //** beforeDelete
830+ //**************************************************************************
831+ /** This method is called immediately before a record is deleted in the
832+ * database. Override this method to process the event.
833+ * @param obj Object. If this method is called by this class, the Object
834+ * will correspond to an instance of a javaxt.sql.Model
835+ */
836+ public void beforeDelete (Object obj , ServiceRequest request ){};
837+
838+
839+ //**************************************************************************
840+ //** onDelete
841+ //**************************************************************************
842+ /** This method is called immediately after a record is deleted in the
843+ * database. Override this method to process the event.
844+ * @param obj Object. If this method is called by this class, the Object
845+ * will correspond to an instance of a javaxt.sql.Model
846+ */
775847 public void onDelete (Object obj , ServiceRequest request ){};
776848
777849
0 commit comments