io.datarouter.gcp.spanner.op.read.index.write.SpannerDeleteUniqueOp Maven / Gradle / Ivy
The newest version!
/*
* Copyright © 2009 HotPads ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.datarouter.gcp.spanner.op.read.index.write;
import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;
import com.google.cloud.spanner.DatabaseClient;
import io.datarouter.gcp.spanner.field.SpannerFieldCodecs;
import io.datarouter.model.databean.Databean;
import io.datarouter.model.field.Field;
import io.datarouter.model.key.primary.PrimaryKey;
import io.datarouter.model.key.unique.UniqueKey;
import io.datarouter.model.serialize.fielder.DatabeanFielder;
import io.datarouter.scanner.Scanner;
import io.datarouter.storage.config.Config;
import io.datarouter.storage.serialize.fieldcache.PhysicalDatabeanFieldInfo;
import io.datarouter.util.collection.ListTool;
public class SpannerDeleteUniqueOp<
PK extends PrimaryKey,
K extends UniqueKey,
D extends Databean,
F extends DatabeanFielder>
extends SpannerBaseIndexDelete{
public SpannerDeleteUniqueOp(
DatabaseClient client,
PhysicalDatabeanFieldInfo fieldInfo,
Collection keys,
Config config,
SpannerFieldCodecs fieldCodecs){
super(client, fieldInfo, keys, config, fieldCodecs);
}
@Override
protected String getIndexName(K key){
List indexFields = key.getFieldNames();
for(Entry>> uniqueIndex : fieldInfo.getUniqueIndexes().entrySet()){
List fieldNames = Scanner.of(uniqueIndex.getValue())
.map(field -> field.getKey().getName())
.list();
if(ListTool.compare(indexFields, fieldNames) == 0){
return uniqueIndex.getKey();
}
}
throw new RuntimeException("Cannot find index Name for key");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy