public class EntitySqlGenerator extends Object implements Closeable
GeneratorDialect.| Modifier and Type | Field and Description |
|---|---|
private GeneratorContext |
context
Used to keep the state of indices and to store any configuration.
|
private StatementsWriter |
writer
The target of any generated SQL statement, e.g. a file or database.
|
| Constructor and Description |
|---|
EntitySqlGenerator(GeneratorContext context,
Connection connection)
Creates a new instance for a database connection.
|
EntitySqlGenerator(GeneratorContext context,
StatementsWriter writer) |
EntitySqlGenerator(GeneratorContext context,
Writer writer)
Creates a new instance for a output writer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Writes any missing SQL and closes any open resources.
|
protected <E> boolean |
findEntity(E entity)
Tries to find an entity in an online store.
|
void |
flush()
Writes any open and alignment statements.
|
GeneratorContext |
getContext()
Used to keep the state of indices and to store any configuration.
|
StatementsWriter |
getWriter()
The target of any generated SQL statement, e.g. a file or database.
|
private static <E> boolean |
isPostponedInsert(List<Object> postInsertEntities,
E entity) |
<E> void |
markExistingEntities(Iterable<E> entities)
Marks a set of entity references, where we don't know the ID in the database.
|
<E> void |
markExistingEntity(E entity,
Number id)
Marks an entity reference, where we know the ID in the database.
|
<E> void |
write(E entity)
Creates the Import-SQL for an entity.
|
private <E> void |
write(E entity,
List<Object> postponedEntities)
Creates the Import-SQL for an entity.
|
<E> void |
write(Iterable<? extends E> entities)
Creates the SQL for the given entities.
|
void |
writeAlignmentStatements()
Writes all statements that are necessary to align ID generators in the database with the current IDs.
|
void |
writeComment(String comment)
Writes a SQL comment to the target writer.
|
private <E> void |
writeInserts(E entity,
List<Object> postponedEntities,
EntityClass<E> classDescription,
ColumnExpression discriminator) |
void |
writePlainStatement(String statement)
Writes a plain SQL statement to the target writer.
|
void |
writeSectionSeparator()
Writes a new line to the target to separate different sections in the SQL file.
|
private <E,T> void |
writeTableEntities(E entity,
List<Object> postponedEntities,
Collection<Property<? super E,?>> properties) |
private final GeneratorContext context
private final StatementsWriter writer
public EntitySqlGenerator(GeneratorContext context, Connection connection) throws SQLException
context - the current context that stores any indices and configurationconnection - the database connectionSQLException - if the database is not accessiblepublic EntitySqlGenerator(GeneratorContext context, Writer writer)
context - the current context that stores any indices and configurationwriter - the stream for the generated file@ConstructorProperties(value={"context","writer"}) @Generated(value="lombok") public EntitySqlGenerator(GeneratorContext context, StatementsWriter writer)
private static <E> boolean isPostponedInsert(List<Object> postInsertEntities, E entity)
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - if the target writer throws oneprotected <E> boolean findEntity(E entity)
throws IOException
entity - the entity to checktrue if the entity was found and has an id nowIOException - if something wents wrongpublic void flush()
throws IOException
IOException - if the writer throws onepublic <E> void markExistingEntities(Iterable<E> entities) throws IOException
entities - the entity to ignore during write(Object)IOException - if the writer throws onepublic <E> void markExistingEntity(E entity,
Number id)
markExistingEntities(Iterable), we know the id for the given entity.entity - the entity to ignore during write(Object)id - the id of the entity inpublic <E> void write(E entity)
throws IOException
entity - the entity to create the SQL forIOException - if the writer throws oneIllegalArgumentException - if the entity is invalidprivate <E> void write(E entity,
List<Object> postponedEntities)
throws IOException
entity - the entity to create the SQL forpostponedEntities - contains entities that will be written later and can be ignoredIOException - if the writer throws onepublic <E> void write(Iterable<? extends E> entities) throws IOException
entities - the entities for SQL creationIOException - if the writer throws onepublic void writeAlignmentStatements()
throws IOException
IOException - if the target writer throws onepublic void writeComment(String comment) throws IOException
getWriter().writeComment(comment).comment - the comment to writeIOException - if the writer throws oneprivate <E> void writeInserts(E entity,
List<Object> postponedEntities,
EntityClass<E> classDescription,
ColumnExpression discriminator)
throws IOException
IOExceptionpublic void writePlainStatement(String statement) throws IOException
getWriter().writePlainStatement(getContext().getDialect(), statement).statement - the statement to writeIOException - if the writer throws onepublic void writeSectionSeparator()
throws IOException
getWriter().writeSectionSeparator().IOException - if the writer throws such an exceptionprivate <E,T> void writeTableEntities(E entity,
List<Object> postponedEntities,
Collection<Property<? super E,?>> properties)
throws IOException
IOException@Generated(value="lombok") public GeneratorContext getContext()
@Generated(value="lombok") public StatementsWriter getWriter()
Copyright © 2022 fastnate.org. All rights reserved.