AMashenkov commented on a change in pull request #284: URL: https://github.com/apache/ignite-3/pull/284#discussion_r704209404
########## File path: modules/client/src/main/java/org/apache/ignite/internal/jdbc/ConnectionPropertiesImpl.java ########## @@ -0,0 +1,757 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc; + +import java.io.Serializable; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Properties; +import java.util.StringTokenizer; +import org.apache.ignite.client.IgniteClientConfiguration; +import org.apache.ignite.client.proto.query.SqlStateCode; +import org.apache.ignite.internal.client.HostAndPortRange; +import org.apache.ignite.internal.util.ArrayUtils; +import org.apache.ignite.lang.IgniteException; +import org.jetbrains.annotations.Nullable; + +/** + * Holds JDBC connection properties. + */ +public class ConnectionPropertiesImpl implements ConnectionProperties, Serializable { + /** URL prefix. */ + public static final String URL_PREFIX = "jdbc:ignite:thin://"; + + /** Serial version UID. */ + private static final long serialVersionUID = 0L; + + /** Prefix for property names. */ + public static final String PROP_PREFIX = "ignite.jdbc."; + + /** Property: schema. */ + private static final String PROP_SCHEMA = "schema"; + + /** Connection URL. */ + private String url; + + /** Addresses. */ + private HostAndPortRange[] addrs; + + /** Schema name. Hidden property. Is used to set default schema name part of the URL. */ + private final StringProperty schema = new StringProperty(PROP_SCHEMA, + "Schema name of the connection", "PUBLIC", null, false, null); + + /** Query timeout. */ + private final IntegerProperty qryTimeout = new IntegerProperty("queryTimeout", + "Sets the number of seconds the driver will wait for a <code>Statement</code> object to execute." + + " Zero means there is no limits.", + null, false, 0, Integer.MAX_VALUE); + + /** JDBC connection timeout. */ + private final IntegerProperty connTimeout = new IntegerProperty("connectionTimeout", + "Sets the number of milliseconds JDBC client will waits for server to response." + + " Zero means there is no limits.", + 0L, false, 0, Integer.MAX_VALUE); + + /** Properties array. */ + private final ConnectionProperty[] propsArray = {qryTimeout, connTimeout}; + + /** {@inheritDoc} */ + @Override public String getSchema() { + return schema.value(); + } + + /** {@inheritDoc} */ + @Override public void setSchema(String schema) { + this.schema.setValue(schema); + } + + /** {@inheritDoc} */ + @Override public String getUrl() { + if (url != null) + return url; + else { + if (ArrayUtils.nullOrEmpty(getAddresses())) + return null; + + StringBuilder sbUrl = new StringBuilder(URL_PREFIX); + + HostAndPortRange[] addrs = getAddresses(); + + for (int i = 0; i < addrs.length; i++) { + if (i > 0) + sbUrl.append(','); + + sbUrl.append(addrs[i].toString()); + } + + if (!isEmpty(getSchema())) + sbUrl.append('/').append(getSchema()); + + return sbUrl.toString(); + } + } + + /** {@inheritDoc} */ + @Override public void setUrl(String url) throws SQLException { + this.url = url; + + init(url, new Properties()); + } + + /** {@inheritDoc} */ + @Override public HostAndPortRange[] getAddresses() { + return addrs; + } + + /** {@inheritDoc} */ + @Override public void setAddresses(HostAndPortRange[] addrs) { + this.addrs = addrs; + } + + /** {@inheritDoc} */ + @Override public Integer getQueryTimeout() { + return qryTimeout.value(); + } + + /** {@inheritDoc} */ + @Override public void setQueryTimeout(@Nullable Integer timeout) throws SQLException { + qryTimeout.setValue(timeout); + } + + /** {@inheritDoc} */ + @Override public int getConnectionTimeout() { + return connTimeout.value(); + } + + /** {@inheritDoc} */ + @Override public void setConnectionTimeout(@Nullable Integer timeout) throws SQLException { + connTimeout.setValue(timeout); + } + + /** + * Init connection properties. + * + * @param url URL connection. + * @param props Environment properties. + * @throws SQLException On error. + */ + public void init(String url, Properties props) throws SQLException { Review comment: ```suggestion private void init(String url, Properties props) throws SQLException { assert props != null; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
