Skip to content

Commit ed73654

Browse files
committed
WL#11858, DevAPI: Core API v1 alignment
1 parent 7cbd2cd commit ed73654

File tree

8 files changed

+77
-50
lines changed

8 files changed

+77
-50
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.12
55

6+
- WL#11858, DevAPI: Core API v1 alignment.
7+
68
- Fix for Bug#27652379, NPE FROM GETSESSION(PROPERTIES) WHEN HOST PARAMETER IS GIVEN IN SMALL LETTER.
79

810
- Fix for BUG#87600 (26724154), CONNECTOR THROWS 'MALFORMED DATABASE URL' ON NON MYSQL CONNECTION-URLS.

src/main/core-api/java/com/mysql/cj/conf/ConnectionUrl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,10 @@ protected HostInfo fixHostInfo(HostInfo hi) {
475475
}
476476

477477
/**
478-
* Subclasses should override this to perform any required preprocessing on the host information properties.
478+
* Subclasses should override this to perform any required pre-processing on the host information properties.
479479
*
480480
* @param hostProps
481481
* the host properties map to process
482-
* @return
483-
* the processed host properties map
484482
*/
485483
protected void preprocessPerTypeHostProperties(Map<String, String> hostProps) {
486484
// To be overridden in subclasses if needed.

src/main/core-api/java/com/mysql/cj/conf/HostInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public HostInfo(DatabaseUrlContainer url, String host, int port, String user, St
137137
/**
138138
* Constructs a {@link HostInfo} instance initialized with the provided properties.
139139
*
140-
* @param properties
140+
* @param props
141141
* a connection arguments map.
142142
*/
143143
public HostInfo(Properties props) {

src/main/user-api/java/com/mysql/cj/xdevapi/FindStatement.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,21 @@ public interface FindStatement extends Statement<FindStatement, DocResult> {
9595
* @param limitOffset
9696
* number of documents to skip
9797
* @return {@link FindStatement}
98+
* @deprecated Deprecated in c/J 8.0.12, please use {@link #offset(long)} instead.
9899
*/
99-
FindStatement skip(long limitOffset);
100+
@Deprecated
101+
default FindStatement skip(long limitOffset) {
102+
return offset(limitOffset);
103+
}
104+
105+
/**
106+
* Add/replace the document offset for this query.
107+
*
108+
* @param limitOffset
109+
* number of documents to skip
110+
* @return {@link FindStatement}
111+
*/
112+
FindStatement offset(long limitOffset);
100113

101114
/**
102115
* Add/replace the document limit for this query.

src/main/user-api/java/com/mysql/cj/xdevapi/ModifyStatement.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ public interface ModifyStatement extends Statement<ModifyStatement, Result> {
8282
*/
8383
ModifyStatement unset(String... fields);
8484

85-
/**
86-
* Unsupported.
87-
*
88-
* @param document
89-
* document
90-
* @return {@link ModifyStatement}
91-
*/
92-
// TODO determine status of this feature
93-
ModifyStatement merge(String document);
94-
9585
/**
9686
* Takes in a patch object and applies it on all documents matching the modify() filter, using the JSON_MERGE_PATCH() function.
9787
* Please note that {@link DbDoc} does not support expressions as a field values, please use {@link #patch(String)} method if you need
@@ -139,16 +129,4 @@ public interface ModifyStatement extends Statement<ModifyStatement, Result> {
139129
* @return {@link ModifyStatement}
140130
*/
141131
ModifyStatement arrayAppend(String field, Object value);
142-
143-
/**
144-
* Unsupported.
145-
*
146-
* @param field
147-
* document path to the array field
148-
* @param position
149-
* array index
150-
* @return {@link ModifyStatement}
151-
*/
152-
// TODO determine status of this feature
153-
ModifyStatement arrayDelete(String field, int position);
154132
}

src/main/user-impl/java/com/mysql/cj/xdevapi/FilterableStatement.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ public STMT_T limit(long numberOfRows) {
122122
return (STMT_T) this;
123123
}
124124

125-
/**
126-
* Synonym to {@link #offset(long)}.
127-
*
128-
* @param limitOffset
129-
* number of rows to skip
130-
* @return this statement
131-
*/
132-
public STMT_T skip(long limitOffset) {
133-
return offset(limitOffset);
134-
}
135-
136125
/**
137126
* Add maximum number of rows to skip before find others.
138127
*

src/main/user-impl/java/com/mysql/cj/xdevapi/ModifyStatementImpl.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import com.mysql.cj.Messages;
3939
import com.mysql.cj.MysqlxSession;
40-
import com.mysql.cj.exceptions.FeatureNotAvailableException;
4140
import com.mysql.cj.protocol.x.StatementExecuteOk;
4241
import com.mysql.cj.protocol.x.XMessage;
4342
import com.mysql.cj.protocol.x.XMessageBuilder;
@@ -90,11 +89,6 @@ public ModifyStatement unset(String... fields) {
9089
return this;
9190
}
9291

93-
@Override
94-
public ModifyStatement merge(String document) {
95-
throw new FeatureNotAvailableException("TODO: not supported in xplugin");
96-
}
97-
9892
@Override
9993
public ModifyStatement patch(DbDoc document) {
10094
return patch(document.toString());
@@ -117,9 +111,4 @@ public ModifyStatement arrayAppend(String docPath, Object value) {
117111
this.updates.add(new UpdateSpec(UpdateType.ARRAY_APPEND, docPath).setValue(value));
118112
return this;
119113
}
120-
121-
@Override
122-
public ModifyStatement arrayDelete(String field, int position) {
123-
throw new FeatureNotAvailableException("TODO: not supported in xplugin");
124-
}
125114
}

src/test/java/testsuite/x/devapi/CollectionFindTest.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public void basicCollectionAsTable() {
183183
assertEquals(new Integer(1), ((JsonNumber) doc.get("xyz")).getInteger());
184184
}
185185

186+
@SuppressWarnings("deprecation")
186187
@Test
187188
public void testLimitOffset() {
188189
if (!this.isSetForXTests) {
@@ -210,14 +211,21 @@ public void testLimitOffset() {
210211
assertFalse(docs.hasNext());
211212

212213
// limit 3, offset 1, order by ID, make sure we don't see the first ID
213-
docs = this.collection.find().orderBy("$._id").limit(3).skip(1).execute();
214+
docs = this.collection.find().orderBy("$._id").limit(3).offset(1).execute();
214215
assertTrue(docs.hasNext());
215216
assertNotEquals(firstId, ((JsonString) docs.next().get("_id")).getString());
216217
assertTrue(docs.hasNext());
217218
assertNotEquals(firstId, ((JsonString) docs.next().get("_id")).getString());
218219
assertTrue(docs.hasNext());
219220
assertNotEquals(firstId, ((JsonString) docs.next().get("_id")).getString());
220221
assertFalse(docs.hasNext());
222+
223+
// Test deprecated skip(n) alias for offset
224+
// limit 1, offset 1, order by ID, make sure we don't see the first ID
225+
docs = this.collection.find().orderBy("$._id").limit(1).skip(1).execute();
226+
assertTrue(docs.hasNext());
227+
assertNotEquals(firstId, ((JsonString) docs.next().get("_id")).getString());
228+
assertFalse(docs.hasNext());
221229
}
222230

223231
@Test
@@ -885,4 +893,54 @@ public void getOne() {
885893
doc = this.collection.getOne(null);
886894
assertNull(doc);
887895
}
896+
897+
@Test
898+
public void testGroupingQuery() {
899+
if (!this.isSetForXTests) {
900+
return;
901+
}
902+
903+
this.collection.add("{\"_id\": \"01\", \"name\":\"Mamie\", \"age\":11, \"something\":0}").execute();
904+
this.collection.add("{\"_id\": \"02\", \"name\":\"Eulalia\", \"age\":11, \"something\":0}").execute();
905+
this.collection.add("{\"_id\": \"03\", \"name\":\"Polly\", \"age\":12, \"something\":0}").execute();
906+
this.collection.add("{\"_id\": \"04\", \"name\":\"Rufus\", \"age\":12, \"something\":0}").execute();
907+
this.collection.add("{\"_id\": \"05\", \"name\":\"Cassidy\", \"age\":13, \"something\":0}").execute();
908+
this.collection.add("{\"_id\": \"06\", \"name\":\"Olympia\", \"age\":14, \"something\":0}").execute();
909+
this.collection.add("{\"_id\": \"07\", \"name\":\"Lev\", \"age\":14, \"something\":0}").execute();
910+
this.collection.add("{\"_id\": \"08\", \"name\":\"Tierney\", \"age\":15, \"something\":0}").execute();
911+
this.collection.add("{\"_id\": \"09\", \"name\":\"Octavia\", \"age\":15, \"something\":0}").execute();
912+
this.collection.add("{\"_id\": \"10\", \"name\":\"Vesper\", \"age\":16, \"something\":0}").execute();
913+
this.collection.add("{\"_id\": \"11\", \"name\":\"Caspian\", \"age\":17, \"something\":0}").execute();
914+
this.collection.add("{\"_id\": \"12\", \"name\":\"Romy\", \"age\":17, \"something\":0}").execute();
915+
916+
// Result:
917+
// age_group | cnt
918+
// 11 | 2 <-- filtered out by where
919+
// 12 | 2 <-- filtered out by limit
920+
// 13 | 1 <-- filtered out by having
921+
// 14 | 2 * second row in result
922+
// 15 | 2 * first row in result
923+
// 16 | 1 <-- filtered out by having
924+
// 17 | 2 <-- filtered out by offset
925+
DocResult res = this.collection.find("age > 11 and 1 < 2 and 40 between 30 and 900") //
926+
.fields("age as age_group, count(name) as cnt, something as something") //
927+
.groupBy("something, age") //
928+
.having("count(name) > 1") //
929+
.orderBy("age desc") //
930+
.limit(2).offset(1) //
931+
.execute();
932+
933+
assertEquals(2, res.count());
934+
935+
DbDoc doc = res.fetchOne();
936+
assertEquals(15, ((JsonNumber) doc.get("age_group")).getInteger().intValue());
937+
assertEquals(2, ((JsonNumber) doc.get("cnt")).getInteger().intValue());
938+
assertEquals(0, ((JsonNumber) doc.get("something")).getInteger().intValue());
939+
940+
doc = res.fetchOne();
941+
assertEquals(14, ((JsonNumber) doc.get("age_group")).getInteger().intValue());
942+
assertEquals(2, ((JsonNumber) doc.get("cnt")).getInteger().intValue());
943+
assertEquals(0, ((JsonNumber) doc.get("something")).getInteger().intValue());
944+
945+
}
888946
}

0 commit comments

Comments
 (0)