Search in sources :

Example 1 with PgInterval

use of ca.nrc.cadc.dali.postgresql.PgInterval in project caom2db by opencadc.

the class PostgreSQLGenerator method getSubIntervalList.

@Override
protected List<Interval> getSubIntervalList(ResultSet rs, int col) throws SQLException {
    String s = rs.getString(col);
    if (s == null) {
        return null;
    }
    PgInterval pgi = new PgInterval();
    ca.nrc.cadc.dali.DoubleInterval[] dis = pgi.getIntervalArray(s);
    List<Interval> ret = new ArrayList<Interval>();
    for (ca.nrc.cadc.dali.DoubleInterval di : dis) {
        ret.add(new Interval(di.getLower(), di.getUpper()));
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) PgInterval(ca.nrc.cadc.dali.postgresql.PgInterval) PgInterval(ca.nrc.cadc.dali.postgresql.PgInterval) Interval(ca.nrc.cadc.caom2.types.Interval) SampledInterval(ca.nrc.cadc.caom2.types.SampledInterval)

Example 2 with PgInterval

use of ca.nrc.cadc.dali.postgresql.PgInterval in project caom2db by opencadc.

the class PostgreSQLGenerator method safeSetSubIntervalList.

/**
 * Store a list of intervals in a polygon column.
 *
 * @param sb
 * @param ps
 * @param col
 * @param subs
 * @throws SQLException
 */
@Override
protected void safeSetSubIntervalList(StringBuilder sb, PreparedStatement ps, int col, List<Interval> subs) throws SQLException {
    if (subs == null || subs.isEmpty()) {
        ps.setObject(col, null);
        if (sb != null) {
            sb.append("null,");
        }
    } else {
        log.debug("[safeSetSubIntervalList] in: " + subs.size() + " Intervals");
        ca.nrc.cadc.dali.DoubleInterval[] dis = new ca.nrc.cadc.dali.DoubleInterval[subs.size()];
        int i = 0;
        for (Interval si : subs) {
            dis[i++] = new ca.nrc.cadc.dali.DoubleInterval(si.getLower(), si.getUpper());
        }
        PgInterval pgi = new PgInterval();
        PGpolygon poly = pgi.generatePolygon2D(dis);
        ps.setObject(col, poly);
        if (sb != null) {
            sb.append(poly.getValue());
            sb.append(",");
        }
    }
}
Also used : PGpolygon(org.postgresql.geometric.PGpolygon) PgInterval(ca.nrc.cadc.dali.postgresql.PgInterval) PgSpoint(ca.nrc.cadc.dali.postgresql.PgSpoint) Point(ca.nrc.cadc.caom2.types.Point) PgInterval(ca.nrc.cadc.dali.postgresql.PgInterval) Interval(ca.nrc.cadc.caom2.types.Interval) SampledInterval(ca.nrc.cadc.caom2.types.SampledInterval)

Example 3 with PgInterval

use of ca.nrc.cadc.dali.postgresql.PgInterval in project caom2db by opencadc.

the class PostgreSQLGenerator method safeSetSampledInterval.

/**
 * Store an interval in a polygon column.
 *
 * @param sb
 * @param ps
 * @param col
 * @param val
 * @throws SQLException
 */
@Override
protected void safeSetSampledInterval(StringBuilder sb, PreparedStatement ps, int col, SampledInterval val) throws SQLException {
    if (val == null) {
        ps.setObject(col, null);
        if (sb != null) {
            sb.append("null,");
        }
    } else {
        log.debug("[safeSetSampledInterval] in: " + val);
        PgInterval pgi = new PgInterval();
        PGpolygon poly = pgi.generatePolygon2D(new ca.nrc.cadc.dali.DoubleInterval(val.getLower(), val.getUpper()));
        ps.setObject(col, poly);
        if (sb != null) {
            sb.append(poly.getValue());
            sb.append(",");
        }
    }
}
Also used : PGpolygon(org.postgresql.geometric.PGpolygon) PgInterval(ca.nrc.cadc.dali.postgresql.PgInterval)

Example 4 with PgInterval

use of ca.nrc.cadc.dali.postgresql.PgInterval in project caom2db by opencadc.

the class PostgreSQLGenerator method safeSetInterval.

@Override
protected void safeSetInterval(StringBuilder sb, PreparedStatement ps, int col, Interval val) throws SQLException {
    if (val == null) {
        ps.setObject(col, null);
        if (sb != null) {
            sb.append("null,");
        }
    } else {
        log.debug("[safeSetInterval] in: " + val);
        PgInterval pgi = new PgInterval();
        PGpolygon poly = pgi.generatePolygon2D(new ca.nrc.cadc.dali.DoubleInterval(val.getLower(), val.getUpper()));
        ps.setObject(col, poly);
        if (sb != null) {
            sb.append(poly.getValue());
            sb.append(",");
        }
    }
}
Also used : PGpolygon(org.postgresql.geometric.PGpolygon) PgInterval(ca.nrc.cadc.dali.postgresql.PgInterval)

Example 5 with PgInterval

use of ca.nrc.cadc.dali.postgresql.PgInterval in project caom2db by opencadc.

the class PostgreSQLGenerator method getInterval.

@Override
protected SampledInterval getInterval(ResultSet rs, int col) throws SQLException {
    String s = rs.getString(col);
    if (s == null) {
        return null;
    }
    PgInterval pgi = new PgInterval();
    ca.nrc.cadc.dali.DoubleInterval di = pgi.getInterval(s);
    return new SampledInterval(di.getLower(), di.getUpper());
}
Also used : SampledInterval(ca.nrc.cadc.caom2.types.SampledInterval) PgInterval(ca.nrc.cadc.dali.postgresql.PgInterval)

Aggregations

PgInterval (ca.nrc.cadc.dali.postgresql.PgInterval)5 SampledInterval (ca.nrc.cadc.caom2.types.SampledInterval)3 PGpolygon (org.postgresql.geometric.PGpolygon)3 Interval (ca.nrc.cadc.caom2.types.Interval)2 Point (ca.nrc.cadc.caom2.types.Point)1 PgSpoint (ca.nrc.cadc.dali.postgresql.PgSpoint)1 ArrayList (java.util.ArrayList)1