com.github.chengyuxing.sql.Baki Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rabbit-sql Show documentation
Show all versions of rabbit-sql Show documentation
Light wrapper of JDBC, support ddl, dml, query, plsql/procedure/function, transaction and manage sql
file.
package com.github.chengyuxing.sql;
import com.github.chengyuxing.sql.dsl.*;
import com.github.chengyuxing.sql.support.executor.Executor;
import com.github.chengyuxing.sql.support.executor.QueryExecutor;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.util.Collection;
import java.util.function.Function;
/**
* Basic database access interface
* work perfectly with Rabbit-SQL IDEA Plugin,
* Features:
*
* - Native sql execute.
* - Basic single entity CRUD depends on JPA.
* Implemented annotations: {@link javax.persistence.Entity @Entity}
* {@link javax.persistence.Table @Table}
* {@link javax.persistence.Id @Id}
* {@link javax.persistence.Column @Column}
* {@link javax.persistence.Transient @Transient}
*
*
*/
public interface Baki {
/**
* Query executor.
*
* @param sql sql statement or sql name
* @return Query executor
*/
QueryExecutor query(@NotNull String sql);
/**
* Query.
*
* @param clazz entity class
* @param entity type
* @param query builder
* @return Query instance
* @see javax.persistence.Entity @Entity
*/
@ApiStatus.AvailableSince("8.0.0")
> Query query(@NotNull Class clazz);
/**
* Insert.
*
* @param entity entity
* @param entity type
* @return affected rows
* @see javax.persistence.Entity @Entity
*/
@ApiStatus.AvailableSince("8.0.0")
int insert(@NotNull T entity);
/**
* Batch insert.
*
* @param entities entities
* @param entity type
* @return affected rows
* @see javax.persistence.Entity @Entity
*/
@ApiStatus.AvailableSince("8.0.0")
int insert(@NotNull Collection entities);
/**
* Update by {@link javax.persistence.Id id}.
*
* @param entity entity
* @param ignoreNull ignore null value or not for update sets
* @param entity type
* @return affected rows
* @see javax.persistence.Entity @Entity
*/
@ApiStatus.AvailableSince("8.0.1")
int update(@NotNull T entity, boolean ignoreNull);
/**
* Batch update by {@link javax.persistence.Id id}.
* Notice: the real update statement depends on first data,
* it means 'ignoreNull' just available on first data.
*
* @param entities entities
* @param ignoreNull ignore null value or not for update sets
* @param entity type
* @return affected rows
* @see javax.persistence.Entity @Entity
*/
@ApiStatus.AvailableSince("8.0.1")
int update(@NotNull Collection entities, boolean ignoreNull);
/**
* Delete by {@link javax.persistence.Id id}.
*
* @param entity entity
* @param entity type
* @return affected rows
* @see javax.persistence.Entity @Entity
*/
@ApiStatus.AvailableSince("8.0.1")
int delete(@NotNull T entity);
/**
* Batch delete by {@link javax.persistence.Id id}.
*
* @param entities entities
* @param entity type
* @return affected rows
* @see javax.persistence.Entity @Entity
*/
@ApiStatus.AvailableSince("8.0.1")
int delete(@NotNull Collection entities);
/**
* Basic executor.
*
* @param sql Support:
* - ddl
* - dml
* - query
* - function/procedure
* - plsql
*
* @return Basic executor
*/
Executor of(@NotNull String sql);
/**
* Get an auto-closeable connection.
*
* @param func connection -> any
* @param result type
* @return any result
*/
T using(Function func);
/**
* Get current database metadata.
* Offline(which connection was closed) database metadata, maybe proxy databaseMetadata of
* some datasource has different implementation.
*
* @return current database metadata
*/
DatabaseMetaData metaData();
/**
* Get current database name.
*
* @return database name
*/
@NotNull String databaseId();
}