public synchronized void delete( long logRowId ) throws IOException { checkIfClosed(); if ( logRowId <= 0 ) { throw new IllegalArgumentException( "Argument 'recid' is invalid: " + logRowId ); } if ( DEBUG ) { System.out.println( "BaseRecordManager.delete() recid " + logRowId ) ; } logRowId = decompressRecid(logRowId); long physRowId = _logicMgr.fetch( logRowId ); _physMgr.delete( physRowId ); _logicMgr.delete( logRowId ); }
/** * Insert at forced location, use only for defragmentation !! * @param logicalRowId * @param physLoc * @throws IOException */ void forceInsert(long logicalRowId, long physLoc) throws IOException { //create pages until we reach requested block long lastBlock = pageman.getLast(Magic.TRANSLATION_PAGE); while(lastBlock!=Location.getBlock(logicalRowId)){ lastBlock = pageman.allocate(Magic.TRANSLATION_PAGE); if(lastBlock>Location.getBlock(logicalRowId)) throw new Error("outallocated"); } if(fetch(logicalRowId) != 0) throw new Error("can not forceInsert, record already exists: "+logicalRowId); update(logicalRowId, physLoc); }
/** * Deletes a record. * * @param recid the rowid for the record that should be deleted. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized void delete( long recid ) throws IOException { checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } if ( DEBUG ) { System.out.println( "BaseRecordManager.delete() recid " + recid ); } Location logRowId = new Location( recid ); Location physRowId = logMgr.fetch( logRowId ); physMgr.delete( physRowId ); logMgr.delete( logRowId ); }
/** * Deletes a record. * * @param recid the rowid for the record that should be deleted. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized void delete( long recid ) throws IOException { checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } if ( DEBUG ) { System.out.println( "BaseRecordManager.delete() recid " + recid ) ; } Location logRowId = new Location( recid ); Location physRowId = logMgr.fetch( logRowId ); physMgr.delete( physRowId ); logMgr.delete( logRowId ); }
/** * Fetches a record using a custom serializer. * * @param recid the recid for the record that must be fetched. * @param serializer a custom serializer * @return the object contained in the record. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized Object fetch( long recid, Serializer serializer ) throws IOException { byte[] data; checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } data = physMgr.fetch( logMgr.fetch( new Location( recid ) ) ); if ( DEBUG ) { System.out.println( "BaseRecordManager.fetch() recid " + recid + " length " + data.length ); } return serializer.deserialize( data ); }
/** * Fetches a record using a custom serializer. * * @param recid the recid for the record that must be fetched. * @param serializer a custom serializer * @return the object contained in the record. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized Object fetch( long recid, Serializer serializer ) throws IOException { byte[] data; checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } data = physMgr.fetch( logMgr.fetch( new Location( recid ) ) ); if ( DEBUG ) { System.out.println( "BaseRecordManager.fetch() recid " + recid + " length " + data.length ) ; } return serializer.deserialize( data ); }
/** * Deletes a record. * * @param recid the rowid for the record that should be deleted. * @throws IOException when one of the underlying I/O operations fails. */ public void delete( long recid ) throws IOException { LockElement element; checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } LOG.debug( "BaseRecordManager.delete() recid {}", recid ); element = beginIO( recid, IOType.WRITE_IO ); try { Location logRowId = new Location( recid ); Location physRowId = logMgr.fetch( logRowId ); physMgr.delete( physRowId ); logMgr.delete( logRowId ); } finally { this.endIO( recid, element, IOType.WRITE_IO ); } }
Location location = logMgr.fetch( new Location( recid ) ); data = physMgr.fetch( location );
/** * Updates a record using a custom serializer. * * @param recid the recid for the record that is to be updated. * @param obj the new object for the record. * @param serializer a custom serializer * @throws IOException when one of the underlying I/O operations fails. */ public synchronized void update( long recid, Object obj, Serializer serializer ) throws IOException { checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } Location logRecid = new Location( recid ); Location physRecid = logMgr.fetch( logRecid ); byte[] data = serializer.serialize( obj ); if ( DEBUG ) { System.out.println( "BaseRecordManager.update() recid " + recid + " length " + data.length ); } Location newRecid = physMgr.update( physRecid, data, 0, data.length ); if ( !newRecid.equals( physRecid ) ) { logMgr.update( logRecid, newRecid ); } }
Location physRecid = logMgr.fetch( logRecid );
Location physRecid = logMgr.fetch( logRecid );
private <A> void update2(long logRecid, A obj, Serializer<A> serializer,byte[] insertBuffer, OpenByteArrayOutputStream insertBAO, SerializerOutput insertOut) throws IOException { logRecid = decompressRecid(logRecid); long physRecid = _logicMgr.fetch( logRecid ); if(physRecid == 0) throw new IOException("Can not update, recid does not exist: "+logRecid); insertBAO.reset(insertBuffer); serializer.serialize(insertOut, obj ); if(compress){ byte[] data = compress(insertBAO.getBuf(),insertBAO.size()); insertBAO.reset(insertBuffer); insertBAO.write(data); } if ( DEBUG ) { System.out.println( "BaseRecordManager.update() recid " + logRecid + " length " + insertBAO.size() ) ; } long newRecid = _physMgr.update( physRecid, insertBAO.getBuf(), 0, insertBAO.size() ); _logicMgr.update( logRecid, newRecid ); }
private <A> A fetch2(long recid, Serializer<A> serializer,byte[] insertBuffer, OpenByteArrayOutputStream insertBAO, SerializerOutput insertOut, OpenByteArrayInputStream insertBAI, SerializerInput insertIn) throws IOException { recid = decompressRecid(recid); insertBAO.reset(insertBuffer); long physLocation = _logicMgr.fetch(recid); if(physLocation == 0){ //throw new IOException("Record not found, recid: "+recid); return null; } _physMgr.fetch(insertBAO, physLocation); if ( DEBUG ) { System.out.println( "BaseRecordManager.fetch() recid " + recid + " length " + insertBAO.size() ) ; } insertBAI.reset(insertBAO.getBuf(), insertBAO.size()); try{ if(compress) return serializer.deserialize(decompress( insertIn )); else return serializer.deserialize( insertIn ); }catch(ClassNotFoundException e){ throw new IOError(e); } }