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.LongSerializer;
24 import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.Id;
29 import java.io.Serializable;
30 import java.util.Date;
33 * Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata}
35 * @author Olivier Lamy
38 public class ArtifactMetadataModel
39 implements Serializable
42 // repositoryId + namespaceId + project + projectVersion + id
44 @Serializer( HugeStringSerializer.class )
45 private String artifactMetadataModelId;
47 @Column( name = "id" )
48 @Serializer( HugeStringSerializer.class )
51 @Column( name = "repositoryId" )
52 @Serializer( HugeStringSerializer.class )
53 private String repositoryId;
55 @Column( name = "namespace" )
56 @Serializer( HugeStringSerializer.class )
57 private String namespace;
59 @Column( name = "project" )
60 @Serializer( HugeStringSerializer.class )
61 private String project;
63 @Column( name = "projectVersion" )
64 @Serializer( HugeStringSerializer.class )
65 private String projectVersion;
67 @Column( name = "version" )
68 @Serializer( HugeStringSerializer.class )
69 private String version;
71 @Column( name = "fileLastModified" )
72 @Serializer( LongSerializer.class )
73 private long fileLastModified;
75 @Column( name = "size" )
76 @Serializer( LongSerializer.class )
79 @Column( name = "md5" )
80 @Serializer( HugeStringSerializer.class )
83 @Column( name = "sha1" )
84 @Serializer( HugeStringSerializer.class )
87 @Column( name = "whenGathered" )
88 @Serializer( LongSerializer.class )
89 private long whenGathered;
91 public ArtifactMetadataModel()
96 public ArtifactMetadataModel( String artifactMetadataModelId, String id, String repositoryId, String namespace,
97 String project, String projectVersion, String version, Date fileLastModified,
98 long size, String md5, String sha1, Date whenGathered )
100 this.artifactMetadataModelId = artifactMetadataModelId;
102 this.repositoryId = repositoryId;
103 this.namespace = namespace;
104 this.project = project;
105 this.projectVersion = projectVersion;
106 this.version = version;
107 this.fileLastModified = ( fileLastModified != null ? fileLastModified.getTime() : 0 );
111 this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime();
114 public String getArtifactMetadataModelId()
116 return artifactMetadataModelId;
119 public void setArtifactMetadataModelId( String artifactMetadataModelId )
121 this.artifactMetadataModelId = artifactMetadataModelId;
124 public String getId()
129 public void setId( String id )
134 public String getRepositoryId()
139 public void setRepositoryId( String repositoryId )
141 this.repositoryId = repositoryId;
144 public String getNamespace()
149 public void setNamespace( String namespace )
151 this.namespace = namespace;
154 public String getProject()
159 public void setProject( String project )
161 this.project = project;
164 public String getProjectVersion()
166 return projectVersion;
169 public void setProjectVersion( String projectVersion )
171 this.projectVersion = projectVersion;
174 public String getVersion()
179 public void setVersion( String version )
181 this.version = version;
184 public long getFileLastModified()
186 return fileLastModified;
189 public void setFileLastModified( long fileLastModified )
191 this.fileLastModified = fileLastModified;
194 public long getSize()
199 public void setSize( long size )
204 public String getMd5()
209 public void setMd5( String md5 )
214 public String getSha1()
219 public void setSha1( String sha1 )
224 public Date getWhenGathered()
226 return new Date( whenGathered );
229 public void setWhenGathered( long whenGathered )
231 this.whenGathered = whenGathered;
235 public boolean equals( Object o )
241 if ( o == null || getClass() != o.getClass() )
246 ArtifactMetadataModel that = (ArtifactMetadataModel) o;
248 if ( !artifactMetadataModelId.equals( that.artifactMetadataModelId ) )
257 public int hashCode()
259 return artifactMetadataModelId.hashCode();
263 public String toString()
265 final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" );
266 sb.append( "artifactMetadataModelId='" ).append( artifactMetadataModelId ).append( '\'' );
267 sb.append( ", id='" ).append( id ).append( '\'' );
268 sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
269 sb.append( ", namespace='" ).append( namespace ).append( '\'' );
270 sb.append( ", project='" ).append( project ).append( '\'' );
271 sb.append( ", projectVersion='" ).append( projectVersion ).append( '\'' );
272 sb.append( ", version='" ).append( version ).append( '\'' );
273 sb.append( ", fileLastModified=" ).append( fileLastModified );
274 sb.append( ", size=" ).append( size );
275 sb.append( ", md5='" ).append( md5 ).append( '\'' );
276 sb.append( ", sha1='" ).append( sha1 ).append( '\'' );
277 sb.append( ", whenGathered=" ).append( whenGathered );
279 return sb.toString();
282 public static class KeyBuilder
285 private String project;
289 private String namespaceId;
291 private String repositoryId;
293 private String projectVersion;
300 public KeyBuilder withId( String id )
307 public KeyBuilder withNamespace( Namespace namespace )
309 this.namespaceId = namespace.getName();
310 this.repositoryId = namespace.getRepository().getId();
314 public KeyBuilder withNamespace( String namespaceId )
316 this.namespaceId = namespaceId;
320 public KeyBuilder withProject( String project )
322 this.project = project;
326 public KeyBuilder withProjectVersion( String projectVersion )
328 this.projectVersion = projectVersion;
332 public KeyBuilder withRepositoryId( String repositoryId )
334 this.repositoryId = repositoryId;
338 public String build()
340 //repositoryId + namespaceId + project + projectVersion + id
341 // FIXME add some controls
344 CassandraUtils.generateKey( this.repositoryId, this.namespaceId, this.project, this.projectVersion,
347 //return Long.toString( str.hashCode() );