@Override
protected VDBMetaData mergeMetaData(VFSDeploymentUnit unit, Map<Class<?>, List<Object>> metadata) throws Exception {
VDBMetaData vdb = getInstance(metadata, VDBMetaData.class);
UDFMetaData udf = getInstance(metadata, UDFMetaData.class);
IndexMetadataFactory imf = getInstance(metadata, IndexMetadataFactory.class);
if (vdb == null) {
LogManager.logError(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.getString("invlaid_vdb_file",unit.getRoot().getName())); //$NON-NLS-1$
return null;
}
vdb.setUrl(unit.getRoot().toURL());
// build the metadata store
if (imf != null) {
imf.addEntriesPlusVisibilities(unit.getRoot(), vdb);
unit.addAttachment(IndexMetadataFactory.class, imf);
// add the cached store.
File cacheFile = VDBDeployer.buildCachedVDBFileName(this.serializer, unit, vdb);
// check to see if the vdb has been modified when server is down; if it is then clear the old files
if (this.serializer.isStale(cacheFile, unit.getRoot().getLastModified())) {
this.serializer.removeAttachments(unit);
LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB", unit.getRoot().getName(), "old cached metadata has been removed"); //$NON-NLS-1$ //$NON-NLS-2$
}
MetadataStoreGroup stores = this.serializer.loadSafe(cacheFile, MetadataStoreGroup.class);
if (stores == null) {
// start to build the new metadata
stores = new MetadataStoreGroup();
stores.addStore(imf.getMetadataStore(vdbRepository.getSystemStore().getDatatypes()));
}
else {
LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB", unit.getRoot().getName(), "was loaded from cached metadata"); //$NON-NLS-1$ //$NON-NLS-2$
}
unit.addAttachment(MetadataStoreGroup.class, stores);