1 | if ( args.size() == 1 ) {↵ | | |
|
2 | // we have the form: trim(trimSource)↵ | | |
|
3 | // so we trim leading and trailing spaces↵ | | |
|
4 | return BOTH_SPACE_TRIM.render( args, factory );↵ | | |
|
5 | }↵ | | |
|
6 | else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {↵ | | |
|
7 | // we have the form: trim(from trimSource).↵ | | |
|
8 | // This is functionally equivalent to trim(trimSource)↵ | | |
|
9 | return BOTH_SPACE_TRIM_FROM.render( args, factory );↵ | | |
|
10 | }↵ | | |
|
11 | else {↵ | | |
|
12 | // otherwise, a trim-specification and/or a trim-character↵ | | |
|
13 | // have been specified; we need to decide which options↵ | | |
|
14 | // are present and "do the right thing"↵ | | |
|
15 | boolean leading = true; // should leading trim-characters be trimmed?↵ | | 1 | boolean leading = true; // should leading trim-characters be trimmed?↵
|
16 | boolean trailing = true; // should trailing trim-characters be trimmed?↵ | | 2 | boolean trailing = true; // should trailing trim-characters be trimmed?↵
|
17 | String trimCharacter; // the trim-character↵ | | 3 | String trimCharacter; // the trim-character (what is to be trimmed off?)↵
|
18 | String trimSource; // the trim-source↵ | | 4 | String trimSource; // the trim-source (from where should it be trimmed?)↵
|
|
19 | // potentialTrimCharacterArgIndex = 1 assumes that a↵ | | 5 | // potentialTrimCharacterArgIndex = 1 assumes that a↵
|
20 | // trim-specification has been specified. we handle the↵ | | 6 | // trim-specification has been specified. we handle the↵
|
21 | // exception to that explicitly↵ | | 7 | // exception to that explicitly↵
|
22 | int potentialTrimCharacterArgIndex = 1;↵ | | 8 | int potentialTrimCharacterArgIndex = 1;↵
|
23 | String firstArg = ( String ) args.get( 0 );↵ | | 9 | String firstArg = ( String ) args.get( 0 );↵
|
24 | if ( "leading".equalsIgnoreCase( firstArg ) ) {↵ | | 10 | if ( "leading".equalsIgnoreCase( firstArg ) ) {↵
|
25 | trailing = false;↵ | | 11 | trailing = false;↵
|
26 | }↵ | | 12 | }↵
|
27 | else if ( "trailing".equalsIgnoreCase( firstArg ) ) {↵ | | 13 | else if ( "trailing".equalsIgnoreCase( firstArg ) ) {↵
|
28 | leading = false;↵ | | 14 | leading = false;↵
|
29 | }↵ | | 15 | }↵
|
30 | else if ( "both".equalsIgnoreCase( firstArg ) ) {↵ | | 16 | else if ( "both".equalsIgnoreCase( firstArg ) ) {↵
|
31 | }↵ | | 17 | }↵
|
32 | else {↵ | | 18 | else {↵
|
33 | potentialTrimCharacterArgIndex = 0;↵ | | 19 | potentialTrimCharacterArgIndex = 0;↵
|
34 | }↵ | | 20 | }↵
|
|
35 | String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );↵ | | 21 | String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );↵
|
36 | if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {↵ | | 22 | if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) { ↵
|
37 | trimCharacter = "' '";↵ | | 23 | trimCharacter = "' '";↵
|
38 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵ | | 24 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵
|
39 | }↵ | | 25 | }↵
|
40 | else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {↵ | | 26 | else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {↵
|
41 | trimCharacter = "' '";↵ | | 27 | trimCharacter = "' '";↵
|
42 | trimSource = potentialTrimCharacter;↵ | | 28 | trimSource = potentialTrimCharacter;↵
|
43 | }↵ | | 29 | }↵
|
44 | else {↵ | | 30 | else {↵
|
45 | trimCharacter = potentialTrimCharacter;↵ | | 31 | trimCharacter = potentialTrimCharacter;↵
|
46 | if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {↵ | | 32 | if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {↵
|
47 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );↵ | | 33 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );↵
|
48 | }↵ | | 34 | }↵
|
49 | else {↵ | | 35 | else {↵
|
50 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵ | | 36 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵
|
51 | }↵ | | 37 | }↵
|
52 | }↵ | | 38 | }↵
|
|
53 | List argsToUse = new ArrayList();↵ | | 39 | List argsToUse = new ArrayList();↵
|
54 | argsToUse.add( trimSource );↵ | | 40 | argsToUse.add( trimSource );↵
|
55 | argsToUse.add( trimCharacter );↵ | | 41 | argsToUse.add( trimCharacter );↵
|
|
56 | if ( trimCharacter.equals( "' '" ) ) {↵ | | 42 | if ( trimCharacter.equals( "' '" ) ) {↵
|
57 | if ( leading && trailing ) {↵ | | 43 | if ( leading && trailing ) {↵
|
58 | return BOTH_SPACE_TRIM.render( argsToUse, factory );↵ | | 44 | return resolveBothSpaceTrimFunction().render( argsToUse, factory );↵
|
59 | }↵ | | 45 | }↵
|
60 | else if ( leading ) {↵ | | 46 | else if ( leading ) {↵
|
61 | return LEADING_SPACE_TRIM.render( argsToUse, factory );↵ | | 47 | return resolveLeadingSpaceTrimFunction().render( argsToUse, factory );↵
|
62 | }↵ | | 48 | }↵
|
63 | else {↵ | | 49 | else {↵
|
64 | return TRAILING_SPACE_TRIM.render( argsToUse, factory );↵ | | 50 | return resolveTrailingSpaceTrimFunction().render( argsToUse, factory );↵
|
65 | }↵ | | 51 | }↵
|
66 | }↵ | | 52 | }↵
|
67 | else {↵ | | 53 | else {↵
|
68 | throw new HibernateException( "cannot specify trim character when using Derby as Derby does not support the ANSI t↵ | | 54 | if ( leading && trailing ) {↵
|
| | | 55 | return resolveBothTrimFunction().render( argsToUse, factory );↵
|
| | | 56 | }↵
|
| | | 57 | else if ( leading ) {↵
|
69 | rim function, not does it support a replace function to properly emmulate it"↵ | | 58 | return resolveLeadingTrimFunction().render( argsToUse, factory );↵
|
| | | 59 | }↵
|
| | | 60 | else {↵
|
70 | );↵ | | 61 | return resolveTrailingTrimFunction().render( argsToUse, factory );↵
|
71 | }↵ | | 62 | }↵
|
72 | } | | 63 | }
|