
io.kazuki.v0.store.sequence.SequenceHelper Maven / Gradle / Ivy
The newest version!
/**
* Copyright 2014 Sunny Gleason and original author or authors
*
* 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.kazuki.v0.store.sequence;
import io.kazuki.v0.internal.helper.JDBIHelper;
import io.kazuki.v0.store.KazukiException;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.Query;
import org.skife.jdbi.v2.Update;
import com.google.common.base.Preconditions;
public class SequenceHelper {
private final boolean strictTypeCreation;
private final String dbPrefix;
private final String sequenceTableName;
private final String keyTypesTableName;
@Inject
public SequenceHelper(SequenceServiceConfiguration config) {
this(config.getDbPrefix(), config.getGroupName(), config.getStoreName(), config
.isStrictTypeCreation());
}
public SequenceHelper(String dbPrefix, String groupName, String storeName,
boolean strictTypeCreation) {
Preconditions.checkNotNull(dbPrefix, "dbPrefix");
Preconditions.checkNotNull(groupName, "groupName");
Preconditions.checkNotNull(storeName, "storeName");
this.dbPrefix = dbPrefix;
this.sequenceTableName = "_" + groupName + "_" + storeName + "__seq";
this.keyTypesTableName = "_" + groupName + "_" + storeName + "__types";
this.strictTypeCreation = strictTypeCreation;
}
public String getDbPrefix() {
return dbPrefix;
}
public String getSequenceTableName() {
return sequenceTableName;
}
public String getKeyTypesTableName() {
return keyTypesTableName;
}
public Integer validateType(Handle handle, Map typeCodes,
Map typeNames, final String type, boolean doCreate) throws KazukiException {
doCreate |= !strictTypeCreation;
if (type == null || type.length() == 0 || type.indexOf(":") != -1 || type.length() > 72) {
throw new IllegalArgumentException("Invalid entity 'type'");
}
if (typeCodes.containsKey(type)) {
Integer typeId = typeCodes.get(type);
return typeId;
}
Query
© 2015 - 2025 Weber Informatics LLC | Privacy Policy