All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avaje.ebeaninternal.server.query.DefaultSqlRow Maven / Gradle / Ivy

There is a newer version: 8.1.1
Show newest version
package com.avaje.ebeaninternal.server.query;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import com.avaje.ebean.SqlQuery;
import com.avaje.ebean.SqlRow;
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;

/**
 * Used to return raw SQL query results.
 * 

* Refer to {@link SqlQuery} for examples. *

*

* There are convenience methods such as getInteger(), getBigDecimal() etc. The * reason for these methods is that the values put into this map often come * straight from the JDBC resultSet. Depending on the JDBC driver it may put a * different type into a given property. For example an Integer, BigDecimal, * Double could all be put into a property depending on the JDBC driver used. * These convenience methods automatically convert the value as required * returning the type you expect. *

*/ public class DefaultSqlRow implements SqlRow { static final long serialVersionUID = -3120927797041336242L; private final String dbTrueValue; /** * The underlying map of property data. */ final Map map; /** * Create with an initialCapacity and loadFactor. *

* The defaults of these are 16 and 0.75. *

*

* Note that the Map will rehash the contents when the number of keys in * this map reaches its threshold (initialCapacity * loadFactor). *

*/ public DefaultSqlRow(int initialCapacity, float loadFactor, String dbTrueValue) { this.map = new LinkedHashMap(initialCapacity, loadFactor); this.dbTrueValue = dbTrueValue; } public Iterator keys() { return map.keySet().iterator(); } public Object remove(Object name) { name = ((String) name).toLowerCase(); return map.remove(name); } public Object get(Object name) { name = ((String) name).toLowerCase(); return map.get(name); } public Object put(String name, Object value) { return setInternal(name, value); } public Object set(String name, Object value) { return setInternal(name, value); } private Object setInternal(String name, Object newValue) { // MapBean properties are always lowercase name = name.toLowerCase(); // valueList = null; return map.put(name, newValue); } public UUID getUUID(String name) { Object val = get(name); return BasicTypeConverter.toUUID(val); } public Boolean getBoolean(String name) { Object val = get(name); return BasicTypeConverter.toBoolean(val, dbTrueValue); } public Integer getInteger(String name) { Object val = get(name); return BasicTypeConverter.toInteger(val); } public BigDecimal getBigDecimal(String name) { Object val = get(name); return BasicTypeConverter.toBigDecimal(val); } public Long getLong(String name) { Object val = get(name); return BasicTypeConverter.toLong(val); } public Double getDouble(String name) { Object val = get(name); return BasicTypeConverter.toDouble(val); } public Float getFloat(String name) { Object val = get(name); return BasicTypeConverter.toFloat(val); } public String getString(String name) { Object val = get(name); return BasicTypeConverter.toString(val); } public java.util.Date getUtilDate(String name) { Object val = get(name); return BasicTypeConverter.toUtilDate(val); } public Date getDate(String name) { Object val = get(name); return BasicTypeConverter.toDate(val); } public Timestamp getTimestamp(String name) { Object val = get(name); return BasicTypeConverter.toTimestamp(val); } public String toString() { return map.toString(); } // ------------------------------------ // Normal map methods... public void clear() { map.clear(); } public boolean containsKey(Object key) { key = ((String) key).toLowerCase(); return map.containsKey(key); } public boolean containsValue(Object value) { return map.containsValue(value); } public Set> entrySet() { return map.entrySet(); } public boolean isEmpty() { return map.isEmpty(); } public Set keySet() { return map.keySet(); } public void putAll(Map t) { map.putAll(t); } public int size() { return map.size(); } public Collection values() { return map.values(); } }