All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viiyue.plugins.mybatis.api.defaults.version.DefaultNextVersionProvider Maven / Gradle / Ivy

Go to download

Mybatis generic mapper plugin for solving most basic operations, simplifying sql syntax and improving dynamic execution efficiency

There is a newer version: 1.3.7
Show newest version
/**
 * Copyright (C) 2017 the 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 com.viiyue.plugins.mybatis.api.defaults.version;

import java.sql.Timestamp;

import com.viiyue.plugins.mybatis.api.NextVersionProvider;
import com.viiyue.plugins.mybatis.exceptions.ParameterValidateException;
import com.viiyue.plugins.mybatis.metadata.Property;

/**
 * 

Default optimistic lock auto increment version number provider * *

* This class will be incremented by 1 each time based on the existing version * number * * @author tangxbai * @since 1.1.0 */ public class DefaultNextVersionProvider implements NextVersionProvider { @Override public Object nextVersion( Property property, Object currentVersion ) { if ( currentVersion instanceof Short ) { return ( Short ) currentVersion + 1; } if ( currentVersion instanceof Integer ) { return ( Integer ) currentVersion + 1; } if ( currentVersion instanceof Long ) { return ( Long ) currentVersion + 1L; } if ( currentVersion instanceof Timestamp ) { return new Timestamp( System.currentTimeMillis() ); } throw new ParameterValidateException( "The default optimistic lock version number only supports [ Short, Integer, Long, java.sql.Timestamp ]" ); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy