Package org.nuiton.topia.framework
Class TopiaUtil
java.lang.Object
org.nuiton.topia.framework.TopiaUtil
TODO-fdesbois-20100507 : Need javadoc + translations for existing methods.
- Version:
- $Id$
- Author:
- bpoussin <poussin@codelutin.com>, tchemit <chemit@codelutin.com>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHibernate 4.3.x compatible Supplier<ConnectionProvider>. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.static final StringDeprecated.since 2.5.3, use the already presentTopiaContextImpl.TOPIA_PERSISTENCE_CLASSES. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends org.hibernate.service.Service>
SgetHibernateService(org.hibernate.SessionFactory sessionFactory, 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 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 StringReturn 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 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 booleanTest if the db associated to the givenconfigurationcontaisn any of the dealed entities.static booleanisSchemaExist(TopiaContext tx, String entityName) Test si une entite donnee correspondant a une configuration existe en base.static booleanisSchemaExist(TopiaContext tx, org.hibernate.boot.Metadata metadata, String entityName) Test si une entite donnee correspondant a une configuration existe en base.
-
Field Details
-
HIBERNATE_DEFAULT_SCHEMA
Deprecated.since 2.5.3, use now the constantTopiaContextFactory.CONFIG_DEFAULT_SCHEMA.- See Also:
-
TOPIA_PERSISTENCE_CLASSES
Deprecated.since 2.5.3, use the already presentTopiaContextImpl.TOPIA_PERSISTENCE_CLASSES.- See Also:
-
-
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
public static boolean isSchemaExist(TopiaContext tx, org.hibernate.boot.Metadata metadata, 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, 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
-
TopiaContextFactory.CONFIG_DEFAULT_SCHEMA.