0
# X DevAPI Core
1
2
Core X DevAPI interfaces for session management, schema access, and basic document/table operations. X DevAPI provides a modern, NoSQL-style API for MySQL document store and relational operations.
3
4
## Capabilities
5
6
### Session Factory
7
8
Factory for creating X DevAPI sessions.
9
10
```java { .api }
11
package com.mysql.cj.xdevapi;
12
13
public class SessionFactory {
14
// Constructor
15
public SessionFactory();
16
17
// Create session from URL string
18
public Session getSession(String url);
19
20
// Create session from properties
21
public Session getSession(Properties properties);
22
}
23
```
24
25
Usage:
26
27
```java
28
SessionFactory factory = new SessionFactory();
29
30
// Create session from URL
31
Session session = factory.getSession("mysqlx://root:password@localhost:33060/mydb");
32
33
// Create session from properties
34
Properties props = new Properties();
35
props.setProperty("host", "localhost");
36
props.setProperty("port", "33060");
37
props.setProperty("user", "root");
38
props.setProperty("password", "password");
39
props.setProperty("database", "mydb");
40
Session session2 = factory.getSession(props);
41
42
// Use session...
43
session.close();
44
```
45
46
### Client Factory
47
48
Factory for creating X DevAPI clients with connection pooling.
49
50
```java { .api }
51
package com.mysql.cj.xdevapi;
52
53
public class ClientFactory {
54
// Constructor
55
public ClientFactory();
56
57
// Create client from URL and JSON properties
58
public Client getClient(String url, String clientPropsJson);
59
60
// Create client from URL and properties object
61
public Client getClient(String url, Properties clientProps);
62
}
63
```
64
65
Usage:
66
67
```java
68
// Create client with pooling configuration
69
ClientFactory factory = new ClientFactory();
70
String url = "mysqlx://root:password@localhost:33060/mydb";
71
String poolConfig = "{" +
72
"\"pooling\": {" +
73
"\"enabled\": true," +
74
"\"maxSize\": 25," +
75
"\"maxIdleTime\": 30000," +
76
"\"queueTimeout\": 5000" +
77
"}" +
78
"}";
79
80
Client client = factory.getClient(url, poolConfig);
81
82
// Get sessions from pool
83
Session session1 = client.getSession();
84
Session session2 = client.getSession();
85
86
// Use sessions...
87
session1.close(); // Returns to pool
88
session2.close(); // Returns to pool
89
90
// Close client and all pooled connections
91
client.close();
92
```
93
94
### Client Interface
95
96
Client interface for managing pooled sessions.
97
98
```java { .api }
99
package com.mysql.cj.xdevapi;
100
101
public interface Client extends Closeable {
102
// Get session from pool
103
Session getSession();
104
105
// Close client and all sessions
106
void close();
107
108
// Client property keys
109
public enum ClientProperty {
110
POOLING_ENABLED("pooling.enabled"),
111
POOLING_MAX_SIZE("pooling.maxSize"),
112
POOLING_MAX_IDLE_TIME("pooling.maxIdleTime"),
113
POOLING_QUEUE_TIMEOUT("pooling.queueTimeout");
114
115
public String getKeyName();
116
}
117
}
118
119
public class ClientImpl implements Client {
120
// Implementation of Client interface
121
122
public Session getSession();
123
public void close();
124
}
125
```
126
127
### Session Interface
128
129
Session interface for database operations and transaction management.
130
131
```java { .api }
132
package com.mysql.cj.xdevapi;
133
134
public interface Session extends Closeable {
135
// Schema access
136
Schema getDefaultSchema();
137
Schema getSchema(String schemaName);
138
List<Schema> getSchemas();
139
140
// Create schema
141
Schema createSchema(String schemaName);
142
Schema createSchema(String schemaName, boolean reuseExisting);
143
144
// Drop schema
145
void dropSchema(String schemaName);
146
147
// SQL execution
148
SqlStatement sql(String sql);
149
150
// Session state
151
String getUri();
152
boolean isOpen();
153
void close();
154
155
// Schema information
156
String getDefaultSchemaName();
157
158
// Transaction management
159
void startTransaction();
160
void commit();
161
void rollback();
162
void rollbackTo(String name);
163
164
// Savepoints
165
String setSavepoint();
166
String setSavepoint(String name);
167
void releaseSavepoint(String name);
168
}
169
170
```
171
172
Usage:
173
174
```java
175
Session session = factory.getSession("mysqlx://root:password@localhost:33060/mydb");
176
177
// Get default schema
178
Schema defaultSchema = session.getDefaultSchema();
179
180
// Get specific schema
181
Schema schema = session.getSchema("mydb");
182
183
// Create new schema
184
Schema newSchema = session.createSchema("newdb");
185
186
// Drop schema
187
session.dropSchema("olddb");
188
189
// Transaction management
190
session.startTransaction();
191
try {
192
Collection users = schema.getCollection("users");
193
users.add("{\"name\": \"Alice\", \"age\": 30}").execute();
194
195
session.commit();
196
} catch (Exception e) {
197
session.rollback();
198
throw e;
199
}
200
201
// Savepoints
202
session.startTransaction();
203
String sp1 = session.setSavepoint("sp1");
204
// Do some work...
205
session.rollbackTo(sp1);
206
session.commit();
207
208
session.close();
209
```
210
211
### FilterParams Interface
212
213
Internal interface for transforming X DevAPI filter parameters into X Protocol message entities.
214
215
```java { .api }
216
package com.mysql.cj.xdevapi;
217
218
public interface FilterParams {
219
// Row lock types
220
public enum RowLock {
221
SHARED_LOCK(1), // Lock matching rows against updates
222
EXCLUSIVE_LOCK(2); // Lock matching rows so no other transactions can read or write to it
223
224
private int rowLock;
225
226
private RowLock(int rowLock);
227
public int asNumber();
228
}
229
230
// Row lock options
231
public enum RowLockOptions {
232
NOWAIT(1), // Do not wait to acquire row lock, fail with an error if a requested row is locked
233
SKIP_LOCKED(2); // Do not wait to acquire a row lock, remove locked rows from the result set
234
235
private int rowLockOption;
236
237
private RowLockOptions(int rowLockOption);
238
public int asNumber();
239
}
240
241
// Collection and order
242
Object getCollection();
243
Object getOrder();
244
void setOrder(String... orderExpression);
245
246
// Limit and offset
247
Long getLimit();
248
void setLimit(Long limit);
249
Long getOffset();
250
void setOffset(Long offset);
251
boolean supportsOffset();
252
253
// Criteria and arguments
254
Object getCriteria();
255
void setCriteria(String criteriaString);
256
Object getArgs();
257
void addArg(String name, Object value);
258
void verifyAllArgsBound();
259
void clearArgs();
260
261
// Projection and grouping
262
boolean isRelational();
263
void setFields(String... projection);
264
Object getFields();
265
void setGrouping(String... groupBy);
266
Object getGrouping();
267
void setGroupingCriteria(String having);
268
Object getGroupingCriteria();
269
270
// Locking
271
RowLock getLock();
272
void setLock(RowLock rowLock);
273
RowLockOptions getLockOption();
274
void setLockOption(RowLockOptions rowLockOption);
275
}
276
```
277
278
### Schema Interface
279
280
Schema interface for accessing collections and tables.
281
282
```java { .api }
283
package com.mysql.cj.xdevapi;
284
285
public interface Schema extends DatabaseObject {
286
// Collection operations
287
Collection getCollection(String name);
288
Collection getCollection(String name, boolean requireExists);
289
Collection createCollection(String name);
290
Collection createCollection(String name, boolean reuseExisting);
291
Collection createCollection(String collectionName, CreateCollectionOptions options);
292
void modifyCollection(String collectionName, ModifyCollectionOptions options);
293
List<Collection> getCollections();
294
List<Collection> getCollections(String pattern);
295
void dropCollection(String collectionName);
296
297
// Table operations
298
Table getTable(String name);
299
Table getTable(String name, boolean requireExists);
300
Table getCollectionAsTable(String name);
301
List<Table> getTables();
302
List<Table> getTables(String pattern);
303
304
// Schema metadata
305
String getName();
306
Session getSession();
307
boolean existsInDatabase();
308
309
// Nested classes for collection configuration
310
public class CreateCollectionOptions {
311
public CreateCollectionOptions setReuseExisting(boolean reuse);
312
public Boolean getReuseExisting();
313
public CreateCollectionOptions setValidation(Validation validation);
314
public Validation getValidation();
315
}
316
317
public class ModifyCollectionOptions {
318
public ModifyCollectionOptions setValidation(Validation validation);
319
public Validation getValidation();
320
}
321
322
public static class Validation {
323
public static enum ValidationLevel {
324
STRICT, // Enable JSON schema validation for documents
325
OFF; // Disable JSON schema validation
326
}
327
328
public Validation setLevel(ValidationLevel level);
329
public ValidationLevel getLevel();
330
public Validation setSchema(String schema);
331
public String getSchema();
332
}
333
}
334
```
335
336
Usage:
337
338
```java
339
Schema schema = session.getSchema("mydb");
340
341
// Get collection (create if doesn't exist)
342
Collection users = schema.createCollection("users", true);
343
344
// Get existing collection
345
Collection products = schema.getCollection("products");
346
347
// Get collection with existence check
348
try {
349
Collection orders = schema.getCollection("orders", true);
350
} catch (XDevAPIError e) {
351
System.out.println("Collection does not exist");
352
}
353
354
// Create collection with validation
355
Schema.CreateCollectionOptions options = new Schema.CreateCollectionOptions()
356
.setReuseExisting(true)
357
.setValidation(new Schema.Validation()
358
.setLevel(Schema.Validation.ValidationLevel.STRICT)
359
.setSchema("{\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}}}"));
360
361
Collection validatedColl = schema.createCollection("validated_users", options);
362
363
// Modify collection validation
364
Schema.ModifyCollectionOptions modifyOptions = new Schema.ModifyCollectionOptions()
365
.setValidation(new Schema.Validation()
366
.setLevel(Schema.Validation.ValidationLevel.OFF));
367
368
schema.modifyCollection("validated_users", modifyOptions);
369
370
// List all collections
371
List<Collection> collections = schema.getCollections();
372
for (Collection coll : collections) {
373
System.out.println("Collection: " + coll.getName());
374
}
375
376
// List collections matching pattern
377
List<Collection> userCollections = schema.getCollections("user%");
378
379
// Drop collection
380
schema.dropCollection("temp_collection");
381
382
// Get table
383
Table employees = schema.getTable("employees");
384
385
// List all tables
386
List<Table> tables = schema.getTables();
387
for (Table table : tables) {
388
System.out.println("Table: " + table.getName());
389
}
390
```
391
392
### Collection Interface
393
394
Collection interface for document operations.
395
396
```java { .api }
397
package com.mysql.cj.xdevapi;
398
399
public interface Collection extends DatabaseObject {
400
// Document operations
401
AddStatement add(DbDoc document);
402
AddStatement add(DbDoc... docs);
403
AddStatement add(String... jsonStrings);
404
AddStatement add(Map<String, ?> docMap);
405
406
FindStatement find();
407
FindStatement find(String searchCondition);
408
409
ModifyStatement modify(String searchCondition);
410
411
RemoveStatement remove(String searchCondition);
412
413
// Document retrieval
414
DbDoc getOne(String id);
415
DbDoc newDoc();
416
417
// Index management
418
Result createIndex(String indexName, String indexDefinition);
419
Result createIndex(String indexName, DbDoc indexDefinition);
420
void dropIndex(String indexName);
421
422
// Collection metadata
423
String getName();
424
Schema getSchema();
425
Session getSession();
426
boolean existsInDatabase();
427
428
// Document count
429
long count();
430
431
// Replace one document
432
Result replaceOne(String id, DbDoc doc);
433
Result replaceOne(String id, String jsonString);
434
435
// Add or replace one document
436
Result addOrReplaceOne(String id, DbDoc doc);
437
Result addOrReplaceOne(String id, String jsonString);
438
439
// Remove one document
440
Result removeOne(String id);
441
}
442
443
public class CollectionImpl implements Collection {
444
// Implementation of Collection interface
445
446
public AddStatement add(DbDoc... docs);
447
public AddStatement add(String... jsonStrings);
448
public AddStatement add(Map<String, ?> docMap);
449
public FindStatement find();
450
public FindStatement find(String searchCondition);
451
public ModifyStatement modify(String searchCondition);
452
public RemoveStatement remove(String searchCondition);
453
public DbDoc getOne(String id);
454
public DbDoc newDoc();
455
public Result createIndex(String indexName, String indexDefinition);
456
public Result createIndex(String indexName, DbDoc indexDefinition);
457
public void dropIndex(String indexName);
458
public String getName();
459
public Schema getSchema();
460
public Session getSession();
461
public boolean existsInDatabase();
462
public long count();
463
public Result replaceOne(String id, DbDoc doc);
464
public Result replaceOne(String id, String jsonString);
465
public Result addOrReplaceOne(String id, DbDoc doc);
466
public Result addOrReplaceOne(String id, String jsonString);
467
public Result removeOne(String id);
468
}
469
```
470
471
Usage:
472
473
```java
474
Schema schema = session.getSchema("mydb");
475
Collection users = schema.getCollection("users");
476
477
// Add document
478
DbDoc newUser = users.newDoc()
479
.add("name", new JsonString().setValue("Alice"))
480
.add("age", new JsonNumber().setValue("30"))
481
.add("email", new JsonString().setValue("alice@example.com"));
482
AddResult addResult = users.add(newUser).execute();
483
484
// Add JSON string
485
users.add("{\"name\": \"Bob\", \"age\": 25}").execute();
486
487
// Add multiple documents
488
users.add(
489
"{\"name\": \"Charlie\", \"age\": 35}",
490
"{\"name\": \"David\", \"age\": 28}"
491
).execute();
492
493
// Find documents
494
DocResult result = users.find("age > :minAge")
495
.bind("minAge", 25)
496
.execute();
497
498
// Get one document by ID
499
DbDoc user = users.getOne("00005f3a6b7700000000000000000001");
500
501
// Count documents
502
long count = users.count();
503
504
// Replace one document
505
DbDoc updatedUser = users.newDoc()
506
.add("name", new JsonString().setValue("Alice Updated"))
507
.add("age", new JsonNumber().setValue("31"));
508
users.replaceOne("00005f3a6b7700000000000000000001", updatedUser);
509
510
// Remove one document
511
users.removeOne("00005f3a6b7700000000000000000002");
512
513
// Create index
514
String indexDef = "{\"fields\": [{\"field\": \"$.age\", \"type\": \"INT\"}]}";
515
users.createIndex("age_idx", indexDef);
516
517
// Drop index
518
users.dropIndex("age_idx");
519
```
520
521
### Table Interface
522
523
Table interface for relational operations.
524
525
```java { .api }
526
package com.mysql.cj.xdevapi;
527
528
public interface Table extends DatabaseObject {
529
// Data manipulation
530
InsertStatement insert();
531
InsertStatement insert(String... projection);
532
InsertStatement insert(Map<String, Object> fieldsAndValues);
533
534
SelectStatement select(String... projection);
535
536
UpdateStatement update();
537
538
DeleteStatement delete();
539
540
// Table metadata
541
String getName();
542
Schema getSchema();
543
Session getSession();
544
boolean existsInDatabase();
545
boolean isView();
546
547
// Row count
548
long count();
549
}
550
551
```
552
553
Usage:
554
555
```java
556
Schema schema = session.getSchema("mydb");
557
Table employees = schema.getTable("employees");
558
559
// Insert row
560
employees.insert("name", "age", "department")
561
.values("Alice", 30, "Engineering")
562
.execute();
563
564
// Insert multiple rows
565
employees.insert("name", "age", "department")
566
.values("Bob", 25, "Sales")
567
.values("Charlie", 35, "Marketing")
568
.execute();
569
570
// Select rows
571
RowResult rows = employees.select("name", "age", "department")
572
.where("age > :minAge")
573
.bind("minAge", 25)
574
.orderBy("age DESC")
575
.execute();
576
577
while (rows.hasNext()) {
578
Row row = rows.next();
579
System.out.println(row.getString("name") + " - " + row.getInt("age"));
580
}
581
582
// Update rows
583
employees.update()
584
.set("age", 31)
585
.where("name = :name")
586
.bind("name", "Alice")
587
.execute();
588
589
// Delete rows
590
employees.delete()
591
.where("age < :minAge")
592
.bind("minAge", 25)
593
.execute();
594
595
// Count rows
596
long totalEmployees = employees.count();
597
598
// Check if table is a view
599
boolean isView = employees.isView();
600
```
601
602
### Database Object Interface
603
604
Base interface for database objects.
605
606
```java { .api }
607
package com.mysql.cj.xdevapi;
608
609
public interface DatabaseObject {
610
// Get object name
611
String getName();
612
613
// Get parent schema
614
Schema getSchema();
615
616
// Get session
617
Session getSession();
618
619
// Check existence
620
boolean existsInDatabase();
621
}
622
```
623
624
### DbDoc Interface
625
626
Interface for JSON document objects.
627
628
```java { .api }
629
package com.mysql.cj.xdevapi;
630
631
import java.util.Map;
632
import java.util.Set;
633
634
public interface DbDoc extends JsonValue, Map<String, JsonValue> {
635
// Add key-value pair
636
DbDoc add(String key, JsonValue value);
637
638
// Get value by key (inherited from Map)
639
JsonValue get(Object key);
640
641
// Remove key (inherited from Map)
642
JsonValue remove(Object key);
643
644
// Get document size (inherited from Map)
645
int size();
646
647
// Get all keys (inherited from Map)
648
Set<String> keySet();
649
650
// Convert to JSON string
651
String toString();
652
653
// Convert to formatted JSON string (inherited from JsonValue)
654
String toFormattedString();
655
}
656
657
public class DbDocImpl implements DbDoc {
658
// Constructor
659
public DbDocImpl();
660
public DbDocImpl(String jsonString);
661
public DbDocImpl(Map<String, ?> map);
662
663
// Implementation
664
public DbDoc add(String key, JsonValue value);
665
public JsonValue get(String key);
666
public JsonValue remove(String key);
667
public int size();
668
public Set<String> keySet();
669
public String toString();
670
public String toFormattedString();
671
}
672
```
673
674
Usage:
675
676
```java
677
// Create document
678
DbDoc doc = new DbDocImpl();
679
doc.add("name", new JsonString().setValue("Alice"));
680
doc.add("age", new JsonNumber().setValue("30"));
681
doc.add("active", JsonLiteral.TRUE);
682
683
// Create from JSON string
684
DbDoc doc2 = new DbDocImpl("{\"name\": \"Bob\", \"age\": 25}");
685
686
// Create from map
687
Map<String, Object> map = new HashMap<>();
688
map.put("name", "Charlie");
689
map.put("age", 35);
690
DbDoc doc3 = new DbDocImpl(map);
691
692
// Access values
693
JsonValue name = doc.get("name");
694
if (name instanceof JsonString) {
695
System.out.println("Name: " + ((JsonString) name).getString());
696
}
697
698
// Remove key
699
doc.remove("active");
700
701
// Get all keys
702
Set<String> keys = doc.keySet();
703
for (String key : keys) {
704
System.out.println(key + ": " + doc.get(key));
705
}
706
707
// Convert to JSON string
708
String json = doc.toString();
709
System.out.println(json);
710
711
// Formatted output
712
String formatted = doc.toFormattedString();
713
System.out.println(formatted);
714
```
715
716
### JSON Value Types
717
718
Interfaces and classes for JSON values.
719
720
```java { .api }
721
package com.mysql.cj.xdevapi;
722
723
public interface JsonValue {
724
// Base interface for all JSON values
725
726
// Get formatted JSON string
727
default String toFormattedString() {
728
return toString();
729
}
730
}
731
732
public class JsonString implements JsonValue {
733
// Constructor
734
public JsonString();
735
736
// Set value
737
public JsonString setValue(String value);
738
739
// Get value
740
public String getString();
741
742
// String representation
743
public String toString();
744
}
745
746
public class JsonNumber implements JsonValue {
747
// Constructor
748
public JsonNumber();
749
750
// Set value
751
public JsonNumber setValue(String value);
752
753
// Get value
754
public String getString();
755
public Integer getInteger();
756
public Long getLong();
757
public BigDecimal getBigDecimal();
758
759
// String representation
760
public String toString();
761
}
762
763
public class JsonArray extends ArrayList<JsonValue> implements JsonValue {
764
// Constructor
765
public JsonArray();
766
767
// Add value (convenience method)
768
public JsonArray addValue(JsonValue val);
769
770
// Inherited from ArrayList:
771
// public boolean add(JsonValue val);
772
// public JsonValue get(int index);
773
// public int size();
774
// public JsonValue remove(int index);
775
// public void clear();
776
// ... and all other ArrayList methods
777
778
// String representation
779
public String toString();
780
public String toFormattedString();
781
}
782
783
public enum JsonLiteral implements JsonValue {
784
TRUE("true"),
785
FALSE("false"),
786
NULL("null");
787
788
private final String value;
789
790
JsonLiteral(String value) {
791
this.value = value;
792
}
793
794
public String toString() {
795
return this.value;
796
}
797
}
798
```
799
800
Usage:
801
802
```java
803
// String value
804
JsonString name = new JsonString().setValue("Alice");
805
System.out.println(name.getString()); // "Alice"
806
807
// Number value
808
JsonNumber age = new JsonNumber().setValue("30");
809
System.out.println(age.getInteger()); // 30
810
811
JsonNumber price = new JsonNumber().setValue("19.99");
812
System.out.println(price.getBigDecimal()); // 19.99
813
814
// Array value
815
JsonArray hobbies = new JsonArray();
816
hobbies.add(new JsonString().setValue("reading"));
817
hobbies.add(new JsonString().setValue("coding"));
818
hobbies.add(new JsonString().setValue("gaming"));
819
System.out.println(hobbies.size()); // 3
820
821
// Literal values
822
JsonValue isActive = JsonLiteral.TRUE;
823
JsonValue nothing = JsonLiteral.NULL;
824
825
// Build document with all types
826
DbDoc user = new DbDocImpl();
827
user.add("name", name);
828
user.add("age", age);
829
user.add("hobbies", hobbies);
830
user.add("active", isActive);
831
user.add("middleName", JsonLiteral.NULL);
832
```
833
834
### JSON Parser Utility
835
836
Utility class for parsing JSON strings into DbDoc and JsonArray objects.
837
838
```java { .api }
839
package com.mysql.cj.xdevapi;
840
841
import java.io.IOException;
842
import java.io.StringReader;
843
844
public class JsonParser {
845
// Parse JSON string into DbDoc
846
public static DbDoc parseDoc(String jsonString);
847
848
// Parse JSON string into DbDoc (with reader)
849
public static DbDoc parseDoc(StringReader reader) throws IOException;
850
851
// Parse JSON array string into JsonArray (with reader)
852
public static JsonArray parseArray(StringReader reader) throws IOException;
853
}
854
```
855
856
Usage:
857
858
```java
859
// Parse JSON string to DbDoc
860
String jsonString = "{\"name\": \"Alice\", \"age\": 30, \"active\": true}";
861
DbDoc doc = JsonParser.parseDoc(jsonString);
862
863
// Access parsed values
864
JsonValue nameValue = doc.get("name");
865
if (nameValue instanceof JsonString) {
866
System.out.println("Name: " + ((JsonString) nameValue).getString());
867
}
868
869
// Parse with StringReader for advanced use cases
870
StringReader reader = new StringReader("{\"city\": \"New York\", \"zip\": 10001}");
871
try {
872
DbDoc addressDoc = JsonParser.parseDoc(reader);
873
System.out.println(addressDoc.toString());
874
} catch (IOException e) {
875
e.printStackTrace();
876
}
877
```
878
879
### Column Interface
880
881
Interface for result set column metadata.
882
883
```java { .api }
884
package com.mysql.cj.xdevapi;
885
886
public interface Column {
887
// Column identification
888
String getSchemaName();
889
String getTableName();
890
String getTableLabel();
891
String getColumnName();
892
String getColumnLabel();
893
894
// Type information
895
Type getType();
896
long getLength();
897
int getFractionalDigits();
898
899
// Numeric properties
900
boolean isNumberSigned();
901
902
// String properties
903
String getCollationName();
904
String getCharacterSetName();
905
boolean isPadded();
906
907
// Column properties
908
boolean isNullable();
909
boolean isAutoIncrement();
910
boolean isPrimaryKey();
911
boolean isUniqueKey();
912
boolean isPartKey();
913
}
914
915
public class ColumnImpl implements Column {
916
// Implementation of Column interface
917
918
public ColumnImpl(com.mysql.cj.result.Field field);
919
920
public String getSchemaName();
921
public String getTableName();
922
public String getTableLabel();
923
public String getColumnName();
924
public String getColumnLabel();
925
public Type getType();
926
public long getLength();
927
public int getFractionalDigits();
928
public boolean isNumberSigned();
929
public String getCollationName();
930
public String getCharacterSetName();
931
public boolean isPadded();
932
public boolean isNullable();
933
public boolean isAutoIncrement();
934
public boolean isPrimaryKey();
935
public boolean isUniqueKey();
936
public boolean isPartKey();
937
}
938
939
public enum Type {
940
// Column types
941
BIT,
942
TINYINT,
943
SMALLINT,
944
MEDIUMINT,
945
INT,
946
BIGINT,
947
FLOAT,
948
DECIMAL,
949
DOUBLE,
950
JSON,
951
STRING,
952
BYTES,
953
TIME,
954
DATE,
955
DATETIME,
956
TIMESTAMP,
957
SET,
958
ENUM,
959
GEOMETRY;
960
}
961
```
962
963
### Row Interface
964
965
Interface for result row access.
966
967
```java { .api }
968
package com.mysql.cj.xdevapi;
969
970
public interface Row {
971
// Get value by position
972
Object getObject(int pos);
973
974
// Get value by name
975
Object getObject(String columnName);
976
977
// Convert to DbDoc
978
DbDoc toDbDoc();
979
980
// String values
981
String getString(int pos);
982
String getString(String columnName);
983
984
// Numeric values
985
int getInt(int pos);
986
int getInt(String columnName);
987
long getLong(int pos);
988
long getLong(String columnName);
989
double getDouble(int pos);
990
double getDouble(String columnName);
991
BigDecimal getBigDecimal(int pos);
992
BigDecimal getBigDecimal(String columnName);
993
994
// Boolean values
995
boolean getBoolean(int pos);
996
boolean getBoolean(String columnName);
997
998
// Binary values
999
byte[] getBytes(int pos);
1000
byte[] getBytes(String columnName);
1001
1002
// Date/Time values
1003
Date getDate(int pos);
1004
Date getDate(String columnName);
1005
Timestamp getTimestamp(int pos);
1006
Timestamp getTimestamp(String columnName);
1007
Time getTime(int pos);
1008
Time getTime(String columnName);
1009
}
1010
1011
public class RowImpl implements Row {
1012
// Implementation of Row interface
1013
1014
public Object getObject(int pos);
1015
public Object getObject(String columnName);
1016
public DbDoc toDbDoc();
1017
public String getString(int pos);
1018
public String getString(String columnName);
1019
public int getInt(int pos);
1020
public int getInt(String columnName);
1021
public long getLong(int pos);
1022
public long getLong(String columnName);
1023
public double getDouble(int pos);
1024
public double getDouble(String columnName);
1025
public BigDecimal getBigDecimal(int pos);
1026
public BigDecimal getBigDecimal(String columnName);
1027
public boolean getBoolean(int pos);
1028
public boolean getBoolean(String columnName);
1029
public byte[] getBytes(int pos);
1030
public byte[] getBytes(String columnName);
1031
public Date getDate(int pos);
1032
public Date getDate(String columnName);
1033
public Timestamp getTimestamp(int pos);
1034
public Timestamp getTimestamp(String columnName);
1035
public Time getTime(int pos);
1036
public Time getTime(String columnName);
1037
}
1038
```
1039
1040
### Warning Interface
1041
1042
Interface for server warnings.
1043
1044
```java { .api }
1045
package com.mysql.cj.xdevapi;
1046
1047
public interface Warning {
1048
// Get warning level
1049
int getLevel();
1050
1051
// Get warning code
1052
long getCode();
1053
1054
// Get warning message
1055
String getMessage();
1056
}
1057
1058
public class WarningImpl implements Warning {
1059
// Implementation of Warning interface
1060
1061
public WarningImpl(int level, long code, String message);
1062
1063
public int getLevel();
1064
public long getCode();
1065
public String getMessage();
1066
}
1067
```
1068
1069
### Expression Wrapper
1070
1071
Wrapper for expression strings used in queries.
1072
1073
```java { .api }
1074
package com.mysql.cj.xdevapi;
1075
1076
public class Expression {
1077
// Create expression from string
1078
public static Expression expr(String expressionString);
1079
1080
// Get expression string
1081
public String getExpressionString();
1082
}
1083
```
1084
1085
Usage:
1086
1087
```java
1088
// Use expression in find
1089
Collection users = schema.getCollection("users");
1090
DocResult result = users.find("age > 25")
1091
.fields(Expression.expr("name"), Expression.expr("age * 2 as doubleAge"))
1092
.execute();
1093
1094
// Use expression in modify
1095
users.modify("_id = :id")
1096
.set("visits", Expression.expr("visits + 1"))
1097
.bind("id", "someId")
1098
.execute();
1099
1100
// Use expression in select
1101
Table employees = schema.getTable("employees");
1102
RowResult rows = employees.select("name", "salary")
1103
.where(Expression.expr("salary > 50000 AND department = 'Engineering'"))
1104
.execute();
1105
```
1106
1107
### Database Object Description
1108
1109
Description of database objects returned from list operations.
1110
1111
```java { .api }
1112
package com.mysql.cj.xdevapi;
1113
1114
public class DatabaseObjectDescription {
1115
// Constructor
1116
public DatabaseObjectDescription(String name, String type);
1117
1118
// Get object name
1119
public String getObjectName();
1120
1121
// Get object type
1122
public String getObjectType();
1123
}
1124
```
1125