forked from pgjdbc/pgjdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseTest4.java
130 lines (104 loc) · 3.5 KB
/
BaseTest4.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (c) 2004, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.test.jdbc2;
import org.postgresql.PGConnection;
import org.postgresql.PGProperty;
import org.postgresql.core.Version;
import org.postgresql.jdbc.PreferQueryMode;
import org.postgresql.test.TestUtil;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
public class BaseTest4 {
public enum BinaryMode {
REGULAR, FORCE
}
public enum ReWriteBatchedInserts {
YES, NO
}
public enum AutoCommit {
YES, NO
}
public enum StringType {
UNSPECIFIED, VARCHAR;
}
protected Connection con;
private BinaryMode binaryMode;
private ReWriteBatchedInserts reWriteBatchedInserts;
protected PreferQueryMode preferQueryMode;
private StringType stringType;
protected void updateProperties(Properties props) {
if (binaryMode == BinaryMode.FORCE) {
forceBinary(props);
}
if (reWriteBatchedInserts == ReWriteBatchedInserts.YES) {
PGProperty.REWRITE_BATCHED_INSERTS.set(props, true);
}
if (stringType != null) {
PGProperty.STRING_TYPE.set(props, stringType.name().toLowerCase());
}
}
protected void forceBinary(Properties props) {
PGProperty.PREPARE_THRESHOLD.set(props, -1);
}
public final void setBinaryMode(BinaryMode binaryMode) {
this.binaryMode = binaryMode;
}
public StringType getStringType() {
return stringType;
}
public void setStringType(StringType stringType) {
this.stringType = stringType;
}
public void setReWriteBatchedInserts(
ReWriteBatchedInserts reWriteBatchedInserts) {
this.reWriteBatchedInserts = reWriteBatchedInserts;
}
@Before
public void setUp() throws Exception {
Properties props = new Properties();
updateProperties(props);
con = TestUtil.openDB(props);
PGConnection pg = con.unwrap(PGConnection.class);
preferQueryMode = pg == null ? PreferQueryMode.EXTENDED : pg.getPreferQueryMode();
}
@After
public void tearDown() throws SQLException {
TestUtil.closeDB(con);
}
public void assumeByteaSupported() {
Assume.assumeTrue("bytea is not supported in simple protocol execution mode",
preferQueryMode.compareTo(PreferQueryMode.EXTENDED) >= 0);
}
public void assumeCallableStatementsSupported() {
Assume.assumeTrue("callable statements are not fully supported in simple protocol execution mode",
preferQueryMode.compareTo(PreferQueryMode.EXTENDED) >= 0);
}
public void assumeBinaryModeRegular() {
Assume.assumeTrue(binaryMode == BinaryMode.REGULAR);
}
public void assumeBinaryModeForce() {
Assume.assumeTrue(binaryMode == BinaryMode.FORCE);
Assume.assumeTrue(preferQueryMode != PreferQueryMode.SIMPLE);
}
public void assumeNotSimpleQueryMode() {
Assume.assumeTrue(preferQueryMode != PreferQueryMode.SIMPLE);
}
/**
* Shorthand for {@code Assume.assumeTrue(TestUtil.haveMinimumServerVersion(conn, version)}.
*/
public void assumeMinimumServerVersion(String message, Version version) throws SQLException {
Assume.assumeTrue(message, TestUtil.haveMinimumServerVersion(con, version));
}
/**
* Shorthand for {@code Assume.assumeTrue(TestUtil.haveMinimumServerVersion(conn, version)}.
*/
public void assumeMinimumServerVersion(Version version) throws SQLException {
Assume.assumeTrue(TestUtil.haveMinimumServerVersion(con, version));
}
}