File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/dialect/function/AbstractAnsiTrimEmulationFunction.java | File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/dialect/DerbyDialect.java | |||
Method name: String render(List, SessionFactoryImplementor)
|
Method name: String render(List, SessionFactoryImplementor)
|
|||
Number of AST nodes: 41 | Number of AST nodes: 37 | |||
1 | if ( args.size() == 1 ) {↵ | 1 | if ( args.size() == 1 ) {↵ | |
2 | // we have the form: trim(trimSource)↵ | 2 | // we have the form: trim(trimSource)↵ | |
3 | // so we trim leading and trailing spaces↵ | 3 | // so we trim leading and trailing spaces↵ | |
4 | return resolveBothSpaceTrimFunction().render( args, factory );↵ | 4 | return BOTH_SPACE_TRIM.render( args, factory );↵ | |
5 | // EARLY EXIT!!!!↵ | 5 | ↵ | |
6 | }↵ | 6 | }↵ | |
7 | else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {↵ | 7 | else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {↵ | |
8 | // we have the form: trim(from trimSource).↵ | 8 | // we have the form: trim(from trimSource).↵ | |
9 | // This is functionally equivalent to trim(trimSource)↵ | 9 | // This is functionally equivalent to trim(trimSource)↵ | |
10 | return resolveBothSpaceTrimFromFunction().render( args, factory ); // EARLY EXIT!!!!↵ | 10 | return BOTH_SPACE_TRIM_FROM.render( args, factory );↵ | |
11 | }↵ | 11 | }↵ | |
12 | else {↵ | 12 | else {↵ | |
13 | // otherwise, a trim-specification and/or a trim-character↵ | 13 | // otherwise, a trim-specification and/or a trim-character↵ | |
14 | // have been specified; we need to decide which options↵ | 14 | // have been specified; we need to decide which options↵ | |
15 | // are present and "do the right thing"↵ | 15 | // are present and "do the right thing"↵ | |
16 | boolean leading = true; // should leading trim-characters be trimmed?↵ | 16 | boolean leading = true; // should leading trim-characters be trimmed?↵ | |
17 | boolean trailing = true; // should trailing trim-characters be trimmed?↵ | 17 | boolean trailing = true; // should trailing trim-characters be trimmed?↵ | |
18 | String trimCharacter; // the trim-character (what is to be trimmed off?)↵ | 18 | String trimCharacter; // the trim-character↵ | |
19 | String trimSource; // the trim-source (from where should it be trimmed?)↵ | 19 | String trimSource; // the trim-source↵ | |
20 | // potentialTrimCharacterArgIndex = 1 assumes that a↵ | 20 | // potentialTrimCharacterArgIndex = 1 assumes that a↵ | |
21 | // trim-specification has been specified. we handle the↵ | 21 | // trim-specification has been specified. we handle the↵ | |
22 | // exception to that explicitly↵ | 22 | // exception to that explicitly↵ | |
23 | int potentialTrimCharacterArgIndex = 1;↵ | 23 | int potentialTrimCharacterArgIndex = 1;↵ | |
24 | String firstArg = ( String ) args.get( 0 );↵ | 24 | String firstArg = ( String ) args.get( 0 );↵ | |
25 | if ( "leading".equalsIgnoreCase( firstArg ) ) {↵ | 25 | if ( "leading".equalsIgnoreCase( firstArg ) ) {↵ | |
26 | trailing = false;↵ | 26 | trailing = false;↵ | |
27 | }↵ | 27 | }↵ | |
28 | else if ( "trailing".equalsIgnoreCase( firstArg ) ) {↵ | 28 | else if ( "trailing".equalsIgnoreCase( firstArg ) ) {↵ | |
29 | leading = false;↵ | 29 | leading = false;↵ | |
30 | }↵ | 30 | }↵ | |
31 | else if ( "both".equalsIgnoreCase( firstArg ) ) {↵ | 31 | else if ( "both".equalsIgnoreCase( firstArg ) ) {↵ | |
32 | }↵ | 32 | }↵ | |
33 | else {↵ | 33 | else {↵ | |
34 | potentialTrimCharacterArgIndex = 0;↵ | 34 | potentialTrimCharacterArgIndex = 0;↵ | |
35 | }↵ | 35 | }↵ | |
36 | String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );↵ | 36 | String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );↵ | |
37 | if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) { ↵ | 37 | if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {↵ | |
38 | trimCharacter = "' '";↵ | 38 | trimCharacter = "' '";↵ | |
39 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵ | 39 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵ | |
40 | }↵ | 40 | }↵ | |
41 | else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {↵ | 41 | else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {↵ | |
42 | trimCharacter = "' '";↵ | 42 | trimCharacter = "' '";↵ | |
43 | trimSource = potentialTrimCharacter;↵ | 43 | trimSource = potentialTrimCharacter;↵ | |
44 | }↵ | 44 | }↵ | |
45 | else {↵ | 45 | else {↵ | |
46 | trimCharacter = potentialTrimCharacter;↵ | 46 | trimCharacter = potentialTrimCharacter;↵ | |
47 | if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {↵ | 47 | if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {↵ | |
48 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );↵ | 48 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );↵ | |
49 | }↵ | 49 | }↵ | |
50 | else {↵ | 50 | else {↵ | |
51 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵ | 51 | trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );↵ | |
52 | }↵ | 52 | }↵ | |
53 | }↵ | 53 | }↵ | |
54 | List argsToUse = new ArrayList();↵ | 54 | List argsToUse = new ArrayList();↵ | |
55 | argsToUse.add( trimSource );↵ | 55 | argsToUse.add( trimSource );↵ | |
56 | argsToUse.add( trimCharacter );↵ | 56 | argsToUse.add( trimCharacter );↵ | |
57 | if ( trimCharacter.equals( "' '" ) ) {↵ | 57 | if ( trimCharacter.equals( "' '" ) ) {↵ | |
58 | if ( leading && trailing ) {↵ | 58 | if ( leading && trailing ) {↵ | |
59 | return resolveBothSpaceTrimFunction().render( argsToUse, factory );↵ | 59 | return BOTH_SPACE_TRIM.render( argsToUse, factory );↵ | |
60 | }↵ | 60 | }↵ | |
61 | else if ( leading ) {↵ | 61 | else if ( leading ) {↵ | |
62 | return resolveLeadingSpaceTrimFunction().render( argsToUse, factory );↵ | 62 | return LEADING_SPACE_TRIM.render( argsToUse, factory );↵ | |
63 | }↵ | 63 | }↵ | |
64 | else {↵ | 64 | else {↵ | |
65 | return resolveTrailingSpaceTrimFunction().render( argsToUse, factory );↵ | 65 | return TRAILING_SPACE_TRIM.render( argsToUse, factory );↵ | |
66 | }↵ | 66 | }↵ | |
67 | }↵ | 67 | }↵ | |
68 | else {↵ | 68 | else {↵ | |
69 | if ( leading && trailing ) {↵ | 69 | ↵ | |
70 | return resolveBothTrimFunction().render( argsToUse, factory );↵ | |||
71 | }↵ | |||
72 | else if ( leading ) {↵ | |||
73 | return resolveLeadingTrimFunction().render( argsToUse, factory );↵ | 70 | throw new HibernateException( "cannot specify trim character when using Derby as Derby does not support the ANSI trim function↵ | |
74 | }↵ | |||
75 | else {↵ | |||
76 | return resolveTrailingTrimFunction().render( argsToUse, factory );↵ | 71 | , not does it support a replace function to properly emmulate it" );↵ | |
77 | }↵ | 72 | }↵ | |
78 | }↵ | 73 |
| |
79 | } | |||
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 2 |
Number of refactorable cases | 1 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 4.9 |
Clones location | Clones are in different classes |
Number of node comparisons | 364 |
Number of mapped statements | 5 |
Number of unmapped statements in the first code fragment | 0 |
Number of unmapped statements in the second code fragment | 0 |
Time elapsed for statement mapping (ms) | 3.1 |
Clone type | Type 2 |
ID | Statement | ID | Statement | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
37 | if (leading && trailing) | 32 | if (leading && trailing) | |||||||||||
38 | return resolveBothTrimFunction().render(argsToUse, factory); |
| 33 | return BOTH_SPACE_TRIM.render(argsToUse, factory); | ||||||||||
39 | else if (leading) | 34 | else if (leading) | |||||||||||
40 | return resolveLeadingTrimFunction().render(argsToUse, factory); |
| 35 | return LEADING_SPACE_TRIM.render(argsToUse, factory); | ||||||||||
else | else | |||||||||||||
41 | return resolveTrailingTrimFunction().render(argsToUse, factory); |
| 36 | return TRAILING_SPACE_TRIM.render(argsToUse, factory); |
Row | Violation |
---|
Number of mapped statements | 36 |
Number of unmapped statements in the first code fragment | 0 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 35.2 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | if (args.size() == 1) | 1 | if (args.size() == 1) | |||||||||||
2 | return resolveBothSpaceTrimFunction().render(args, factory); |
| 2 | return BOTH_SPACE_TRIM.render(args, factory); | ||||||||||
3 | else if ("from".equalsIgnoreCase((String)args.get(0))) | 3 | else if ("from".equalsIgnoreCase((String)args.get(0))) | |||||||||||
4 | return resolveBothSpaceTrimFromFunction().render(args, factory); |
| 4 | return BOTH_SPACE_TRIM_FROM.render(args, factory); | ||||||||||
else | else | |||||||||||||
5 | boolean leading = true; | 5 | boolean leading = true; | |||||||||||
6 | boolean trailing = true; | 6 | boolean trailing = true; | |||||||||||
7 | String trimCharacter; | 7 | String trimCharacter; | |||||||||||
8 | String trimSource; | 8 | String trimSource; | |||||||||||
9 | int potentialTrimCharacterArgIndex = 1; | 9 | int potentialTrimCharacterArgIndex = 1; | |||||||||||
10 | String firstArg = (String)args.get(0); | 10 | String firstArg = (String)args.get(0); | |||||||||||
11 | if ("leading".equalsIgnoreCase(firstArg)) | 11 | if ("leading".equalsIgnoreCase(firstArg)) | |||||||||||
12 | trailing = false; | 12 | trailing = false; | |||||||||||
13 | else if ("trailing".equalsIgnoreCase(firstArg)) | 13 | else if ("trailing".equalsIgnoreCase(firstArg)) | |||||||||||
14 | leading = false; | 14 | leading = false; | |||||||||||
15 | else if ("both".equalsIgnoreCase(firstArg)) | 15 | else if ("both".equalsIgnoreCase(firstArg)) | |||||||||||
else | else | |||||||||||||
16 | potentialTrimCharacterArgIndex = 0; | 16 | potentialTrimCharacterArgIndex = 0; | |||||||||||
17 | String potentialTrimCharacter = (String)args.get(potentialTrimCharacterArgIndex); | 17 | String potentialTrimCharacter = (String)args.get(potentialTrimCharacterArgIndex); | |||||||||||
18 | if ("from".equalsIgnoreCase(potentialTrimCharacter)) | 18 | if ("from".equalsIgnoreCase(potentialTrimCharacter)) | |||||||||||
19 | trimCharacter = "' '"; | 19 | trimCharacter = "' '"; | |||||||||||
20 | trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1); | 20 | trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1); | |||||||||||
21 | else if (potentialTrimCharacterArgIndex + 1 >= args.size()) | 21 | else if (potentialTrimCharacterArgIndex + 1 >= args.size()) | |||||||||||
22 | trimCharacter = "' '"; | 22 | trimCharacter = "' '"; | |||||||||||
23 | trimSource = potentialTrimCharacter; | 23 | trimSource = potentialTrimCharacter; | |||||||||||
else | else | |||||||||||||
24 | trimCharacter = potentialTrimCharacter; | 24 | trimCharacter = potentialTrimCharacter; | |||||||||||
25 | if ("from".equalsIgnoreCase((String)args.get(potentialTrimCharacterArgIndex + 1))) | 25 | if ("from".equalsIgnoreCase((String)args.get(potentialTrimCharacterArgIndex + 1))) | |||||||||||
26 | trimSource = (String)args.get(potentialTrimCharacterArgIndex + 2); | 26 | trimSource = (String)args.get(potentialTrimCharacterArgIndex + 2); | |||||||||||
else | else | |||||||||||||
27 | trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1); | 27 | trimSource = (String)args.get(potentialTrimCharacterArgIndex + 1); | |||||||||||
28 | List argsToUse = new ArrayList(); | 28 | List argsToUse = new ArrayList(); | |||||||||||
29 | argsToUse.add(trimSource); | 29 | argsToUse.add(trimSource); | |||||||||||
30 | argsToUse.add(trimCharacter); | 30 | argsToUse.add(trimCharacter); | |||||||||||
31 | if (trimCharacter.equals("' '")) | 31 | if (trimCharacter.equals("' '")) | |||||||||||
32 | if (leading && trailing) | 32 | if (leading && trailing) | |||||||||||
33 | return resolveBothSpaceTrimFunction().render(argsToUse, factory); |
| 33 | return BOTH_SPACE_TRIM.render(argsToUse, factory); | ||||||||||
34 | else if (leading) | 34 | else if (leading) | |||||||||||
35 | return resolveLeadingSpaceTrimFunction().render(argsToUse, factory); |
| 35 | return LEADING_SPACE_TRIM.render(argsToUse, factory); | ||||||||||
else | else | |||||||||||||
36 | return resolveTrailingSpaceTrimFunction().render(argsToUse, factory); |
| 36 | return TRAILING_SPACE_TRIM.render(argsToUse, factory); | ||||||||||
| else | |||||||||||||
|
| 37 | throw new HibernateException("cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it"); |
Row | Violation |
---|---|
1 | Unmatched throw new HibernateException("cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it"); |
2 | Clone fragment #1 returns variables leading, trailing, argsToUse , while Clone fragment #2 returns variables |