@Test public void testBatchUpsert() { IMetadataService ms = repositoryService.getRepository(repoName).getMetadataService(); MetaClass b1 = createMetaClass(); b1.setName("b1"); MetaRelationship r1 = new MetaRelationship(); r1.setRelationType(RelationTypeEnum.Reference); r1.setName("r1"); r1.setRefDataType("b2"); b1.addField(r1); MetaClass b2 = createMetaClass(); b2.setName("b2"); b2.setParent(b1.getName()); MetaRelationship r2 = new MetaRelationship(); r2.setRelationType(RelationTypeEnum.Reference); r2.setName("r2"); r2.setRefDataType(b1.getName()); b2.addField(r2); ms.batchUpsert(Arrays.asList(b1, b2), metaContext); b1 = createMetaClass(); b1.setName("b1"); MetaRelationship r3 = new MetaRelationship(); r3.setRelationType(RelationTypeEnum.Reference); r3.setName("r3"); r3.setRefDataType("b3"); b1.addField(r3); MetaClass updateB2 = createMetaClass(); updateB2.setName(b2.getName()); updateB2.setParent(b1.getName()); MetaAttribute ma = new MetaAttribute(); ma.setName("newB2Attribute"); ma.setDataType(DataTypeEnum.STRING); updateB2.addField(ma); MetaClass b3 = createMetaClass(); b3.setName("b3"); MetaRelationship r4 = new MetaRelationship(); r4.setRelationType(RelationTypeEnum.Reference); r4.setName("r4"); r4.setRefDataType("b1"); b3.addField(r4); ms.batchUpsert(Arrays.asList(b1, updateB2, b3), metaContext); }
@Override public List<MetaClass> batchUpsert(List<MetaClass> metaClasses, MetadataContext context) { try { metadataLock.lock(); if (metaClasses == null || metaClasses.isEmpty()) { return Collections.emptyList(); } Map<String, MetaClass> metas = prepareMetaClassMap(metaClasses); ArrayList<MetaClass> result = new ArrayList<MetaClass>(metaClasses.size()); Collection<MetaClass> mergedMetaClasses = new ArrayList<MetaClass>(); for (MetaClass mc : graph.getMetaClasses()) { mergedMetaClasses.add(mc); } mergedMetaClasses.addAll(metaClasses); MetaClassGraph tempGraph = new MetaClassGraph(mergedMetaClasses); for (MetaClass m : mergedMetaClasses) { m.setMetadataService(this); tempGraph.updateMetaClass(m); } for (MetaClass m : metaClasses) { MetaClass m1 = getMetaClass(m.getName()); if (m1 != null && m1.getName().equals(m.getName())) { checkMetaClassVersion(m); validator.validateForUpdate(m, metas, tempGraph); } else { validator.validateForCreation(m, metas, tempGraph); } } for (MetaClass m : metaClasses){ String name = m.getName(); MetaClass value = m; MetaClass m1 = getMetaClass(name); if (m1 == null || !m1.getName().equals(name)) { MetaClass meta = innerCreateMetaClass(value, false, context); result.add(meta); } else { cacheManager.deleteMetaClassFromCache(m1); setupParentVersion(value); MetaClass meta = innerUpdateMetaClass(value, false, false); result.add(meta); addMetaHistory(m1, "updateMetaClass", context); } } for (MetaClass m : result) { graph.updateMetaClass(m); } return result; } catch (InterruptedException e) { logger.info("lock interrupted for batchUpsert"); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for batchUpsert ", e); } finally { metadataLock.unlock(); } }
MongoMetadataServiceImpl implements IMetadataService { @Override public List<MetaClass> batchUpsert(List<MetaClass> metaClasses, MetadataContext context) { try { metadataLock.lock(); if (metaClasses == null || metaClasses.isEmpty()) { return Collections.emptyList(); } Map<String, MetaClass> metas = prepareMetaClassMap(metaClasses); ArrayList<MetaClass> result = new ArrayList<MetaClass>(metaClasses.size()); Collection<MetaClass> mergedMetaClasses = new ArrayList<MetaClass>(); for (MetaClass mc : graph.getMetaClasses()) { mergedMetaClasses.add(mc); } mergedMetaClasses.addAll(metaClasses); MetaClassGraph tempGraph = new MetaClassGraph(mergedMetaClasses); for (MetaClass m : mergedMetaClasses) { m.setMetadataService(this); tempGraph.updateMetaClass(m); } for (MetaClass m : metaClasses) { MetaClass m1 = getMetaClass(m.getName()); if (m1 != null && m1.getName().equals(m.getName())) { checkMetaClassVersion(m); validator.validateForUpdate(m, metas, tempGraph); } else { validator.validateForCreation(m, metas, tempGraph); } } for (MetaClass m : metaClasses){ String name = m.getName(); MetaClass value = m; MetaClass m1 = getMetaClass(name); if (m1 == null || !m1.getName().equals(name)) { MetaClass meta = innerCreateMetaClass(value, false, context); result.add(meta); } else { cacheManager.deleteMetaClassFromCache(m1); setupParentVersion(value); MetaClass meta = innerUpdateMetaClass(value, false, false); result.add(meta); addMetaHistory(m1, "updateMetaClass", context); } } for (MetaClass m : result) { graph.updateMetaClass(m); } return result; } catch (InterruptedException e) { logger.info("lock interrupted for batchUpsert"); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for batchUpsert ", e); } finally { metadataLock.unlock(); } } }
MongoMetadataServiceImpl implements IMetadataService { @Override public List<MetaClass> batchUpsert(List<MetaClass> metaClasses, MetadataContext context) { try { metadataLock.lock(); if (metaClasses == null || metaClasses.isEmpty()) { return Collections.emptyList(); } Map<String, MetaClass> metas = prepareMetaClassMap(metaClasses); ArrayList<MetaClass> result = new ArrayList<MetaClass>(metaClasses.size()); Collection<MetaClass> mergedMetaClasses = new ArrayList<MetaClass>(); for (MetaClass mc : graph.getMetaClasses()) { mergedMetaClasses.add(mc); } mergedMetaClasses.addAll(metaClasses); MetaClassGraph tempGraph = new MetaClassGraph(mergedMetaClasses); for (MetaClass m : mergedMetaClasses) { m.setMetadataService(this); tempGraph.updateMetaClass(m); } for (MetaClass m : metaClasses) { MetaClass m1 = getMetaClass(m.getName()); if (m1 != null && m1.getName().equals(m.getName())) { checkMetaClassVersion(m); validator.validateForUpdate(m, metas, tempGraph); } else { validator.validateForCreation(m, metas, tempGraph); } } for (MetaClass m : metaClasses){ String name = m.getName(); MetaClass value = m; MetaClass m1 = getMetaClass(name); if (m1 == null || !m1.getName().equals(name)) { MetaClass meta = innerCreateMetaClass(value, false, context); result.add(meta); } else { cacheManager.deleteMetaClassFromCache(m1); setupParentVersion(value); MetaClass meta = innerUpdateMetaClass(value, false, false); result.add(meta); addMetaHistory(m1, "updateMetaClass", context); } } for (MetaClass m : result) { graph.updateMetaClass(m); } return result; } catch (InterruptedException e) { logger.info("lock interrupted for batchUpsert"); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for batchUpsert ", e); } finally { metadataLock.unlock(); } } MongoMetadataServiceImpl(Mongo mongo, int maxCacheSize,
            int cacheExpiredTime, int collectionCountCacheSize, int collectionCountCacheExpiredTime,
            Repository repo, ICMSLock metadataLock); }
MongoMetadataServiceImpl implements IMetadataService { @Override public List<MetaClass> batchUpsert(List<MetaClass> metaClasses, MetadataContext context) { try { metadataLock.lock(); if (metaClasses == null || metaClasses.isEmpty()) { return Collections.emptyList(); } Map<String, MetaClass> metas = prepareMetaClassMap(metaClasses); ArrayList<MetaClass> result = new ArrayList<MetaClass>(metaClasses.size()); Collection<MetaClass> mergedMetaClasses = new ArrayList<MetaClass>(); for (MetaClass mc : graph.getMetaClasses()) { mergedMetaClasses.add(mc); } mergedMetaClasses.addAll(metaClasses); MetaClassGraph tempGraph = new MetaClassGraph(mergedMetaClasses); for (MetaClass m : mergedMetaClasses) { m.setMetadataService(this); tempGraph.updateMetaClass(m); } for (MetaClass m : metaClasses) { MetaClass m1 = getMetaClass(m.getName()); if (m1 != null && m1.getName().equals(m.getName())) { checkMetaClassVersion(m); validator.validateForUpdate(m, metas, tempGraph); } else { validator.validateForCreation(m, metas, tempGraph); } } for (MetaClass m : metaClasses){ String name = m.getName(); MetaClass value = m; MetaClass m1 = getMetaClass(name); if (m1 == null || !m1.getName().equals(name)) { MetaClass meta = innerCreateMetaClass(value, false, context); result.add(meta); } else { cacheManager.deleteMetaClassFromCache(m1); setupParentVersion(value); MetaClass meta = innerUpdateMetaClass(value, false, false); result.add(meta); addMetaHistory(m1, "updateMetaClass", context); } } for (MetaClass m : result) { graph.updateMetaClass(m); } return result; } catch (InterruptedException e) { logger.info("lock interrupted for batchUpsert"); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for batchUpsert ", 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 List<MetaClass> batchUpsert(List<MetaClass> metaClasses, MetadataContext context) { try { metadataLock.lock(); if (metaClasses == null || metaClasses.isEmpty()) { return Collections.emptyList(); } Map<String, MetaClass> metas = prepareMetaClassMap(metaClasses); ArrayList<MetaClass> result = new ArrayList<MetaClass>(metaClasses.size()); Collection<MetaClass> mergedMetaClasses = new ArrayList<MetaClass>(); for (MetaClass mc : graph.getMetaClasses()) { mergedMetaClasses.add(mc); } mergedMetaClasses.addAll(metaClasses); MetaClassGraph tempGraph = new MetaClassGraph(mergedMetaClasses); for (MetaClass m : mergedMetaClasses) { m.setMetadataService(this); tempGraph.updateMetaClass(m); } for (MetaClass m : metaClasses) { MetaClass m1 = getMetaClass(m.getName()); if (m1 != null && m1.getName().equals(m.getName())) { checkMetaClassVersion(m); validator.validateForUpdate(m, metas, tempGraph); } else { validator.validateForCreation(m, metas, tempGraph); } } for (MetaClass m : metaClasses){ String name = m.getName(); MetaClass value = m; MetaClass m1 = getMetaClass(name); if (m1 == null || !m1.getName().equals(name)) { MetaClass meta = innerCreateMetaClass(value, false, context); result.add(meta); } else { cacheManager.deleteMetaClassFromCache(m1); setupParentVersion(value); MetaClass meta = innerUpdateMetaClass(value, false, false); result.add(meta); addMetaHistory(m1, "updateMetaClass", context); } } for (MetaClass m : result) { graph.updateMetaClass(m); } return result; } catch (InterruptedException e) { logger.info("lock interrupted for batchUpsert"); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for batchUpsert ", 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; }