File: ExtensionsSuite.java

package info (click to toggle)
libpgjava 9.2-1002-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,308 kB
  • ctags: 4,503
  • sloc: java: 37,623; xml: 3,376; makefile: 22; sh: 10
file content (60 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*-------------------------------------------------------------------------
*
* Copyright (c) 2007-2011, PostgreSQL Global Development Group
*
*
*-------------------------------------------------------------------------
*/
package org.postgresql.test.extensions;

import junit.framework.TestSuite;

import java.sql.*;
import org.postgresql.test.TestUtil;

/*
 * Executes all known tests for PostgreSQL extensions supported by JDBC driver
 */
public class ExtensionsSuite extends TestSuite
{

    /*
     * The main entry point for JUnit
     */
    public static TestSuite suite() throws Exception
    {
        Class.forName("org.postgresql.Driver");
        TestSuite suite = new TestSuite();
        
        Connection connection = TestUtil.openDB();
        try
        {
            if (isHStoreEnabled(connection)) {
              suite.addTestSuite(HStoreTest.class);
            }
        }
        finally
        {
            connection.close();
        }

        return suite;
    }

    /**
     * Not all servers have hstore extensions installed.
     */
    private static boolean isHStoreEnabled(Connection conn) {
        try {
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT 'a=>1'::hstore::text");
            rs.close();
            stmt.close();
            return true;
        } catch (SQLException sqle) {
            return false;
        }
    }

}