001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.server.config.beans;
021
022
023import java.util.ArrayList;
024import java.util.List;
025
026import org.apache.directory.api.ldap.model.name.Dn;
027import org.apache.directory.server.config.ConfigurationElement;
028
029
030/**
031 * A class used to store the Partition configuration. It can't be instanciated
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public abstract class PartitionBean extends AdsBaseBean
036{
037    /** The Partition identifier */
038    @ConfigurationElement(attributeType = "ads-partitionId", isRdn = true)
039    private String partitionId;
040
041    /** The Partition suffix */
042    @ConfigurationElement(attributeType = "ads-partitionSuffix")
043    private Dn partitionSuffix;
044
045    /** Tells if the data should be flushed to disk immediately */
046    @ConfigurationElement(attributeType = "ads-partitionSyncOnWrite", isOptional = true)
047    private boolean partitionSyncOnWrite;
048
049    /** The partition's ContextEntry */
050    @ConfigurationElement(attributeType = "ads-contextEntry", isOptional = true)
051    private String contextEntry;
052
053    /** The list of declared indexes */
054    @ConfigurationElement(objectClass = "ads-index", container = "indexes")
055    private List<IndexBean> indexes = new ArrayList<>();
056
057
058    /**
059     * Create a new PartitionBean instance
060     */
061    public PartitionBean()
062    {
063    }
064
065
066    /**
067     * @return the partitionId
068     */
069    public String getPartitionId()
070    {
071        return partitionId;
072    }
073
074
075    /**
076     * @param partitionId the partitionId to set
077     */
078    public void setPartitionId( String partitionId )
079    {
080        this.partitionId = partitionId;
081    }
082
083
084    /**
085     * @return the partitionSuffix
086     */
087    public Dn getPartitionSuffix()
088    {
089        return partitionSuffix;
090    }
091
092
093    /**
094     * @param partitionSuffix the partitionSuffix to set
095     */
096    public void setPartitionSuffix( Dn partitionSuffix )
097    {
098        this.partitionSuffix = partitionSuffix;
099    }
100
101
102    /**
103     * @return the partitionSyncOnWrite
104     */
105    public boolean isPartitionSyncOnWrite()
106    {
107        return partitionSyncOnWrite;
108    }
109
110
111    /**
112     * @param partitionSyncOnWrite the partitionSyncOnWrite to set
113     */
114    public void setPartitionSyncOnWrite( boolean partitionSyncOnWrite )
115    {
116        this.partitionSyncOnWrite = partitionSyncOnWrite;
117    }
118
119
120    /**
121     * @return the indexes
122     */
123    public List<IndexBean> getIndexes()
124    {
125        return indexes;
126    }
127
128
129    /**
130     * @param indexes the indexes to set
131     */
132    public void setIndexes( List<IndexBean> indexes )
133    {
134        this.indexes = indexes;
135    }
136
137
138    /**
139     * @param contextEntry the contextEntry to set
140     */
141    public void setContextEntry( String contextEntry )
142    {
143        this.contextEntry = contextEntry;
144    }
145
146
147    /**
148     * @return the contextEntry
149     */
150    public String getContextEntry()
151    {
152        return contextEntry;
153    }
154
155
156    /**
157     * {@inheritDoc}
158     */
159    @Override
160    public String toString( String tabs )
161    {
162        StringBuilder sb = new StringBuilder();
163
164        sb.append( super.toString( tabs + "  " ) );
165        sb.append( tabs ).append( "  partition ID : " ).append( partitionId ).append( '\n' );
166        sb.append( tabs ).append( "  suffix : " ).append( partitionSuffix.getName() ).append( '\n' );
167        sb.append( toString( tabs, "  sync on write", partitionSyncOnWrite ) );
168        sb.append( toString( tabs, "  contextEntry", contextEntry ) );
169
170        sb.append( tabs ).append( "  indexes : \n" );
171
172        if ( indexes != null )
173        {
174            for ( IndexBean index : indexes )
175            {
176                sb.append( index.toString( tabs + "    " ) );
177            }
178        }
179
180        return sb.toString();
181    }
182
183
184    /**
185     * {@inheritDoc}
186     */
187    @Override
188    public String toString()
189    {
190        return toString( "" );
191    }
192}