@Override public CtlSchemaMetaInfoDto updateCtlSchemaMetaInfoScope(CtlSchemaMetaInfoDto ctlSchemaMetaInfo) { validateObject(ctlSchemaMetaInfo, "Incorrect ctl schema meta info object"); LOG.debug("Update ctl schema meta info scope with id [{}]", ctlSchemaMetaInfo.getId()); CtlSchemaMetaInfo schemaMetaInfo = ctlSchemaMetaInfoDao.findById(ctlSchemaMetaInfo.getId()); if (schemaMetaInfo != null) { synchronized (this) { ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(schemaMetaInfo); if (checkScopeUpdate(ctlSchemaMetaInfo, schemaMetaInfo.toDto())) { List<CtlSchemaMetaInfo> others = ctlSchemaMetaInfoDao.findOthersByFqnAndTenantId( ctlSchemaMetaInfo.getFqn(), ctlSchemaMetaInfo.getTenantId(), ctlSchemaMetaInfo .getId()); if (others != null && !others.isEmpty()) { throw new DatabaseProcessingException("Can't update scope of the common type due to " + "an FQN conflict."); } schemaMetaInfo = ctlSchemaMetaInfoDao.updateScope( new CtlSchemaMetaInfo(ctlSchemaMetaInfo)); } return DaoUtil.getDto(schemaMetaInfo); } } else { throw new DatabaseProcessingException("Can't find common type by id."); } }
@Override public List<CtlSchemaMetaInfoDto> findSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { if (isBlank(fqn)) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } LOG.debug("Find sibling ctl schemas by fqn {}, tenant id {} and application id {}", fqn, tenantId, applicationId); return convertDtoList(ctlSchemaMetaInfoDao.findSiblingsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId)); }
CTLSchemaDto dto; synchronized (this) { List<CtlSchemaMetaInfo> existingFqns = ctlSchemaMetaInfoDao.findExistingFqns(metaInfo .getFqn(), metaInfo.getTenantId(), metaInfo.getApplicationId()); if (existingFqns != null && !existingFqns.isEmpty()) { CtlSchemaMetaInfo uniqueMetaInfo = ctlSchemaMetaInfoDao.save( new CtlSchemaMetaInfo(metaInfo)); ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(uniqueMetaInfo); CtlSchema ctlSchema = new CtlSchema(unSavedSchema); ctlSchema.setMetaInfo(uniqueMetaInfo); ctlSchema.setCreatedTime(System.currentTimeMillis()); ctlSchemaMetaInfoDao.refresh(uniqueMetaInfo); try { dto = getDto(ctlSchemaDao.save(ctlSchema, true));
synchronized (this) { CtlSchemaMetaInfo metaInfo = ctlSchema.getMetaInfo(); ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); try { ctlSchemaDao.removeById(ctlSchema.getStringId()); List<CtlSchema> schemas = ctlSchemaDao.findAllByMetaInfoId(metaInfo.getStringId()); if (schemas == null || schemas.isEmpty()) { ctlSchemaMetaInfoDao.removeById(metaInfo.getStringId());
protected CtlSchema generateCTLSchema(String fqn, int version, Tenant tenant, CTLSchemaScopeDto scope) { if (scope == null) { if (tenant == null) { scope = CTLSchemaScopeDto.SYSTEM; } else { scope = CTLSchemaScopeDto.TENANT; } } CtlSchemaMetaInfo metaInfo = new CtlSchemaMetaInfo(); metaInfo.setFqn(fqn); metaInfo.setTenant(tenant); metaInfo = ctlSchemaMetaInfoDao.save(metaInfo); CtlSchema ctlSchema = new CtlSchema(); ctlSchema.setMetaInfo(metaInfo); ctlSchema.setVersion(version); ctlSchema.setBody(UUID.randomUUID().toString()); ctlSchema.setDependencySet(new HashSet<CtlSchema>()); ctlSchema = ctlSchemaDao.save(ctlSchema); return ctlSchema; }
@Override public CTLSchemaDto updateCtlSchema(CTLSchemaDto ctlSchema) { validateCtlSchemaObject(ctlSchema); LOG.debug("Update ctl schema with id [{}]", ctlSchema.getId()); CtlSchema schema = ctlSchemaDao.findById(ctlSchema.getId()); if (schema != null) { synchronized (this) { if (ctlSchema.getVersion() != schema.getVersion()) { throw new DatabaseProcessingException("Can't change version of existing common type " + "version."); } CtlSchemaMetaInfo metaInfo = schema.getMetaInfo(); if (!ctlSchema.getMetaInfo().equals(metaInfo.toDto())) { throw new DatabaseProcessingException("Can't update scope of existing common type " + "version within update procedure."); } ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); schema.update(ctlSchema); return DaoUtil.getDto(ctlSchemaDao.save(schema, true)); } } else { throw new DatabaseProcessingException("Can't find common type version by id."); } }