package com.venky.swf.db.annotations.column.defaulting;

import java.sql.Date;
import java.sql.Timestamp;

import com.venky.swf.db.Database;
import com.venky.swf.db.annotations.column.COLUMN_DEF;
import com.venky.swf.db.model.User;

public class StandardDefaulter {
	public static Object getDefaultValue(COLUMN_DEF columnDef){
		return getDefaultValue(columnDef.value(), columnDef.someValue());
	}
	public static Object getDefaultValue(StandardDefault defaultKey){
		return getDefaultValue(defaultKey,"");
	}
	public static Object getDefaultValue(StandardDefault defaultKey,String someValue){
		Object ret = null;
		switch (defaultKey){
			case NULL:
				ret = null;
				break;
			case ONE:
				ret = 1;
				break;
			case ZERO:
				ret = 0;
				break;
			case CURRENT_USER:
				User user = Database.getInstance().getCurrentUser();
				ret = user == null ? 0 : user.getId();
				break;
			case CURRENT_DATE:
				ret = new Date(System.currentTimeMillis());
				break;
			case CURRENT_TIMESTAMP:
				ret = new Timestamp(System.currentTimeMillis());
				break;
			case BOOLEAN_FALSE: 
				ret = false; 
				break;
			case BOOLEAN_TRUE:
				ret = true; 
				break;
			case SOME_VALUE:
				ret = someValue;
				break;
		}
		return ret;
	}
	
}

@@ -850,17 +850,17 @@
  null ? 
-0
+1
  : user.

Id 1 is root