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 org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
24 import javax.persistence.Column;
25 import java.io.Serializable;
26 import java.util.Date;
29 * Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata}
31 * @author Olivier Lamy
34 public class ArtifactMetadataModel
35 implements Serializable
41 @Column(name = "repositoryName")
42 private String repositoryId;
44 @Column(name = "namespaceId")
45 private String namespace;
47 @Column(name = "project")
48 private String project;
50 @Column(name = "projectVersion")
51 private String projectVersion;
53 @Column(name = "version")
54 private String version;
56 @Column(name = "fileLastModified")
57 private long fileLastModified;
59 @Column(name = "size")
65 @Column(name = "sha1")
68 @Column(name = "whenGathered")
69 private long whenGathered;
71 public ArtifactMetadataModel()
76 public ArtifactMetadataModel( String id, String repositoryId, String namespace, String project,
77 String projectVersion, String version, Date fileLastModified, long size, String md5,
78 String sha1, Date whenGathered )
81 this.repositoryId = repositoryId;
82 this.namespace = namespace;
83 this.project = project;
84 this.projectVersion = projectVersion;
85 this.version = version;
86 this.fileLastModified = ( fileLastModified != null ? fileLastModified.getTime() : 0 );
90 this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime();
99 public void setId( String id )
104 public String getRepositoryId()
109 public void setRepositoryId( String repositoryId )
111 this.repositoryId = repositoryId;
114 public String getNamespace()
119 public void setNamespace( String namespace )
121 this.namespace = namespace;
124 public String getProject()
129 public void setProject( String project )
131 this.project = project;
134 public String getProjectVersion()
136 return projectVersion;
139 public void setProjectVersion( String projectVersion )
141 this.projectVersion = projectVersion;
144 public String getVersion()
149 public void setVersion( String version )
151 this.version = version;
154 public long getFileLastModified()
156 return fileLastModified;
159 public void setFileLastModified( long fileLastModified )
161 this.fileLastModified = fileLastModified;
164 public long getSize()
169 public void setSize( long size )
174 public String getMd5()
179 public void setMd5( String md5 )
184 public String getSha1()
189 public void setSha1( String sha1 )
194 public Date getWhenGathered()
196 return new Date( whenGathered );
199 public void setWhenGathered( long whenGathered )
201 this.whenGathered = whenGathered;
206 public String toString()
208 final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" );
209 sb.append( ", id='" ).append( id ).append( '\'' );
210 sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
211 sb.append( ", namespace='" ).append( namespace ).append( '\'' );
212 sb.append( ", project='" ).append( project ).append( '\'' );
213 sb.append( ", projectVersion='" ).append( projectVersion ).append( '\'' );
214 sb.append( ", version='" ).append( version ).append( '\'' );
215 sb.append( ", fileLastModified=" ).append( fileLastModified );
216 sb.append( ", size=" ).append( size );
217 sb.append( ", md5='" ).append( md5 ).append( '\'' );
218 sb.append( ", sha1='" ).append( sha1 ).append( '\'' );
219 sb.append( ", whenGathered=" ).append( whenGathered );
221 return sb.toString();
224 public static class KeyBuilder
227 private String project;
231 private String namespaceId;
233 private String repositoryId;
235 private String projectVersion;
242 public KeyBuilder withId( String id )
249 public KeyBuilder withNamespace( Namespace namespace )
251 this.namespaceId = namespace.getName();
252 this.repositoryId = namespace.getRepository().getName();
256 public KeyBuilder withNamespace( String namespaceId )
258 this.namespaceId = namespaceId;
262 public KeyBuilder withProject( String project )
264 this.project = project;
268 public KeyBuilder withProjectVersion( String projectVersion )
270 this.projectVersion = projectVersion;
274 public KeyBuilder withRepositoryId( String repositoryId )
276 this.repositoryId = repositoryId;
280 public String build()
282 //repositoryId + namespaceId + project + projectVersion + id
283 // FIXME add some controls
286 CassandraUtils.generateKey( this.repositoryId, this.namespaceId, this.project, this.projectVersion,
289 //return Long.toString( str.hashCode() );