package sur.snapps.sentoff.domain.table;

import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;

import sur.snapps.sentoff.domain.Message;
import sur.snapps.sentoff.domain.repo.MessageRowMapper;
import sur.snapps.sentoff.domain.repo.Table;

/**
 * @author sur
 * @since 02/01/2017
 */
public class MessagesTable implements Table<Message> {

	@Override
	public RowMapper<Message> getRowMapper() {
		return new MessageRowMapper();
	}
	
    public Map<String, Object> getInsertValues(Message message) {
        Map<String, Object> values = new HashMap<>();
        values.put("request_timestamp", message.getRequestTimestamp());
        values.put("request_uri", message.getRequestUri());
        values.put("request_method", message.getRequestMethod());
        values.put("request_payload", message.getRequestPayload());
        return values;
    }
    
    public Map<String, Object> getUpdateValues(Message message) {
    	Map<String, Object> values = new HashMap<>();
    	addIfNotNull(values, "request_payload", message.getRequestPayload());
    	addIfNotNull(values, "response_timestamp", message.getResponseTimestamp());
    	addIfNotNull(values, "response_status", message.getResponseStatus());
    	addIfNotNull(values, "response_payload", message.getResponsePayload());
    	return values;
    }
    
    private void addIfNotNull(Map<String, Object> values, String key, Object value) {
    	if (value != null) {
    		values.put(key, value);
    	}
    }

    @Override
    public String getTableName() {
        return "MESSAGES";
    }
}

@@ -35,16 +35,43 @@
 table;%0A%0A
+import java.sql.Timestamp;%0A
 import j
@@ -88,16 +88,16 @@
 ashMap;%0A
-
 import j
@@ -649,32 +649,50 @@
 est_timestamp%22, 
+Timestamp.valueOf(
 message.getReque
@@ -701,24 +701,25 @@
 Timestamp())
+)
 ;%0A        va
@@ -1176,16 +1176,34 @@
 stamp%22, 
+Timestamp.valueOf(
 message.
@@ -1225,16 +1225,17 @@
 stamp())
+)
 ;%0A    %09a

fix tests