feat: support options property
This commit is contained in:
@ -553,8 +553,18 @@ public enum PGProperty {
|
|||||||
"if the active node is down, set the timeout threshold for searching for the active node. If the active node is not detected within this timeout period, " +
|
"if the active node is down, set the timeout threshold for searching for the active node. If the active node is not detected within this timeout period, " +
|
||||||
"the cluster is considered to have no active node and no maintenance is performed on the current cluster. This time should include the RTO time of the active node."),
|
"the cluster is considered to have no active node and no maintenance is performed on the current cluster. This time should include the RTO time of the active node."),
|
||||||
|
|
||||||
ADAPTIVE_SET_SQL_TYPE("adaptiveSetSQLType","false","Adaptively modify the inconsistent set sqlType in batch mode. If the first set sqlType is INTEGER and the second set is LONG, " +
|
/**
|
||||||
"the first one will be automatically modify to LONG")
|
* Adaptively modify the inconsistent set sqlType in batch mode. If the first set sqlType is INTEGER and
|
||||||
|
* the second set is LONG, the first one will be automatically modify to LONG
|
||||||
|
*/
|
||||||
|
ADAPTIVE_SET_SQL_TYPE("adaptiveSetSQLType", "false", "Adaptively modify the inconsistent set sqlType in batch mode. If the first set sqlType is INTEGER and" +
|
||||||
|
" the second set is LONG, the first one will be automatically modify to LONG"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify 'options' connection initialization parameter.
|
||||||
|
* The value of this parameter may contain spaces and other special characters or their URL representation.
|
||||||
|
*/
|
||||||
|
OPTIONS("options", null, "Specify 'options' connection initialization parameter."),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@ -470,6 +470,11 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
|
|||||||
if (PGProperty.PG_CLIENT_LOGIC.get(info) != null && PGProperty.PG_CLIENT_LOGIC.get(info).equals("1")) {
|
if (PGProperty.PG_CLIENT_LOGIC.get(info) != null && PGProperty.PG_CLIENT_LOGIC.get(info).equals("1")) {
|
||||||
paramList.add(new String[]{"enable_full_encryption", "1"});
|
paramList.add(new String[]{"enable_full_encryption", "1"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String options = PGProperty.OPTIONS.get(info);
|
||||||
|
if (options != null) {
|
||||||
|
paramList.add(new String[]{"options", options});
|
||||||
|
}
|
||||||
return paramList;
|
return paramList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) openGauss 2023. All rights reserved.
|
||||||
|
*
|
||||||
|
* openGauss is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
*
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.postgresql.test.jdbc2;
|
package org.postgresql.test.jdbc2;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.postgresql.test.TestUtil;
|
import org.postgresql.test.TestUtil;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class AdaptiveSetTypeTest extends BaseTest4{
|
/**
|
||||||
|
* Some simple tests url adaptiveSetSQLType
|
||||||
|
*
|
||||||
|
* @author bin.liu
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class AdaptiveSetTypeTest extends BaseTest4 {
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
@ -19,26 +41,28 @@ public class AdaptiveSetTypeTest extends BaseTest4{
|
|||||||
public void tearDown() throws SQLException {
|
public void tearDown() throws SQLException {
|
||||||
TestUtil.dropTable(con, "test_numeric");
|
TestUtil.dropTable(con, "test_numeric");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateProperties(Properties props) {
|
protected void updateProperties(Properties props) {
|
||||||
props.setProperty("adaptiveSetSQLType","true");
|
props.setProperty("adaptiveSetSQLType", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void AdaptiveSetTypeTrue() throws SQLException {
|
public void AdaptiveSetTypeTrue() throws SQLException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
Long a = new Long("2180000000");
|
Long a = new Long("2180000000");
|
||||||
try {
|
try {
|
||||||
ps = con.prepareStatement("INSERT INTO test_numeric (F_MEMBER_ID,F_REGISTER_CAPITAL) VALUES ( ?, ?)");
|
ps = con.prepareStatement("INSERT INTO test_numeric (F_MEMBER_ID,F_REGISTER_CAPITAL) VALUES ( ?, ?)");
|
||||||
ps.setString(1,"2097 ");
|
ps.setString(1, "2097 ");
|
||||||
ps.setNull(2, Types.INTEGER);
|
ps.setNull(2, Types.INTEGER);
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
ps.setString(1,"3020 " );
|
ps.setString(1, "3020 ");
|
||||||
ps.setLong(2,a);
|
ps.setLong(2, a);
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
ps.executeBatch();
|
ps.executeBatch();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}finally {
|
} finally {
|
||||||
TestUtil.closeQuietly(ps);
|
TestUtil.closeQuietly(ps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) openGauss 2023. All rights reserved.
|
||||||
|
*
|
||||||
|
* openGauss is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
*
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.postgresql.test.jdbc2;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.postgresql.test.TestUtil;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some simple tests url options
|
||||||
|
*
|
||||||
|
* @author bin.liu
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class OptionTest extends BaseTest4 {
|
||||||
|
|
||||||
|
private final String behaviorCompatOptionsName = "behavior_compat_options";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection conDB(Properties props) throws Exception {
|
||||||
|
return TestUtil.openDB(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String setOptionsAndGet(String name, String value) throws Exception {
|
||||||
|
Properties props = new Properties();
|
||||||
|
if (value != null && !value.equals("")) {
|
||||||
|
props.setProperty("options", "-c " + name + "=" + value);
|
||||||
|
}
|
||||||
|
con = conDB(props);
|
||||||
|
Statement s = con.createStatement();
|
||||||
|
ResultSet rs = s.executeQuery("show " + name);
|
||||||
|
while (rs.next()) {
|
||||||
|
return rs.getString(1);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void optionsBehaviorCompatOptions() throws Exception {
|
||||||
|
// options applied successfully
|
||||||
|
String s = setOptionsAndGet(behaviorCompatOptionsName, "");
|
||||||
|
assertEquals("", s);
|
||||||
|
// behavior_compat_options_name more option
|
||||||
|
String value = "hide_tailing_zero,display_leading_zero";
|
||||||
|
s = setOptionsAndGet(behaviorCompatOptionsName, value);
|
||||||
|
assertEquals(value, s);
|
||||||
|
// behavior_compat_options_name duplicate option
|
||||||
|
s = setOptionsAndGet(behaviorCompatOptionsName, "hide_tailing_zero,hide_tailing_zero");
|
||||||
|
assertEquals("hide_tailing_zero,hide_tailing_zero", s);
|
||||||
|
// options applied failed
|
||||||
|
optionsBehaviorCompatOptionsFailed(behaviorCompatOptionsName, "''");
|
||||||
|
optionsBehaviorCompatOptionsFailed(behaviorCompatOptionsName, "hide_tailing_zero,,");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void optionsBehaviorCompatOptionsFailed(String name, String value) throws Exception {
|
||||||
|
Properties props = new Properties();
|
||||||
|
String s = name + "=" + value;
|
||||||
|
props.setProperty("options", "-c " + s);
|
||||||
|
Connection con1 = null;
|
||||||
|
try {
|
||||||
|
con1 = conDB(props);
|
||||||
|
Assert.fail("set options " + s);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// Ignored.
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (con1 != null) {
|
||||||
|
con1.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user