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     */
020    package org.apache.directory.server.core.partition.avl;
021    
022    
023    import java.util.Comparator;
024    import java.util.Properties;
025    import java.util.concurrent.atomic.AtomicLong;
026    
027    import org.apache.directory.server.xdbm.MasterTable;
028    
029    
030    /**
031     * TODO Make it so the master table does not extend table interface - not needed
032     * with this single use of delete so we should just use containment.
033     *
034     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035     * @version $Rev$, $Date$
036     */
037    public class AvlMasterTable<E> extends AvlTable<Long, E> implements MasterTable<E>
038    {
039        private Properties props = new Properties();
040        private AtomicLong counter = new AtomicLong( 0 );
041        
042        
043        public AvlMasterTable( String name, Comparator<Long> keyComparator, Comparator<E> valComparator, 
044            boolean dupsEnabled )
045        {
046            super( name, keyComparator, valComparator, dupsEnabled );
047        }
048    
049        
050        public void delete( Long id ) throws Exception
051        {
052            super.remove( id );
053        }
054    
055    
056        public Long getCurrentId() throws Exception
057        {
058            return counter.longValue();
059        }
060    
061        public Long getNextId() throws Exception
062        {
063            return counter.incrementAndGet();
064        }
065    
066        
067        public String getProperty( String property ) throws Exception
068        {
069            return props.getProperty( property );
070        }
071    
072        
073        public void setProperty( String property, String value ) throws Exception
074        {
075            props.setProperty( property, value );
076        }
077    }