@Override public SchemaMetadataInfo getSchemaMetadataInfo(String schemaName) { SchemaMetadataStorable givenSchemaMetadataStorable = new SchemaMetadataStorable(); givenSchemaMetadataStorable.setName(schemaName); SchemaMetadataStorable schemaMetadataStorable = storageManager.get(givenSchemaMetadataStorable.getStorableKey()); return schemaMetadataStorable != null ? schemaMetadataStorable.toSchemaMetadataInfo() : null; }
public SchemaMetadataInfo toSchemaMetadataInfo() { SchemaMetadata schemaMetadata = toSchemaMetadata(); return new SchemaMetadataInfo(schemaMetadata, getId(), getTimestamp()); }
public static SchemaMetadataStorable fromSchemaMetadataInfo(SchemaMetadataInfo schemaMetadataInfo) { SchemaMetadata schemaMetadata = schemaMetadataInfo.getSchemaMetadata(); SchemaMetadataStorable schemaMetadataStorable = updateSchemaMetadata(new SchemaMetadataStorable(), schemaMetadata); schemaMetadataStorable.setId(schemaMetadataInfo.getId()); schemaMetadataStorable.setTimestamp(schemaMetadataInfo.getTimestamp()); return schemaMetadataStorable; }
public SchemaMetadata toSchemaMetadata() { return new SchemaMetadata.Builder(getName()) .type(getType()) .schemaGroup(getSchemaGroup()) .compatibility(getCompatibility()) .validationLevel(getValidationLevel()) .description(getDescription()) .evolve(getEvolve()) .build(); }
public Long addSchemaMetadata(SchemaMetadata schemaMetadata, boolean throwErrorIfExists) throws UnsupportedSchemaTypeException { SchemaMetadataStorable givenSchemaMetadataStorable = SchemaMetadataStorable.fromSchemaMetadataInfo(new SchemaMetadataInfo(schemaMetadata)); String type = schemaMetadata.getType(); if (schemaTypeWithProviders.get(type) == null) { throw new UnsupportedSchemaTypeException("Given schema type " + type + " not supported"); } if (!throwErrorIfExists) { Storable schemaMetadataStorable = storageManager.get(givenSchemaMetadataStorable.getStorableKey()); if (schemaMetadataStorable != null) { return schemaMetadataStorable.getId(); } } final Long nextId = storageManager.nextId(givenSchemaMetadataStorable.getNameSpace()); givenSchemaMetadataStorable.setId(nextId); givenSchemaMetadataStorable.setTimestamp(System.currentTimeMillis()); storageManager.add(givenSchemaMetadataStorable); // Add a schema branch for this metadata SchemaBranchStorable schemaBranchStorable = new SchemaBranchStorable(SchemaBranch.MASTER_BRANCH, schemaMetadata.getName(), String.format(SchemaBranch.MASTER_BRANCH_DESC, schemaMetadata.getName()), System.currentTimeMillis()); schemaBranchStorable.setId(storageManager.nextId(SchemaBranchStorable.NAME_SPACE)); storageManager.add(schemaBranchStorable); storageManager.add(new SchemaLockStorable(givenSchemaMetadataStorable.getNameSpace(), givenSchemaMetadataStorable.getName(), System.currentTimeMillis())); return givenSchemaMetadataStorable.getId(); }
@Override public SchemaMetadataInfo getSchemaMetadataInfo(Long schemaMetadataId) { SchemaMetadataStorable givenSchemaMetadataStorable = new SchemaMetadataStorable(); givenSchemaMetadataStorable.setId(schemaMetadataId); List<QueryParam> params = Collections.singletonList(new QueryParam(SchemaMetadataStorable.ID, schemaMetadataId.toString())); Collection<SchemaMetadataStorable> schemaMetadataStorables = storageManager.find(SchemaMetadataStorable.NAME_SPACE, params); SchemaMetadataInfo schemaMetadataInfo = null; if (schemaMetadataStorables != null && !schemaMetadataStorables.isEmpty()) { schemaMetadataInfo = schemaMetadataStorables.iterator().next().toSchemaMetadataInfo(); if (schemaMetadataStorables.size() > 1) { LOG.warn("No unique entry with schemaMetatadataId: [{}]", schemaMetadataId); } LOG.info("SchemaMetadata entries with id [{}] is [{}]", schemaMetadataStorables); } return schemaMetadataInfo; }
@Override public SchemaMetadataInfo updateSchemaMetadata(String schemaName, SchemaMetadata schemaMetadata) { if (!schemaName.equals(schemaMetadata.getName())) { throw new IllegalArgumentException("schemaName must match the name in schemaMetadata"); } SchemaMetadataStorable givenSchemaMetadataStorable = new SchemaMetadataStorable(); givenSchemaMetadataStorable.setName(schemaName); SchemaMetadataStorable schemaMetadataStorable = storageManager.get(givenSchemaMetadataStorable.getStorableKey()); if (schemaMetadataStorable != null) { schemaMetadataStorable = SchemaMetadataStorable.updateSchemaMetadata(schemaMetadataStorable, schemaMetadata); storageManager.update(schemaMetadataStorable); return schemaMetadataStorable.toSchemaMetadataInfo(); } else { return null; } }