Package org.nuiton.topia.framework
Class TopiaUtil
java.lang.Object
org.nuiton.topia.framework.TopiaUtil
public class TopiaUtil
extends java.lang.Object
TODO-fdesbois-20100507 : Need javadoc + translations for existing methods.
- Version:
- $Id$
- Author:
- bpoussin <poussin@codelutin.com>, tchemit <chemit@codelutin.com>
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTopiaUtil.ConnectionProviderSupplierHibernate 4.3.x compatible Supplier<ConnectionProvider>. -
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHIBERNATE_DEFAULT_SCHEMADeprecated.since 2.5.3, use now the constantTopiaContextFactory.CONFIG_DEFAULT_SCHEMA.static java.lang.StringTOPIA_PERSISTENCE_CLASSESDeprecated.since 2.5.3, use the already presentTopiaContextImpl.TOPIA_PERSISTENCE_CLASSES. -
Constructor Summary
Constructors Constructor Description TopiaUtil() -
Method Summary
Modifier and Type Method Description static <S extends org.hibernate.service.Service>
SgetHibernateService(org.hibernate.SessionFactory sessionFactory, java.lang.Class<S> serviceClass)Method to get an Hibernate service instance from a given Hibernate SessionFactory NB: This method is static to make sure it does not depend on the current instancestatic java.util.PropertiesgetProperties(java.lang.String pathOrUrl)Permet de récupérer le fichier de propriété ayant le nom passé en argument.static java.util.PropertiesgetProperties(java.util.Properties parent, java.lang.String pathOrUrl)Permet de récupérer le fichier de propriété ayant le nom passé en argument.static java.lang.StringgetSchemaName(TopiaContext tx)Return hibernate schema nameprotected static org.hibernate.service.spi.SessionFactoryServiceRegistrygetSessionFactoryServiceRegistry(org.hibernate.SessionFactory sessionFactory)Method to extract from the given Hibernate SessionFactory a working instance of SessionFactoryServiceRegistry IMPORTANT : If possible, prefer using this method instead ofgetStandardServiceRegistry(org.hibernate.SessionFactory)because the SessionFactoryServiceRegistry is a child of the StandardServiceRegistry NB: This method is static to make sure it does not depend on the current instanceprotected static org.hibernate.boot.registry.StandardServiceRegistrygetStandardServiceRegistry(org.hibernate.SessionFactory sessionFactory)Method to extract from the given Hibernate SessionFactory a working instance of StandardServiceRegistry IMPORTANT : As much as possible, prefer using thegetSessionFactoryServiceRegistry(org.hibernate.SessionFactory)mthod instead of the current one because the SessionFactoryServiceRegistry is a child of the StandardServiceRegistry NB: This method is static to make sure it does not depend on the current instancestatic java.lang.StringgetTopiaIdPattern(java.lang.Class<? extends TopiaEntity> klass)Compute the pattern to be used to capture a topia id for a given entity class.static java.util.regex.PatterngetTopiaPattern(java.lang.String format, java.lang.Class<? extends TopiaEntity>... classes)Compute a regex pattern given a format string.static booleanisSchemaEmpty(TopiaContext tx)Test if the db associated to the givenconfigurationcontaisn any of the dealed entities.static booleanisSchemaExist(TopiaContext tx, java.lang.String entityName)Test si une entite donnee correspondant a une configuration existe en base.static booleanisSchemaExist(TopiaContext tx, org.hibernate.boot.Metadata metadata, java.lang.String entityName)Test si une entite donnee correspondant a une configuration existe en base.
-
Field Details
-
HIBERNATE_DEFAULT_SCHEMA
@Deprecated public static final java.lang.String HIBERNATE_DEFAULT_SCHEMADeprecated.since 2.5.3, use now the constantTopiaContextFactory.CONFIG_DEFAULT_SCHEMA.- See Also:
- Constant Field Values
-
TOPIA_PERSISTENCE_CLASSES
@Deprecated public static final java.lang.String TOPIA_PERSISTENCE_CLASSESDeprecated.since 2.5.3, use the already presentTopiaContextImpl.TOPIA_PERSISTENCE_CLASSES.- See Also:
- Constant Field Values
-
-
Constructor Details
-
TopiaUtil
public TopiaUtil()
-
-
Method Details
-
getProperties
public static java.util.Properties getProperties(java.lang.String pathOrUrl) throws TopiaNotFoundExceptionPermet 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 java.util.Properties getProperties(java.util.Properties parent, java.lang.String pathOrUrl) throws TopiaNotFoundExceptionPermet 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
public static java.util.regex.Pattern getTopiaPattern(java.lang.String format, java.lang.Class<? extends TopiaEntity>... classes)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
public static boolean isSchemaExist(TopiaContext tx, org.hibernate.boot.Metadata metadata, java.lang.String entityName)Test si une entite donnee correspondant a une configuration existe en base.- Parameters:
tx- la session topiametadata- mapping des entitésentityName- le nom de l'entite a tester- Returns:
truesi le schema de la table existe- Since:
- 2.6.4
-
isSchemaExist
Test si une entite donnee correspondant a une configuration existe en base.- Parameters:
tx- le context hibernateentityName- le nom de l'entite a tester- Returns:
truesi le schema de la table existe
-
isSchemaEmpty
Test if the db associated to the givenconfigurationcontaisn any of the dealed entities.- Parameters:
tx- topia context- Returns:
trueif there is no schema for any of the dealed entities,falseotherwise.- Since:
- 2.5.3
-
getStandardServiceRegistry
protected static org.hibernate.boot.registry.StandardServiceRegistry getStandardServiceRegistry(org.hibernate.SessionFactory sessionFactory)Method to extract from the given Hibernate SessionFactory a working instance of StandardServiceRegistry IMPORTANT : As much as possible, prefer using thegetSessionFactoryServiceRegistry(org.hibernate.SessionFactory)mthod instead of the current one because the SessionFactoryServiceRegistry is a child of the StandardServiceRegistry NB: This method is static to make sure it does not depend on the current instance- Parameters:
sessionFactory- the Hibernate's SessionFactory instance- Returns:
- the StandardServiceRegistry instance used by the given SessionFactory
-
getSessionFactoryServiceRegistry
protected static org.hibernate.service.spi.SessionFactoryServiceRegistry getSessionFactoryServiceRegistry(org.hibernate.SessionFactory sessionFactory)Method to extract from the given Hibernate SessionFactory a working instance of SessionFactoryServiceRegistry IMPORTANT : If possible, prefer using this method instead ofgetStandardServiceRegistry(org.hibernate.SessionFactory)because the SessionFactoryServiceRegistry is a child of the StandardServiceRegistry NB: This method is static to make sure it does not depend on the current instance- Parameters:
sessionFactory- the Hibernate's SessionFactory instance- Returns:
- the SessionFactoryServiceRegistry instance used by the given SessionFactory
-
getHibernateService
public static <S extends org.hibernate.service.Service> S getHibernateService(org.hibernate.SessionFactory sessionFactory, java.lang.Class<S> serviceClass)Method to get an Hibernate service instance from a given Hibernate SessionFactory NB: This method is static to make sure it does not depend on the current instance- Parameters:
sessionFactory- the Hibernate's SessionFactory instanceserviceClass- the expected service class- Returns:
- the found service instance
- Throws:
org.hibernate.service.UnknownServiceException- Indicates the service was not known.- See Also:
ServiceRegistry.getService(Class)
-
getSchemaName
Return hibernate schema name- Parameters:
tx- topia context- Returns:
- schema name
-