@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; }
@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; } }
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(); }