@Test public void testDeleteMetaClass() { String pooledClusterMetaName = "PooledCluster"; String resourceContainerName = "ResourceContainer"; IMetadataService metaService = repositoryService.getRepository("stratus-ci").getMetadataService(); MetaClass resourceContainerMeta = metaService.getMetaClass(resourceContainerName); MetaClass resourceMeta = metaService.getMetaClass(pooledClusterMetaName); List<MetaRelationship> inReference = resourceMeta.getFromReference(); Set<String> resourceInNames = new HashSet<String>(); for (MetaRelationship rel : inReference) { resourceInNames.add(rel.getSourceDataType()); } Assert.assertTrue(resourceInNames.contains(resourceContainerName)); MetaClass baseMeta = metaService.getMetaClass("Base"); List<MetaClass> descentClass = baseMeta.getDescendants(); Assert.assertTrue(descentClass.contains(resourceContainerMeta)); MetadataContext metaContext = new MetadataContext(); metaService.deleteMetaClass(resourceContainerName, metaContext); MetaClass mc = metaService.getMetaClass(resourceContainerName); Assert.assertNull(mc); MetaClass resourceMeta2 = metaService.getMetaClass(pooledClusterMetaName); List<MetaRelationship> inReference2 = resourceMeta2.getFromReference(); Set<String> resourceInNames2 = new HashSet<String>(); for (MetaRelationship rel : inReference2) { resourceInNames2.add(rel.getSourceDataType()); } Assert.assertFalse(resourceInNames2.contains(resourceContainerName)); baseMeta = metaService.getMetaClass("Base"); descentClass = baseMeta.getDescendants(); Assert.assertFalse(descentClass.contains(resourceContainerMeta)); }
@Override public void deleteMetaClass(String className, MetadataContext metaContext) { long start = System.currentTimeMillis(); try { metadataLock.lock(); MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } if (!meta.getFromReference().isEmpty() || !meta.getDescendants().isEmpty()) { StringBuilder sb = new StringBuilder(); for (MetaRelationship mr : meta.getFromReference()) { sb.append(mr.getSourceDataType()).append(","); } for (MetaClass mc : meta.getDescendants()) { sb.append(mc.getName()).append(","); } sb.deleteCharAt(sb.length() - 1); throw new MetaDataException(MetaErrCodeEnum.NONE_ORPHAN_META_CLASS, MessageFormat.format("MetaClass {0} is referenced by other meta class: {1}!", className, sb.toString())); } innerDeleteMetaClass(meta); addMetaHistory(meta, "deleteMetaClass", metaContext); long duration = System.currentTimeMillis() - start; metaContext.addDbTimeCost(duration); } catch (InterruptedException e) { logger.info("lock interrupted for deletaMetaClass {}", className); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for deleteMetaClass " + className, e); } finally { metadataLock.unlock(); } }
MongoMetadataServiceImpl implements IMetadataService { @Override public void deleteMetaClass(String className, MetadataContext metaContext) { long start = System.currentTimeMillis(); try { metadataLock.lock(); MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } if (!meta.getFromReference().isEmpty() || !meta.getDescendants().isEmpty()) { StringBuilder sb = new StringBuilder(); for (MetaRelationship mr : meta.getFromReference()) { sb.append(mr.getSourceDataType()).append(","); } for (MetaClass mc : meta.getDescendants()) { sb.append(mc.getName()).append(","); } sb.deleteCharAt(sb.length() - 1); throw new MetaDataException(MetaErrCodeEnum.NONE_ORPHAN_META_CLASS, MessageFormat.format("MetaClass {0} is referenced by other meta class: {1}!", className, sb.toString())); } innerDeleteMetaClass(meta); addMetaHistory(meta, "deleteMetaClass", metaContext); long duration = System.currentTimeMillis() - start; metaContext.addDbTimeCost(duration); } catch (InterruptedException e) { logger.info("lock interrupted for deletaMetaClass {}", className); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for deleteMetaClass " + className, e); } finally { metadataLock.unlock(); } } }
MongoMetadataServiceImpl implements IMetadataService { @Override public void deleteMetaClass(String className, MetadataContext metaContext) { long start = System.currentTimeMillis(); try { metadataLock.lock(); MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } if (!meta.getFromReference().isEmpty() || !meta.getDescendants().isEmpty()) { StringBuilder sb = new StringBuilder(); for (MetaRelationship mr : meta.getFromReference()) { sb.append(mr.getSourceDataType()).append(","); } for (MetaClass mc : meta.getDescendants()) { sb.append(mc.getName()).append(","); } sb.deleteCharAt(sb.length() - 1); throw new MetaDataException(MetaErrCodeEnum.NONE_ORPHAN_META_CLASS, MessageFormat.format("MetaClass {0} is referenced by other meta class: {1}!", className, sb.toString())); } innerDeleteMetaClass(meta); addMetaHistory(meta, "deleteMetaClass", metaContext); long duration = System.currentTimeMillis() - start; metaContext.addDbTimeCost(duration); } catch (InterruptedException e) { logger.info("lock interrupted for deletaMetaClass {}", className); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for deleteMetaClass " + className, e); } finally { metadataLock.unlock(); } } MongoMetadataServiceImpl(Mongo mongo, int maxCacheSize,
            int cacheExpiredTime, int collectionCountCacheSize, int collectionCountCacheExpiredTime,
            Repository repo, ICMSLock metadataLock); }
MongoMetadataServiceImpl implements IMetadataService { @Override public void deleteMetaClass(String className, MetadataContext metaContext) { long start = System.currentTimeMillis(); try { metadataLock.lock(); MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } if (!meta.getFromReference().isEmpty() || !meta.getDescendants().isEmpty()) { StringBuilder sb = new StringBuilder(); for (MetaRelationship mr : meta.getFromReference()) { sb.append(mr.getSourceDataType()).append(","); } for (MetaClass mc : meta.getDescendants()) { sb.append(mc.getName()).append(","); } sb.deleteCharAt(sb.length() - 1); throw new MetaDataException(MetaErrCodeEnum.NONE_ORPHAN_META_CLASS, MessageFormat.format("MetaClass {0} is referenced by other meta class: {1}!", className, sb.toString())); } innerDeleteMetaClass(meta); addMetaHistory(meta, "deleteMetaClass", metaContext); long duration = System.currentTimeMillis() - start; metaContext.addDbTimeCost(duration); } catch (InterruptedException e) { logger.info("lock interrupted for deletaMetaClass {}", className); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for deleteMetaClass " + className, e); } finally { metadataLock.unlock(); } } MongoMetadataServiceImpl(Mongo mongo, int maxCacheSize,
            int cacheExpiredTime, int collectionCountCacheSize, int collectionCountCacheExpiredTime,
            Repository repo, ICMSLock metadataLock); @Override Repository getRepository(); @Override MetaClass getMetaClass(String className); @Override MetaClass getMetaClass(String className, int version, MetadataContext context); @Override MetaClass createMetaClass(MetaClass metaClass, MetadataContext context); @Override void deleteMetaClass(String className, MetadataContext metaContext); @Override MetaClass deleteMetaField(String className, String fieldName, MetadataContext metaContext); @Override MetaClass updateMetaClass(MetaClass metaClass, MetadataContext context); @Override List<MetaClass> batchUpsert(List<MetaClass> metaClasses, MetadataContext context); @Override final List<MetaClass> getMetaClasses(MetadataContext ctx); @Override void updateMetaOption(String className, MetaOption options, MetadataContext context); @Override int getCollectionCount(String dbCollectionName); @Override MetaClass updateMetaField(MetaClass metaClass, String fieldName, MetadataContext context); @Override void validateMetaClass(String className); @Override void setMetaHistoryService(IMetadataHistoryService historyService); }
MongoMetadataServiceImpl implements IMetadataService { @Override public void deleteMetaClass(String className, MetadataContext metaContext) { long start = System.currentTimeMillis(); try { metadataLock.lock(); MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } if (!meta.getFromReference().isEmpty() || !meta.getDescendants().isEmpty()) { StringBuilder sb = new StringBuilder(); for (MetaRelationship mr : meta.getFromReference()) { sb.append(mr.getSourceDataType()).append(","); } for (MetaClass mc : meta.getDescendants()) { sb.append(mc.getName()).append(","); } sb.deleteCharAt(sb.length() - 1); throw new MetaDataException(MetaErrCodeEnum.NONE_ORPHAN_META_CLASS, MessageFormat.format("MetaClass {0} is referenced by other meta class: {1}!", className, sb.toString())); } innerDeleteMetaClass(meta); addMetaHistory(meta, "deleteMetaClass", metaContext); long duration = System.currentTimeMillis() - start; metaContext.addDbTimeCost(duration); } catch (InterruptedException e) { logger.info("lock interrupted for deletaMetaClass {}", className); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for deleteMetaClass " + className, e); } finally { metadataLock.unlock(); } } MongoMetadataServiceImpl(Mongo mongo, int maxCacheSize,
            int cacheExpiredTime, int collectionCountCacheSize, int collectionCountCacheExpiredTime,
            Repository repo, ICMSLock metadataLock); @Override Repository getRepository(); @Override MetaClass getMetaClass(String className); @Override MetaClass getMetaClass(String className, int version, MetadataContext context); @Override MetaClass createMetaClass(MetaClass metaClass, MetadataContext context); @Override void deleteMetaClass(String className, MetadataContext metaContext); @Override MetaClass deleteMetaField(String className, String fieldName, MetadataContext metaContext); @Override MetaClass updateMetaClass(MetaClass metaClass, MetadataContext context); @Override List<MetaClass> batchUpsert(List<MetaClass> metaClasses, MetadataContext context); @Override final List<MetaClass> getMetaClasses(MetadataContext ctx); @Override void updateMetaOption(String className, MetaOption options, MetadataContext context); @Override int getCollectionCount(String dbCollectionName); @Override MetaClass updateMetaField(MetaClass metaClass, String fieldName, MetadataContext context); @Override void validateMetaClass(String className); @Override void setMetaHistoryService(IMetadataHistoryService historyService); static final Logger logger; }