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

org.babyfish.jimmer.sql.cache.CacheEnvironment Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.cache;

import org.babyfish.jimmer.sql.JSqlClient;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.sql.Connection;
import java.util.Objects;

public class CacheEnvironment {

    private final JSqlClient sqlClient;

    private final Connection connection;

    private final CacheLoader loader;

    public CacheEnvironment(
            JSqlClient sqlClient,
            Connection connection,
            CacheLoader loader,
            boolean requiresNewDraftContext) {
        this.sqlClient = Objects.requireNonNull(sqlClient, "sqlClient cannot be null");
        this.connection = Objects.requireNonNull(connection, "connection cannot be null");
        this.loader = CacheLoaderWrapper.wrap(
                Objects.requireNonNull(loader, "loader cannot be null"),
                requiresNewDraftContext
        );
    }

    @NotNull
    public JSqlClient getSqlClient() {
        return sqlClient;
    }

    @NotNull
    public Connection getConnection() {
        return connection;
    }

    @NotNull
    public CacheLoader getLoader() {
        return loader;
    }

    @Override
    public int hashCode() {
        return Objects.hash(sqlClient, connection, loader);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CacheEnvironment that = (CacheEnvironment) o;
        return sqlClient.equals(that.sqlClient) &&
                connection.equals(that.connection) &&
                Objects.equals(loader, that.loader);
    }

    @Override
    public String toString() {
        return "CacheEnvironment{" +
                "sqlClient=" + sqlClient +
                ", connection=" + connection +
                ", loader=" + loader +
                '}';
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy