Skip to content

Commit 28ab636

Browse files
committed
Removed nvarchar2/nclob/raw support, changed table name defaulting
Removes nvarchar2/nclob/raw since they are not supported by Oracle SQL Changes table name defaulting algorithm to avoid case-sensitive table names in common cases
1 parent 34b0fbf commit 28ab636

File tree

8 files changed

+102
-25
lines changed

8 files changed

+102
-25
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<fileset dir="${classes.dir}"/>
7777
<fileset dir="${resources.dir}"/>
7878
<manifest>
79-
<attribute name="Repository-Id" value="XDK_SODA1.0.0_LINUX.X64_151210 GITHUB"/>
79+
<attribute name="Repository-Id" value="XDK_SODA1.0.0_LINUX.X64_151227 GITHUB"/>
8080
</manifest>
8181
</jar>
8282
</target>

json.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<property name="jsr353.jar" value="${env.SODA_JSR353_JAR}"/>
2323

2424
<property name="xdk.lib.dir" value="${xdk.json.src.dir}/lib"/>
25-
<property name="jar.orajsoda" value="${xdk.lib.dir}/orajsoda-1.0.1.jar"/>
25+
<property name="jar.orajsoda" value="${xdk.lib.dir}/orajsoda-1.0.2.jar"/>
2626

2727
<!--
2828
Generic project layout

src/oracle/soda/rdbms/impl/CollectionDescriptor.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222

2323
import java.util.Map;
24+
import java.util.Locale;
2425

2526
import javax.json.JsonObject;
2627
import javax.json.JsonString;
@@ -161,14 +162,30 @@ public class CollectionDescriptor
161162
final String doctypeColumnName;
162163
final String creationColumnName;
163164

165+
/**
166+
* Return a SQL identifier derived from the string, case-preserving
167+
*/
164168
static String stringToIdentifier(String jsonName)
169+
{
170+
return(CollectionDescriptor.stringToIdentifier(jsonName, true));
171+
}
172+
173+
/**
174+
* Return a SQL identifier derived from the string,
175+
* optionally either case-preserving or upper-casing
176+
*/
177+
static String stringToIdentifier(String jsonName, boolean preserveCase)
165178
{
166179
String identifierName = null;
167180
if (jsonName != null)
168181
{
169182
char[] data = jsonName.toCharArray();
170183
if (data.length == 0) return("");
171184

185+
boolean hasUpper = false;
186+
boolean hasLower = false;
187+
boolean toUpper = !preserveCase;
188+
172189
// Examine all characters of data
173190
for (int i = 0; i < data.length; ++i)
174191
{
@@ -177,9 +194,32 @@ static String stringToIdentifier(String jsonName)
177194
data[i] = '_'; // Replace double quotes with underscores
178195
else if (ch < ' ')
179196
data[i] = '_'; // Replace control characters with underscores
197+
else if ((ch >= 'A') && (ch <= 'Z'))
198+
hasUpper = true;
199+
else if ((ch >= 'a') && (ch <= 'z'))
200+
hasLower = true;
201+
// If the string contains non-alphanumeric characters
202+
// that aren't allowed by SQL, we shouldn't uppercase it
203+
else if (((ch < '0') || (ch > '9')) &&
204+
((ch != '_') && (ch != '$') && (ch != '#')))
205+
toUpper = false;
206+
}
207+
208+
// If the string is mixed case, we shouldn't uppercase it
209+
if (toUpper && hasUpper && hasLower)
210+
toUpper = false;
211+
// If the string doesn't start with an alphabetic character
212+
// we shouldn't upper case it
213+
if (toUpper)
214+
{
215+
char ch = data[0];
216+
if (((ch < 'A') || (ch > 'Z')) && ((ch < 'a') || (ch > 'z')))
217+
toUpper = false;
180218
}
181219

182220
identifierName = new String(data);
221+
222+
if (toUpper) identifierName = identifierName.toUpperCase(Locale.US);
183223
}
184224
return(identifierName);
185225
}
@@ -1036,7 +1076,7 @@ CollectionDescriptor buildDescriptor(String uriName,
10361076
byte dbObjectType = this.dbObjectType;
10371077
if (dbObjectName == null)
10381078
{
1039-
dbObjectName = stringToIdentifier(uriName);
1079+
dbObjectName = stringToIdentifier(uriName, false); // Case converting
10401080
dbObjectType = DBOBJECT_TABLE;
10411081
}
10421082

@@ -1217,6 +1257,7 @@ else if (sqlType.equalsIgnoreCase("varchar"))
12171257
type = CHAR_CONTENT;
12181258
else if (sqlType.equalsIgnoreCase("varchar2"))
12191259
type = CHAR_CONTENT;
1260+
/* Raw, and n-types are not currently supported
12201261
else if (sqlType.equalsIgnoreCase("raw"))
12211262
type = RAW_CONTENT;
12221263
else if (sqlType.equalsIgnoreCase("nchar"))
@@ -1225,12 +1266,13 @@ else if (sqlType.equalsIgnoreCase("nvarchar"))
12251266
type = NCHAR_CONTENT;
12261267
else if (sqlType.equalsIgnoreCase("nvarchar2"))
12271268
type = NCHAR_CONTENT;
1269+
else if (sqlType.equalsIgnoreCase("nclob"))
1270+
type = NCLOB_CONTENT;
1271+
*/
12281272
else if (sqlType.equalsIgnoreCase("blob"))
12291273
type = BLOB_CONTENT;
12301274
else if (sqlType.equalsIgnoreCase("clob"))
12311275
type = CLOB_CONTENT;
1232-
else if (sqlType.equalsIgnoreCase("nclob"))
1233-
type = NCLOB_CONTENT;
12341276
else
12351277
throw SODAUtils.makeException(SODAMessage.EX_INVALID_ARG_VALUE, sqlType);
12361278

test/src/oracle/json/tests/soda/test_OracleCollectionAdmin.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void testIsHeterogeneous() throws Exception {
5252
assertEquals(msg, e.getMessage());
5353
}
5454

55+
/* ### Oracle Database does not support NVARCHAR2 and RAW storage for JSON
5556
try {
5657
// Test with mediaTypeColumn, but content type = "NVARCHAR2"
5758
client.createMetadataBuilder().mediaTypeColumnName("CONTENT_TYPE").contentColumnType("NVARCHAR2")
@@ -69,6 +70,7 @@ public void testIsHeterogeneous() throws Exception {
6970
} catch (OracleException e) {
7071
assertEquals(msg, e.getMessage());
7172
}
73+
*/
7274

7375
try {
7476
// Test with mediaTypeColumn, but content type = "CLOB"
@@ -79,6 +81,7 @@ public void testIsHeterogeneous() throws Exception {
7981
assertEquals(msg, e.getMessage());
8082
}
8183

84+
/* ### Oracle Database does not support NCLOB storage for JSON
8285
try {
8386
// Test with mediaTypeColumn, but content type = "NCLOB"
8487
client.createMetadataBuilder().mediaTypeColumnName("CONTENT_TYPE").contentColumnType("NCLOB")
@@ -87,7 +90,7 @@ public void testIsHeterogeneous() throws Exception {
8790
} catch (OracleException e) {
8891
assertEquals(msg, e.getMessage());
8992
}
90-
93+
*/
9194

9295
OracleCollection col6 = dbAdmin.createCollection("testIsHeterogeneous6");
9396
assertEquals(false, col6.admin().isHeterogeneous());
@@ -558,6 +561,7 @@ public void testIndexAll() throws Exception {
558561
OracleCollection col3 = dbAdmin.createCollection("testIndexAll3", mDoc3);
559562
testIndexAllwithCol(col3);
560563

564+
/* ### Oracle Database does not support NVARCHAR2, NCLOB, or RAW storage for JSON
561565
// Test with contentColumnType=RAW
562566
OracleDocument mDoc5 = client.createMetadataBuilder()
563567
.contentColumnType("RAW").build();
@@ -588,6 +592,7 @@ public void testIndexAll() throws Exception {
588592
// Expect an OracleException
589593
assertEquals("indexAll is not implemented for content columns with type NCLOB.", e.getMessage());
590594
}
595+
*/
591596

592597
}
593598

@@ -907,6 +912,8 @@ public void testCreateIndex() throws Exception {
907912
assertTrue(t.getMessage().contains("ORA-01452"));
908913
}
909914

915+
/* ### Oracle Database does not support NVARCHAR2 or NCLOB storage for JSON
916+
910917
String indexSpecN9 =
911918
"{ \"name\":\"STUDENT_INDEXN9\", \"language\" : \"english\" }";
912919
@@ -933,6 +940,7 @@ public void testCreateIndex() throws Exception {
933940
// Expect an OracleException
934941
assertEquals("indexAll is not implemented for content columns with type NCLOB.", e.getMessage());
935942
}
943+
*/
936944

937945
}
938946

test/src/oracle/json/tests/soda/test_OracleDatabaseAdmin.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ public void testCreateCollection2() throws Exception {
199199
}
200200

201201
//Test with unmatched contentColumnMaxLength
202-
OracleDocument metaDoc10 = client.createMetadataBuilder().contentColumnType("NVARCHAR2").contentColumnMaxLength(1024).build();
202+
OracleDocument metaDoc10 = client.createMetadataBuilder().contentColumnType("VARCHAR2").contentColumnMaxLength(1024).build();
203203
String colName10 = "testCreateCollection10";
204204
dbAdmin.createCollection(colName10, metaDoc10);
205-
OracleDocument metaDoc10_1 = client.createMetadataBuilder().contentColumnType("NVARCHAR2").contentColumnMaxLength(256).build();
205+
OracleDocument metaDoc10_1 = client.createMetadataBuilder().contentColumnType("VARCHAR2").contentColumnMaxLength(256).build();
206206
try {
207207
dbAdmin.createCollection(colName10, metaDoc10_1);
208208
fail("No exception when mismatch on collection metadata");
@@ -385,7 +385,7 @@ public void testCreateCollection2() throws Exception {
385385
OracleDocument metaDoc24 = client.createMetadataBuilder().contentColumnType("CLOB").build();
386386
String colName24 = "testCreateCollection24";
387387
dbAdmin.createCollection(colName24, metaDoc24);
388-
OracleDocument metaDoc24_1 = client.createMetadataBuilder().contentColumnType("RAW").build();
388+
OracleDocument metaDoc24_1 = client.createMetadataBuilder().contentColumnType("BLOB").build();
389389
try {
390390
dbAdmin.createCollection(colName24, metaDoc24_1);
391391
fail("No exception when mismatch on collection metadata");
@@ -863,15 +863,17 @@ private void testContColType(String contColType) throws Exception {
863863
public void testContentColumnTypes() throws Exception {
864864
testContColType("VARCHAR2");
865865

866+
testContColType("BLOB");
867+
868+
testContColType("CLOB");
869+
870+
/* ### Oracle Database does not support NVARCHAR2, NCLOB, or RAW storage for JSON
866871
testContColType("NVARCHAR2");
867872
868873
testContColType("RAW");
869874
870-
testContColType("BLOB");
871-
872-
testContColType("CLOB");
873-
874875
testContColType("NCLOB");
876+
*/
875877

876878
// Test with invalid CONTENT_COLUMN_TYPE for collection creation
877879
try {
@@ -1070,9 +1072,12 @@ private void testContentMaxLength(String contentSQLType) throws Exception {
10701072

10711073
public void testContentMaxLength() throws Exception {
10721074

1073-
testContentMaxLength("NVARCHAR2");
10741075
testContentMaxLength("VARCHAR2");
1076+
1077+
/* ### Oracle Database does not support NVARCHAR2 or RAW storage for JSON
1078+
testContentMaxLength("NVARCHAR2");
10751079
testContentMaxLength("RAW");
1080+
*/
10761081

10771082
// Test about specifying CONTENT_MAX_LENGTH for "BLOB" type
10781083
try {
@@ -1120,6 +1125,7 @@ public void testContentMaxLength() throws Exception {
11201125
}
11211126

11221127
// Test about specifying CONTENT_MAX_LENGTH for "NCLOB" type
1128+
/* ### Oracle Database does not support NCLOB storage for JSON
11231129
try {
11241130
OracleDocument mDoc6 = client.createMetadataBuilder()
11251131
.keyColumnAssignmentMethod("CLIENT").contentColumnType("NCLOB")
@@ -1130,6 +1136,7 @@ public void testContentMaxLength() throws Exception {
11301136
// Expect an OracleException
11311137
assertEquals("A maximum length cannot be set for LOB types.", e.getMessage());
11321138
}
1139+
*/
11331140

11341141
}
11351142

@@ -1157,7 +1164,7 @@ public void testKeyMetadata() throws Exception {
11571164

11581165
// Test with key column type=NVARCHAR2 && max key length=512 && key method=GUID
11591166
OracleDocument mDoc2 = client.createMetadataBuilder()
1160-
.contentColumnType("NVARCHAR2").contentColumnMaxLength(512)
1167+
.keyColumnType("NVARCHAR2").keyColumnMaxLength(512)
11611168
.keyColumnAssignmentMethod("GUID").build();
11621169

11631170
OracleCollection col2 = dbAdmin.createCollection("testKeyMetadata2", mDoc2);
@@ -1167,7 +1174,7 @@ public void testKeyMetadata() throws Exception {
11671174

11681175
// Test with key column type=RAW && key method=UUID
11691176
OracleDocument mDoc3 = client.createMetadataBuilder()
1170-
.contentColumnType("RAW").keyColumnAssignmentMethod("UUID").build();
1177+
.keyColumnType("RAW").keyColumnAssignmentMethod("UUID").build();
11711178

11721179
OracleCollection col3 = dbAdmin.createCollection("testKeyMetadata3", mDoc3);
11731180
OracleDocument doc3 = col3.insertAndGet(db.createDocumentFromString(null, "{ \"d\" : 3 }", null));
@@ -1368,7 +1375,10 @@ private void testBasicOperations(OracleCollection col) throws Exception {
13681375

13691376
public void testSecureFileMetadata() throws Exception {
13701377

1371-
final String[] sqlTypes = { "BLOB", "CLOB", "NCLOB"};
1378+
// ### Oracle Database does not support NVARCHAR2 or NCLOB storage for JSON
1379+
//final String[] sqlTypes = { "BLOB", "CLOB", "NCLOB"};
1380+
1381+
final String[] sqlTypes = { "BLOB", "CLOB"};
13721382
final String[] compressions = { "NONE", "HIGH", "MEDIUM", "LOW"};
13731383
final boolean[] cachings = {true, false};
13741384
final String[] encryptions = {"3DES168", "AES128", "AES192", "AES256"};
@@ -1399,7 +1409,9 @@ public void testSecureFileMetadata() throws Exception {
13991409
}
14001410
} // end for "for lobTypes" loop
14011411

1402-
final String[] nonLobTypes = { "VARCHAR2", "NVARCHAR2", "RAW"};
1412+
// ### Oracle Database does not support NVARCHAR2 or RAW storage for JSON
1413+
//final String[] nonLobTypes = { "VARCHAR2", "NVARCHAR2", "RAW"};
1414+
final String[] nonLobTypes = { "VARCHAR2" };
14031415
counter = 100;
14041416
for (String nonLobType : nonLobTypes) {
14051417
OracleDocument mDoc = client.createMetadataBuilder()
@@ -1431,6 +1443,7 @@ public void testSecureFileMetadata() throws Exception {
14311443
assertEquals("SecureFile LOB settings cannot be used when the content column type is \"VARCHAR2\"", e.getMessage());
14321444
}
14331445

1446+
/* ### Oracle Database does not support NVARCHAR2 or RAW for JSON
14341447
try {
14351448
OracleDocument mDoc2 = client.createMetadataBuilder()
14361449
.contentColumnType("NVARCHAR2")
@@ -1454,6 +1467,7 @@ public void testSecureFileMetadata() throws Exception {
14541467
// Expect an OracleException
14551468
assertEquals("SecureFile LOB settings cannot be used when the content column type is \"RAW\"", e.getMessage());
14561469
}
1470+
*/
14571471

14581472
}
14591473

test/src/oracle/json/tests/soda/test_OracleDocument2.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public void testDocumentEncoding() throws Exception {
525525
OracleDocument meta = client.createMetadataBuilder()
526526
.keyColumnAssignmentMethod("CLIENT")
527527
.contentColumnType("BLOB")
528-
.build();
528+
.build();
529529
OracleDocument mDoc = db.createDocumentFromByteArray(null, meta.getContentAsString().getBytes(UTF8), null);
530530
OracleCollection col = dbAdmin.createCollection("testDocumentEncoding", mDoc);
531531
for (Charset c : CHARSETS) {
@@ -535,6 +535,7 @@ public void testDocumentEncoding() throws Exception {
535535
}
536536

537537
// Test with RAW
538+
/* ### Oracle Database does not support RAW storage for JSON
538539
OracleDocument meta2 = client.createMetadataBuilder()
539540
.keyColumnAssignmentMethod("CLIENT").contentColumnType("RAW").build();
540541
OracleDocument mDoc2 = db.createDocumentFromByteArray(null,
@@ -547,6 +548,7 @@ public void testDocumentEncoding() throws Exception {
547548
if (c != UTF32 && c != UTF32LE && c != UTF32BE)
548549
basicTestForEncoding(c, col2);
549550
}
551+
*/
550552

551553
// Test with VARCHAR2
552554
OracleDocument meta3 = client.createMetadataBuilder()
@@ -559,6 +561,7 @@ public void testDocumentEncoding() throws Exception {
559561
}
560562

561563
// Test with NVARCHAR2
564+
/* ### Oracle Database does not support NVARCHAR2 storage for JSON
562565
OracleDocument meta4 = client.createMetadataBuilder()
563566
.keyColumnAssignmentMethod("CLIENT").contentColumnType("NVARCHAR2").build();
564567
OracleDocument mDoc4 = db.createDocumentFromByteArray(null,
@@ -567,6 +570,7 @@ public void testDocumentEncoding() throws Exception {
567570
for (Charset c : CHARSETS) {
568571
basicTestForEncoding(c, col4);
569572
}
573+
*/
570574

571575
// Test with CLOB
572576
OracleDocument meta5 = client.createMetadataBuilder()
@@ -579,6 +583,7 @@ public void testDocumentEncoding() throws Exception {
579583
}
580584

581585
// Test with NCLOB
586+
/* ### Oracle Database does not support NCLOB storage for JSON
582587
OracleDocument meta6 = client.createMetadataBuilder()
583588
.keyColumnAssignmentMethod("CLIENT").contentColumnType("NCLOB").build();
584589
OracleDocument mDoc6 = db.createDocumentFromByteArray(null,
@@ -587,7 +592,7 @@ public void testDocumentEncoding() throws Exception {
587592
for (Charset c : CHARSETS) {
588593
basicTestForEncoding(c, col6);
589594
}
590-
595+
*/
591596
}
592597

593598
private void testlargeContentWithCol(OracleCollection col) throws Exception {

0 commit comments

Comments
 (0)