All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jwebmp.guicedpersistence.readers.hibernateproperties.HibernateEntityManagerProperties Maven / Gradle / Ivy

Go to download

Reads and Configures Hibernate Properties programmatically and replaces the values in the persistence properties.

The newest version!
package com.jwebmp.guicedpersistence.readers.hibernateproperties;

import com.jwebmp.guicedpersistence.services.IPropertiesEntityManagerReader;
import com.oracle.jaxb21.PersistenceUnit;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Assigns entity manager properties based on progammatic changes
 */
@SuppressWarnings({"unused", "WeakerAccess"})
public class HibernateEntityManagerProperties
		implements IPropertiesEntityManagerReader
{
	/**
	 * A map of properties specific to a persistence unit
	 */
	private static final Map persistenceUnitSpecificMappings = new HashMap<>();
	/**
	 * The default properties to apply
	 */
	private static final HibernateEntityManagerProperties defaultProperties = new HibernateEntityManagerProperties();

	/**
	 * Whether to set show sql true or not
	 */
	private Boolean showSql;
	/**
	 * Whether to format the output sql
	 */
	private Boolean formatSql;
	/**
	 * Whether or not to use sql comments
	 */
	private Boolean useSqlComments;

	/**
	 * Specifies the maximum fetch depth
	 * 

* default min value */ private Integer maxFetchDepth; /** * If it should be possible to lazy fetch outside of transactions, *

* default true */ private Boolean enableFetchOutsizeLadyLoad; /** * it is used to control whether we should consult the JDBC metadata to determine * certain Settings default values; it is useful to *not* do this when the database * may not be available (mainly in tools usage). */ private Boolean useJdbcMetadataDefaults; /** * Sets if lobs are non contextual */ private Boolean useLobNonContextualCreation; /** * Sometimes required to actually set it to true */ private Boolean useGetGeneratedKeys; /** * Enables hibernate versioning */ private Boolean useEnvers; /** * Performs named query startup checks */ private Boolean useQueryStartupCheck; /** * validation-mode *

* By default, Bean Validation (and Hibernate Validator) is activated. * When an entity is created, updated (and optionally deleted), it is validated before being sent to the database. * The database schema generated by Hibernate also reflects the constraints declared on the entity. */ private HibernatePersistenceValidationMode persistenceValidationMode; /** * Field useValidatorAutoRegisterListeners */ private Boolean useValidatorAutoRegisterListeners; /** * Field useValidatorApplyToDDL */ private Boolean useValidatorApplyToDDL; /** * Method getMaxFetchDepth returns the maxFetchDepth of this HibernateEntityManagerProperties object. *

* Specifies the maximum fetch depth * * @return the maxFetchDepth (type int) of this HibernateEntityManagerProperties object. */ public int getMaxFetchDepth() { return maxFetchDepth; } /** * Method setMaxFetchDepth sets the maxFetchDepth of this HibernateEntityManagerProperties object. *

* Specifies the maximum fetch depth * * @param maxFetchDepth * the maxFetchDepth of this HibernateEntityManagerProperties object. */ public void setMaxFetchDepth(Integer maxFetchDepth) { this.maxFetchDepth = maxFetchDepth; } /** * Method isEnableFetchOutsizeLadyLoad returns the enableFetchOutsizeLadyLoad of this HibernateEntityManagerProperties object. *

* If it should be possible to lazy fetch outside of transactions, * * @return the enableFetchOutsizeLadyLoad (type boolean) of this HibernateEntityManagerProperties object. */ public boolean isEnableFetchOutsizeLadyLoad() { return enableFetchOutsizeLadyLoad; } /** * Method isShowSql returns the showSql of this HibernateEntityManagerProperties object. *

* Whether to set show sql true or not * * @return the showSql (type boolean) of this HibernateEntityManagerProperties object. */ public boolean isShowSql() { return showSql; } /** * Method isFormatSql returns the formatSql of this HibernateEntityManagerProperties object. *

* Whether to format the output sql * * @return the formatSql (type boolean) of this HibernateEntityManagerProperties object. */ public boolean isFormatSql() { return formatSql; } /** * Method isUseSqlComments returns the useSqlComments of this HibernateEntityManagerProperties object. *

* Whether or not to use sql comments * * @return the useSqlComments (type boolean) of this HibernateEntityManagerProperties object. */ public boolean isUseSqlComments() { return useSqlComments; } /** * Goes through the defaults then applies per annotated unit * * @param persistenceUnit * The unit * @param incomingProperties * The properties * * @return The string,string map to apply * * @see com.jwebmp.guicedpersistence.services.IPropertiesEntityManagerReader#processProperties(PersistenceUnit, Properties) */ @Override public Map processProperties(PersistenceUnit persistenceUnit, Properties incomingProperties) { Map props = new HashMap<>(); HibernateEntityManagerProperties.getDefaultProperties() .process(persistenceUnit, incomingProperties); if (HibernateEntityManagerProperties.getPersistenceUnitSpecificMappings() .containsKey(persistenceUnit.getName())) { HibernateEntityManagerProperties.getPersistenceUnitSpecificMappings() .get(persistenceUnit.getName()) .process(persistenceUnit, incomingProperties); } return props; } /** * Method process ... * * @param persistenceUnit * of type PersistenceUnit * @param incomingProperties * of type Properties * * @return Map String , String */ public Map process(PersistenceUnit persistenceUnit, Properties incomingProperties) { if (enableFetchOutsizeLadyLoad != null) { incomingProperties.put("hibernate.enable_lazy_load_no_trans", Boolean.toString(enableFetchOutsizeLadyLoad)); } if (maxFetchDepth != null) { incomingProperties.put("hibernate.max_fetch_depth", Integer.toString(maxFetchDepth)); } if (showSql != null) { incomingProperties.put("hibernate.show_sql", Boolean.toString(showSql)); } if (formatSql != null) { incomingProperties.put("hibernate.format_sql", Boolean.toString(formatSql)); } if (useSqlComments != null) { incomingProperties.put("hibernate.use_sql_comments", Boolean.toString(useSqlComments)); } if (useJdbcMetadataDefaults != null) { incomingProperties.put("hibernate.temp.use_jdbc_metadata_defaults", Boolean.toString(useJdbcMetadataDefaults)); } if (useLobNonContextualCreation != null) { incomingProperties.put("hibernate.jdbc.lob.non_contextual_creation", Boolean.toString(useLobNonContextualCreation)); } if (useGetGeneratedKeys != null) { incomingProperties.put("hibernate.jdbc.use_get_generated_keys", Boolean.toString(useGetGeneratedKeys)); } if (useEnvers != null) { incomingProperties.put("hibernate.integration.envers.enabled", Boolean.toString(useEnvers)); } if (useQueryStartupCheck != null) { incomingProperties.put("hibernate.query.startup_check", Boolean.toString(useQueryStartupCheck)); } if (persistenceValidationMode != null) { incomingProperties.put("javax.persistence.validation.mode", persistenceValidationMode.toString()); } if (useValidatorAutoRegisterListeners != null) { incomingProperties.put("hibernate.validator.autoregister_listeners", Boolean.toString(useValidatorAutoRegisterListeners)); } if (useValidatorApplyToDDL != null) { incomingProperties.put("hibernate.validator.apply_to_ddl", Boolean.toString(useValidatorApplyToDDL)); } return new HashMap<>(); } /** * Method getDefaultProperties returns the defaultProperties of this HibernateEntityManagerProperties object. *

* The default properties to apply * * @return the defaultProperties (type HibernateEntityManagerProperties) of this HibernateEntityManagerProperties object. */ public static HibernateEntityManagerProperties getDefaultProperties() { return HibernateEntityManagerProperties.defaultProperties; } /** * Method getPersistenceUnitSpecificMappings returns the persistenceUnitSpecificMappings of this HibernateEntityManagerProperties object. *

* A map of properties specific to a persistence unit * * @return the persistenceUnitSpecificMappings (type Map String, HibernateEntityManagerProperties) of this HibernateEntityManagerProperties object. */ public static Map getPersistenceUnitSpecificMappings() { return HibernateEntityManagerProperties.persistenceUnitSpecificMappings; } /** * Sets the following properties *

* Use JDBC Metadata : false * Lob NonContextual Creation : true * Get generated keys : true * Envers : false * Query Startup Check : false * Validation Mode : None * Auto Register Listeners : false * Validator apply to ddl : false *

* Make sure on your dialect and db driver!! You have been warned.... */ public void enableQuickestBoot() { useJdbcMetadataDefaults = false; useLobNonContextualCreation = true; useGetGeneratedKeys = true; useEnvers = false; useQueryStartupCheck = false; persistenceValidationMode = HibernatePersistenceValidationMode.None; useValidatorAutoRegisterListeners = false; useValidatorApplyToDDL = false; } /** * Method getShowSql returns the showSql of this HibernateEntityManagerProperties object. *

* Whether to set show sql true or not * * @return the showSql (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getShowSql() { return showSql; } /** * Method setShowSql sets the showSql of this HibernateEntityManagerProperties object. *

* Whether to set show sql true or not * * @param showSql * the showSql of this HibernateEntityManagerProperties object. */ public void setShowSql(Boolean showSql) { this.showSql = showSql; } /** * Method getFormatSql returns the formatSql of this HibernateEntityManagerProperties object. *

* Whether to format the output sql * * @return the formatSql (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getFormatSql() { return formatSql; } /** * Method setFormatSql sets the formatSql of this HibernateEntityManagerProperties object. *

* Whether to format the output sql * * @param formatSql * the formatSql of this HibernateEntityManagerProperties object. */ public void setFormatSql(Boolean formatSql) { this.formatSql = formatSql; } /** * Method getUseSqlComments returns the useSqlComments of this HibernateEntityManagerProperties object. *

* Whether or not to use sql comments * * @return the useSqlComments (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseSqlComments() { return useSqlComments; } /** * Method setUseSqlComments sets the useSqlComments of this HibernateEntityManagerProperties object. *

* Whether or not to use sql comments * * @param useSqlComments * the useSqlComments of this HibernateEntityManagerProperties object. */ public void setUseSqlComments(Boolean useSqlComments) { this.useSqlComments = useSqlComments; } /** * Method getEnableFetchOutsizeLadyLoad returns the enableFetchOutsizeLadyLoad of this HibernateEntityManagerProperties object. *

* If it should be possible to lazy fetch outside of transactions, * * @return the enableFetchOutsizeLadyLoad (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getEnableFetchOutsizeLadyLoad() { return enableFetchOutsizeLadyLoad; } /** * Method setEnableFetchOutsizeLadyLoad sets the enableFetchOutsizeLadyLoad of this HibernateEntityManagerProperties object. *

* If it should be possible to lazy fetch outside of transactions, * * @param enableFetchOutsizeLadyLoad * the enableFetchOutsizeLadyLoad of this HibernateEntityManagerProperties object. */ public void setEnableFetchOutsizeLadyLoad(Boolean enableFetchOutsizeLadyLoad) { this.enableFetchOutsizeLadyLoad = enableFetchOutsizeLadyLoad; } /** * Method getUseJdbcMetadataDefaults returns the useJdbcMetadataDefaults of this HibernateEntityManagerProperties object. *

* it is used to control whether we should consult the JDBC metadata to determine * * @return the useJdbcMetadataDefaults (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseJdbcMetadataDefaults() { return useJdbcMetadataDefaults; } /** * Method setUseJdbcMetadataDefaults sets the useJdbcMetadataDefaults of this HibernateEntityManagerProperties object. *

* it is used to control whether we should consult the JDBC metadata to determine * * @param useJdbcMetadataDefaults * the useJdbcMetadataDefaults of this HibernateEntityManagerProperties object. */ public void setUseJdbcMetadataDefaults(Boolean useJdbcMetadataDefaults) { this.useJdbcMetadataDefaults = useJdbcMetadataDefaults; } /** * Method getUseLobNonContextualCreation returns the useLobNonContextualCreation of this HibernateEntityManagerProperties object. *

* Sets if lobs are non contextual * * @return the useLobNonContextualCreation (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseLobNonContextualCreation() { return useLobNonContextualCreation; } /** * Method setUseLobNonContextualCreation sets the useLobNonContextualCreation of this HibernateEntityManagerProperties object. *

* Sets if lobs are non contextual * * @param useLobNonContextualCreation * the useLobNonContextualCreation of this HibernateEntityManagerProperties object. */ public void setUseLobNonContextualCreation(Boolean useLobNonContextualCreation) { this.useLobNonContextualCreation = useLobNonContextualCreation; } /** * Method getUseGetGeneratedKeys returns the useGetGeneratedKeys of this HibernateEntityManagerProperties object. *

* Sometimes required to actually set it to true * * @return the useGetGeneratedKeys (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseGetGeneratedKeys() { return useGetGeneratedKeys; } /** * Method setUseGetGeneratedKeys sets the useGetGeneratedKeys of this HibernateEntityManagerProperties object. *

* Sometimes required to actually set it to true * * @param useGetGeneratedKeys * the useGetGeneratedKeys of this HibernateEntityManagerProperties object. */ public void setUseGetGeneratedKeys(Boolean useGetGeneratedKeys) { this.useGetGeneratedKeys = useGetGeneratedKeys; } /** * Method getUseEnvers returns the useEnvers of this HibernateEntityManagerProperties object. *

* Enables hibernate versioning * * @return the useEnvers (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseEnvers() { return useEnvers; } /** * Method setUseEnvers sets the useEnvers of this HibernateEntityManagerProperties object. *

* Enables hibernate versioning * * @param useEnvers * the useEnvers of this HibernateEntityManagerProperties object. */ public void setUseEnvers(Boolean useEnvers) { this.useEnvers = useEnvers; } /** * Method getUseQueryStartupCheck returns the useQueryStartupCheck of this HibernateEntityManagerProperties object. *

* Performs named query startup checks * * @return the useQueryStartupCheck (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseQueryStartupCheck() { return useQueryStartupCheck; } /** * Method setUseQueryStartupCheck sets the useQueryStartupCheck of this HibernateEntityManagerProperties object. *

* Performs named query startup checks * * @param useQueryStartupCheck * the useQueryStartupCheck of this HibernateEntityManagerProperties object. */ public void setUseQueryStartupCheck(Boolean useQueryStartupCheck) { this.useQueryStartupCheck = useQueryStartupCheck; } /** * Method getPersistenceValidationMode returns the persistenceValidationMode of this HibernateEntityManagerProperties object. *

* validation-mode * * @return the persistenceValidationMode (type HibernatePersistenceValidationMode) of this HibernateEntityManagerProperties object. */ public HibernatePersistenceValidationMode getPersistenceValidationMode() { return persistenceValidationMode; } /** * Method setPersistenceValidationMode sets the persistenceValidationMode of this HibernateEntityManagerProperties object. *

* validation-mode * * @param persistenceValidationMode * the persistenceValidationMode of this HibernateEntityManagerProperties object. */ public void setPersistenceValidationMode(HibernatePersistenceValidationMode persistenceValidationMode) { this.persistenceValidationMode = persistenceValidationMode; } /** * Method getUseValidatorAutoRegisterListeners returns the useValidatorAutoRegisterListeners of this HibernateEntityManagerProperties object. * * @return the useValidatorAutoRegisterListeners (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseValidatorAutoRegisterListeners() { return useValidatorAutoRegisterListeners; } /** * Method setUseValidatorAutoRegisterListeners sets the useValidatorAutoRegisterListeners of this HibernateEntityManagerProperties object. * * @param useValidatorAutoRegisterListeners * the useValidatorAutoRegisterListeners of this HibernateEntityManagerProperties object. */ public void setUseValidatorAutoRegisterListeners(Boolean useValidatorAutoRegisterListeners) { this.useValidatorAutoRegisterListeners = useValidatorAutoRegisterListeners; } /** * Method getUseValidatorApplyToDDL returns the useValidatorApplyToDDL of this HibernateEntityManagerProperties object. * * @return the useValidatorApplyToDDL (type Boolean) of this HibernateEntityManagerProperties object. */ public Boolean getUseValidatorApplyToDDL() { return useValidatorApplyToDDL; } /** * Method setUseValidatorApplyToDDL sets the useValidatorApplyToDDL of this HibernateEntityManagerProperties object. * * @param useValidatorApplyToDDL * the useValidatorApplyToDDL of this HibernateEntityManagerProperties object. */ public void setUseValidatorApplyToDDL(Boolean useValidatorApplyToDDL) { this.useValidatorApplyToDDL = useValidatorApplyToDDL; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy