private String buildInsert(boolean disableReturning){
  sb.setLength(0);
  sb.append("insert into ");
  appendTable(sb);
  sb.append(" (\"");
  sb.append(options.keyColumnName);
  sb.append("\",\"");
  if (options.doctypeColumnName != null) {
    sb.append(options.doctypeColumnName);
    sb.append("\",\"");
  }
  sb.append(options.contentColumnName);
  sb.append("\"");
  if (options.timestampColumnName != null) {
    sb.append(",\"");
    sb.append(options.timestampColumnName);
    sb.append("\"");
  }
  if (options.creationColumnName != null) {
    sb.append(",\"");
    sb.append(options.creationColumnName);
    sb.append("\"");
  }
  if ((options.versionColumnName != null) && (options.versioningMethod) != CollectionDescriptor.VERSION_NONE) {
    sb.append(",\"");
    sb.append(options.versionColumnName);
    sb.append("\"");
  }
  sb.append(") values (");
  if ((options.keySequenceName != null) && (!disableReturning)) {
switch (options.keyDataType) {
case CollectionDescriptor.INTEGER_KEY:
      sb.append("\"");
    sb.append(options.keySequenceName);
  sb.append("\".NEXTVAL");
break;
case CollectionDescriptor.RAW_KEY:
sb.append("hextoraw(substr(to_char(\"");
sb.append(options.keySequenceName);
sb.append("\".NEXTVAL,'0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),3))");
break;
case CollectionDescriptor.STRING_KEY:
case CollectionDescriptor.NCHAR_KEY:
default :
sb.append("to_char(\"");
sb.append(options.keySequenceName);
sb.append("\".NEXTVAL)");
break;
}
}
 else if ((options.keyAssignmentMethod == CollectionDescriptor.KEY_ASSIGN_GUID) && (!disableReturning)) {
switch (options.keyDataType) {
case CollectionDescriptor.INTEGER_KEY:
sb.append("to_number(");
sb.append("rawtohex(SYS_GUID()),");
sb.append("'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')");
break;
case CollectionDescriptor.RAW_KEY:
sb.append("SYS_GUID()");
break;
case CollectionDescriptor.STRING_KEY:
case CollectionDescriptor.NCHAR_KEY:
default :
sb.append("rawtohex(SYS_GUID())");
break;
}
}
 else {
addKey(sb);
}
if (options.doctypeColumnName != null) {
sb.append(",?");
}
sb.append(",?");
if (options.timestampColumnName != null) {
if (disableReturning) OracleDatabaseImpl.addToTimestamp(",",sb);
 else sb.append(",sys_extract_utc(SYSTIMESTAMP)");
}
if (options.creationColumnName != null) {
if (disableReturning) OracleDatabaseImpl.addToTimestamp(",",sb);
 else sb.append(",sys_extract_utc(SYSTIMESTAMP)");
}
if ((options.versionColumnName != null) && (options.versioningMethod) != CollectionDescriptor.VERSION_NONE) sb.append(",?");
sb.append(")");
if (insertHasReturnClause(disableReturning)) {
sb.append(" returning ");
int count=0;
if (returnInsertedKey()) {
sb.append("\"");
sb.append(options.keyColumnName);
sb.append("\"");
count++;
}
if (returnInsertedTime()) {
addComma(sb,count);
sb.append("to_char(\"");
if (options.timestampColumnName != null) sb.append(options.timestampColumnName);
 else sb.append(options.creationColumnName);
sb.append('"');
OracleDatabaseImpl.addTimestampReturningFormat(sb);
count++;
}
if (returnInsertedVersion()) {
addComma(sb,count);
sb.append("\"");
sb.append(options.versionColumnName);
sb.append("\"");
count++;
}
addInto(sb,count);
}
return (sb.toString());
}

private String buildInsert ( boolean disableReturning ) { sb . setLength ( 0 ) ; sb . append ( "insert into " ) ; appendTable ( sb ) ; sb . append ( " (\"" ) ; sb . append ( options . keyColumnName ) ; sb . append ( "\",\"" ) ; if ( options . doctypeColumnName != null ) { sb . append ( options . doctypeColumnName ) ; sb . append ( "\",\"" ) ; } sb . append ( options . contentColumnName ) ; sb . append ( "\"" ) ; if ( options . timestampColumnName != null ) { sb . append ( ",\"" ) ; sb . append ( options . timestampColumnName ) ; sb . append ( "\"" ) ; } if ( options . creationColumnName != null ) { sb . append ( ",\"" ) ; sb . append ( options . creationColumnName ) ; sb . append ( "\"" ) ; } if ( ( options . versionColumnName != null ) && ( options . versioningMethod ) != CollectionDescriptor . VERSION_NONE ) { sb . append ( ",\"" ) ; sb . append ( options . versionColumnName ) ; sb . append ( "\"" ) ; } sb . append ( ") values (" ) ; if ( ( options . keySequenceName != null ) && ( ! disableReturning ) ) { switch ( options . keyDataType ) { case CollectionDescriptor . INTEGER_KEY : sb . append ( "\"" ) ; sb . append ( options . keySequenceName ) ; sb . append ( "\".NEXTVAL" ) ; break ; case CollectionDescriptor . RAW_KEY : sb . append ( "hextoraw(substr(to_char(\"" ) ; sb . append ( options . keySequenceName ) ; sb . append ( "\".NEXTVAL,'0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),3))" ) ; break ; case CollectionDescriptor . STRING_KEY : case CollectionDescriptor . NCHAR_KEY : default : sb . append ( "to_char(\"" ) ; sb . append ( options . keySequenceName ) ; sb . append ( "\".NEXTVAL)" ) ; break ; } } else if ( ( options . keyAssignmentMethod == CollectionDescriptor . KEY_ASSIGN_GUID ) && ( ! disableReturning ) ) { switch ( options . keyDataType ) { case CollectionDescriptor . INTEGER_KEY : sb . append ( "to_number(" ) ; sb . append ( "rawtohex(SYS_GUID())," ) ; sb . append ( "'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')" ) ; break ; case CollectionDescriptor . RAW_KEY : sb . append ( "SYS_GUID()" ) ; break ; case CollectionDescriptor . STRING_KEY : case CollectionDescriptor . NCHAR_KEY : default : sb . append ( "rawtohex(SYS_GUID())" ) ; break ; } } else { addKey ( sb ) ; } if ( options . doctypeColumnName != null ) { sb . append ( ",?" ) ; } sb . append ( ",?" ) ; if ( options . timestampColumnName != null ) { if ( disableReturning ) OracleDatabaseImpl . addToTimestamp ( "," , sb ) ; else sb . append ( ",sys_extract_utc(SYSTIMESTAMP)" ) ; } if ( options . creationColumnName != null ) { if ( disableReturning ) OracleDatabaseImpl . addToTimestamp ( "," , sb ) ; else sb . append ( ",sys_extract_utc(SYSTIMESTAMP)" ) ; } if ( ( options . versionColumnName != null ) && ( options . versioningMethod ) != CollectionDescriptor . VERSION_NONE ) sb . append ( ",?" ) ; sb . append ( ")" ) ; if ( insertHasReturnClause ( disableReturning ) ) { sb . append ( " returning " ) ; int count = 0 ; if ( returnInsertedKey ( ) ) { sb . append ( "\"" ) ; sb . append ( options . keyColumnName ) ; sb . append ( "\"" ) ; count ++ ; } if ( returnInsertedTime ( ) ) { addComma ( sb , count ) ; sb . append ( "to_char(\"" ) ; if ( options . timestampColumnName != null ) sb . append ( options . timestampColumnName ) ; else sb . append ( options . creationColumnName ) ; sb . append ( '"' ) ; OracleDatabaseImpl . addTimestampReturningFormat ( sb ) ; count ++ ; } if ( returnInsertedVersion ( ) ) { addComma ( sb , count ) ; sb . append ( "\"" ) ; sb . append ( options . versionColumnName ) ; sb . append ( "\"" ) ; count ++ ; } addInto ( sb , count ) ; } return ( sb . toString ( ) ) ; }
build one of two variants of insert to the collection . the base version may have a returning clause for server - generated guid or sequence keys , and / or the optional last - modified timestamp . the batch version disables the returning clause , obliging the caller to supply those values from the server .
