org.jooq.DAO Maven / Gradle / Ivy
Show all versions of hello-world-plugin Show documentation
/*
* Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.jooq.conf.Settings;
import org.jooq.exception.DataAccessException;
/**
* A generic DAO interface for a pojo and a primary key type.
*
* This type is implemented by generated DAO classes to provide a common API for
* common actions on POJOs
*
* @author Lukas Eder
* @param The generic record type.
* @param The generic POJO type.
* @param The generic primary key type. This is a regular
* <T>
type for single-column keys, or a
* {@link Record} subtype for composite keys.
*/
public interface DAO, P, T> {
/**
* Expose the configuration in whose context this DAO
is
* operating.
*
* @return the DAO
's underlying Configuration
*/
Configuration configuration();
/**
* The settings wrapped by this context.
*
* This method is a convenient way of accessing
* configuration().settings()
.
*/
Settings settings();
/**
* The {@link SQLDialect} wrapped by this context.
*
* This method is a convenient way of accessing
* configuration().dialect()
.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
*
* This method is a convenient way of accessing
* configuration().dialect().family()
.
*/
SQLDialect family();
/**
* Expose the {@link RecordMapper} that is used internally by this
* DAO
to map from records of type R
to POJOs of
* type P
.
*
* @return the DAO
's underlying RecordMapper
*/
RecordMapper mapper();
/**
* Performs an INSERT
statement for a given POJO
*
* @param object The POJO to be inserted
* @throws DataAccessException if something went wrong executing the query
*/
void insert(P object) throws DataAccessException;
/**
* Performs a batch INSERT
statement for a given set of POJOs
*
* @param objects The POJOs to be inserted
* @throws DataAccessException if something went wrong executing the query
* @see #insert(Collection)
*/
void insert(P... objects) throws DataAccessException;
/**
* Performs a batch INSERT
statement for a given set of POJOs
*
* @param objects The POJOs to be inserted
* @throws DataAccessException if something went wrong executing the query
* @see #insert(Object...)
*/
void insert(Collection objects) throws DataAccessException;
/**
* Performs an UPDATE
statement for a given POJO
*
* @param object The POJO to be updated
* @throws DataAccessException if something went wrong executing the query
*/
void update(P object) throws DataAccessException;
/**
* Performs a batch UPDATE
statement for a given set of POJOs
*
* @param objects The POJOs to be updated
* @throws DataAccessException if something went wrong executing the query
* @see #update(Collection)
*/
void update(P... objects) throws DataAccessException;
/**
* Performs a batch UPDATE
statement for a given set of POJOs
*
* @param objects The POJOs to be updated
* @throws DataAccessException if something went wrong executing the query
* @see #update(Object...)
*/
void update(Collection
objects) throws DataAccessException;
/**
* Performs a DELETE
statement for a POJO
*
* @param object The POJO to be deleted
* @throws DataAccessException if something went wrong executing the query
* @see #delete(Collection)
*/
void delete(P object) throws DataAccessException;
/**
* Performs a DELETE
statement for a given set of POJOs
*
* @param objects The POJOs to be deleted
* @throws DataAccessException if something went wrong executing the query
* @see #delete(Collection)
*/
void delete(P... objects) throws DataAccessException;
/**
* Performs a DELETE
statement for a given set of POJOs
*
* @param objects The POJOs to be deleted
* @throws DataAccessException if something went wrong executing the query
* @see #delete(Object...)
*/
void delete(Collection
objects) throws DataAccessException;
/**
* Performs a DELETE
statement for a given set of IDs
*
* @param ids The IDs to be deleted
* @throws DataAccessException if something went wrong executing the query
* @see #delete(Collection)
*/
void deleteById(T... ids) throws DataAccessException;
/**
* Performs a DELETE
statement for a given set of IDs
*
* @param ids The IDs to be deleted
* @throws DataAccessException if something went wrong executing the query
* @see #delete(Object...)
*/
void deleteById(Collection ids) throws DataAccessException;
/**
* Checks if a given POJO exists
*
* @param object The POJO whose existence is checked
* @return Whether the POJO already exists
* @throws DataAccessException if something went wrong executing the query
*/
boolean exists(P object) throws DataAccessException;
/**
* Checks if a given ID exists
*
* @param id The ID whose existence is checked
* @return Whether the ID already exists
* @throws DataAccessException if something went wrong executing the query
*/
boolean existsById(T id) throws DataAccessException;
/**
* Count all records of the underlying table.
*
* @return The number of records of the underlying table
* @throws DataAccessException if something went wrong executing the query
*/
long count() throws DataAccessException;
/**
* Find all records of the underlying table.
*
* @return All records of the underlying table
* @throws DataAccessException if something went wrong executing the query
*/
List findAll() throws DataAccessException;
/**
* Find a record of the underlying table by ID.
*
* @param id The ID of a record in the underlying table
* @return A record of the underlying table given its ID, or
* null
if no record was found.
* @throws DataAccessException if something went wrong executing the query
*/
P findById(T id) throws DataAccessException;
/**
* Find records by a given field and a set of values.
*
* @param field The field to compare values against
* @param values The accepted values
* @return A list of records fulfilling field IN (values)
* @throws DataAccessException if something went wrong executing the query
*/
List fetch(Field field, Z... values) throws DataAccessException;
/**
* Find a unique record by a given field and a value.
*
* @param field The field to compare value against
* @param value The accepted value
* @return A record fulfilling field = value
, or
* null
* @throws DataAccessException This exception is thrown
*
* - if something went wrong executing the query
* - if the query returned more than one value
*
*/
P fetchOne(Field field, Z value) throws DataAccessException;
/**
* Find a unique record by a given field and a value.
*
* @param field The field to compare value against
* @param value The accepted value
* @return A record fulfilling field = value
* @throws DataAccessException This exception is thrown
*
* - if something went wrong executing the query
* - if the query returned more than one value
*
*/
Optional fetchOptional(Field field, Z value) throws DataAccessException;
/**
* Get the underlying table
*/
Table getTable();
/**
* Get the underlying POJO type
*/
Class getType();
}