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

org.rx.io.EntityDatabase Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.io;

import lombok.SneakyThrows;
import org.rx.bean.DataTable;
import org.rx.util.function.Action;
import org.rx.util.function.Func;

import java.io.Serializable;
import java.util.List;

public interface EntityDatabase extends AutoCloseable {
    String DEFAULT_FILE_PATH = "./rx";
    EntityDatabase DEFAULT = new EntityDatabaseImpl();

     void save(T entity);

     void save(T entity, boolean doInsert);

     boolean deleteById(Class entityType, Serializable id);

     long delete(EntityQueryLambda query);

     long count(EntityQueryLambda query);

     boolean exists(EntityQueryLambda query);

     boolean existsById(Class entityType, Serializable id);

     T findById(Class entityType, Serializable id);

     T findOne(EntityQueryLambda query);

     List findBy(EntityQueryLambda query);

    void compact();

     void dropMapping(Class entityType);

    void createMapping(Class... entityTypes);

    String tableName(Class entityType);

     DataTable executeQuery(String sql, Class entityType);

    int executeUpdate(String sql);

    @SneakyThrows
    default void transInvoke(int transactionIsolation, Action fn) {
        boolean doCommit = false;
        begin(transactionIsolation);
        try {
            fn.invoke();
            doCommit = true;
        } finally {
            if (doCommit) {
                commit();
            } else {
                rollback();
            }
        }
    }

    @SneakyThrows
    default  T transInvoke(int transactionIsolation, Func fn) {
        boolean doCommit = false;
        begin(transactionIsolation);
        try {
            T r = fn.invoke();
            doCommit = true;
            return r;
        } finally {
            if (doCommit) {
                commit();
            } else {
                rollback();
            }
        }
    }

    boolean isInTransaction();

    void begin();

    void begin(int transactionIsolation);

    void commit();

    void rollback();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy