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

com.github.chengyuxing.sql.Baki Maven / Gradle / Ivy

Go to download

Light wrapper of JDBC, support ddl, dml, query, plsql/procedure/function, transaction and manage sql file.

There is a newer version: 9.0.2
Show newest version
package com.github.chengyuxing.sql;

import com.github.chengyuxing.sql.support.executor.EntitySaveExecutor;
import com.github.chengyuxing.sql.support.executor.Executor;
import com.github.chengyuxing.sql.support.executor.QueryExecutor;
import com.github.chengyuxing.sql.support.executor.SaveExecutor;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.util.function.Function;

/**
 * Basic database access interface
 * work perfectly with Rabbit-SQL IDEA Plugin.
 */
public interface Baki {
    /**
     * Query executor.
     *
     * @param sql sql statement or sql name
     * @return Query executor
     */
    QueryExecutor query(String sql);

    /**
     * Update executor.
     * 

Generate update statement by 1st row of data, e.g.

*

args:

*
*
{id:14, name:'cyx', address:'kunming'}, {...}, ...
     *  
*

where condition:

*
*
id = :id
*
*

generated update statement:

*
*
update [table] set
     * name = :name,
     * address = :address
     * where id = :id
*
* Notice: where condition must contain at least 1 named parameter and args must contain its value. * * @param tableName table name * @param where condition * @param entity type * @return Update executor */ SaveExecutor update(String tableName, String where); /** * Insert executor. * * @param tableName table name * @param entity type * @return Insert executor */ SaveExecutor insert(String tableName); /** * Delete executor. *

Methods {@link SaveExecutor#safe() safe(boolean?)} and {@link SaveExecutor#ignoreNull() ignoreNull(boolean?)} * were not implements, ignore please.

* * @param tableName table name * @param where condition * @param entity type * @return Delete executor */ SaveExecutor delete(String tableName, String where); /** * Entity executor. *

{@link com.github.chengyuxing.common.anno.Alias @Alias} is optional, use {@link com.github.chengyuxing.common.anno.Alias @Alias} if:

*
    *
  • table name not equals entity class name.
  • *
  • column name not equals entity field name.
  • *
*
     *     {@code @}Alias("test.user") // table name 'test.user'
     *     public class User{
     *        {@code @}Alias("name") // column name 'name'
     *        private String userName;
     *        private Integer age;  // column name 'age'
     *
     *        // getter...
     *        // setter...
     *     }
     * 
* * @param entity type * @param entityClass entity class * @return Entity Save Executor * @see com.github.chengyuxing.common.anno.Alias @Alias */ EntitySaveExecutor entity(Class entityClass); /** * Basic Executor. * * @param sql Support:
    *
  • ddl
  • *
  • dml
  • *
  • query
  • *
  • function/procedure
  • *
  • plsql
  • *
* @return Basic executor */ Executor of(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 */ String databaseId(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy