it.tidalwave.metadata.persistence.spi.MetadataItemPersistenceSupport Maven / Gradle / Ivy
The newest version!
/***********************************************************************************************************************
*
* blueMarine Metadata - open source media workflow
* Copyright (C) 2007-2011 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://bluemarine.tidalwave.it
* SCM: https://kenai.com/hg/bluemarine~metadata-src
*
**********************************************************************************************************************/
package it.tidalwave.metadata.persistence.spi;
import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import it.tidalwave.util.logging.Logger;
import org.openide.loaders.DataObject;
import it.tidalwave.metadata.Metadata.FindOption;
import it.tidalwave.metadata.Metadata.StorageType;
import it.tidalwave.metadata.Metadata.StoreOption;
import it.tidalwave.metadata.MetadataItemHolder;
import it.tidalwave.metadata.spi.MetadataItemSourceSinkSupport;
class PersistenceMetadataHolder- extends MetadataItemHolder
-
{
private static final long serialVersionUID = 351706783745243051L;
public PersistenceMetadataHolder (@Nonnull final Item bean,
@Nonnull final Date latestModificationTime)
{
super(bean, null, "Persistence", latestModificationTime);
}
@Override
public boolean isAvailable()
{
return true; // If an item is in the persistence, it's available by default
}
}
/*******************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
******************************************************************************/
public class MetadataItemPersistenceSupport
- extends MetadataItemSourceSinkSupport
-
{
private final static String CLASS = MetadataItemPersistenceSupport.class.getName();
private final static Logger logger = Logger.getLogger(CLASS);
@Nonnull
private final String propertySetName;
@Nonnull
protected final MetadataPersistenceSpi persistenceSpi = MetadataPersistenceSpi.Locator.findPersistenceSpi();
/***************************************************************************
*
*
**************************************************************************/
public MetadataItemPersistenceSupport (@Nonnull final Class
- itemClass,
@Nonnull final String name,
@Nonnull final StorageType storageType,
@Nonnull final String propertySetName)
{
super(itemClass, name, storageType);
this.propertySetName = propertySetName;
}
/***************************************************************************
*
* {@inheritDocs}
*
**************************************************************************/
@Nonnull
public Collection
> loadMetadataItems (@Nonnull final DataObject dataObject,
@Nonnull final FindOption ... options)
throws Exception
{
logger.fine("loadMetadataItem(%s, %s)", dataObject, Arrays.toString(options));
final Item item = createInstance();
final Date timestamp = new Date(0); // FIXME: get from database
final MetadataItemHolder- holder = new PersistenceMetadataHolder
- (item, timestamp);
persistenceSpi.refresh(dataObject, holder);
return Collections.singletonList(holder);
}
/***************************************************************************
*
* {@inheritDocs}
*
**************************************************************************/
public void storeMetadataItem (@Nonnull final DataObject dataObject,
@Nonnull final MetadataItemHolder
- holder,
@Nonnull final StoreOption... options)
throws Exception
{
logger.fine("storeMetadataItem(%s, %s, %s)", dataObject, holder, Arrays.toString(options));
persistenceSpi.manage(dataObject, holder, options);
}
/***************************************************************************
*
* {@inheritDocs}
*
**************************************************************************/
@Nonnull
public String getPropertySetName()
{
return propertySetName;
}
/***************************************************************************
*
*
**************************************************************************/
@Nonnull
protected Item createInstance()
{
try
{
return getItemClass().newInstance();
}
catch (InstantiationException e)
{
throw new RuntimeException(e);
}
catch (IllegalAccessException e)
{
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy