Skip to content

Commit 1d15612

Browse files
authored
Update with latest code from NSON
1 parent bcb0416 commit 1d15612

File tree

6 files changed

+183
-24
lines changed

6 files changed

+183
-24
lines changed

driver/src/main/java/oracle/nosql/driver/Nson.java

Lines changed: 172 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
* <pre>
5959
* Tag value: 0
6060
* Value:
61-
* 4-byte (unpacked int) – size of the entire array in bytes
62-
* 4-byte (unpacked int) – number of elements in the array
61+
* 4-byte (unpacked int) - size of the entire array in bytes
62+
* 4-byte (unpacked int) - number of elements in the array
6363
* The array fields, which are NSON values. Because NSON is schemaless the
6464
* array elements may be of any type
6565
* </pre>
@@ -101,13 +101,13 @@
101101
* <pre>
102102
* Tag value: 6
103103
* Value:
104-
* 4-byte (unpacked int) – size of the entire map in bytes (value as written
104+
* 4-byte (unpacked int) - size of the entire map in bytes (value as written
105105
* by Java's DataOutput.writeInt)
106-
* 4-byte (unpacked int) – number of elements in the map (value as written
106+
* 4-byte (unpacked int) - number of elements in the map (value as written
107107
* by Java's DataOutput.writeInt)
108108
* The map fields, which are:
109-
* key – String (see String below), cannot be null
110-
* value – an NSON value. Because NSON is schemaless the map values may be
109+
* key - String (see String below), cannot be null
110+
* value - an NSON value. Because NSON is schemaless the map values may be
111111
* of any type
112112
* </pre>
113113
* </li>
@@ -147,8 +147,8 @@
147147
* </li>
148148
* <li> Packed formats (TBD)
149149
* <pre>
150-
* packed int, long -- – describe algorithm
151-
* unpacked int – endian?
150+
* packed int, long -- - describe algorithm
151+
* unpacked int - endian?
152152
* Java BigDecimal/number format
153153
* </pre>
154154
* </li>
@@ -990,6 +990,170 @@ public static MapValue readNsonMap(ByteInputStream in)
990990
return (MapValue) readFieldValue(in);
991991
}
992992

993+
/**
994+
* Write a key/value integer map field to an Nson serializer.
995+
* @param ns the serializer to use
996+
* @param fieldName the name of the key
997+
* @param value the integer value to write
998+
* @throws IOException if there are problems writing to the serializer
999+
*/
1000+
public static void writeMapField(NsonSerializer ns,
1001+
String fieldName,
1002+
int value) throws IOException {
1003+
ns.startMapField(fieldName);
1004+
ns.integerValue(value);
1005+
ns.endMapField(fieldName);
1006+
}
1007+
1008+
/**
1009+
* Write a key/value long map field to an Nson serializer.
1010+
* @param ns the serializer to use
1011+
* @param fieldName the name of the key
1012+
* @param value the long value to write
1013+
* @throws IOException if there are problems writing to the serializer
1014+
*/
1015+
public static void writeMapField(NsonSerializer ns,
1016+
String fieldName,
1017+
long value) throws IOException {
1018+
ns.startMapField(fieldName);
1019+
ns.longValue(value);
1020+
ns.endMapField(fieldName);
1021+
}
1022+
1023+
/**
1024+
* Write a key/value byte array map field to an Nson serializer.
1025+
* @param ns the serializer to use
1026+
* @param fieldName the name of the key
1027+
* @param value the byte array value to write
1028+
* @throws IOException if there are problems writing to the serializer
1029+
*/
1030+
public static void writeMapField(NsonSerializer ns,
1031+
String fieldName,
1032+
byte[] value) throws IOException {
1033+
ns.startMapField(fieldName);
1034+
ns.binaryValue(value);
1035+
ns.endMapField(fieldName);
1036+
}
1037+
1038+
/**
1039+
* Write a key/value byte array map field to an Nson serializer,
1040+
* given a specific offset and length.
1041+
* @param ns the serializer to use
1042+
* @param fieldName the name of the key
1043+
* @param value the byte arrayinteger value to write
1044+
* @param offset the offset into the given byte array to start from
1045+
* @param length the number of bytes from the offset to write
1046+
* @throws IOException if there are problems writing to the serializer
1047+
*/
1048+
public static void writeMapField(NsonSerializer ns,
1049+
String fieldName,
1050+
byte[] value,
1051+
int offset,
1052+
int length) throws IOException {
1053+
ns.startMapField(fieldName);
1054+
ns.binaryValue(value, offset, length);
1055+
ns.endMapField(fieldName);
1056+
}
1057+
1058+
/**
1059+
* Write a key/value string array map field to an Nson serializer.
1060+
* Note: a null or empty array will result in nothing being written.
1061+
* @param ns the serializer to use
1062+
* @param fieldName the name of the key
1063+
* @param value the string array value to write
1064+
* @throws IOException if there are problems writing to the serializer
1065+
*/
1066+
public static void writeMapField(NsonSerializer ns,
1067+
String fieldName,
1068+
String[] value) throws IOException {
1069+
if (value == null || value.length == 0) {
1070+
return;
1071+
}
1072+
ns.startMapField(fieldName);
1073+
ns.startArray(0);
1074+
for (String s : value) {
1075+
ns.stringValue(s);
1076+
ns.incrSize(1);
1077+
}
1078+
ns.endArray(0);
1079+
ns.endMapField(fieldName);
1080+
}
1081+
1082+
/**
1083+
* Write a key/value integer array map field to an Nson serializer.
1084+
* Note: a null or empty array will result in nothing being written.
1085+
* @param ns the serializer to use
1086+
* @param fieldName the name of the key
1087+
* @param value the integer array value to write
1088+
* @throws IOException if there are problems writing to the serializer
1089+
*/
1090+
public static void writeMapField(NsonSerializer ns,
1091+
String fieldName,
1092+
int[] value) throws IOException {
1093+
if (value == null || value.length == 0) {
1094+
return;
1095+
}
1096+
ns.startMapField(fieldName);
1097+
ns.startArray(0);
1098+
for (int i : value) {
1099+
ns.integerValue(i);
1100+
ns.incrSize(1);
1101+
}
1102+
ns.endArray(0);
1103+
ns.endMapField(fieldName);
1104+
}
1105+
1106+
/**
1107+
* Write a key/value string map field to an Nson serializer.
1108+
* Note: a null value will result in nothing being written.
1109+
* @param ns the serializer to use
1110+
* @param fieldName the name of the key
1111+
* @param value the string value to write
1112+
* @throws IOException if there are problems writing to the serializer
1113+
*/
1114+
public static void writeMapField(NsonSerializer ns,
1115+
String fieldName,
1116+
String value) throws IOException {
1117+
/* allow null to be a no-op */
1118+
if (value == null) {
1119+
return;
1120+
}
1121+
ns.startMapField(fieldName);
1122+
ns.stringValue(value);
1123+
ns.endMapField(fieldName);
1124+
}
1125+
1126+
/**
1127+
* Write a key/value boolean map field to an Nson serializer.
1128+
* @param ns the serializer to use
1129+
* @param fieldName the name of the key
1130+
* @param value the boolean value to write
1131+
* @throws IOException if there are problems writing to the serializer
1132+
*/
1133+
public static void writeMapField(NsonSerializer ns,
1134+
String fieldName,
1135+
boolean value) throws IOException {
1136+
ns.startMapField(fieldName);
1137+
ns.booleanValue(value);
1138+
ns.endMapField(fieldName);
1139+
}
1140+
1141+
/**
1142+
* Write a key/value MapValue map field to an Nson serializer.
1143+
* This will write a new map object with the given name.
1144+
* @param ns the serializer to use
1145+
* @param fieldName the name of the key
1146+
* @param value the MapValue value to write
1147+
* @throws IOException if there are problems writing to the serializer
1148+
*/
1149+
public static void writeMapField(NsonSerializer ns,
1150+
String fieldName,
1151+
MapValue value) throws IOException {
1152+
ns.startMapField(fieldName);
1153+
FieldValueEventHandler.generate(value, ns);
1154+
ns.endMapField(fieldName);
1155+
}
1156+
9931157
private static void readType(ByteInputStream in, int expected)
9941158
throws IOException {
9951159

driver/src/main/java/oracle/nosql/driver/values/ArrayValue.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ public Type getType() {
5151
}
5252

5353
/**
54-
* internal use only
55-
* @return the internal array
5654
* @hidden
55+
* @return the internal array
5756
*/
5857
public ArrayList<FieldValue> getArrayInternal() {
5958
return array;
@@ -603,7 +602,6 @@ public int hashCode() {
603602
}
604603

605604
/**
606-
* internal use only
607605
* @hidden
608606
*/
609607
@Override
@@ -622,11 +620,11 @@ public long sizeof() {
622620
}
623621

624622
/**
623+
* @hidden
625624
* Sorts the elements of the array according to the given comparator.
626625
*
627626
* @param comparator The Comparator to use for comparing the array
628627
* elements. It must not be null.
629-
* @hidden
630628
*/
631629
public void sort(Comparator<FieldValue> comparator) {
632630
requireNonNull(comparator, "Comparator must be non-null");

driver/src/main/java/oracle/nosql/driver/values/DoubleValue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ public double getValue() {
5757
}
5858

5959
/**
60-
* internal use only
60+
* @hidden
6161
*
6262
* @param v the value to use
63-
* @hidden
6463
*/
6564
public void setValue(double v) {
6665
value = v;

driver/src/main/java/oracle/nosql/driver/values/EmptyValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package oracle.nosql.driver.values;
99

1010
/**
11+
* @hidden
1112
* Only used by hidden scan interface
1213
*
1314
* A {@link FieldValue} instance representing an empty value. This type
@@ -17,7 +18,6 @@
1718
* {@link JsonNullValue} value, which is a concrete value. It is also different
1819
* from NullValue which represents a null/missing field in a fully-typed
1920
* field in the table schema as opposed to a JSON field
20-
* @hidden
2121
*/
2222
public class EmptyValue extends FieldValue {
2323

driver/src/main/java/oracle/nosql/driver/values/FieldValue.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public enum Type {
108108
JSON_NULL,
109109
/** A null value, used only by index keys */
110110
NULL,
111-
/** An empty, or missing value, used only by index keys @hidden */
111+
/** @hidden An empty, or missing value, used only by index keys */
112112
EMPTY;
113113
}
114114

@@ -393,12 +393,13 @@ public NullValue asNull() {
393393
}
394394

395395
/**
396+
* @hidden
397+
*
396398
* Casts to EmptyValue.
397399
*
398400
* @return a EmptyValue
399401
*
400402
* @throws ClassCastException if this is not a EmptyValue
401-
* @hidden
402403
*/
403404
public EmptyValue asEmpty() {
404405
return (EmptyValue) this;
@@ -556,18 +557,16 @@ public boolean isAnyNull() {
556557

557558

558559
/**
559-
* Is empty?
560-
* @return true if is empty
561560
* @hidden
561+
* @return true if is empty
562562
*/
563563
public boolean isEMPTY() {
564564
return this == EmptyValue.getInstance();
565565
}
566566

567567
/**
568-
* Is special?
569-
* @return true if is NULL, json null, or empty
570568
* @hidden
569+
* @return true if is NULL, json null, or empty
571570
*/
572571
public boolean isSpecialValue() {
573572
Type type = getType();
@@ -634,9 +633,8 @@ public int getSerializedSize() {
634633
}
635634

636635
/**
637-
* Size
638-
* @return size of value in bytes
639636
* @hidden
637+
* @return size of value in bytes
640638
*/
641639
public abstract long sizeof();
642640

driver/src/main/java/oracle/nosql/driver/values/PathFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,9 @@ public boolean stop() {
536536
}
537537

538538
/**
539+
* @hidden
539540
* A function that is called when a path has been found. It is passed
540541
* the PathFinder instance and the path that was found.
541-
* @hidden
542542
*/
543543
@FunctionalInterface
544544
public interface PathFinderCallback {

0 commit comments

Comments
 (0)