Class TopiaUtil

java.lang.Object
org.nuiton.topia.persistence.util.TopiaUtil

public class TopiaUtil extends Object
TODO-fdesbois-20100507 : Need javadoc + translations for existing methods.
Author:
Benjamin Poussin - poussin@codelutin.com, Tony Chemit - chemit@codelutin.com
  • 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(TopiaHibernateSupport topiaHibernateSupport, String entityName)
      Test si une entité donnée correspondant a une configuration existe en base.
      Parameters:
      topiaHibernateSupport - the Hibernate support required for this operation
      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(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 hibernate
      entityName - le nom de l'entite a tester
      Returns:
      true si 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 given configuration contains any of the dealed entities.
      Parameters:
      configuration - hibernate db configuration
      metaData - hibernate metadata
      Returns:
      true if there is no schema for any of the dealed entities, false otherwise.
      Since:
      2.5.3
    • isSchemaEmpty

      public static boolean isSchemaEmpty(TopiaHibernateSupport topiaHibernateSupport)
      Test if the db associated to the given configuration contains any of the dealed entities.
      Parameters:
      topiaHibernateSupport - the Hibernate support required for this operation
      Returns:
      true if there is no schema for any of the dealed entities, false otherwise.
      Since:
      2.5.3
    • getSchemaName

      public static String getSchemaName(org.hibernate.cfg.Configuration config)
      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 Configuration
      function - the function to run using a valid Hibernate Session
      Returns:
      the result of the given function