I have a Postgres table, from which I want to get one row. This is necessary for my ‘registration’ procedure, that I need to get up quickly, and as a prototype for the rest of my project.
It has taken forever, as those of you who have read my rants and requests, know, to get this far.
My table:
CREATE TABLE public.customer
(
customerid bigint NOT NULL,
customer text,
password_open text,
password_encrypted text,
buyfor1 bigint,
buyfor2 bigint,
buyfor3 bigint,
buyfor4 bigint,
buyfor5 bigint,
lastchanged_date timestamp without time zone,
created_date timestamp without time zone,
CONSTRAINT customer_pkey PRIMARY KEY (customerid)
)
WITH (
OIDS=FALSE
);
Pretty simple that.
I have attached a simple (not for me, but for others) process (bos file) that reads, successfully one row. It packages it up nicely, as I think it should.
But I still can’t get the data out of it. The error “Declared return type class java.lang.String is not compatible with evaluated type class java.util.ArrayList for expression scrGetPostgresData” doesn’t make sense as I don’t have a String involved at this point.
My script is pretty simple to get the data, and it is returned using JsonBuilder:
import groovy.json.JsonBuilder;
import groovy.sql.Sql;
import java.sql.Driver;
List<Object> result = new ArrayList<Object>();
String query = "SELECT customerid, customer, password_open, buyfor1, created_date " +
"FROM customer " +
"LIMIT 1;";
Sql sql = BonitaSql.newInstance("jdbc:postgresql://172.17.0.2:5432/HFDataProd", "bonita_db_user","bpm", new org.postgresql.Driver());
sql.eachRow(query) { row ->
def builder = new JsonBuilder();
def line = builder{
customerid row.customerid.toInteger();
customer row.customer;
password_open row.password_open;
buyfor1 row.buyfor1.toString() == "null" ? ("0").toInteger() : row.buyfor1.toInteger();
created_date row.created_date;
}
result.add(line);
}
return result;</code>
My output target is also defined using JsonBulder. I’d think that JsonBuilder to JsonBuilder should work…
import groovy.json.JsonBuilder;
def builder = new JsonBuilder();
def line = builder{
customerid (“0”).toInteger();
customer null;
password_open null;
buyfor1 (“0”).toInteger();
created_date null;
}
return line;</code>
But it doesn’t. Can someone revise my thinking so that I can get data in and out? For this exercise, if I could have, I would have displayed my row as a table in Step 2…
THANKS!