@Test(expected = MetaClassNotExistsException.class) public void testDeleteMetaClasses01NotExistingMeta() { repo.getMetadataService().deleteMetaClass("any-meta-class", null); }
@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; }