private String nameViewOrVariable ( final String prefix , final String intermediateName , final String suffix , final Collection < String > alreadyDefinedNames , boolean putQuote ) { int borderLength = prefix . length ( ) + suffix . length ( ) ; int signatureVarLength = intermediateName . length ( ) ; if ( borderLength >= ( NAME_MAX_LENGTH - NAME_NUMBER_LENGTH ) ) { throw new IllegalArgumentException ( "The prefix and the suffix are too long (their accumulated length must " + "be less than " + ( NAME_MAX_LENGTH - NAME_NUMBER_LENGTH ) + ")" ) ; } /** * If the length limit is not reached, processes as usual. */ if ( signatureVarLength + borderLength <= NAME_MAX_LENGTH ) { String unquotedName = buildDefaultName ( prefix , intermediateName , suffix ) ; String name = putQuote ? sqlQuote ( unquotedName ) : unquotedName ; return name ; } String shortenIntermediateNamePrefix = intermediateName . substring ( 0 , NAME_MAX_LENGTH - borderLength - NAME_NUMBER_LENGTH ) ; /** * Naive implementation */ for ( int i = 0 ; i < Math . pow ( 10 , NAME_NUMBER_LENGTH ) ; i ++ ) { String unquotedVarName = buildDefaultName ( prefix , shortenIntermediateNamePrefix + i , suffix ) ; String mainVarName = putQuote ? sqlQuote ( unquotedVarName ) : unquotedVarName ; if ( ! alreadyDefinedNames . contains ( mainVarName ) ) { return mainVarName ; } } // TODO: find a better exception throw new RuntimeException ( "Impossible to create a new variable/view " + prefix + shortenIntermediateNamePrefix + "???" + suffix + " : already " + Math . pow ( 10 , NAME_NUMBER_LENGTH ) + " of them." ) ; }
Makes sure the view or variable name never exceeds the max length supported by Oracle .