public class GeneratorContext extends Object
EntitySqlGenerators.| Modifier and Type | Class and Description |
|---|---|
private static class |
GeneratorContext.GeneratorId |
| Modifier and Type | Field and Description |
|---|---|
private List<ContextModelListener> |
contextModelListeners
All listeners of this context.
|
private SequenceIdGenerator |
defaultSequenceGenerator
The default sequence generator, if none is explicitly specified in a
GeneratedValue. |
private TableIdGenerator |
defaultTableGenerator
The default table generator, if none is explicitly specified in a
GeneratedValue. |
private Map<Class<?>,EntityClass<?>> |
descriptions
Contains the extracted metadata to every known class of an
Entity. |
private Map<String,EntityClass<?>> |
descriptionsByName
The mapping from the
name of an entity to the extracted metadata. |
private GeneratorDialect |
dialect
Identifies the SQL dialect for generating SQL statements.
|
static String |
DIALECT_KEY
The settings key for the target SQL dialect.
|
private Map<GeneratorContext.GeneratorId,IdGenerator> |
generators
Mapping from the name of a generator to the generator itself.
|
private static org.slf4j.Logger |
log |
private int |
maxUniqueProperties
The maximum count of columns that are used when referencing an entity using it's unique properties.
|
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. |
private 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. |
private JpaProvider |
provider
Identifies the JPA provider to indicate implementation specific details.
|
static String |
PROVIDER_KEY
The settings key for the JPA provider.
|
static String |
RELATIVE_IDS_KEY
The settings key for
writeRelativeIds. |
private Properties |
settings
Contains the settings that were given during creation, resp. as read from the persistence configuration.
|
private Map<String,Map<Object,GenerationState>> |
states
Contains the state of single entities, maps from an entity name to the mapping of an id to its state.
|
private Map<String,GeneratorTable> |
tables
Mapping from the names of all known database table to their description (including column information).
|
static String |
UNIQUE_PROPERTIES_MAX_KEY
The settings key for the
maxUniqueProperties. |
static String |
UNIQUE_PROPERTIES_QUALITY_KEY
The settings key for the
uniquePropertyQuality. |
private UniquePropertyQuality |
uniquePropertyQuality
Indicates what kind of properties are used for referencing an entity with its unique properties.
|
private boolean |
writeNullValues
Indicates to include null values in statements.
|
private boolean |
writeRelativeIds
Indicates that we write into a schema that is not empty.
|
| 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.
|
private <K,T> T |
addContextObject(Map<K,? super T> objects,
BiConsumer<ContextModelListener,? super T> listenerFunction,
K key,
T object) |
protected <T> void |
fireContextObjectAdded(BiConsumer<ContextModelListener,T> listenerFunction,
T contextObject)
Fires an event to all
listeners. |
List<ContextModelListener> |
getContextModelListeners()
All listeners of this context.
|
private IdGenerator |
getDefaultSequenceGenerator() |
private IdGenerator |
getDefaultTableGenerator() |
<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. |
Map<String,EntityClass<?>> |
getDescriptionsByName()
The mapping from the
name of an entity to the extracted metadata. |
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.
|
(package private) Map<Object,GenerationState> |
getStates(EntityClass<?> entityClass)
The entity states for the given entity class.
|
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.
|
private static void |
readPersistenceFile(Properties settings)
Tries to read any persistence file defined in the settings.
|
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.
|
<A extends Annotation> |
resolveTable(javax.persistence.AssociationOverride override,
A annotation,
Function<A,String> catalogName,
Function<A,String> schemaName,
Function<A,String> tableName,
String defaultTableName)
Finds resp. builds the metadata to the given table from the given (optional) annotation.
|
GeneratorTable |
resolveTable(String catalogName,
String schemaName,
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.
|
@Generated(value="lombok") private static final org.slf4j.Logger log
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.private GeneratorDialect dialect
private JpaProvider provider
private int maxUniqueProperties
private UniquePropertyQuality uniquePropertyQuality
private boolean preferSequenceCurentValue
unique properties.private boolean writeRelativeIds
true -
which will generate relative IDs which respect the existing IDs.private boolean writeNullValues
private final Properties settings
private final Map<Class<?>,EntityClass<?>> descriptions
Entity.private final Map<String,EntityClass<?>> descriptionsByName
name of an entity to the extracted metadata.private final Map<String,GeneratorTable> tables
private final Map<String,Map<Object,GenerationState>> states
private final Map<GeneratorContext.GeneratorId,IdGenerator> generators
private SequenceIdGenerator defaultSequenceGenerator
GeneratedValue.private TableIdGenerator defaultTableGenerator
GeneratedValue.private List<ContextModelListener> contextModelListeners
public GeneratorContext()
public GeneratorContext(GeneratorDialect dialect)
dialect - the database dialect to use during generationpublic GeneratorContext(Properties settings)
GeneratorContext.settings - contains the settingsprivate static void readPersistenceFile(Properties settings)
settings - the current settingspublic void addContextModelListener(ContextModelListener listener)
listener - the listener that is interested in new discovered model elementsprivate <K,T> T addContextObject(Map<K,? super T> objects, BiConsumer<ContextModelListener,? super T> listenerFunction, K key, T object)
protected <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 functionprivate IdGenerator getDefaultSequenceGenerator()
private IdGenerator getDefaultTableGenerator()
public <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 columnMap<Object,GenerationState> getStates(EntityClass<?> entityClass)
entityClass - the current entity classpublic 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 <A extends Annotation> GeneratorTable resolveTable(javax.persistence.AssociationOverride override, A annotation, Function<A,String> catalogName, Function<A,String> schemaName, Function<A,String> tableName, String defaultTableName)
override - contains the overrides for the mapping tableannotation - the optional annotation that contains any metadata to the tablecatalogName - finds the optional name of the catalog that contains the tableschemaName - finds the optional name of the schema that contains the tabletableName - finds the name of the tabledefaultTableName - the name of the talbe, if the annotation is null or contains no value for the table namepublic GeneratorTable resolveTable(String catalogName, String schemaName, String tableName)
catalogName - the optional name of the catalog that contains the tableschemaName - the optional name of the schema that contains the tabletableName - 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,EntityClass<?>> getDescriptionsByName()
name of an entity to the extracted metadata.@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 © 2022 fastnate.org. All rights reserved.