2017-05-27 23:54:22 -04:00
|
|
|
package com.moparisthebest.jdbc.codegen;
|
|
|
|
|
|
|
|
import java.io.Closeable;
|
|
|
|
import java.lang.annotation.ElementType;
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
import java.lang.annotation.Target;
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mopar on 5/24/17.
|
|
|
|
*/
|
|
|
|
public interface JdbcMapper extends Closeable {
|
|
|
|
|
|
|
|
Connection getConnection();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void close();
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
@Target({ElementType.TYPE})
|
|
|
|
public @interface Mapper {
|
|
|
|
/**
|
|
|
|
* The jndi name of the DataSource. This is a required element for this annotation.
|
|
|
|
*/
|
|
|
|
String jndiName() default "";
|
|
|
|
|
2017-05-28 23:38:10 -04:00
|
|
|
/**
|
|
|
|
* This defaults to true if a close() method exists to override/implement, false otherwise
|
|
|
|
*/
|
|
|
|
OptionalBool cachePreparedStatements() default OptionalBool.DEFAULT;
|
2017-05-27 23:54:22 -04:00
|
|
|
|
2017-05-28 23:38:10 -04:00
|
|
|
/**
|
|
|
|
* This defaults to SimpleSQLParser, PrestoSQLParser is another option for Java 8, or implement your own
|
|
|
|
* @return
|
|
|
|
*/
|
2017-05-28 18:01:00 -04:00
|
|
|
Class<? extends SQLParser> sqlParser() default SQLParser.class;
|
2017-06-02 00:39:03 -04:00
|
|
|
|
2017-06-19 00:34:23 -04:00
|
|
|
/**
|
|
|
|
* This defaults to false
|
|
|
|
*/
|
|
|
|
OptionalBool allowReflection() default OptionalBool.DEFAULT;
|
|
|
|
|
2017-06-02 00:39:03 -04:00
|
|
|
/**
|
|
|
|
* This defaults to SimpleSQLParser, PrestoSQLParser is another option for Java 8, or implement your own
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
DatabaseType databaseType() default DatabaseType.DEFAULT;
|
|
|
|
String arrayNumberTypeName() default "";
|
|
|
|
String arrayStringTypeName() default "";
|
2017-05-27 23:54:22 -04:00
|
|
|
}
|
|
|
|
|
2017-08-07 15:26:52 -04:00
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
@Target({ElementType.METHOD})
|
|
|
|
/**
|
|
|
|
* Instead of a compile-time error this will only warn on unused params, mainly for debugging or presenting an unfinished API
|
|
|
|
*/
|
|
|
|
public @interface WarnOnUnusedParams {}
|
|
|
|
|
2017-11-29 23:51:27 -05:00
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
@Target({ElementType.METHOD})
|
|
|
|
/**
|
|
|
|
* Run this method in a transaction, useless on @SQL methods because they only run single statements, helpful on default or abstract methods that chain calls
|
|
|
|
*/
|
|
|
|
public @interface RunInTransaction {}
|
|
|
|
|
2017-05-27 23:54:22 -04:00
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
@Target({ElementType.METHOD})
|
|
|
|
public @interface SQL {
|
|
|
|
/**
|
|
|
|
* The SQL statement to send to the database. Required annotation element.
|
|
|
|
*/
|
|
|
|
String value();
|
|
|
|
|
2017-08-04 13:55:05 -04:00
|
|
|
/**
|
|
|
|
* This avoids parsing SQL for select statements by specifying column names directly, implies SELECT statement, ie isSelect = true
|
|
|
|
*/
|
|
|
|
String[] columnNames() default {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This avoids parsing SQL for non-select statements, set to false if executeUpdate should be ran instead of selection
|
|
|
|
*/
|
|
|
|
boolean isSelect() default true;
|
|
|
|
|
2017-05-28 23:38:10 -04:00
|
|
|
/**
|
|
|
|
* This defaults to the value of the class-level @JdbcMapper.Mapper.cachePreparedStatements annotation, but can be configured on a per-method level here
|
|
|
|
*/
|
|
|
|
OptionalBool cachePreparedStatement() default OptionalBool.DEFAULT;
|
2017-05-27 23:54:22 -04:00
|
|
|
|
2017-06-19 00:34:23 -04:00
|
|
|
/**
|
|
|
|
* This defaults to the value of the class-level @JdbcMapper.Mapper.allowReflection annotation, but can be configured on a per-method level here
|
|
|
|
*/
|
|
|
|
OptionalBool allowReflection() default OptionalBool.DEFAULT;
|
|
|
|
|
2017-05-27 23:54:22 -04:00
|
|
|
/**
|
2017-06-08 00:09:00 -04:00
|
|
|
* Maximum rows returned in collections/maps/arrays/etc, < 1 mean no limit
|
|
|
|
*
|
|
|
|
* Use with care because you normally do not want truncated query results
|
|
|
|
*
|
|
|
|
* Can also send in dynamically to function as a primitive integer (long/int/short/byte) named one of the options
|
|
|
|
* in JdbcMapper.allowedMaxRowParamNames (default one of maxRows,rowLimit,arrayMaxLength if not set)
|
2017-05-27 23:54:22 -04:00
|
|
|
*/
|
2017-06-08 00:09:00 -04:00
|
|
|
long maxRows() default -1;
|
2017-05-27 23:54:22 -04:00
|
|
|
}
|
|
|
|
|
2017-10-23 00:34:37 -04:00
|
|
|
/**
|
|
|
|
* Equivalent to QueryMapper.toObject for arrays, and .toSingleMap for maps
|
|
|
|
*/
|
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
@Target({ElementType.METHOD})
|
|
|
|
public @interface SingleRow {}
|
|
|
|
|
2017-05-27 23:54:22 -04:00
|
|
|
public enum OptionalBool {
|
2017-05-28 23:38:10 -04:00
|
|
|
DEFAULT,
|
2017-05-27 23:54:22 -04:00
|
|
|
TRUE,
|
|
|
|
FALSE;
|
|
|
|
|
2017-05-28 23:38:10 -04:00
|
|
|
public boolean combine(final boolean def) {
|
2017-05-27 23:54:22 -04:00
|
|
|
switch (this) {
|
|
|
|
case TRUE:
|
|
|
|
return true;
|
|
|
|
case FALSE:
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-28 23:38:10 -04:00
|
|
|
return def;
|
2017-05-27 23:54:22 -04:00
|
|
|
}
|
|
|
|
}
|
2017-06-02 00:39:03 -04:00
|
|
|
|
|
|
|
public enum DatabaseType {
|
|
|
|
DEFAULT(null, null),
|
2018-05-22 00:08:14 -04:00
|
|
|
BIND(null, null),
|
2018-05-22 00:11:54 -04:00
|
|
|
ANY("NUMERIC", "TEXT"),
|
2018-05-20 12:51:37 -04:00
|
|
|
UNNEST("NUMERIC", "VARCHAR"),
|
2018-05-22 00:08:14 -04:00
|
|
|
ORACLE("ARRAY_NUM_TYPE", "ARRAY_STR_TYPE"),
|
|
|
|
;
|
2017-06-02 00:39:03 -04:00
|
|
|
|
|
|
|
public final String arrayNumberTypeName, arrayStringTypeName;
|
|
|
|
|
|
|
|
private DatabaseType(final String arrayNumberTypeName, final String arrayStringTypeName) {
|
|
|
|
this.arrayNumberTypeName = arrayNumberTypeName;
|
|
|
|
this.arrayStringTypeName = arrayStringTypeName;
|
|
|
|
}
|
|
|
|
}
|
2017-05-27 23:54:22 -04:00
|
|
|
}
|