All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.netbeans.indexeddataobject.impl.IndexedDataObjectManagerImpl Maven / Gradle / Ivy

There is a newer version: 1.5.20
Show newest version
/***********************************************************************************************************************
 *
 * OpenBlueSky - NetBeans Platform Enhancements
 * Copyright (C) 2006-2012 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://openbluesky.java.net
 * SCM: https://bitbucket.org/tidalwave/openbluesky-src
 *
 **********************************************************************************************************************/
package it.tidalwave.netbeans.indexeddataobject.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.util.lookup.ServiceProvider;
import it.tidalwave.util.Id;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.netbeans.indexedfilesystem.IndexedFileSystem;
import it.tidalwave.netbeans.indexeddataobject.IndexedDataObjectManager;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@ServiceProvider(service=IndexedDataObjectManager.class)
public class IndexedDataObjectManagerImpl implements IndexedDataObjectManager
  {
    private static final String CLASS = IndexedDataObjectManagerImpl.class.getName();
    private static final Logger logger = Logger.getLogger(CLASS);
    
    private static final IndexedFileSystem indexedFileSystem = new IndexedFileSystem();
    
    /***************************************************************************
     * 
     * {@inheritDoc}
     *
     **************************************************************************/
    @Override
    public DataObject findById (final Id id)
      throws IOException 
      {
        logger.fine("findById(%s)", id);
        
        final FileObject fileObject = indexedFileSystem.findResourceById(id.stringValue());

        if (fileObject != null)
          {
            assert fileObject.getAttribute(IndexedFileSystem.ID_ATTRIBUTE) != null : "FileObject not indexed";
            return DataObject.find(fileObject);
          }
        
        logger.warning("No DataObject for id = " + id);
        return null;
      }
    
    /***************************************************************************
     * 
     * {@inheritDoc}
     *
     **************************************************************************/
    @Override
    public List findByIds (final Collection ids)
      {
        logger.fine("findByIds(%d)", ids.size());
        
        final List result = new ArrayList(ids.size());
        // TODO: prefetch ids here
        logger.warning("Should prefetch!");
                
        for (final Id id : ids)
          {
            try 
              {
                final DataObject dataObject = findById(id);
                
                // TODO: maybe you could lazy load the photoDataObject - that is get by id and leave photoDataObject null,
                // and put PhotoDataObject.find(id) on the thumbnail.getPhotoDataObject()
                
                if (dataObject != null) 
                  {
                    result.add(dataObject);
                  }
              } 
            catch (IOException e) 
              {
                logger.throwing(CLASS, "findByIds()", e);
              }
          }
        
        return result;
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy