Permalink
Browse files

[core] Append operation, to directly append values to row list:

```java
RowList2<String,Integer> list = new RowList2<String,Integer>();
list.append("cell1", 2);
```
  • Loading branch information...
cchantep
cchantep committed Oct 31, 2013
1 parent 1ff9768 commit 3747ba9c82c25b5741ac3129a4e2fb410b5404c0
@@ -90,6 +90,13 @@ public RowList1(final Class<A> c1) {
*/
public Map<String,Integer> getColumnLabels() { return this.colNames; }
/**
* Convinience append.
*/
public RowList1<A> append(final A value) {
return append(new Row1<A>(value));
} // end of append
/**
* {@inheritDoc}
*/
@@ -101,13 +108,6 @@ public RowList1(final Class<A> c1) {
return new RowList1<A>(this.c1, copy, this.colNames);
} // end of append
/**
* Convinience append.
*/
public RowList1<A> append(final A value) {
return append(new Row1<A>(value));
} // end of append
/**
* {@inheritDoc}
*/
@@ -1,3 +1,4 @@
// -*- mode: java -*-
package acolyte;
import java.util.Collections;
@@ -1,3 +1,4 @@
// -*- mode: java -*-
package acolyte;
import java.util.Collections;
@@ -80,6 +81,15 @@ public final class RowList#N#<#CP#> extends RowList<Row#N#<#CP#>> {
*/
public Map<String,Integer> getColumnLabels() { return this.colNames; }
/**
* Appends row with with given values.
*
* @see #append(acolyte.Row)
*/
public RowList#N#<#CP#> append(#AP#) {
return append(new Row#N#<#CP#>(#AV#));
} // end of append
/**
* {@inheritDoc}
*/
@@ -72,7 +72,7 @@ public QueryResult apply(String sql,
return rowList3(String.class, Float.class, Date.class).
withLabel(1, "String"). // Optional: set labels
withLabel(3, "Date").
append(row3("str", 1.2f, new Date(1l))).
append("str", 1.2f, new Date(1l)).
append(row3("val", 2.34f, new Date(2l))).
asResult();
}
@@ -283,7 +283,8 @@ object RowListSpec extends Specification with RowListTest {
}
"be expected one" in {
lazy val rs = (new RowList1(classOf[Long]).append(row1(123.toLong))).resultSet
lazy val rs = (new RowList1(classOf[Long]).
append(row1(123.toLong))).resultSet
rs.next
rs.getObject(1) aka "cell1" mustEqual 123.toLong
@@ -303,7 +304,8 @@ object RowListSpec extends Specification with RowListTest {
}
"not be read with invalid index" in {
lazy val rs = new RowList1(classOf[Long]).append(row1(123.toLong)).resultSet
lazy val rs = new RowList1(classOf[Long]).append(row1(123.toLong)).
resultSet
rs.next
rs.getObject(2) aka "getObject" must throwA[SQLException](
View
@@ -127,6 +127,7 @@ public final class Rows {""")
colClasses.add(c%d);""".format(i, i, i)
}
val ca = for (i 0 until n) yield "c%d".format(i)
val ap = cp map { l "final %s %s".format(l, l.toLowerCase) }
val ps = for (i 0 until n) yield {
"""/**
* Class of column #%d
@@ -141,6 +142,8 @@ public final class Rows {""")
w.append(l.replaceAll("#N#", n.toString).
replaceAll("#CP#", cp.mkString(",")).
replaceAll("#CS#", cs.mkString(", ")).
replaceAll("#AP#", ap.mkString(", ")).
replaceAll("#AV#", cp.map(_.toLowerCase).mkString(", ")).
replaceAll("#PS#", ps.mkString("\r\n\r\n ")).
replaceAll("#IC#", ic.mkString("\r\n\r\n ")).
replaceAll("#AC#", ac.mkString("\r\n\r\n ")).
View
@@ -92,7 +92,7 @@ StatementHandler handler = new CompositeHandler().
RowList3<String, Float, Date> rows =
rowList3(String.class, Float.class, Date.class).
withLabel(1, "String").withLabel(3, "Date"). // Optional: set labels
append(row3("str", 1.2f, new Date(1, 2, 3))).
append("str", 1.2f, new Date(1, 2, 3)). // values append
append(row3("val", 2.34f, new Date(4, 5, 6)));
return rows.asResult();

0 comments on commit 3747ba9

Please sign in to comment.