Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 Ursa Project LLC (http://ursaj.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.ursaj.hfs.service;
 
 
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;

File service to handle operations over files stored in DB.

Parameters:
<T> File information type your application works with.
 
 public abstract class HfsDbFileServiceAdapter<T> extends HfsDbAdapter implements HfsFileService<T> {
     @Override
     public Map<UUID, T> getFiles(final Set<UUIDfileIdsthrows IOException {
         return doWithinConnection(new Action<Map<UUID, T>>() {
             @Override
             public Map<UUID, T> execute(Connection connectionthrows SQLExceptionIOException {
                 return getFiles(connectionfileIds);
             }
         });
     }
 
     @Override
     public void storeFiles(final Collection<T> filesthrows IOException {
         doWithinConnection(new Action<Void>() {
             @Override
             public Void execute(Connection connectionthrows SQLExceptionIOException {
                 storeFiles(connectionfiles);
 
                 return null;
             }
         });
     }
 
     @Override
     public boolean collectAliveFiles(final UUID fromIdfinal Consumer<UUIDIOExceptionconsumerthrows IOException {
         return doWithinConnection(new Action<Boolean>() {
             @Override
             public Boolean execute(Connection connectionthrows SQLExceptionIOException {
                 return collectAliveFiles(connectionfromIdconsumer);
             }
         });
     }

    
Get stored file information for requested ife IDs.

Parameters:
connection DB connection to persist files information.
fileIds File IDs to retrieve information for.
Returns:
Map of the requested file IDs to the existent file information. No map entry will be provided for the file ID which is not mapped to the stored file information.
Throws:
java.io.IOException In case of any IO exception.
java.sql.SQLException In case of any SQL exception.
 
     protected abstract Map<UUID, T> getFiles(Connection connection,
         Set<UUIDfileIdsthrows SQLExceptionIOException;

    
STore files information into persistent storage.

Parameters:
connection DB connection to persist files information.
files Files information to store into persistent storage.
Throws:
java.io.IOException In case of any IO exception.
java.sql.SQLException In case of any SQL exception.
 
     protected abstract void storeFiles(Connection connectionCollection<T> filesthrows SQLExceptionIOException;

    
Collect stored file IDs.

Parameters:
connection DB connection to persist files information.
fromId File ID to start collecting from (inclusive).
consumer Result consumer. Returns true if expects more results, false if no more results should be provided.
Returns:
True - if operation completes successfully, false - if handling was stopped by consumer.
Throws:
java.io.IOException In case of any IO exception.
java.sql.SQLException In case of any SQL exception.
    protected abstract boolean collectAliveFiles(Connection connection,
        UUID fromIdConsumer<UUIDIOExceptionconsumerthrows SQLExceptionIOException;
New to GrepCode? Check out our FAQ X