com.torodb.backend.tables.KvTable Maven / Gradle / Ivy
/*
* ToroDB
* Copyright © 2014 8Kdata Technology (www.8kdata.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package com.torodb.backend.tables;
import com.torodb.backend.meta.TorodbSchema;
import com.torodb.backend.tables.records.KvRecord;
import org.jooq.Field;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.UniqueKey;
import org.jooq.impl.AbstractKeys;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings({"checkstyle:AbbreviationAsWordInName", "MemberName"})
public abstract class KvTable extends SemanticTable {
private static final long serialVersionUID = -8840058751911188345L;
public static final String TABLE_NAME = "kv";
public enum TableFields {
KEY("key"),
VALUE("value");
public final String fieldName;
TableFields(String fieldName) {
this.fieldName = fieldName;
}
@Override
public String toString() {
return fieldName;
}
}
/**
* The class holding records for this type
*
* @return
*/
@Override
public abstract Class getRecordType();
/**
* The column torodb.kv.key
.
*/
public final TableField KEY = createNameField();
/**
* The column torodb.kv.value
.
*/
public final TableField VALUE =
createIdentifierField();
protected abstract TableField createNameField();
protected abstract TableField createIdentifierField();
private final UniqueKeys uniqueKeys;
/**
* Create a torodb.kv
table reference
*/
public KvTable() {
this(TABLE_NAME, null);
}
protected KvTable(String alias, Table aliased) {
this(alias, aliased, null);
}
protected KvTable(String alias, Table aliased, Field>[] parameters) {
super(alias, TorodbSchema.TORODB, aliased, parameters, "");
this.uniqueKeys = new UniqueKeys(this);
}
/**
* {@inheritDoc}
*/
@Override
public UniqueKey getPrimaryKey() {
return uniqueKeys.DATABASE_PKEY;
}
/**
* {@inheritDoc}
*/
@Override
public List> getKeys() {
return Arrays.>asList(uniqueKeys.DATABASE_PKEY,
uniqueKeys.DATABASE_SCHEMA_UNIQUE
);
}
/**
* {@inheritDoc}
*/
@Override
public abstract KvTable as(String alias);
/**
* Rename this table
*/
public abstract KvTable rename(String name);
public UniqueKeys getUniqueKeys() {
return uniqueKeys;
}
@SuppressWarnings({"checkstyle:LineLength", "checkstyle:AbbreviationAsWordInName",
"checkstyle:MemberName"})
public static class UniqueKeys extends AbstractKeys {
private final UniqueKey DATABASE_PKEY;
private final UniqueKey DATABASE_SCHEMA_UNIQUE;
private UniqueKeys(KvTable databaseTable) {
DATABASE_PKEY = createUniqueKey(databaseTable, databaseTable.KEY);
DATABASE_SCHEMA_UNIQUE = createUniqueKey(databaseTable, databaseTable.VALUE);
}
}
}