Package com.netflix.paas.cassandra.entity

Source Code of com.netflix.paas.cassandra.entity.KeyspaceEntity

/*******************************************************************************
* /***
*  *
*  *  Copyright 2013 Netflix, Inc.
*  *
*  *     Licensed under the Apache License, Version 2.0 (the "License");
*  *     you may not use this file except in compliance with the License.
*  *     You may obtain a copy of the License at
*  *
*  *         http://www.apache.org/licenses/LICENSE-2.0
*  *
*  *     Unless required by applicable law or agreed to in writing, software
*  *     distributed under the License is distributed on an "AS IS" BASIS,
*  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  *     See the License for the specific language governing permissions and
*  *     limitations under the License.
*  *
******************************************************************************/
package com.netflix.paas.cassandra.entity;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;

import com.google.common.base.Preconditions;
import com.netflix.paas.exceptions.NotFoundException;

@Entity
public class KeyspaceEntity {
    public static class Builder {
        private final KeyspaceEntity entity = new KeyspaceEntity();
       
        public Builder withName(String name) {
            entity.name = name;
            return this;
        }
       
        public Builder addColumnFamily(String columnFamilyName) {
            if (entity.getColumnFamilies() == null) {
                entity.setColumnFamilies(new HashSet<String>());
            }
            entity.getColumnFamilies().add(columnFamilyName);
            return this;
        }
       
        public Builder withOptions(Map<String, String> options) {
            entity.setOptions(options);
            return this;
        }
       
        public KeyspaceEntity build() {
            return this.entity;
        }
    }
   
    public static Builder builder() {
        return new Builder();
    }
   
    @Id
    private String id;
   
    @Column(name="name")
    private String name;
   
    @Column(name="cluster")
    private String clusterName;
   
    @Column(name="options")
    private Map<String, String> options;
   
    @Column(name="cfs")
    private Set<String> columnFamilies;

    @Transient
    private Map<String, ColumnFamilyEntity> columnFamilyEntities;
   
    @PrePersist
    private void prePersist() {
        this.id = String.format("%s.%s", clusterName, name);
    }
   
    @PostLoad
    private void postLoad() {
        this.id = String.format("%s.%s", clusterName, name);
    }
   

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, ColumnFamilyEntity> getColumnFamilyEntities() {
        return columnFamilyEntities;
    }

    public void setColumnFamilyEntities(Map<String, ColumnFamilyEntity> columnFamilyEntities) {
        this.columnFamilyEntities = columnFamilyEntities;
    }

    public Map<String, String> getOptions() {
        return options;
    }

    public void setOptions(Map<String, String> options) {
        this.options = options;
    }

    public String getClusterName() {
        return clusterName;
    }

    public void setClusterName(String clusterName) {
        this.clusterName = clusterName;
    }

    public Set<String> getColumnFamilies() {
        return columnFamilies;
    }

    public void setColumnFamilies(Set<String> columnFamilies) {
        this.columnFamilies = columnFamilies;
    }

    public ColumnFamilyEntity getColumnFamily(String columnFamilyName) throws NotFoundException {
        ColumnFamilyEntity entity = columnFamilyEntities.get(columnFamilyName);
        if (entity == null)
            throw new NotFoundException("columnfamily", columnFamilyName);
        return entity;
    }

}
TOP

Related Classes of com.netflix.paas.cassandra.entity.KeyspaceEntity

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.