Package bm.storage

Examples of bm.storage.Store


     * @throws DBException on errors reading from persistent storage
     */
    public Object getElement( final Object key )
            throws DBException
    {
        Store st = null;
        try
        {
            Object obj = cache.get( key );
            if( obj == null )
            {
                final Integer recordId = (Integer) directory.get( key );
                if( recordId != null )
                {
                    st = Store.get( rsName, 1 );
                    st.open();
                    final ByteArrayInputStream bais = new ByteArrayInputStream(
                            st.getRecord( recordId.intValue() )
                    );
                    final DBSerializerInputStream in = new DBSerializerInputStream( bais );
                    obj = in.readObject();
                    cache.add( key, obj );
                }
            }
            return obj;
        }
        catch( Exception e )
        {
            if( !(e instanceof DBException) )
            {
                throw new DBException( Constants.ERR_PM_GET, e );
            }
            else
            {
                throw (DBException) e;
            }
        }
        finally
        {
            if( st != null ) try{ st.close(); }catch( Exception e ){}
        }
    }
View Full Code Here


     */
    public synchronized void setElement( final Object key, final Object value )
            throws DBException
    {
        final Hashtable directory = this.directory;
        Store st = null;
        try
        {
            if( value != null )
            {
                cache.add( key, value );
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final DBSerializerOutputStream out = new DBSerializerOutputStream( baos );
                out.writeObject( value );
                final byte[] data = baos.toByteArray();
                st = Store.get( rsName, 1 );
                st.open( true );
                if( directory.containsKey( key ) )
                {
                    final Integer recordId = (Integer) directory.get( key );
                    st.setRecord( recordId.intValue(), data );
                }
                else
                {
                    final int recordId = st.addRecord( data );
                    directory.put( key, new Integer( recordId ) );
                    saveDirectory();
                }
            }
            else if( directory.containsKey( key ) )
            {
                cache.remove( key );
                st = Store.get( rsName, 1 );
                st.open( true );
                st.deleteRecord( ((Integer) directory.get( key ) ).intValue() );
                directory.remove( key );
                saveDirectory();
            }
        }
        catch( Exception e )
        {
            throw new DBException( Constants.ERR_PM_SET, e );
        }
        finally
        {
            if( st != null ) try{ st.close(); }catch( Exception e ){}
        }
    }
View Full Code Here

            in = new SerializerInputStream( zis );

            final int       order           = in.readInt(); // ToDo: should do something with this?
            final byte      type            = in.readByte();
            final boolean   caseSensitive   = in.readBoolean();
            Store rs = null;
            boolean burstMode = Store.isBurstMode();
            try
            {
                System.gc();
                Store.safeDeleteRecordStore( name );
                Store.setBurstMode( !ControlledTask.isBackgroundTask() );
                rs = Store.get( name, 1 );
                rs.open( true );
                log.debug( "created recordstore" );
                final int size = in.readInt();
                log.debug( "index size (entries): " + size );
                if( size > 0 )
                {
                    final ProgressEvent event = new ProgressEvent();
                    event.setAnimate( false );
                    event.setCurrentValue( 0 );
                    event.setMaxValue( new Integer( size ) );
                    event.dispatch();
                    for( int j = 0; j < size; j++ )
                    {
                        log.debug( "record: " + j );
                        final byte[] data = in.readBlob();
                        int rid = rs.addRecord( data, 0, data.length );
                        log.debug( "record added (" + rid + "): " + data.length + " bytes" );
                        event.increment();
                        event.dispatch();
                        if( j == 0 && rid != 1 )
                        {
                            ErrorLog.addError(
                                    "DbTool",
                                    "processIndex",
                                    null,
                                    "Old not erased, recordId is not 1 (" + rid + ")",
                                    null
                            );
                            log.error( "RecordId is not 1!!!!" );
                            throw new IOException( "Old not erased" );
                        }
                        if( j % 100 == 0 )
                        {
                            System.gc();
                        }
                    }
                }
                System.gc();
                log.debug( "index " + name + " finished" );
            }
            finally
            {
                try{ if( rs != null ) rs.close(); }catch( Exception e ){}
                Store.setBurstMode( burstMode );
            }
        }
        finally
        {
View Full Code Here

TOP

Related Classes of bm.storage.Store

Copyright © 2018 www.massapicom. 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.