Skip to content

Commit cd3f9af

Browse files
committed
Added interfaces for new query attributes classes.
1 parent a1a5ccd commit cd3f9af

File tree

6 files changed

+177
-14
lines changed

6 files changed

+177
-14
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License, version 2.0, as published by the
6+
* Free Software Foundation.
7+
*
8+
* This program is also distributed with certain software (including but not
9+
* limited to OpenSSL) that is licensed under separate terms, as designated in a
10+
* particular file or component or in included license documentation. The
11+
* authors of MySQL hereby grant you an additional permission to link the
12+
* program and your derivative works with the separately licensed software that
13+
* they have included with MySQL.
14+
*
15+
* Without limiting anything contained in the foregoing, this file, which is
16+
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
17+
* version 1.0, a copy of which can be found at
18+
* http://oss.oracle.com/licenses/universal-foss-exception.
19+
*
20+
* This program is distributed in the hope that it will be useful, but WITHOUT
21+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
23+
* for more details.
24+
*
25+
* You should have received a copy of the GNU General Public License along with
26+
* this program; if not, write to the Free Software Foundation, Inc.,
27+
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
*/
29+
30+
package com.mysql.cj;
31+
32+
/**
33+
* An internal representation of a query attribute bind value.
34+
*
35+
*/
36+
public interface QueryAttributesBindValue {
37+
/**
38+
* Checks whether this query attribute is the <code>null</code> value.
39+
*
40+
* @return
41+
* <code>true</code> if this query attribute value is <code>null</code>.
42+
*/
43+
boolean isNull();
44+
45+
/**
46+
* Gets the name of this query attribute.
47+
*
48+
* @return
49+
* the name of this query attribute.
50+
*/
51+
String getName();
52+
53+
/**
54+
* Gets the type of this query attribute. Query attributes types are one of the {@link MysqlType}.FIELD_TYPE_*.
55+
*
56+
* @return
57+
* the type of this query attribute.
58+
*/
59+
int getType();
60+
61+
/**
62+
* Gets the value of this query attribute.
63+
*
64+
* @return
65+
* the value of this query attribute.
66+
*/
67+
Object getValue();
68+
69+
/**
70+
* Gets the length of this query attribute.
71+
*
72+
* @return
73+
* the expected length, in Bytes, of this query attribute value after being encoded.
74+
*/
75+
long getBoundLength();
76+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License, version 2.0, as published by the
6+
* Free Software Foundation.
7+
*
8+
* This program is also distributed with certain software (including but not
9+
* limited to OpenSSL) that is licensed under separate terms, as designated in a
10+
* particular file or component or in included license documentation. The
11+
* authors of MySQL hereby grant you an additional permission to link the
12+
* program and your derivative works with the separately licensed software that
13+
* they have included with MySQL.
14+
*
15+
* Without limiting anything contained in the foregoing, this file, which is
16+
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
17+
* version 1.0, a copy of which can be found at
18+
* http://oss.oracle.com/licenses/universal-foss-exception.
19+
*
20+
* This program is distributed in the hope that it will be useful, but WITHOUT
21+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
23+
* for more details.
24+
*
25+
* You should have received a copy of the GNU General Public License along with
26+
* this program; if not, write to the Free Software Foundation, Inc.,
27+
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
*/
29+
30+
package com.mysql.cj;
31+
32+
import java.sql.Statement;
33+
import java.util.function.Consumer;
34+
35+
/**
36+
* Instances of this interface keep the list of query attributes assigned to a {@link Statement} object.
37+
*/
38+
public interface QueryAttributesBindings {
39+
/**
40+
* Adds a new query attribute to the list of query attributes. Implementations must validate the type of the given the object and reject it or replace it by
41+
* another representation if not supported, by its String version, for example. Query attribute names are not checked for duplication.
42+
*
43+
* @param name
44+
* the query attribute name.
45+
*
46+
* @param value
47+
* the query attribute value.
48+
*/
49+
void setAttribute(String name, Object value);
50+
51+
/**
52+
* Get the count of query attributes in the list.
53+
*
54+
* @return
55+
* the number of query attributes existing in the list.
56+
*/
57+
int getCount();
58+
59+
/**
60+
* Returns an internal representation of the query attribute in the given position of the query attributes list. It's implementation dependent what to do
61+
* when the index value is invalid.
62+
*
63+
* @param index
64+
* the position of the query attribute value to return.
65+
*
66+
* @return
67+
* the {@link QueryAttributesBindValue} in the given position of the query attributes list.
68+
*/
69+
QueryAttributesBindValue getAttributeValue(int index);
70+
71+
/**
72+
* Runs through all query attributes while feeding the given {@link Consumer} with each one of them.
73+
*
74+
* @param bindAttribute
75+
* A {@link Consumer} for each one of the single query attributes.
76+
*/
77+
void runThroughAll(Consumer<QueryAttributesBindValue> bindAttribute);
78+
79+
/**
80+
* Removes all query attributes from the query attributes list.
81+
*/
82+
void clearAttributes();
83+
}

src/main/core-impl/java/com/mysql/cj/AbstractQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public AbstractQuery(NativeSession sess) {
9898
this.session = sess;
9999
this.maxAllowedPacket = sess.getPropertySet().getIntegerProperty(PropertyKey.maxAllowedPacket);
100100
this.charEncoding = sess.getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue();
101-
this.queryAttributesBindings = new QueryAttributesBindings();
101+
this.queryAttributesBindings = new NativeQueryAttributesBindings();
102102
}
103103

104104
@Override

src/main/core-impl/java/com/mysql/cj/QueryAttributesBindValue.java renamed to src/main/core-impl/java/com/mysql/cj/NativeQueryAttributesBindValue.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444
import java.util.Optional;
4545

4646
import com.mysql.cj.protocol.a.NativeConstants;
47-
import com.mysql.cj.util.StringUtils;
4847

49-
public class QueryAttributesBindValue {
48+
public class NativeQueryAttributesBindValue implements QueryAttributesBindValue {
5049
private static final Map<Class<?>, Integer> JAVA_TO_MYSQL_FIELD_TYPE = new HashMap<>();
5150
static {
5251
JAVA_TO_MYSQL_FIELD_TYPE.put(String.class, MysqlType.FIELD_TYPE_STRING);
@@ -83,7 +82,7 @@ public class QueryAttributesBindValue {
8382
/** The attribute MySQL type */
8483
protected int type = MysqlType.FIELD_TYPE_NULL;
8584

86-
protected QueryAttributesBindValue(String name, Object value) {
85+
protected NativeQueryAttributesBindValue(String name, Object value) {
8786
this.name = name;
8887
this.value = value;
8988
this.type = getMysqlFieldType(value);
@@ -109,27 +108,27 @@ private int getMysqlFieldType(Object obj) {
109108
return MysqlType.FIELD_TYPE_STRING;
110109
}
111110

111+
@Override
112112
public boolean isNull() {
113113
return this.type == MysqlType.FIELD_TYPE_NULL;
114114
}
115115

116+
@Override
116117
public String getName() {
117118
return this.name;
118119
}
119120

121+
@Override
120122
public int getType() {
121123
return this.type;
122124
}
123125

126+
@Override
124127
public Object getValue() {
125128
return this.value;
126129
}
127130

128-
public byte[] getByteValue() {
129-
String charEncoding = null;
130-
return charEncoding != null ? StringUtils.getBytes(toString(), charEncoding) : toString().getBytes();
131-
}
132-
131+
@Override
133132
public long getBoundLength() {
134133
if (isNull()) {
135134
return 0;

src/main/core-impl/java/com/mysql/cj/QueryAttributesBindings.java renamed to src/main/core-impl/java/com/mysql/cj/NativeQueryAttributesBindings.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,33 @@
3333
import java.util.List;
3434
import java.util.function.Consumer;
3535

36-
public class QueryAttributesBindings {
37-
private List<QueryAttributesBindValue> bindAttributes = new ArrayList<>();
36+
public class NativeQueryAttributesBindings implements QueryAttributesBindings {
37+
private List<NativeQueryAttributesBindValue> bindAttributes = new ArrayList<>();
3838

39-
public QueryAttributesBindings() {
39+
public NativeQueryAttributesBindings() {
4040
}
4141

42+
@Override
4243
public void setAttribute(String name, Object value) {
43-
this.bindAttributes.add(new QueryAttributesBindValue(name, value));
44+
this.bindAttributes.add(new NativeQueryAttributesBindValue(name, value));
4445
}
4546

47+
@Override
4648
public int getCount() {
4749
return this.bindAttributes.size();
4850
}
4951

52+
@Override
5053
public QueryAttributesBindValue getAttributeValue(int index) {
5154
return this.bindAttributes.get(index);
5255
}
5356

57+
@Override
5458
public void runThroughAll(Consumer<QueryAttributesBindValue> bindAttribute) {
5559
this.bindAttributes.forEach(bindAttribute::accept);
5660
}
5761

62+
@Override
5863
public void clearAttributes() {
5964
this.bindAttributes.clear();
6065
}

src/main/doc/mysqlx-overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<body>
22
<h1>MySQL Connector/J X DevAPI Reference</h1>
3-
<p/>
3+
<p></p>
44

55
This documentation covers the public classes and interfaces of the Java implementation of the X DevAPI. To get started, check out some of the main classes:
66

0 commit comments

Comments
 (0)