Coverage Report - org.apache.maven.archiva.database.constraints.UniqueGroupIdConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
UniqueGroupIdConstraint
0%
0/38
N/A
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.maven.archiva.database.Constraint;
 23  
 import org.apache.maven.archiva.model.ArchivaArtifactModel;
 24  
 
 25  
 import java.util.List;
 26  
 
 27  
 /**
 28  
  * UniqueGroupIdConstraint 
 29  
  *
 30  
  * @version $Id: UniqueGroupIdConstraint.java 1043850 2010-12-09 07:58:00Z brett $
 31  
  */
 32  
 public class UniqueGroupIdConstraint
 33  
     extends AbstractSimpleConstraint
 34  
     implements Constraint
 35  
 {
 36  0
     private StringBuffer sql = new StringBuffer();
 37  
 
 38  
     public UniqueGroupIdConstraint()
 39  0
     {
 40  
         /* this assumes search for no groupId prefix */
 41  0
         appendGroupBy( sql );
 42  0
     }
 43  
 
 44  
     public UniqueGroupIdConstraint( List<String> selectedRepositories )
 45  0
     {
 46  0
         sql.append( " WHERE " );
 47  0
         SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositories );
 48  0
         appendGroupBy( sql );
 49  0
     }
 50  
 
 51  
     public UniqueGroupIdConstraint( List<String> selectedRepositories, String groupIdPrefix )
 52  0
     {
 53  0
         sql.append( " WHERE " );
 54  0
         SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositories );
 55  0
         sql.append( " && " );
 56  0
         appendWhereGroupIdStartsWith( sql );
 57  0
         appendGroupBy( sql );
 58  
 
 59  0
         super.params = new Object[] { groupIdPrefix };
 60  0
     }
 61  
 
 62  
     public UniqueGroupIdConstraint( String groupIdPrefix )
 63  0
     {
 64  0
         sql.append( " WHERE " );
 65  0
         appendWhereGroupIdStartsWith( sql );
 66  0
         appendGroupBy( sql );
 67  
 
 68  0
         super.params = new Object[] { groupIdPrefix };
 69  0
     }
 70  
 
 71  
     @SuppressWarnings("unchecked")
 72  
     public Class getResultClass()
 73  
     {
 74  0
         return String.class;
 75  
     }
 76  
 
 77  
     public String getSelectSql()
 78  
     {
 79  0
         StringBuffer buf = new StringBuffer();
 80  0
         appendSelect( buf );
 81  0
         buf.append( sql );
 82  0
         return buf.toString();
 83  
     }
 84  
 
 85  
     @Override
 86  
     public String getCountSql()
 87  
     {
 88  0
         StringBuffer buf = new StringBuffer();
 89  0
         buf.append( "SELECT count(groupId) FROM " ).append( ArchivaArtifactModel.class.getName() );
 90  0
         buf.append( sql );
 91  0
         return buf.toString();
 92  
     }
 93  
 
 94  
     private void appendGroupBy( StringBuffer buf )
 95  
     {
 96  0
         buf.append( " GROUP BY groupId ORDER BY groupId ASCENDING" );
 97  0
     }
 98  
 
 99  
     private void appendSelect( StringBuffer buf )
 100  
     {
 101  0
         buf.append( "SELECT groupId FROM " ).append( ArchivaArtifactModel.class.getName() );
 102  0
     }
 103  
 
 104  
     private void appendWhereGroupIdStartsWith( StringBuffer buf )
 105  
     {
 106  0
         buf.append( " groupId.startsWith(groupIdPrefix) PARAMETERS String groupIdPrefix" );
 107  0
     }
 108  
 }