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 javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.Id;
25 import java.io.Serializable;
29 * @author Olivier Lamy
32 //@Table( name = "namespace", schema = "ArchivaKeySpace@archiva")
33 public class Namespace
34 implements Serializable
37 private static final long serialVersionUID = 1L;
43 @Column(name = "name")
46 @Column(name = "repository")
47 private Repository repository;
49 //@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
50 //@JoinColumn(name = "repository_id")
51 //private transient Repository repository;
60 public Namespace( String id, Repository repository )
62 this.id = new KeyBuilder().withNamespace( id ).withRepositoryId( repository.getId() ).build();
64 this.repository = repository;
72 public void setId( String id )
77 public String getName()
82 public void setName( String name )
87 public Repository getRepository()
92 public void setRepository( Repository repository )
94 this.repository = repository;
98 public String getRepositoryId()
103 public void setRepositoryId( String repositoryId )
105 this.repositoryId = repositoryId;
109 public boolean equals( Object o )
115 if ( o == null || getClass() != o.getClass() )
120 Namespace namespace = (Namespace) o;
122 if ( !id.equals( namespace.id ) )
126 if ( !repository.getId().equals( namespace.repository.getId() ) )
135 public int hashCode()
137 int result = id.hashCode();
138 result = 31 * result + repository.getId().hashCode();
143 public String toString()
145 final StringBuilder sb = new StringBuilder( "Namespace{" );
146 sb.append( "id='" ).append( id ).append( '\'' );
147 sb.append( ", name='" ).append( name ).append( '\'' );
148 sb.append( ", repository='" ).append( repository ).append( '\'' );
150 return sb.toString();
153 public static class KeyBuilder
156 private String namespace;
158 private String repositoryId;
165 public KeyBuilder withNamespace( Namespace namespace )
167 this.namespace = namespace.getName();
168 this.repositoryId = namespace.getRepository().getId();
172 public KeyBuilder withNamespace( String namespace )
174 this.namespace = namespace;
178 public KeyBuilder withRepositoryId( String repositoryId )
180 this.repositoryId = repositoryId;
184 public String build()
186 // FIXME add some controls
187 return this.repositoryId + "-" + this.namespace;