Package bm.storage

Examples of bm.storage.Store


     * @noinspection FieldRepeatedlyAccessedInMethod
     */
    public synchronized Node getNode( final Node parent, final int recordId )
            throws DBException
    {
        final Store rs = this.rs;
        Node node = null;

        byte[] buffer = this.buffer;
        try
        {
            if( sendProgressEvents )
            {
                event.dispatch();
            }
            rs.open();
            final int recordSize = rs.getRecordSize( recordId );
            if( buffer == null || recordSize > buffer.length )
            {
                buffer = Tools.secureAlloc( recordSize + GROWTH_FACTOR );
                this.buffer = buffer;
            }
            rs.getRecord( recordId, buffer, 0 );
            if( sendProgressEvents )
            {
                event.dispatch();
            }
            node = new Node( this, order, parent );
            node.setRecordId( new Integer( recordId ) );
            node.deserialize( new SerializerInputStream( new ByteArrayInputStream(
                    buffer,
                    0,
                    recordSize
            )));
        }
        catch( InvalidRecordIDException e )
        {
            return null;
        }
        catch( Exception e )
        {
            ErrorLog.addError(
                    "Index",
                    "doGetNode",
                    new Object[] { new Integer( recordId ), parent },
                    null,
                    e
            );
            throw new DBException( Constants.ERR_IDX_GET_NODE, e );
        }
        finally
        {
            try
            {
                rs.close();
            }
            catch( RSException e )
            {
                ErrorLog.addError(
                        "Index",
View Full Code Here


     */
    Node saveNode( final Node node )
            throws RecordStoreFullException,
                   DBException
    {
        final Store rs = this.rs;
        try
        {
            if( sendProgressEvents )
            {
                event.dispatch();
            }
            rs.open();
            baos.reset();
            node.serialize( out );
            final byte[] data = baos.toByteArray();
            if( sendProgressEvents )
            {
                event.dispatch();
            }
            int recordId;
            if( node.getRecordId() != null )
            {
                recordId = node.getRecordId().intValue();
                // Update
                rs.setRecord(
                        recordId,
                        data,
                        0,
                        data.length
                );
            }
            else
            {
//                log.debug( "creating new node: " + node );
                // New
                recordId = rs.addRecord(
                        data,
                        0,
                        data.length
                );
                node.setRecordId( new Integer( recordId ) );
            }
            return node;
        }
        catch( RecordStoreFullException e )
        {
            throw e;
        }
        catch( Exception e )
        {
            log.error( e );
            ErrorLog.addError(
                    "Index",
                    "saveNode",
                    new Object[] { node },
                    null,
                    e
            );
            throw new DBException( Constants.ERR_IDX_SAVE_NODE, e );
        }
        finally
        {
            try
            {
                rs.close();
            }
            catch( RSException e )
            {
                log.error( e );
                ErrorLog.addError(
View Full Code Here

     */
    Node dropNode( final Node node )
            throws DBException,
                   RecordStoreFullException
    {
        final Store rs = this.rs;

//        log.debug( "dropping node: " + node );
        if( node.getRecordId() != null )
        {
            if( toSave.containsKey( node.getRecordId() ) )
            {
                toSave.remove( node.getRecordId() );
            }

            if( findParentIndex( node ) != -1 )
            {
                final CantDropNodeException cantDropNodeException = new CantDropNodeException(
                        Constants.ERR_IDX_DROP_NODE,
                        node.getRecordId() + ", " + node.getParent().getRecordId()
                );
                ErrorLog.addError(
                        "Index",
                        "dropNode",
                        new Object[] { node, node.getParent() },
                        null,
                        cantDropNodeException
                );
                throw cantDropNodeException;
            }
            try
            {
                rs.open();
                if( sendProgressEvents )
                {
                    event.dispatch();
                }
                rs.deleteRecord( node.getRecordId().intValue() );
//                CacheManager.getInstance( CACHE_ZONE ).remove(
//                        getRecordCacheKey( node.getRecordId().intValue() )
//                );
            }
            catch( RSException e )
View Full Code Here

        System.out.println( "IconSets: " + iconSets.size() );
        System.out.println( "Controllers: " + controllers.size() );
        System.out.println( "Views: " + views.size() );

        final Index index = new Index( "sys_compiled_views", order, Index.KT_STRING, true, false );
        final Store store = Store.get( "sys_compiled_views", 1 );
        index.setRecordStore( store );
        if( listBrowser != null && listBrowser.equalsIgnoreCase( "native" ) )
        {
            try
            {
                index.insertObject( "listBrowserMode", "native" );
            }
            catch( Exception e )
            {
                throw new ViewCompilerException( e );
            }
        }
        for( final Iterator i = controllers.values().iterator(); i.hasNext(); )
        {
            final Controller controller = (Controller) i.next();
            controller.store( index );
        }
        for( final Iterator i = iconSets.values().iterator(); i.hasNext(); )
        {
            final IconSet iconSet = (IconSet) i.next();
            iconSet.store( index );
        }
        for( final Iterator i = views.values().iterator(); i.hasNext(); )
        {
            final View view = (View) i.next();
            view.store( index );
        }
        FileOutputStream fos = null;
        try
        {
            System.out.println( "Index size: " + store.getSize() + " bytes" );
            fos = new FileOutputStream( output );
            writeIndex( index, fos );
        }
        catch( Exception e )
        {
View Full Code Here

        }
        catch( RecordStoreFullException e )
        {
            throw new RSException( 0, e );
        }
        final Store rs = index.getRecordStore();
        out.writeInt( index.getOrder() );
        out.writeByte( (byte) index.getType() );
        out.writeBoolean( index.isCaseSensitive() );
        numRecords = rs.getNumRecords();
        System.out.println( "Writing " + numRecords + " records" );
        out.writeInt( numRecords );
        for( int i = 1; i <= numRecords; i++ )
        {
            try
            {
                out.writeBlob( rs.getRecord( i ) );
            }
            catch( InvalidRecordIDException e )
            {
            }
        }
View Full Code Here

    public void write( final Map consolidated )
            throws PackException
    {
        System.out.println( "Writing resources to index file: " + out + ".index" );
        final File file = new File( out + ".index" );
        final Store store = Store.get( out, 1 );
        final Index index = new Index( out, order, Index.KT_STRING, true, false );
        index.setRecordStore( store );
        OutputStream os = null;
        try
        {
            if( !file.getParentFile().exists() )
            {
                file.getParentFile().mkdirs();
            }
            os = new FileOutputStream( file );
            for( final Iterator i = consolidated.keySet().iterator(); i.hasNext(); )
            {
                final String language = (String) i.next();
                final Properties lang = (Properties) consolidated.get( language );
                System.out.println( "Processing language: " + language + ", " + lang.size() + " entries" );
                for( final Iterator j = lang.keySet().iterator(); j.hasNext(); )
                {
                    final String key = (String) j.next();
                    final String value = lang.getProperty( key );
                    index.insertObject( language + "#" + key, value );
                }
            }
            System.out.println( "Index size: " + store.getSize() + " bytes" );
            writeIndex( index, os );
        }
        catch( Exception e )
        {
            throw new PackException( e );
View Full Code Here

        }
        catch( RecordStoreFullException e )
        {
            throw new RSException( 0, e );
        }
        final Store rs = index.getRecordStore();
        out.writeInt( index.getOrder() );
        out.writeByte( (byte) index.getType() );
        out.writeBoolean( index.isCaseSensitive() );
        numRecords = rs.getNumRecords();
        System.out.println( "Writing " + numRecords + " records" );
        out.writeInt( numRecords );
        for( int i = 1; i <= numRecords; i++ )
        {
            try
            {
                out.writeBlob( rs.getRecord( i ) );
            }
            catch( InvalidRecordIDException e )
            {
            }
        }
View Full Code Here

     * @param name store name
     */
    public PersistentMap( final String name )
    {
        this.rsName = name;
        Store st = null;
        try
        {
            // Load directory
            if( Store.exists( name ) )
            {
                st = Store.get( name, 1 );
                st.open( false );
                final byte[] data = st.getRecord( 1 );
                final ByteArrayInputStream bais = new ByteArrayInputStream( data );
                final DBSerializerInputStream in = new DBSerializerInputStream( bais );
                directory = (Hashtable) in.readObject();
            }
            else
            {
                st = saveDirectory();
            }
        }
        catch( Exception e )
        {
            log.error( e );
            ErrorHandler.handleError( name, e);
        }
        finally
        {
            if( st != null ) try{ st.close(); }catch( Exception e ){}
        }
    }
View Full Code Here

     */
    public void packCopy()
            throws RSException,
                   RecordStoreFullException
    {
        Store st = null;
        try
        {
            st = Store.get( rsName, 1 );
            st.packCopy();
        }
        finally
        {
            if( st != null ) try{ st.close(); }catch( Exception e ){}
        }
    }
View Full Code Here

    }

    private Store saveDirectory()
            throws DBException
    {
        Store st = null;
        try
        {
            st = Store.get( rsName, 1 );
            st.open( true );
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            final DBSerializerOutputStream out = new DBSerializerOutputStream( baos );
            out.writeObject( directory );
            if( st.getNumRecords() > 0 )
            {
                st.setRecord( 1, baos.toByteArray() );
            }
            else
            {
                st.addRecord( baos.toByteArray() );
            }
            return st;
        }
        catch( Exception e )
        {
            log.error( e );
            throw new DBException( Constants.ERR_PM_SAVE_DIR, e );
        }
        finally
        {
            if( st != null ) try{ st.close(); }catch( Exception e ){}
        }
    }
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.