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;
}
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(",");
}
}
}
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(",");
}
}
}
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(",");
}
}
}
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());
}
Aggregations