Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SqlBuilder |
|
| 0.0;0 |
1 | package org.apache.maven.archiva.database.constraints; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.commons.lang.StringUtils; | |
23 | ||
24 | import java.util.List; | |
25 | ||
26 | /** | |
27 | * SqlBuilder - common sql building mechanisms. | |
28 | * | |
29 | * @version $Id: SqlBuilder.java 718864 2008-11-19 06:33:35Z brett $ | |
30 | */ | |
31 | 0 | public class SqlBuilder |
32 | { | |
33 | /** | |
34 | * Append a sql specific where clause within <code>"()"</code> braces that selects the specific | |
35 | * repository ids provided. | |
36 | * | |
37 | * NOTE: This does not append the "WHERE" statement itself. | |
38 | * | |
39 | * @param sql the sql buffer to append to. | |
40 | * @param fieldId the field id for the repository Id. | |
41 | * @param selectedRepositoryIds the list of repository ids to provide. | |
42 | */ | |
43 | public static void appendWhereSelectedRepositories( StringBuffer sql, String fieldId, | |
44 | List<String> selectedRepositoryIds ) | |
45 | { | |
46 | 0 | if ( fieldId == null ) |
47 | { | |
48 | 0 | throw new NullPointerException( "Null field id is not allowed." ); |
49 | } | |
50 | ||
51 | 0 | if ( StringUtils.isBlank( fieldId ) ) |
52 | { | |
53 | 0 | throw new IllegalArgumentException( "Blank field id is not allowed." ); |
54 | } | |
55 | ||
56 | 0 | if ( selectedRepositoryIds == null ) |
57 | { | |
58 | 0 | throw new NullPointerException( "Selected repositories cannot be null." ); |
59 | } | |
60 | ||
61 | 0 | if ( selectedRepositoryIds.isEmpty() ) |
62 | { | |
63 | 0 | throw new IllegalArgumentException( "Selected repositories cannot be null." ); |
64 | } | |
65 | ||
66 | 0 | sql.append( " (" ); |
67 | 0 | boolean multiple = false; |
68 | 0 | for ( String repo : selectedRepositoryIds ) |
69 | { | |
70 | 0 | if ( multiple ) |
71 | { | |
72 | 0 | sql.append( " || " ); |
73 | } | |
74 | 0 | sql.append( " " ).append( fieldId ).append( " == \"" ).append( repo ).append( "\"" ); |
75 | 0 | multiple = true; |
76 | } | |
77 | 0 | sql.append( " )" ); |
78 | 0 | } |
79 | } |