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

liquibase.snapshot.CachedRow Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package liquibase.snapshot;

import java.util.Map;

public class CachedRow {
    private Map row;

    public CachedRow(Map row) {
        this.row = row;
    }



    public Object get(String columnName) {
        return row.get(columnName);
    }

    public void set(String columnName, Object value) {
        row.put(columnName, value);
    }


    public boolean containsColumn(String columnName) {
        return row.containsKey(columnName);
    }

    public String getString(String columnName) {
        return (String) row.get(columnName);
    }

    public Integer getInt(String columnName) {
        Object o = row.get(columnName);
        if (o instanceof Number) {
            return ((Number) o).intValue();
        } else if (o instanceof String) {
            return Integer.valueOf((String) o);
        } else if (o instanceof byte[]) {
            //
            // Added this condition after finding that Clustrix (MariadDB/MySQL)
            // returns the size value as a byte[] that contains the ASCII values
            // of the numbers
            //
            return Integer.valueOf(new String((byte[]) o));
        }
        return (Integer) o;
    }

    public Short getShort(String columnName) {
        Object o = row.get(columnName);
        if (o instanceof Number) {
            return ((Number) o).shortValue();
        } else if (o instanceof String) {
            return Short.valueOf((String) o);
        }
        return (Short) o;
    }

    public Boolean getBoolean(String columnName) {
        Object o = row.get(columnName);
        if (o instanceof Number) {
            if (((Number) o).longValue() == 0) {
                return false;
            } else {
                return true;
            }
        }
        if (o instanceof String) {
            String s = (String)o;
            // Firebird JDBC driver quirk:
            // Returns "T" instead of "true" (Boolean.valueOf tests case-insensitively for "true")
            if ("T".equalsIgnoreCase(s))
                s = "TRUE";
            return Boolean.valueOf(s);
        }
        return (Boolean) o;
    }

    /**
     * Convert 'YES'/'NO' value to TRUE/FALSE
     * @nullable
     */
    public Boolean yesNoToBoolean(String columnName) {
        Object o = row.get(columnName);
        if (o instanceof String && "YES".equalsIgnoreCase((String)o)) {
            return Boolean.TRUE;
        }
        return getBoolean(columnName);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy