001/* 002 * Copyright (c) 2004-2013 Tada AB and other contributors, as listed below. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the The BSD 3-Clause License 006 * which accompanies this distribution, and is available at 007 * http://opensource.org/licenses/BSD-3-Clause 008 * 009 * Contributors: 010 * Tada AB 011 */ 012package org.postgresql.pljava.example; 013 014import java.sql.Connection; 015import java.sql.DriverManager; 016import java.sql.ResultSet; 017import java.sql.SQLException; 018import java.sql.Statement; 019import java.util.ArrayList; 020import java.util.Iterator; 021 022/** 023 * This implementation uses another function that returns a set of a complex 024 * type, concatenates the name and value of that type and returns this as a set 025 * of a scalar type. Somewhat cumbersome way to display properties but it's a 026 * good test. 027 * 028 * @author Thomas Hallgren 029 */ 030public class UsingPropertiesAsScalarSet { 031 public static Iterator<String> getProperties() throws SQLException { 032 StringBuffer bld = new StringBuffer(); 033 ArrayList<String> list = new ArrayList<>(); 034 Connection conn = DriverManager 035 .getConnection("jdbc:default:connection"); 036 Statement stmt = conn.createStatement(); 037 try { 038 ResultSet rs = stmt 039 .executeQuery("SELECT name, value FROM propertyExample()"); 040 try { 041 while (rs.next()) { 042 bld.setLength(0); 043 bld.append(rs.getString(1)); 044 bld.append(" = "); 045 bld.append(rs.getString(2)); 046 list.add(bld.toString()); 047 } 048 return list.iterator(); 049 } finally { 050 try { 051 rs.close(); 052 } catch (SQLException e) { 053 } 054 } 055 } finally { 056 try { 057 stmt.close(); 058 } catch (SQLException e) { 059 } 060 } 061 } 062}