Re: Fw: mapping java objects with postgresql types

Поиск
Список
Период
Сортировка
От Andreas Joseph Krogh
Тема Re: Fw: mapping java objects with postgresql types
Дата
Msg-id VisenaEmail.b2.b8c2a9e5722fd824.14b174100f3@tc7-visena
обсуждение исходный текст
Ответ на Re: Fw: mapping java objects with postgresql types  (Oussema Benjemaa <ousema2003@yahoo.fr>)
Список pgsql-jdbc
På fredag 23. januar 2015 kl. 15:36:52, skrev Oussema Benjemaa <ousema2003@yahoo.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 BigIntVarChar AS (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                                  WHERE p.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
 
Вложения

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: Fw: mapping java objects with postgresql types
Следующее
От: Kevin Wooten
Дата:
Сообщение: Re: Fw: mapping java objects with postgresql types