TableColumnBoolean.java [src/soils/db/tables] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package soils.db.tables;
import static csip.ModelDataService.KEY_UNIT;
import soils.utils.EvalResult;
import csip.api.server.ServiceException;
import csip.utils.JSONUtils;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
/**
*
* @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
*/
public class TableColumnBoolean extends TableColumn<Boolean> {
public TableColumnBoolean(String[] nameDesc) {
super(nameDesc);
value = EvalResult.getDefaultBoolean();
}
public TableColumnBoolean(String name, String desc) {
super(name, desc);
value = EvalResult.getDefaultBoolean();
}
public TableColumnBoolean(String name, String desc, String unit) {
super(name, desc, unit);
value = EvalResult.getDefaultBoolean();
}
public TableColumnBoolean(String name, String desc, String unit, String format) {
super(name, desc, unit, format);
value = EvalResult.getDefaultBoolean();
}
@Override
protected void readSQLValue(ResultSet results) throws SQLException {
value = EvalResult.getBoolean(results, name);
}
@Override
public void valueFromJSON(JSONObject dataJSON) throws ServiceException {
foundInJSON = true;
value = EvalResult.getBooleanValue(dataJSON);
}
@Override
public JSONObject toJSON() throws JSONException {
JSONObject ret_val = null;
if (includeInOutput()) {
foundInJSON = true;
if ((null != unit) && (!unit.isEmpty())) {
ret_val = JSONUtils.data(name, EvalResult.writeBoolean(value), description, unit);
} else {
ret_val = JSONUtils.dataDesc(name, EvalResult.writeBoolean(value), description);
}
}
return ret_val;
}
@Override
public JSONObject toBasicJSON() throws JSONException {
JSONObject ret_val = null;
if (includeInOutput()) {
foundInJSON = true;
if ((null != unit) && (!unit.isEmpty())) {
ret_val.put(name,EvalResult.writeBoolean(value));
ret_val.put( KEY_UNIT, unit);
} else {
ret_val.put(name,EvalResult.writeBoolean(value));
}
}
return ret_val;
}
@Override
public String toWriteString(){
return EvalResult.writeBoolean(value);
}
}