Skip to content

Commit

Permalink
Removed nvarchar2/nclob/raw support, changed table name defaulting
Browse files Browse the repository at this point in the history
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
  • Loading branch information
morgiyan committed Jan 5, 2016
1 parent 34b0fbf commit 28ab636
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<fileset dir="${classes.dir}"/>
<fileset dir="${resources.dir}"/>
<manifest>
<attribute name="Repository-Id" value="XDK_SODA1.0.0_LINUX.X64_151210 GITHUB"/>
<attribute name="Repository-Id" value="XDK_SODA1.0.0_LINUX.X64_151227 GITHUB"/>
</manifest>
</jar>
</target>
Expand Down
2 changes: 1 addition & 1 deletion json.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<property name="jsr353.jar" value="${env.SODA_JSR353_JAR}"/>

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

<!--
Generic project layout
Expand Down
48 changes: 45 additions & 3 deletions src/oracle/soda/rdbms/impl/CollectionDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;

import java.util.Map;
import java.util.Locale;

import javax.json.JsonObject;
import javax.json.JsonString;
Expand Down Expand Up @@ -161,14 +162,30 @@ public class CollectionDescriptor
final String doctypeColumnName;
final String creationColumnName;

/**
* Return a SQL identifier derived from the string, case-preserving
*/
static String stringToIdentifier(String jsonName)
{
return(CollectionDescriptor.stringToIdentifier(jsonName, true));
}

/**
* Return a SQL identifier derived from the string,
* optionally either case-preserving or upper-casing
*/
static String stringToIdentifier(String jsonName, boolean preserveCase)
{
String identifierName = null;
if (jsonName != null)
{
char[] data = jsonName.toCharArray();
if (data.length == 0) return("");

boolean hasUpper = false;
boolean hasLower = false;
boolean toUpper = !preserveCase;

// Examine all characters of data
for (int i = 0; i < data.length; ++i)
{
Expand All @@ -177,9 +194,32 @@ static String stringToIdentifier(String jsonName)
data[i] = '_'; // Replace double quotes with underscores
else if (ch < ' ')
data[i] = '_'; // Replace control characters with underscores
else if ((ch >= 'A') && (ch <= 'Z'))
hasUpper = true;
else if ((ch >= 'a') && (ch <= 'z'))
hasLower = true;
// If the string contains non-alphanumeric characters
// that aren't allowed by SQL, we shouldn't uppercase it
else if (((ch < '0') || (ch > '9')) &&
((ch != '_') && (ch != '$') && (ch != '#')))
toUpper = false;
}

// If the string is mixed case, we shouldn't uppercase it
if (toUpper && hasUpper && hasLower)
toUpper = false;
// If the string doesn't start with an alphabetic character
// we shouldn't upper case it
if (toUpper)
{
char ch = data[0];
if (((ch < 'A') || (ch > 'Z')) && ((ch < 'a') || (ch > 'z')))
toUpper = false;
}

identifierName = new String(data);

if (toUpper) identifierName = identifierName.toUpperCase(Locale.US);
}
return(identifierName);
}
Expand Down Expand Up @@ -1036,7 +1076,7 @@ CollectionDescriptor buildDescriptor(String uriName,
byte dbObjectType = this.dbObjectType;
if (dbObjectName == null)
{
dbObjectName = stringToIdentifier(uriName);
dbObjectName = stringToIdentifier(uriName, false); // Case converting
dbObjectType = DBOBJECT_TABLE;
}

Expand Down Expand Up @@ -1217,6 +1257,7 @@ else if (sqlType.equalsIgnoreCase("varchar"))
type = CHAR_CONTENT;
else if (sqlType.equalsIgnoreCase("varchar2"))
type = CHAR_CONTENT;
/* Raw, and n-types are not currently supported
else if (sqlType.equalsIgnoreCase("raw"))
type = RAW_CONTENT;
else if (sqlType.equalsIgnoreCase("nchar"))
Expand All @@ -1225,12 +1266,13 @@ else if (sqlType.equalsIgnoreCase("nvarchar"))
type = NCHAR_CONTENT;
else if (sqlType.equalsIgnoreCase("nvarchar2"))
type = NCHAR_CONTENT;
else if (sqlType.equalsIgnoreCase("nclob"))
type = NCLOB_CONTENT;
*/
else if (sqlType.equalsIgnoreCase("blob"))
type = BLOB_CONTENT;
else if (sqlType.equalsIgnoreCase("clob"))
type = CLOB_CONTENT;
else if (sqlType.equalsIgnoreCase("nclob"))
type = NCLOB_CONTENT;
else
throw SODAUtils.makeException(SODAMessage.EX_INVALID_ARG_VALUE, sqlType);

Expand Down
10 changes: 9 additions & 1 deletion test/src/oracle/json/tests/soda/test_OracleCollectionAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void testIsHeterogeneous() throws Exception {
assertEquals(msg, e.getMessage());
}

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

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

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

*/

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

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

}

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

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

}

Expand Down
38 changes: 26 additions & 12 deletions test/src/oracle/json/tests/soda/test_OracleDatabaseAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ public void testCreateCollection2() throws Exception {
}

//Test with unmatched contentColumnMaxLength
OracleDocument metaDoc10 = client.createMetadataBuilder().contentColumnType("NVARCHAR2").contentColumnMaxLength(1024).build();
OracleDocument metaDoc10 = client.createMetadataBuilder().contentColumnType("VARCHAR2").contentColumnMaxLength(1024).build();
String colName10 = "testCreateCollection10";
dbAdmin.createCollection(colName10, metaDoc10);
OracleDocument metaDoc10_1 = client.createMetadataBuilder().contentColumnType("NVARCHAR2").contentColumnMaxLength(256).build();
OracleDocument metaDoc10_1 = client.createMetadataBuilder().contentColumnType("VARCHAR2").contentColumnMaxLength(256).build();
try {
dbAdmin.createCollection(colName10, metaDoc10_1);
fail("No exception when mismatch on collection metadata");
Expand Down Expand Up @@ -385,7 +385,7 @@ public void testCreateCollection2() throws Exception {
OracleDocument metaDoc24 = client.createMetadataBuilder().contentColumnType("CLOB").build();
String colName24 = "testCreateCollection24";
dbAdmin.createCollection(colName24, metaDoc24);
OracleDocument metaDoc24_1 = client.createMetadataBuilder().contentColumnType("RAW").build();
OracleDocument metaDoc24_1 = client.createMetadataBuilder().contentColumnType("BLOB").build();
try {
dbAdmin.createCollection(colName24, metaDoc24_1);
fail("No exception when mismatch on collection metadata");
Expand Down Expand Up @@ -863,15 +863,17 @@ private void testContColType(String contColType) throws Exception {
public void testContentColumnTypes() throws Exception {
testContColType("VARCHAR2");

testContColType("BLOB");

testContColType("CLOB");

/* ### Oracle Database does not support NVARCHAR2, NCLOB, or RAW storage for JSON
testContColType("NVARCHAR2");
testContColType("RAW");
testContColType("BLOB");

testContColType("CLOB");

testContColType("NCLOB");
*/

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

public void testContentMaxLength() throws Exception {

testContentMaxLength("NVARCHAR2");
testContentMaxLength("VARCHAR2");

/* ### Oracle Database does not support NVARCHAR2 or RAW storage for JSON
testContentMaxLength("NVARCHAR2");
testContentMaxLength("RAW");
*/

// Test about specifying CONTENT_MAX_LENGTH for "BLOB" type
try {
Expand Down Expand Up @@ -1120,6 +1125,7 @@ public void testContentMaxLength() throws Exception {
}

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

}

Expand Down Expand Up @@ -1157,7 +1164,7 @@ public void testKeyMetadata() throws Exception {

// Test with key column type=NVARCHAR2 && max key length=512 && key method=GUID
OracleDocument mDoc2 = client.createMetadataBuilder()
.contentColumnType("NVARCHAR2").contentColumnMaxLength(512)
.keyColumnType("NVARCHAR2").keyColumnMaxLength(512)
.keyColumnAssignmentMethod("GUID").build();

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

// Test with key column type=RAW && key method=UUID
OracleDocument mDoc3 = client.createMetadataBuilder()
.contentColumnType("RAW").keyColumnAssignmentMethod("UUID").build();
.keyColumnType("RAW").keyColumnAssignmentMethod("UUID").build();

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

public void testSecureFileMetadata() throws Exception {

final String[] sqlTypes = { "BLOB", "CLOB", "NCLOB"};
// ### Oracle Database does not support NVARCHAR2 or NCLOB storage for JSON
//final String[] sqlTypes = { "BLOB", "CLOB", "NCLOB"};

final String[] sqlTypes = { "BLOB", "CLOB"};
final String[] compressions = { "NONE", "HIGH", "MEDIUM", "LOW"};
final boolean[] cachings = {true, false};
final String[] encryptions = {"3DES168", "AES128", "AES192", "AES256"};
Expand Down Expand Up @@ -1399,7 +1409,9 @@ public void testSecureFileMetadata() throws Exception {
}
} // end for "for lobTypes" loop

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

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

}

Expand Down
9 changes: 7 additions & 2 deletions test/src/oracle/json/tests/soda/test_OracleDocument2.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public void testDocumentEncoding() throws Exception {
OracleDocument meta = client.createMetadataBuilder()
.keyColumnAssignmentMethod("CLIENT")
.contentColumnType("BLOB")
.build();
.build();
OracleDocument mDoc = db.createDocumentFromByteArray(null, meta.getContentAsString().getBytes(UTF8), null);
OracleCollection col = dbAdmin.createCollection("testDocumentEncoding", mDoc);
for (Charset c : CHARSETS) {
Expand All @@ -535,6 +535,7 @@ public void testDocumentEncoding() throws Exception {
}

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

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

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

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

// Test with NCLOB
/* ### Oracle Database does not support NCLOB storage for JSON
OracleDocument meta6 = client.createMetadataBuilder()
.keyColumnAssignmentMethod("CLIENT").contentColumnType("NCLOB").build();
OracleDocument mDoc6 = db.createDocumentFromByteArray(null,
Expand All @@ -587,7 +592,7 @@ public void testDocumentEncoding() throws Exception {
for (Charset c : CHARSETS) {
basicTestForEncoding(c, col6);
}

*/
}

private void testlargeContentWithCol(OracleCollection col) throws Exception {
Expand Down
Loading

0 comments on commit 28ab636

Please sign in to comment.