package com.backendless.servercode.extension;

import com.backendless.BackendlessCollection;
import com.backendless.commons.persistence.BaseEntityDescription;
import com.backendless.persistence.BackendlessDataQuery;
import com.backendless.property.ObjectProperty;
import com.backendless.servercode.ExecutionResult;
import com.backendless.servercode.RunnerContext;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: ivanlappo
 * Date: 5/20/13
 * Time: 12:40 PM
 * To change this template use File | Settings | File Templates.
 */
public abstract class PersistenceExtender
{
  public PersistenceExtender()
  {

  }

  public void beforeFindById( RunnerContext context, String objectId, String[] relations ) throws Exception
  {
  }

  public BaseEntityDescription afterFindById( RunnerContext context, String objectId, String[] relations,
                                              ExecutionResult<BaseEntityDescription> entity ) throws Exception
  {
    return entity.getResult();
  }

  public void beforeCreate( RunnerContext context, Map entityMap ) throws Exception
  {
  }

  public BaseEntityDescription afterCreate( RunnerContext context, Map entityMap,
                                            ExecutionResult<BaseEntityDescription> entity ) throws Exception
  {
    return entity.getResult();
  }

  public void beforeUpdate( RunnerContext context, Map entityMap ) throws Exception
  {
  }

  public BaseEntityDescription afterUpdate( RunnerContext context, Map entityMap,
                                            ExecutionResult<BaseEntityDescription> entity ) throws Exception
  {
    return entity.getResult();
  }

  public void beforeLoadRelations( RunnerContext context, String objectId, String entityName,
                                   String[] relations ) throws Exception
  {
  }

  public Map afterLoadRelations( RunnerContext context, String objectId, String entityName, String[] relations,
                                 ExecutionResult<Map> entity ) throws Exception
  {
    return entity.getResult();
  }

  public void beforeRemove( RunnerContext context, String objectId ) throws Exception
  {
  }

  public Long afterRemove( RunnerContext context, String objectId, ExecutionResult<Long> removedVal ) throws Exception
  {
    return removedVal.getResult();
  }

  public void beforeDescribe( RunnerContext context, String entityName ) throws Exception
  {
  }

  public ObjectProperty[] afterDescribe( RunnerContext context, String entityName,
                                         ExecutionResult<ObjectProperty[]> propertiesFound ) throws Exception
  {
    return propertiesFound.getResult();
  }

  public void beforeFind( RunnerContext context, BackendlessDataQuery query ) throws Exception
  {
  }

  public BackendlessCollection afterFind( RunnerContext context, BackendlessDataQuery query,
                                          ExecutionResult<BackendlessCollection> collection ) throws Exception
  {
    return collection.getResult();
  }

  public void beforeFirst( RunnerContext context ) throws Exception
  {
  }

  public BaseEntityDescription afterFirst( RunnerContext context,
                                           ExecutionResult<BaseEntityDescription> entity ) throws Exception
  {
    return entity.getResult();
  }

  public void beforeLast( RunnerContext context ) throws Exception
  {
  }

  public BaseEntityDescription afterLast( RunnerContext context,
                                          ExecutionResult<BaseEntityDescription> entity ) throws Exception
  {
    return entity.getResult();
  }
}


@@ -90,74 +90,8 @@
 on;%0A
-import com.backendless.commons.persistence.BaseEntityDescription;%0A
 impo
@@ -292,16 +292,42 @@
 ntext;%0A%0A
+import java.util.HashMap;%0A
 import j
@@ -544,11 +544,45 @@
 nder
+%3CT%3E
 %0A%7B%0A
+  private Class%3CT%3E userClass;%0A%0A
   pu
@@ -612,16 +612,141 @@
 r()%0A  %7B%0A
+    userClass = (Class%3CT%3E) HashMap.class;%0A  %7D%0A%0A  public PersistenceExtender( Class%3CT%3E clazz )%0A  %7B%0A    this.userClass = clazz;
 %0A  %7D%0A%0A  
@@ -869,37 +869,17 @@
  public 
-BaseEntityDescription
+T
  afterFi
@@ -972,36 +972,16 @@
         
-                   
- 
 Executio
@@ -988,37 +988,17 @@
 nResult%3C
-BaseEntityDescription
+T
 %3E entity
@@ -1159,37 +1159,17 @@
  public 
-BaseEntityDescription
+T
  afterCr
@@ -1215,90 +1215,26 @@
 Map,
-%0A                                            ExecutionResult%3CBaseEntityDescription
+ ExecutionResult%3CT
 %3E en
@@ -1399,37 +1399,17 @@
  public 
-BaseEntityDescription
+T
  afterUp
@@ -1455,90 +1455,26 @@
 Map,
-%0A                                            ExecutionResult%3CBaseEntityDescription
+ ExecutionResult%3CT
 %3E en
@@ -2982,37 +2982,17 @@
  public 
-BaseEntityDescription
+T
  afterFi
@@ -3022,89 +3022,26 @@
 ext,
-%0A                                           ExecutionResult%3CBaseEntityDescription
+ ExecutionResult%3CT
 %3E en
@@ -3189,37 +3189,17 @@
  public 
-BaseEntityDescription
+T
  afterLa
@@ -3228,149 +3228,157 @@
 ext,
-%0A                                          ExecutionResult%3CBaseEntityDescription%3E entity ) throws Exception%0A  %7B%0A    return entity.getResult()
+ ExecutionResult%3CT%3E entity ) throws Exception%0A  %7B%0A    return entity.getResult();%0A  %7D%0A%0A  public final Class%3C?%3E getUserClass()%0A  %7B%0A    return userClass
 ;%0A  

Add generic to Persistence Extender