1 package org.apache.archiva.metadata.repository.cassandra.model;
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 com.netflix.astyanax.entitystore.Serializer;
23 import com.netflix.astyanax.serializers.GzipStringSerializer;
24 import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.Id;
31 * Cassandra storage model for {@link org.apache.archiva.metadata.model.MetadataFacet}
33 * @author Olivier Lamy
36 public class MetadataFacetModel
38 // id is repositoryId + namespaceId + projectId + facetId + name + mapKey
40 @Column( name = "id" )
41 @Serializer( HugeStringSerializer.class )
44 @Column( name = "artifactMetadataModel" )
45 private ArtifactMetadataModel artifactMetadataModel;
47 @Column( name = "facetId" )
48 @Serializer( HugeStringSerializer.class )
49 private String facetId;
51 @Column( name = "key" )
52 @Serializer( HugeStringSerializer.class )
55 @Column( name = "name" )
56 @Serializer( HugeStringSerializer.class )
59 @Column( name = "value" )
60 @Serializer( HugeStringSerializer.class )
63 public MetadataFacetModel()
68 public MetadataFacetModel( String id, ArtifactMetadataModel artifactMetadataModel, String facetId, String key,
69 String value, String name )
72 this.artifactMetadataModel = artifactMetadataModel;
76 this.facetId = facetId;
79 public String getFacetId()
84 public void setFacetId( String facetId )
86 this.facetId = facetId;
94 public void setId( String id )
99 public ArtifactMetadataModel getArtifactMetadataModel()
101 return artifactMetadataModel;
104 public void setArtifactMetadataModel( ArtifactMetadataModel artifactMetadataModel )
106 this.artifactMetadataModel = artifactMetadataModel;
109 public String getName()
114 public void setName( String name )
119 public String getKey()
124 public void setKey( String key )
129 public String getValue()
134 public void setValue( String value )
140 public boolean equals( Object o )
146 if ( o == null || getClass() != o.getClass() )
151 MetadataFacetModel that = (MetadataFacetModel) o;
153 if ( !id.equals( that.id ) )
162 public int hashCode()
164 return id.hashCode();
168 public String toString()
170 final StringBuilder sb = new StringBuilder( "MetadataFacetModel{" );
171 sb.append( "id='" ).append( id ).append( '\'' );
172 sb.append( ", artifactMetadataModel=" ).append( artifactMetadataModel );
173 sb.append( ", key='" ).append( key ).append( '\'' );
174 sb.append( ", value='" ).append( value ).append( '\'' );
176 return sb.toString();
179 public static class KeyBuilder
182 private ArtifactMetadataModel artifactMetadataModel;
188 private String facetId;
190 private String repositoryId;
197 public KeyBuilder withArtifactMetadataModel( ArtifactMetadataModel artifactMetadataModel )
199 this.artifactMetadataModel = artifactMetadataModel;
203 public KeyBuilder withKey( String key )
209 public KeyBuilder withName( String name )
215 public KeyBuilder withFacetId( String facetId )
217 this.facetId = facetId;
221 public KeyBuilder withRepositoryId( String repositoryId )
223 this.repositoryId = repositoryId;
227 public String build()
229 // FIXME add some controls
230 // getArtifactMetadataModelId can have no namespace, no project and no projectid for statistics
231 // only repositoryId with artifactMetadataModel
232 String str = CassandraUtils.generateKey( this.artifactMetadataModel == null
234 : this.artifactMetadataModel.getArtifactMetadataModelId(),
235 this.facetId, this.name, this.key );
237 //return Long.toString( str.hashCode() );