1 package org.apache.maven.archiva.database.constraints;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.maven.archiva.database.Constraint;
23 import org.apache.maven.archiva.model.ArchivaArtifactModel;
25 import java.util.List;
28 * UniqueGroupIdConstraint
32 public class UniqueGroupIdConstraint
33 extends AbstractSimpleConstraint
36 private StringBuffer sql = new StringBuffer();
38 public UniqueGroupIdConstraint()
40 /* this assumes search for no groupId prefix */
45 public UniqueGroupIdConstraint( List<String> selectedRepositories )
48 sql.append( " WHERE " );
49 SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositories );
53 public UniqueGroupIdConstraint( List<String> selectedRepositories, String groupIdPrefix )
56 sql.append( " WHERE " );
57 SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositories );
59 appendWhereGroupIdStartsWith( sql );
62 super.params = new Object[] { groupIdPrefix };
65 public UniqueGroupIdConstraint( String groupIdPrefix )
68 sql.append( " WHERE " );
69 appendWhereGroupIdStartsWith( sql );
72 super.params = new Object[] { groupIdPrefix };
75 @SuppressWarnings("unchecked")
76 public Class getResultClass()
81 public String getSelectSql()
83 return sql.toString();
86 private void appendGroupBy( StringBuffer buf )
88 buf.append( " GROUP BY groupId ORDER BY groupId ASCENDING" );
91 private void appendSelect( StringBuffer buf )
93 buf.append( "SELECT groupId FROM " ).append( ArchivaArtifactModel.class.getName() );
96 private void appendWhereGroupIdStartsWith( StringBuffer buf )
98 buf.append( " groupId.startsWith(groupIdPrefix) PARAMETERS String groupIdPrefix" );