Class TopiaUtil

java.lang.Object
org.nuiton.topia.framework.TopiaUtil

public class TopiaUtil extends Object
TODO-fdesbois-20100507 : Need javadoc + translations for existing methods.
Version:
$Id$
Author:
bpoussin <poussin@codelutin.com>, tchemit <chemit@codelutin.com>
  • Field Details

  • Constructor Details

    • TopiaUtil

      public TopiaUtil()
  • Method Details

    • getProperties

      public static Properties getProperties(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 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

      public static Pattern getTopiaPattern(String format, 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 String getTopiaIdPattern(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, 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, 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, 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 String getSchemaName(TopiaContext tx)
      Return hibernate schema name
      Parameters:
      tx - topia context
      Returns:
      schema name