Re: Fw: mapping java objects with postgresql types

From: Andreas Joseph Krogh <andreas(at)visena(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Fw: mapping java objects with postgresql types
Date: 2015-01-23 14:52:23
Message-ID: VisenaEmail.b2.b8c2a9e5722fd824.14b174100f3@tc7-visena
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

På fredag 23. januar 2015 kl. 15:36:52, skrev Oussema Benjemaa <
ousema2003(at)yahoo(dot)fr <mailto:ousema2003(at)yahoo(dot)fr>>:   i downloaded this JAR
pgjdbc-ng-0.3-complete.jar ... i'm asking if there is exemple for mapping java
objects to postgresql ... with this api   You should use 0.4:
https://github.com/impossibl/pgjdbc-ng/releases   Simple example of returning
an array of project name-id pairs for all parent-projects: CREATE TYPE
BigIntVarCharAS (f1 bigint, f2 varchar); SELECT ARRAY(WITH RECURSIVE t AS (
SELECT 1 AS level, p.entity_id, p.id, p.parent_id, p.name FROM onp_crm_project p
WHEREp.entity_id = project.entity_id UNION ALL SELECT t.level + 1, c.entity_id,
c.id, c.parent_id, c.name FROM onp_crm_project c JOIN t ON c.id = t.parent_id)
SELECT ROW (t.entity_id, t.name) :: BigIntVarChar FROM t ORDER BY level DESC) AS
project_parent_array I use a class like this: import java.sql.{SQLOutput,
SQLInput, SQLData} class BigIntVarcharJdbcData extends SQLData { var id: Long =
0 var name: String = null var sqlType: String = null override def
getSQLTypeName:String = { sqlType } override def writeSQL(stream: SQLOutput):
Unit = { stream.writeLong(id) stream.writeNString(name) } override def
readSQL(stream:SQLInput, typeName: String): Unit = { sqlType = typeName id =
stream.readLong()name = stream.readString() } } val typeMap = { val h = new
HashMap[String, Class[_]]() h.put("bigintvarchar", classOf[BigIntVarcharJdbcData
])Collections.unmodifiableMap[String, Class[_]](h) } rs.getObject(
"project_parent_array", RowMapperHelper.typeMap).asInstanceOf[Array[
BigIntVarcharJdbcData]]   -- Andreas Joseph Krogh CTO / Partner - Visena AS
Mobile: +47 909 56 963 andreas(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com> <https://www.visena.com>  

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kevin Wooten 2015-01-23 16:08:05 Re: Fw: mapping java objects with postgresql types
Previous Message Dave Cramer 2015-01-23 14:41:39 Re: Fw: mapping java objects with postgresql types