// Path: src/main/java/com/cqrs/appengine/core/messaging/EventHandler.java
// @SuppressWarnings("serial")
// public abstract class EventHandler<T extends Event> implements DeferredTask {
// 
//     /**
//      * The event
//      */
//     protected T event;
// 
//     /**
//      * Default constructor
//      * 
//      * @param event
//      */
//     public EventHandler(T event){
//         this.event = event;
//     }
// }
// 
// Path: src/main/java/com/cqrs/appengine/sample/MessageLog.java
// public class MessageLog {
// 
//     private static final String LOG_NAME = "Simple CQRS Service Log";
// 
//     private static final Logger log = Logger.getLogger(LOG_NAME);
// 
//     static {
//         log.setLevel(java.util.logging.Level.FINEST);
//     }
// 
//     /**
//      * Log an informational message
//      * 
//      * @param message
//      */
//     public static void log(String message){
//         log.log(Level.INFO, message);
//     }
// 
//     /**
//      * Log an exception
//      * 
//      * @param e
//      */
//     public static void log(Exception e){
// 
//         if(e == null)
//             return;
// 
//         log.log(Level.SEVERE, e.getClass().getName(), e);
//     }
// }
// 
// Path: src/main/java/com/cqrs/appengine/sample/domain/AttendeeNameChanged.java
// public class AttendeeNameChanged implements Event, Serializable{
// 
//     private static final long serialVersionUID = 1L;
// 
//     private UUID attendeeId;
//     private String firstName;
//     private String lastName;
// 
//     /**
//      * Default constructor for serialization
//      */
//     public AttendeeNameChanged(){}
// 
//     /**
//      * Constructor
//      * 
//      * @param attendeeId
//      * @param firstName
//      * @param lastName
//      */
//     public AttendeeNameChanged(UUID attendeeId, String firstName, String lastName){
//         this.attendeeId = attendeeId;
//         this.firstName = firstName;
//         this.lastName = lastName;
//     }
// 
//     /**
//      * Get the first name
//      * @return
//      */
//     public String getFirstName(){
//         return  firstName;
//     }
// 
//     /**
//      * Get the last name
//      * @return
//      */
//     public String getLastName(){
//         return lastName;
//     }
// 
//     /**
//      * Get the attendee Id
//      * @return
//      */
//     public UUID getAttendeeId(){
//         return attendeeId;
//     }
// }


import com.cqrs.appengine.core.messaging.EventHandler;
import com.cqrs.appengine.sample.MessageLog;
import com.cqrs.appengine.sample.domain.AttendeeNameChanged;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Transaction;
package com.cqrs.appengine.sample.handlers.events;


/**
 * Deferred task for handling an attendee name change
 */
public class AttendeeNameChangedEventHandler extends EventHandler<AttendeeNameChanged>{

    private static final long serialVersionUID = 1L;

    public AttendeeNameChangedEventHandler(AttendeeNameChanged event){
        super(event);
    }

    @Override
    public void run() {

        DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
        Transaction transaction = datastoreService.beginTransaction();

        Key attendeeKey = KeyFactory.createKey("Attendee", event.getAttendeeId().toString());
        Entity attendee = null;

        try {
            attendee = datastoreService.get(attendeeKey);
            attendee.setProperty("FirstName", event.getFirstName());
            attendee.setProperty("LastName", event.getLastName());
            datastoreService.put(attendee);
            transaction.commit();

        } catch (EntityNotFoundException e) {
            MessageLog.log(e);
        } finally {
// Path: src/main/java/com/cqrs/appengine/core/messaging/EventHandler.java
// @SuppressWarnings("serial")
// public abstract class EventHandler<T extends Event> implements DeferredTask {
// 
//     /**
//      * The event
//      */
//     protected T event;
// 
//     /**
//      * Default constructor
//      * 
//      * @param event
//      */
//     public EventHandler(T event){
//         this.event = event;
//     }
// }
// 
// Path: src/main/java/com/cqrs/appengine/sample/MessageLog.java
// public class MessageLog {
// 
//     private static final String LOG_NAME = "Simple CQRS Service Log";
// 
//     private static final Logger log = Logger.getLogger(LOG_NAME);
// 
//     static {
//         log.setLevel(java.util.logging.Level.FINEST);
//     }
// 
//     /**
//      * Log an informational message
//      * 
//      * @param message
//      */
//     public static void log(String message){
//         log.log(Level.INFO, message);
//     }
// 
//     /**
//      * Log an exception
//      * 
//      * @param e
//      */
//     public static void log(Exception e){
// 
//         if(e == null)
//             return;
// 
//         log.log(Level.SEVERE, e.getClass().getName(), e);
//     }
// }
// 
// Path: src/main/java/com/cqrs/appengine/sample/domain/AttendeeNameChanged.java
// public class AttendeeNameChanged implements Event, Serializable{
// 
//     private static final long serialVersionUID = 1L;
// 
//     private UUID attendeeId;
//     private String firstName;
//     private String lastName;
// 
//     /**
//      * Default constructor for serialization
//      */
//     public AttendeeNameChanged(){}
// 
//     /**
//      * Constructor
//      * 
//      * @param attendeeId
//      * @param firstName
//      * @param lastName
//      */
//     public AttendeeNameChanged(UUID attendeeId, String firstName, String lastName){
//         this.attendeeId = attendeeId;
//         this.firstName = firstName;
//         this.lastName = lastName;
//     }
// 
//     /**
//      * Get the first name
//      * @return
//      */
//     public String getFirstName(){
//         return  firstName;
//     }
// 
//     /**
//      * Get the last name
//      * @return
//      */
//     public String getLastName(){
//         return lastName;
//     }
// 
//     /**
//      * Get the attendee Id
//      * @return
//      */
//     public UUID getAttendeeId(){
//         return attendeeId;
//     }
// }


// Path: src/main/java/com/cqrs/appengine/sample/handlers/events/AttendeeNameChangedEventHandler.java
import com.cqrs.appengine.core.messaging.EventHandler;
import com.cqrs.appengine.sample.MessageLog;
import com.cqrs.appengine.sample.domain.AttendeeNameChanged;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Transaction;

package com.cqrs.appengine.sample.handlers.events;


/**
 * Deferred task for handling an attendee name change
 */
public class AttendeeNameChangedEventHandler extends EventHandler<AttendeeNameChanged>{

    private static final long serialVersionUID = 1L;

    public AttendeeNameChangedEventHandler(AttendeeNameChanged event){
        super(event);
    }

    @Override
    public void run() {

        DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
        Transaction transaction = datastoreService.beginTransaction();

        Key attendeeKey = KeyFactory.createKey("Attendee", event.getAttendeeId().toString());
        Entity attendee = null;

        try {
            attendee = datastoreService.get(attendeeKey);
            attendee.setProperty("FirstName", event.getFirstName());
            attendee.setProperty("LastName", event.getLastName());
            datastoreService.put(attendee);
            transaction.commit();

        } catch (EntityNotFoundException e) {
            MessageLog.log(e);
        } finally {
            if(transaction != null && transaction.isActive())