
org.datanucleus.store.excel.ExcelStoreManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datanucleus-excel Show documentation
Show all versions of datanucleus-excel Show documentation
DataNucleus supports persistence to heterogeneous datastores and this plugin provides persistence to Excel.
The newest version!
/**********************************************************************
Copyright (c) 2010 Andy Jefferson and others. All rights reserved.
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.
Contributors :
...
***********************************************************************/
package org.datanucleus.store.excel;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.poi.ss.usermodel.Workbook;
import org.datanucleus.ClassLoaderResolver;
import org.datanucleus.PersistenceNucleusContext;
import org.datanucleus.metadata.ClassMetaData;
import org.datanucleus.metadata.ClassPersistenceModifier;
import org.datanucleus.store.AbstractStoreManager;
import org.datanucleus.store.StoreData;
import org.datanucleus.store.StoreManager;
import org.datanucleus.store.connection.ManagedConnection;
import org.datanucleus.store.schema.SchemaAwareStoreManager;
import org.datanucleus.store.schema.table.CompleteClassTable;
import org.datanucleus.util.ClassUtils;
import org.datanucleus.util.Localiser;
/**
* StoreManager for data access to Excel documents (XSL or OOXML).
* Makes use of Apache POI project.
*/
public abstract class ExcelStoreManager extends AbstractStoreManager implements SchemaAwareStoreManager
{
static
{
// Register our localisation
Localiser.registerBundle("org.datanucleus.store.excel.Localisation", ExcelStoreManager.class.getClassLoader());
}
public ExcelStoreManager(String storeMgrKey, ClassLoaderResolver clr, PersistenceNucleusContext ctx, Map props)
{
super(storeMgrKey, clr, ctx, props);
// Check if Apache POI JAR is in CLASSPATH
ClassUtils.assertClassForJarExistsInClasspath(clr, "org.apache.poi.hssf.usermodel.HSSFWorkbook", "poi.jar");
schemaHandler = new ExcelSchemaHandler(this);
persistenceHandler = new ExcelPersistenceHandler(this);
logConfiguration();
}
/**
* Accessor for the supported options in string form
*/
public Collection getSupportedOptions()
{
Set set = new HashSet();
set.add(StoreManager.OPTION_APPLICATION_ID);
set.add(StoreManager.OPTION_APPLICATION_COMPOSITE_ID);
set.add(StoreManager.OPTION_DATASTORE_ID);
set.add(StoreManager.OPTION_NONDURABLE_ID);
set.add(StoreManager.OPTION_ORM);
set.add(StoreManager.OPTION_ORM_EMBEDDED_PC);
set.add(StoreManager.OPTION_TXN_ISOLATION_READ_COMMITTED);
set.add(StoreManager.OPTION_QUERY_JDOQL_BULK_DELETE);
set.add(StoreManager.OPTION_QUERY_JPQL_BULK_DELETE);
return set;
}
public void manageClasses(ClassLoaderResolver clr, String... classNames)
{
if (classNames == null)
{
return;
}
ManagedConnection mconn = getConnection(-1);
try
{
Workbook wb = (Workbook)mconn.getConnection();
manageClasses(classNames, clr, wb);
}
finally
{
mconn.release();
}
}
public void manageClasses(String[] classNames, ClassLoaderResolver clr, Workbook wb)
{
if (classNames == null)
{
return;
}
// Filter out any "simple" type classes
String[] filteredClassNames = getNucleusContext().getTypeManager().filterOutSupportedSecondClassNames(classNames);
// Find the ClassMetaData for these classes and all referenced by these classes
Set clsNameSet = new HashSet();
Iterator iter = getMetaDataManager().getReferencedClasses(filteredClassNames, clr).iterator();
while (iter.hasNext())
{
ClassMetaData cmd = (ClassMetaData)iter.next();
if (cmd.getPersistenceModifier() == ClassPersistenceModifier.PERSISTENCE_CAPABLE && !cmd.isEmbeddedOnly())
{
if (!storeDataMgr.managesClass(cmd.getFullClassName()))
{
StoreData sd = storeDataMgr.get(cmd.getFullClassName());
if (sd == null)
{
CompleteClassTable table = new CompleteClassTable(this, cmd, null);
sd = newStoreData(cmd, clr);
sd.setTable(table);
registerStoreData(sd);
}
clsNameSet.add(cmd.getFullClassName());
}
}
}
// Create schema for classes
schemaHandler.createSchemaForClasses(clsNameSet, null, wb);
}
public void createSchema(String schemaName, Properties props)
{
schemaHandler.createSchema(schemaName, props, null);
}
public void deleteSchema(String schemaName, Properties props)
{
schemaHandler.deleteSchema(schemaName, props, null);
}
public void createSchemaForClasses(Set classNames, Properties props)
{
schemaHandler.createSchemaForClasses(classNames, props, null);
}
public void deleteSchemaForClasses(Set classNames, Properties props)
{
schemaHandler.deleteSchemaForClasses(classNames, props, null);
}
public void validateSchemaForClasses(Set classNames, Properties props)
{
schemaHandler.validateSchema(classNames, props, null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy