public class DbSqlBuilder extends TemplateData implements DbSqlGenerator
Query is built by appending 'chunks' - parts of the query. These chunks may be very simple, as a simple string. However, the main reason of existence of this class are chunks that auto-generate part of the query based on provided domain object. They can be used to easily create some most common queries in an efficient way.
Although it is not necessary, use of DbId
annotation boost the functionality
of this query builder.
Some chunks deals with relations between tables, so they must be aware of foreign key names. Here the naming convention is used, and even users might have their own foreign key naming convention.
Furthermore, if all queries are generated using just sql builder, it is possible to use dialects for various database types.
Modifier and Type | Field and Description |
---|---|
protected SqlChunk |
firstChunk |
protected java.lang.String |
generatedQuery |
protected SqlChunk |
lastChunk |
protected static jodd.db.oom.sqlgen.TemplateParser |
templateParser |
protected int |
totalChunks |
columnAliasType, columnCount, columnData, defaultColumnAliasType, entityManager, hintCount, hints, lastColumnDec, objectRefs, paramCount, parameters, tableRefs
Constructor and Description |
---|
DbSqlBuilder()
Creates new SQL builder.
|
DbSqlBuilder(DbOom dbOom) |
DbSqlBuilder(DbOom dbOom,
java.lang.String template) |
DbSqlBuilder(java.lang.String template) |
Modifier and Type | Method and Description |
---|---|
DbSqlBuilder |
$()
Single space shortcut.
|
DbSqlBuilder |
$(SqlChunk chunk) |
DbSqlBuilder |
$(java.lang.String text)
User-friendly
append(String) . |
DbSqlBuilder |
addChunk(SqlChunk chunk)
Appends chunk to the list.
|
DbSqlBuilder |
aliasColumnsAs(ColumnAliasType aliasesType)
Specifies column alias type.
|
DbSqlBuilder |
append(java.lang.String text)
Parses provided text into the list of chunks and appends them to the list.
|
DbSqlBuilder |
appendRaw(java.lang.String text)
Simply adds text without parsing to the query.
|
DbSqlBuilder |
column(java.lang.String reference) |
DbSqlBuilder |
column(java.lang.String tableRef,
java.lang.String columnRef) |
DbSqlBuilder |
columnsAll(java.lang.String tableRef) |
DbSqlBuilder |
columnsIds(java.lang.String tableRef) |
DbSqlBuilder |
columnValue(java.lang.Object value) |
DbSqlBuilder |
columnValue(java.lang.String name,
java.lang.Object value) |
DbSqlBuilder |
columnValueRef(java.lang.String objectReference) |
java.lang.String |
generateQuery()
Generates SQL query.
|
java.util.Map<java.lang.String,ColumnData> |
getColumnData()
Returns an optional map of table and column names, used by
ResultSetMapper . |
java.lang.String[] |
getJoinHints()
Returns join hints.
|
java.util.Map<java.lang.String,ParameterValue> |
getQueryParameters()
Returns a map of SQL parameters used by generated query.
|
DbSqlBuilder |
insert(java.lang.Class entity,
java.lang.Object values) |
DbSqlBuilder |
insert(java.lang.Object values) |
DbSqlBuilder |
insert(java.lang.String entityName,
java.lang.Object values) |
DbSqlBuilder |
match(java.lang.String expression) |
DbSqlBuilder |
match(java.lang.String tableRef,
java.lang.Object value)
Creates condition part of the query only for existing columns.
|
DbSqlBuilder |
match(java.lang.String tableRef,
java.lang.String objectRef) |
DbSqlBuilder |
matchAll(java.lang.String tableRef,
java.lang.Object value)
Creates condition part of the query for all columns, including the null values.
|
DbSqlBuilder |
matchAll(java.lang.String tableRef,
java.lang.String objectRef) |
DbSqlBuilder |
matchIds(java.lang.String tableRef,
java.lang.Object value)
Creates condition part of the query for id columns
|
DbSqlBuilder |
matchIds(java.lang.String tableRef,
java.lang.String objectRef) |
ParsedSql |
parse()
Builds the query and returns parsed data.
|
DbOomQuery |
query()
Returns
DbOomQuery instance for more fluent interface. |
DbOomQuery |
query(DbSession session) |
DbSqlBuilder |
ref(java.lang.String columnRef) |
DbSqlBuilder |
ref(java.lang.String tableRef,
java.lang.String columnRef) |
DbSqlBuilder |
refId(java.lang.String tableRef) |
DbSqlBuilder |
reset()
Resets the builder (soft reset), so it can be used again.
|
DbSqlBuilder |
resetAll()
Hard reset of the builder, all configuration is reset.
|
DbSqlBuilder |
set(java.lang.String tableRef,
java.lang.Object values) |
DbSqlBuilder |
setAll(java.lang.String tableRef,
java.lang.Object values) |
static DbSqlBuilder |
sql()
Template static constructor.
|
static DbSqlBuilder |
sql(java.lang.String template)
Template static constructor.
|
DbSqlBuilder |
table(java.lang.Object entity) |
DbSqlBuilder |
table(java.lang.Object entity,
java.lang.String alias) |
DbSqlBuilder |
table(java.lang.Object entity,
java.lang.String alias,
java.lang.String tableReference) |
DbSqlBuilder |
table(java.lang.String entityName) |
DbSqlBuilder |
table(java.lang.String entityName,
java.lang.String alias) |
DbSqlBuilder |
use(java.lang.String name,
java.lang.Object value)
Defines object reference and an object.
|
DbSqlBuilder |
value(java.lang.Object value) |
DbSqlBuilder |
value(java.lang.String name,
java.lang.Object value) |
DbSqlBuilder |
valueRef(java.lang.String objectReference) |
addParameter, defineParameter, findTableDescriptorByColumnRef, getColumnAliasType, getNextParameterName, getObjectReference, getTableAlias, getTableDescriptor, hasHints, incrementHintsCount, lookupName, lookupObject, lookupTableRef, lookupType, registerColumnDataForColumnCode, registerColumnDataForTableRef, registerHint, registerTableReference, resetHard, resetSoft, setObjectReference
protected SqlChunk firstChunk
protected SqlChunk lastChunk
protected int totalChunks
protected static final jodd.db.oom.sqlgen.TemplateParser templateParser
protected java.lang.String generatedQuery
public DbSqlBuilder()
public DbSqlBuilder(java.lang.String template)
public DbSqlBuilder(DbOom dbOom)
public DbSqlBuilder(DbOom dbOom, java.lang.String template)
public static DbSqlBuilder sql()
public static DbSqlBuilder sql(java.lang.String template)
public DbSqlBuilder reset()
TemplateData.resetSoft()
public DbSqlBuilder resetAll()
TemplateData.resetHard()
public ParsedSql parse()
public DbSqlBuilder aliasColumnsAs(ColumnAliasType aliasesType)
null
when column aliases are not used.public DbSqlBuilder use(java.lang.String name, java.lang.Object value)
public DbSqlBuilder addChunk(SqlChunk chunk)
public DbSqlBuilder append(java.lang.String text)
public DbSqlBuilder appendRaw(java.lang.String text)
public DbSqlBuilder $(java.lang.String text)
append(String)
.public DbSqlBuilder $()
public DbSqlBuilder $(SqlChunk chunk)
public java.lang.String generateQuery()
generateQuery
in interface DbSqlGenerator
public java.util.Map<java.lang.String,ColumnData> getColumnData()
ResultSetMapper
.
May be null
.getColumnData
in interface DbSqlGenerator
public java.util.Map<java.lang.String,ParameterValue> getQueryParameters()
DbSqlGenerator
DbSqlGenerator.generateQuery()
.
May be null
getQueryParameters
in interface DbSqlGenerator
public java.lang.String[] getJoinHints()
null
.getJoinHints
in interface DbSqlGenerator
public DbSqlBuilder table(java.lang.String entityName)
public DbSqlBuilder table(java.lang.String entityName, java.lang.String alias)
public DbSqlBuilder table(java.lang.Object entity, java.lang.String alias)
public DbSqlBuilder table(java.lang.Object entity, java.lang.String alias, java.lang.String tableReference)
public DbSqlBuilder table(java.lang.Object entity)
public DbSqlBuilder column(java.lang.String reference)
public DbSqlBuilder column(java.lang.String tableRef, java.lang.String columnRef)
public DbSqlBuilder columnsAll(java.lang.String tableRef)
public DbSqlBuilder columnsIds(java.lang.String tableRef)
public DbSqlBuilder ref(java.lang.String columnRef)
public DbSqlBuilder ref(java.lang.String tableRef, java.lang.String columnRef)
public DbSqlBuilder refId(java.lang.String tableRef)
public DbSqlBuilder match(java.lang.String tableRef, java.lang.Object value)
public DbSqlBuilder match(java.lang.String tableRef, java.lang.String objectRef)
public DbSqlBuilder matchIds(java.lang.String tableRef, java.lang.Object value)
public DbSqlBuilder matchIds(java.lang.String tableRef, java.lang.String objectRef)
public DbSqlBuilder matchAll(java.lang.String tableRef, java.lang.Object value)
public DbSqlBuilder matchAll(java.lang.String tableRef, java.lang.String objectRef)
public DbSqlBuilder match(java.lang.String expression)
public DbSqlBuilder value(java.lang.String name, java.lang.Object value)
public DbSqlBuilder value(java.lang.Object value)
public DbSqlBuilder valueRef(java.lang.String objectReference)
public DbSqlBuilder columnValue(java.lang.String name, java.lang.Object value)
public DbSqlBuilder columnValue(java.lang.Object value)
public DbSqlBuilder columnValueRef(java.lang.String objectReference)
public DbSqlBuilder insert(java.lang.String entityName, java.lang.Object values)
public DbSqlBuilder insert(java.lang.Class entity, java.lang.Object values)
public DbSqlBuilder insert(java.lang.Object values)
public DbSqlBuilder set(java.lang.String tableRef, java.lang.Object values)
public DbSqlBuilder setAll(java.lang.String tableRef, java.lang.Object values)
public DbOomQuery query()
DbOomQuery
instance for more fluent interface.public DbOomQuery query(DbSession session)
Copyright © 2003-present Jodd Team