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 org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.Id;
28 import java.io.Serializable;
32 * @author Olivier Lamy
36 public class Namespace
37 implements Serializable
41 @Column( name = "id" )
42 @Serializer( DeflateStringSerializer.class )
45 @Column( name = "name" )
46 @Serializer( DeflateStringSerializer.class )
49 @Column( name = "repository" )
50 private Repository repository;
52 //@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
53 //@JoinColumn(name = "repository_id")
54 //private transient Repository repository;
63 public Namespace( String id, Repository repository )
65 this.id = new KeyBuilder().withNamespace( id ).withRepositoryId( repository.getId() ).build();
67 this.repository = repository;
75 public void setId( String id )
80 public String getName()
85 public void setName( String name )
90 public Repository getRepository()
95 public void setRepository( Repository repository )
97 this.repository = repository;
101 public boolean equals( Object o )
107 if ( o == null || getClass() != o.getClass() )
112 Namespace namespace = (Namespace) o;
114 if ( !id.equals( namespace.id ) )
118 if ( !repository.getId().equals( namespace.repository.getId() ) )
127 public int hashCode()
129 int result = id.hashCode();
130 result = 31 * result + repository.getId().hashCode();
135 public String toString()
137 final StringBuilder sb = new StringBuilder( "Namespace{" );
138 sb.append( "id='" ).append( id ).append( '\'' );
139 sb.append( ", name='" ).append( name ).append( '\'' );
140 sb.append( ", repository='" ).append( repository ).append( '\'' );
142 return sb.toString();
145 public static class KeyBuilder
148 private String namespace;
150 private String repositoryId;
157 public KeyBuilder withNamespace( Namespace namespace )
159 this.namespace = namespace.getName();
160 this.repositoryId = namespace.getRepository().getId();
164 public KeyBuilder withNamespace( String namespace )
166 this.namespace = namespace;
170 public KeyBuilder withRepositoryId( String repositoryId )
172 this.repositoryId = repositoryId;
176 public String build()
178 // FIXME add some controls
179 return CassandraUtils.generateKey( this.repositoryId, this.namespace );