io.shardingsphere.api.HintManager Maven / Gradle / Ivy
/*
* Copyright 2016-2018 shardingsphere.io.
*
* 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.shardingsphere.api;
import io.shardingsphere.core.hint.HintManagerHolder;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* The manager that use hint to inject sharding key directly through {@code ThreadLocal}.
*
* @author gaohongtao
* @author zhangliang
* @author panjun
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class HintManager implements AutoCloseable {
/**
* Get a new instance for {@code HintManager}.
*
* @return {@code HintManager} instance
*/
public static HintManager getInstance() {
HintManager result = new HintManager();
HintManagerHolder.setHintManager(result);
return result;
}
/**
* Add sharding value for database sharding only.
*
* The sharding operator is {@code =}
* When you only need to sharding database, use this method to add database sharding value.
*
* @param value sharding value
*/
public void setDatabaseShardingValue(final Comparable> value) {
HintManagerHolder.setDatabaseShardingValue(value);
}
/**
* Set CRUD operation force route to master database only.
*/
public void setMasterRouteOnly() {
HintManagerHolder.setMasterRouteOnly(true);
}
/**
* Add sharding value for database.
*
* The sharding operator is {@code =}
*
* @param logicTable logic table name
* @param value sharding value
*/
public void addDatabaseShardingValue(final String logicTable, final Comparable> value) {
HintManagerHolder.addDatabaseShardingValue(logicTable, value);
}
/**
* Add sharding value for table.
*
* The sharding operator is {@code =}
*
* @param logicTable logic table name
* @param value sharding value
*/
public void addTableShardingValue(final String logicTable, final Comparable> value) {
HintManagerHolder.addTableShardingValue(logicTable, value);
}
@Override
public void close() {
HintManagerHolder.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy