Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.storemate.store.util;
 
Callback interface used with calls that may try to overwrite existing entries; and if so may decide whether overwrite should or should not proceed.
 
public interface OverwriteChecker
{
    
Method that may be called at first, to see if ovewrite for given key is always allowed (java.lang.Boolean.TRUE), never allowed (java.lang.Boolean.FALSE), or "depends on entries involved" (null).
    public Boolean mayOverwrite(StorableKey key);
    
    
Method called to determine whether specified overwrite operation should succeeed or not. Note that checker will only have access to metadata, not data itself, since reading data may incur significant overhead and/or buffering.

Returns:
Whether specified existing entry may be overridden by specified new entry (or not).
Throws:
com.fasterxml.storemate.store.StoreException May be thrown to indicate that overwrite operation is not allowed, as an alternative to returning specific fail
    public boolean mayOverwrite(StorableKey keyStorable oldEntryStorable newEntry)
        throws StoreException;
    /*
    /**********************************************************************
    /* Standard implementations
    /**********************************************************************
     */

    
Simple implementation that simply allows all overwrites.
    public static class AlwaysOkToOverwrite implements OverwriteChecker
    {
        public final static OverwriteChecker instance = new AlwaysOkToOverwrite();
        
        @Override
        public Boolean mayOverwrite(StorableKey key) { return .; }
        @Override
        public boolean mayOverwrite(StorableKey keyStorable oldEntryStorable newEntry)
            throws StoreException {
            return true;
        }
    }

    
Simple implementation that simply denies all overwrites.
    public static class NeverOkToOverwrite implements OverwriteChecker
    {
        public final static OverwriteChecker instance = new NeverOkToOverwrite();
        @Override
        public Boolean mayOverwrite(StorableKey key) { return .; }
        
        @Override
        public boolean mayOverwrite(StorableKey keyStorable oldEntryStorable newEntry)
            throws StoreException {
            return false;
        }
    }
New to GrepCode? Check out our FAQ X