public class GeneratorContext extends Object
EntitySqlGenerators.| Modifier and Type | Field and Description |
|---|---|
static String |
DIALECT_KEY
The settings key for the target SQL dialect.
|
static String |
NULL_VALUES_KEY
The settings key for
writeNullValues. |
static String |
PERSISTENCE_FILE_KEY
The settings key for the path to the persistence.xml, either relative to the current directory or absolute.
|
static String |
PERSISTENCE_UNIT_KEY
The settings key for the name of the persistence unit in the persistence.xml.
|
static String |
PREFER_SEQUENCE_CURRENT_VALUE
The settings key for
preferSequenceCurentValue. |
static String |
PROVIDER_KEY
The settings key for the JPA provider.
|
static String |
RELATIVE_IDS_KEY
The settings key for
writeRelativeIds. |
static String |
UNIQUE_PROPERTIES_MAX_KEY
The settings key for the
maxUniqueProperties. |
static String |
UNIQUE_PROPERTIES_QUALITY_KEY
The settings key for the
uniquePropertyQuality. |
| Constructor and Description |
|---|
GeneratorContext()
Creates a default generator context.
|
GeneratorContext(GeneratorDialect dialect)
Creates a generator context for a dialect.
|
GeneratorContext(Properties settings)
Creates a new instance of
GeneratorContext. |
| Modifier and Type | Method and Description |
|---|---|
void |
addContextModelListener(ContextModelListener listener)
Adds a new listener to this context.
|
protected <T> void |
fireContextObjectAdded(BiConsumer<ContextModelListener,T> listenerFunction,
T contextObject)
Fires an event to all
listeners. |
List<ContextModelListener> |
getContextModelListeners()
All listeners of this context.
|
<E> EntityClass<E> |
getDescription(Class<E> entityClass)
Finds the description for a class.
|
<E> EntityClass<E> |
getDescription(E entity)
Finds the description for the class of an entity.
|
Map<Class<?>,EntityClass<?>> |
getDescriptions()
Contains the extracted metadata to every known class of an
Entity. |
GeneratorDialect |
getDialect()
Identifies the SQL dialect for generating SQL statements.
|
IdGenerator |
getGenerator(javax.persistence.GeneratedValue generatedValue,
GeneratorTable table,
GeneratorColumn column)
Finds the correct generator for the given annotation.
|
int |
getMaxUniqueProperties()
The maximum count of columns that are used when referencing an entity using it's unique properties.
|
JpaProvider |
getProvider()
Identifies the JPA provider to indicate implementation specific details.
|
Properties |
getSettings()
Contains the settings that were given during creation, resp. as read from the persistence configuration.
|
Map<String,Map<Object,GenerationState>> |
getStates()
Contains the state of single entities, maps from an entity name to the mapping of an id to its state.
|
Map<String,GeneratorTable> |
getTables()
Mapping from the names of all known database table to their description (including column information).
|
UniquePropertyQuality |
getUniquePropertyQuality()
Indicates what kind of properties are used for referencing an entity with its unique properties.
|
boolean |
isPreferSequenceCurentValue()
Indiciates to use "currval" of a sequence if the referenced entity is the last created entity for that sequence
before checking for
unique properties. |
boolean |
isWriteNullValues()
Indicates to include null values in statements.
|
boolean |
isWriteRelativeIds()
Indicates that we write into a schema that is not empty.
|
void |
registerGenerators(AnnotatedElement element,
GeneratorTable table)
Registers the
TableGenerator and SequenceGenerator declared at the given element. |
void |
removeContextModelListener(ContextModelListener listener)
Removes a listener from this context.
|
GeneratorTable |
resolveTable(String tableName)
Finds resp. builds the metadata to the given table.
|
void |
setContextModelListeners(List<ContextModelListener> contextModelListeners)
All listeners of this context.
|
void |
setDefaultSequenceGenerator(SequenceIdGenerator defaultSequenceGenerator)
The default sequence generator, if none is explicitly specified in a
GeneratedValue. |
void |
setDefaultTableGenerator(TableIdGenerator defaultTableGenerator)
The default table generator, if none is explicitly specified in a
GeneratedValue. |
void |
setDialect(GeneratorDialect dialect)
Identifies the SQL dialect for generating SQL statements.
|
void |
setMaxUniqueProperties(int maxUniqueProperties)
The maximum count of columns that are used when referencing an entity using it's unique properties.
|
void |
setPreferSequenceCurentValue(boolean preferSequenceCurentValue)
Indiciates to use "currval" of a sequence if the referenced entity is the last created entity for that sequence
before checking for
unique properties. |
void |
setProvider(JpaProvider provider)
Identifies the JPA provider to indicate implementation specific details.
|
void |
setUniquePropertyQuality(UniquePropertyQuality uniquePropertyQuality)
Indicates what kind of properties are used for referencing an entity with its unique properties.
|
void |
setWriteNullValues(boolean writeNullValues)
Indicates to include null values in statements.
|
void |
setWriteRelativeIds(boolean writeRelativeIds)
Indicates that we write into a schema that is not empty.
|
void |
writeAlignmentStatements(StatementsWriter writer)
Builds all statements that are necessary to align ID generators in the database with the current IDs.
|
public static final String PROVIDER_KEY
JpaProvider or the simple name of one
of the classes from org.fastnate.generator.provider.
Defaults to HibernateProvider.public static final String PERSISTENCE_FILE_KEY
public static final String PERSISTENCE_UNIT_KEY
public static final String DIALECT_KEY
Contains either the fully qualified name of a class that extends GeneratorDialect or the simple class
name of one of the classes from org.fastnate.generator.dialect. The suffix 'Dialect' may be omitted in
that case. For example 'MySql' would map to org.fastnate.generator.dialect.MySqlDialect.
If no dialect is set explicitly then the configured persistence.xml is scanned for
a connection URL or provider specific dialect, which would be converted to our known dialects.
If nothing is found, H2 is used as default.
public static final String NULL_VALUES_KEY
writeNullValues.public static final String RELATIVE_IDS_KEY
writeRelativeIds.public static final String UNIQUE_PROPERTIES_QUALITY_KEY
uniquePropertyQuality.public static final String UNIQUE_PROPERTIES_MAX_KEY
maxUniqueProperties.public static final String PREFER_SEQUENCE_CURRENT_VALUE
preferSequenceCurentValue.public GeneratorContext()
public GeneratorContext(GeneratorDialect dialect)
dialect - the database dialect to use during generationpublic GeneratorContext(Properties settings)
GeneratorContext.settings - contains the settingspublic void addContextModelListener(ContextModelListener listener)
listener - the listener that is interested in new discovered model elementsprotected <T> void fireContextObjectAdded(BiConsumer<ContextModelListener,T> listenerFunction, T contextObject)
listeners.listenerFunction - the function that is called on the listenerscontextObject - the object to offer to the listener functionpublic <E> EntityClass<E> getDescription(Class<E> entityClass)
entityClass - the class to lookupnull if the class is not an Entitypublic <E> EntityClass<E> getDescription(E entity)
entity - the entity to lookupIllegalArgumentException - if the given object is no Entitypublic IdGenerator getGenerator(javax.persistence.GeneratedValue generatedValue, GeneratorTable table, GeneratorColumn column)
generatedValue - the annotation of the current primary keytable - the name of the current tablecolumn - the name of the current columnpublic void registerGenerators(AnnotatedElement element, GeneratorTable table)
TableGenerator and SequenceGenerator declared at the given element.
If neither annotation is present, nothing happens.element - the inspected class, method or fieldtable - the table of the current entitypublic void removeContextModelListener(ContextModelListener listener)
listener - the listener that is not interested anymorepublic GeneratorTable resolveTable(String tableName)
tableName - the name of the table from the databasepublic void writeAlignmentStatements(StatementsWriter writer) throws IOException
writer - the target of any write operationIOException - if the writer throws one@Generated(value="lombok") public GeneratorDialect getDialect()
@Generated(value="lombok") public JpaProvider getProvider()
@Generated(value="lombok") public int getMaxUniqueProperties()
@Generated(value="lombok") public UniquePropertyQuality getUniquePropertyQuality()
@Generated(value="lombok") public boolean isPreferSequenceCurentValue()
unique properties.@Generated(value="lombok") public boolean isWriteRelativeIds()
true -
which will generate relative IDs which respect the existing IDs.@Generated(value="lombok") public boolean isWriteNullValues()
@Generated(value="lombok") public Properties getSettings()
@Generated(value="lombok") public Map<Class<?>,EntityClass<?>> getDescriptions()
Entity.@Generated(value="lombok") public Map<String,GeneratorTable> getTables()
@Generated(value="lombok") public Map<String,Map<Object,GenerationState>> getStates()
@Generated(value="lombok") public List<ContextModelListener> getContextModelListeners()
@Generated(value="lombok") public void setDialect(GeneratorDialect dialect)
@Generated(value="lombok") public void setProvider(JpaProvider provider)
@Generated(value="lombok") public void setMaxUniqueProperties(int maxUniqueProperties)
@Generated(value="lombok") public void setUniquePropertyQuality(UniquePropertyQuality uniquePropertyQuality)
@Generated(value="lombok") public void setPreferSequenceCurentValue(boolean preferSequenceCurentValue)
unique properties.@Generated(value="lombok") public void setWriteRelativeIds(boolean writeRelativeIds)
true -
which will generate relative IDs which respect the existing IDs.@Generated(value="lombok") public void setWriteNullValues(boolean writeNullValues)
@Generated(value="lombok") public void setDefaultSequenceGenerator(SequenceIdGenerator defaultSequenceGenerator)
GeneratedValue.@Generated(value="lombok") public void setDefaultTableGenerator(TableIdGenerator defaultTableGenerator)
GeneratedValue.@Generated(value="lombok") public void setContextModelListeners(List<ContextModelListener> contextModelListeners)
Copyright © 2018 fastnate.org. All rights reserved.