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 class  TopiaUtil.ConnectionProviderSupplier
    Hibernate 4.3.x compatible Supplier<ConnectionProvider>.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String HIBERNATE_DEFAULT_SCHEMA
    Deprecated.
    since 2.5.3, use now the constant TopiaContextFactory.CONFIG_DEFAULT_SCHEMA.
    static java.lang.String TOPIA_PERSISTENCE_CLASSES
    Deprecated.
    since 2.5.3, use the already present TopiaContextImpl.TOPIA_PERSISTENCE_CLASSES.
  • Constructor Summary

    Constructors 
    Constructor Description
    TopiaUtil()  
  • Method Summary

    Modifier and Type Method Description
    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
    static java.util.Properties getProperties​(java.lang.String pathOrUrl)
    Permet de récupérer le fichier de propriété ayant le nom passé en argument.
    static java.util.Properties getProperties​(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.String getSchemaName​(TopiaContext tx)
    Return hibernate schema name
    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 of getStandardServiceRegistry(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
    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 the getSessionFactoryServiceRegistry(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
    static java.lang.String getTopiaIdPattern​(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.Pattern getTopiaPattern​(java.lang.String format, java.lang.Class<? extends TopiaEntity>... classes)
    Compute a regex pattern given a format string.
    static boolean isSchemaEmpty​(TopiaContext tx)
    Test if the db associated to the given configuration contaisn any of the dealed entities.
    static boolean isSchemaExist​(TopiaContext tx, java.lang.String entityName)
    Test si une entite donnee correspondant a une configuration existe en base.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • getProperties

      public static java.util.Properties getProperties​(java.lang.String pathOrUrl) throws TopiaNotFoundException
      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 java.util.Properties getProperties​(java.util.Properties parent, java.lang.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

      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. A String.format(String, Object...) will be apply to format, with for parameters the list of klass transformed in topia pattern via method getTopiaIdPattern(Class) ready to be capture (enclosed by ()).
      Parameters:
      format - the format
      classes - the list of class to use
      Returns:
      the pattern computed
    • getTopiaIdPattern

      public static java.lang.String getTopiaIdPattern​(java.lang.Class<? extends TopiaEntity> klass)
      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 topia
      metadata - mapping des entités
      entityName - le nom de l'entite a tester
      Returns:
      true si le schema de la table existe
      Since:
      2.6.4
    • isSchemaExist

      public static boolean isSchemaExist​(TopiaContext tx, java.lang.String entityName)
      Test si une entite donnee correspondant a une configuration existe en base.
      Parameters:
      tx - le context hibernate
      entityName - le nom de l'entite a tester
      Returns:
      true si le schema de la table existe
    • isSchemaEmpty

      public static boolean isSchemaEmpty​(TopiaContext tx)
      Test if the db associated to the given configuration contaisn any of the dealed entities.
      Parameters:
      tx - topia context
      Returns:
      true if there is no schema for any of the dealed entities, false otherwise.
      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 the getSessionFactoryServiceRegistry(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 of getStandardServiceRegistry(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 instance
      serviceClass - 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

      public static java.lang.String getSchemaName​(TopiaContext tx)
      Return hibernate schema name
      Parameters:
      tx - topia context
      Returns:
      schema name