Class TopiaUtil
java.lang.Object
org.nuiton.topia.persistence.util.TopiaUtil
TODO-fdesbois-20100507 : Need javadoc + translations for existing methods.
- Author:
- Benjamin Poussin - poussin@codelutin.com, Tony Chemit - chemit@codelutin.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHibernate 4.3.x compatibleSupplier<ConnectionProvider>. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertPropertiesArrayToMap(Object... propertyNamesAndValues) convertPropertiesArrayToMap(String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues) static PropertiesgetProperties(String pathOrUrl) Permet de récupérer le fichier de propriété ayant le nom passé en argument.static PropertiesgetProperties(Properties parent, String pathOrUrl) Permet de récupérer le fichier de propriété ayant le nom passé en argument.static StringgetSchemaName(org.hibernate.cfg.Configuration config) Return hibernate schema namestatic StringgetTopiaIdPattern(Class<? extends TopiaEntity> klass) Compute the pattern to be used to capture a topia id for a given entity class.static PatterngetTopiaPattern(String format, Class<? extends TopiaEntity>... classes) Compute a regex pattern given a format string.static booleanisSchemaEmpty(org.hibernate.cfg.Configuration configuration, org.hibernate.boot.Metadata metaData) Test if the db associated to the givenconfigurationcontains any of the dealed entities.static booleanisSchemaEmpty(TopiaHibernateSupport topiaHibernateSupport) Test if the db associated to the givenconfigurationcontains any of the dealed entities.static booleanisSchemaExist(org.hibernate.cfg.Configuration configuration, org.hibernate.boot.Metadata metadata, String entityName) Test si une entite donnee correspondant a une configuration existe en base.static booleanisSchemaExist(TopiaHibernateSupport topiaHibernateSupport, String entityName) Test si une entité donnée correspondant a une configuration existe en base.static org.hibernate.SessionFactorynewSessionFactory(org.hibernate.cfg.Configuration hibernateConfiguration) Builds a new instance of Hibernate SessionFactory according to the given Hibernate Configurationstatic <V> VrunInSession(org.hibernate.cfg.Configuration configuration, com.google.common.base.Function<org.hibernate.Session, V> function) Apply the given Function in a Hibernate transaction.static voidwarnOnAutomaticSchemaOperationRisk(org.hibernate.cfg.Configuration configuration)
-
Constructor Details
-
TopiaUtil
public TopiaUtil()
-
-
Method Details
-
getProperties
Permet de récupérer le fichier de propriété ayant le nom passé en argument.- Parameters:
pathOrUrl- le nom du fichier de propriété à charger, s'il est null ou vide retourne un objet Properties vide.- Returns:
- Un nouvel objet de propriete
- Throws:
TopiaNotFoundException- Si pathOrUrl n'est pas null ou vide et que le fichier devant contenir les propriétés n'est pas retrouvé.
-
getProperties
public static Properties getProperties(Properties parent, String pathOrUrl) throws TopiaNotFoundException Permet de récupérer le fichier de propriété ayant le nom passé en argument.- Parameters:
parent- l'objet properties utilisé comme parent de l'objet retournépathOrUrl- le nom du fichier de propriété à charger, s'il est null ou vide retourne un objet Properties vide.- Returns:
- Un nouvel objet de propriete
- Throws:
TopiaNotFoundException- Si pathOrUrl n'est pas null ou vide et que le fichier devant contenir les propriétés n'est pas retrouvé.
-
getTopiaPattern
Compute a regex pattern given a format string. AString.format(String, Object...)will be apply toformat, with for parameters the list ofklasstransformed in topia pattern via methodgetTopiaIdPattern(Class)ready to be capture (enclosed by ()).- Parameters:
format- the formatclasses- the list of class to use- Returns:
- the pattern computed
-
getTopiaIdPattern
Compute the pattern to be used to capture a topia id for a given entity class.- Parameters:
klass- the entity class- Returns:
- the pattern to capture a topia id for the given entity class.
-
isSchemaExist
Test si une entité donnée correspondant a une configuration existe en base.- Parameters:
topiaHibernateSupport- the Hibernate support required for this operationentityName- le nom de l'entite a tester- Returns:
truesi le schema de la table existe- Since:
- 2.6.4
-
isSchemaExist
public static boolean isSchemaExist(org.hibernate.cfg.Configuration configuration, org.hibernate.boot.Metadata metadata, String entityName) Test si une entite donnee correspondant a une configuration existe en base.- Parameters:
configuration- la configuration hibernateentityName- le nom de l'entite a tester- Returns:
truesi le schema de la table existe
-
warnOnAutomaticSchemaOperationRisk
public static void warnOnAutomaticSchemaOperationRisk(org.hibernate.cfg.Configuration configuration) -
isSchemaEmpty
public static boolean isSchemaEmpty(org.hibernate.cfg.Configuration configuration, org.hibernate.boot.Metadata metaData) Test if the db associated to the givenconfigurationcontains any of the dealed entities.- Parameters:
configuration- hibernate db configurationmetaData- hibernate metadata- Returns:
trueif there is no schema for any of the dealed entities,falseotherwise.- Since:
- 2.5.3
-
isSchemaEmpty
Test if the db associated to the givenconfigurationcontains any of the dealed entities.- Parameters:
topiaHibernateSupport- the Hibernate support required for this operation- Returns:
trueif there is no schema for any of the dealed entities,falseotherwise.- Since:
- 2.5.3
-
getSchemaName
Return hibernate schema name- Parameters:
config- of hibernate- Returns:
- schema name
-
convertPropertiesArrayToMap
public static Map<String,Object> convertPropertiesArrayToMap(Object... propertyNamesAndValues) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
convertPropertiesArrayToMap
public static Map<String,Object> convertPropertiesArrayToMap(String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
newSessionFactory
public static org.hibernate.SessionFactory newSessionFactory(org.hibernate.cfg.Configuration hibernateConfiguration) Builds a new instance of Hibernate SessionFactory according to the given Hibernate Configuration- Parameters:
hibernateConfiguration- an initialized Hibernate Configuration- Returns:
- an instance of SessionFactory
-
runInSession
public static <V> V runInSession(org.hibernate.cfg.Configuration configuration, com.google.common.base.Function<org.hibernate.Session, V> function) Apply the given Function in a Hibernate transaction. This method will init and destroy an Hibernate SessionFactory together with a single Session. This Session will be commited if no exception is raised by the function, otherwise will rollback.- Type Parameters:
V- the return type, match the function- Parameters:
configuration- an initialized Hibernate Configurationfunction- the function to run using a valid Hibernate Session- Returns:
- the result of the given function
-