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

win.doyto.query.entity.UserIdProvider Maven / Gradle / Ivy

There is a newer version: 0.2.2.1-RELEASE
Show newest version
package win.doyto.query.entity;

import java.io.Serializable;
import java.util.Date;

/**
 * UserIdProvider
 *
 * @author f0rb
 */
public interface UserIdProvider {

    I getUserId();

    @SuppressWarnings("unchecked")
    default void setupUserId(Object e) {
        I userId = getUserId();
        if (userId != null) {
            if (e instanceof Persistable && ((Persistable) e).isNew()) {
                if( e instanceof CreateUserAware) {
                    ((CreateUserAware) e).setCreateUserId(userId);
                    ((CreateUserAware) e).setCreateTime(new Date());
                }
            } else {
                if (e instanceof UpdateUserAware) {
                    ((UpdateUserAware) e).setUpdateUserId(userId);
                    ((UpdateUserAware) e).setUpdateTime(new Date());
                }
            }
        }
    }

}