Package net.sf.hibernate.cfg

Examples of net.sf.hibernate.cfg.Configuration


        if (persistenceOn) {

            // Create the Hibernate config, do not create database, the engine does this.
            try {
                cfg = new Configuration();
                //cfg.addClass(Capability.class);
                //cfg.addClass(HResOccupiesPosition.class);
                cfg.addClass(HumanResourceRole.class);
                //cfg.addClass(OrgGroup.class);
                //cfg.addClass(Position.class);
View Full Code Here


        }
        return _myInstance;
    }

    private WorklistDBConnector() throws HibernateException {
        Configuration cfg = new Configuration();
        _factory = cfg.buildSessionFactory();
    }
View Full Code Here

    /** initialises the worklet tables in the database */
     public void initialise() throws HibernateException {
        if (_persistOn) {
            try {
                _cfg = new Configuration();

                // add each persisted worklet class to config
                _cfg.addClass(au.edu.qut.yawl.worklet.selection.CheckedOutItem.class);
                _cfg.addClass(au.edu.qut.yawl.worklet.selection.CheckedOutChildItem.class);
                _cfg.addClass(au.edu.qut.yawl.worklet.admin.AdministrationTask.class);
View Full Code Here

    protected static SessionFactory initialise(boolean journalising) throws YPersistenceException {
        String loggerName = "au.edu.qut.yawl.engine.YPersistenceManager";
        SessionFactory factory = null;
        Connection con = null;
        Transaction tx = null;
        Configuration cfg = null;

        // Create the Hibernate config, check and create database if required, and generally set things up .....
        if (journalising) {
            try {
                cfg = new Configuration();
                cfg.addClass(YSpecFile.class);
                cfg.addClass(YNetRunner.class);
                cfg.addClass(YWorkItem.class);
                cfg.addClass(P_YIdentifier.class);
                cfg.addClass(YCaseData.class);
                cfg.addClass(YLogData.class);
                cfg.addClass(YWorkItemEvent.class);
                cfg.addClass(YLogIdentifier.class);
                cfg.addClass(YAWLServiceReference.class);

                cfg.addClass(au.edu.qut.yawl.admintool.model.Resource.class);
                cfg.addClass(au.edu.qut.yawl.admintool.model.Role.class);
                cfg.addClass(au.edu.qut.yawl.admintool.model.HumanResourceRole.class);
                cfg.addClass(au.edu.qut.yawl.admintool.model.Capability.class);
                cfg.addClass(au.edu.qut.yawl.admintool.model.ResourceCapability.class);
                cfg.addClass(au.edu.qut.yawl.admintool.model.OrgGroup.class);
                cfg.addClass(au.edu.qut.yawl.admintool.model.Position.class);
                cfg.addClass(au.edu.qut.yawl.admintool.model.HResOccupiesPosition.class);
                cfg.addClass(au.edu.qut.yawl.exceptions.Problem.class);

                factory = cfg.buildSessionFactory();

                Logger.getLogger(loggerName).debug("Validating existance of database for persistence");

                boolean createtables = false;
View Full Code Here

   * @throws IllegalArgumentException in case of illegal property values
   * @throws HibernateException in case of Hibernate initialization errors
   */
  public void afterPropertiesSet() throws IllegalArgumentException, HibernateException, IOException {
    // Create Configuration instance.
    Configuration config = newConfiguration();

    if (this.dataSource != null) {
      // Make given DataSource available for SessionFactory configuration.
      configTimeDataSourceHolder.set(this.dataSource);
    }

    if (this.jtaTransactionManager != null) {
      // Make Spring-provided JTA TransactionManager available.
      configTimeTransactionManagerHolder.set(this.jtaTransactionManager);
    }

    if (this.lobHandler != null) {
      // Make given LobHandler available for SessionFactory configuration.
      // Do early because because mapping resource might refer to custom types.
      configTimeLobHandlerHolder.set(this.lobHandler);
    }

    try {

      if (this.entityInterceptor != null) {
        // Set given entity interceptor at SessionFactory level.
        config.setInterceptor(this.entityInterceptor);
      }

      if (this.namingStrategy != null) {
        // Pass given naming strategy to Hibernate Configuration.
        config.setNamingStrategy(this.namingStrategy);
      }

      if (this.configLocation != null) {
        // Load Hibernate configuration from given location.
        config.configure(this.configLocation.getURL());
      }

      if (this.hibernateProperties != null) {
        // Add given Hibernate properties to Configuration.
        config.addProperties(this.hibernateProperties);
      }

      if (this.dataSource != null) {
        // Set Spring-provided DataSource as Hibernate property.
        config.setProperty(Environment.CONNECTION_PROVIDER,
            this.useTransactionAwareDataSource ?
            TransactionAwareDataSourceConnectionProvider.class.getName() :
            LocalDataSourceConnectionProvider.class.getName());
      }

      if (this.jtaTransactionManager != null) {
        // Set Spring-provided JTA TransactionManager as Hibernate property.
        config.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, LocalTransactionManagerLookup.class.getName());
      }

      if (this.mappingLocations != null) {
        // Register given Hibernate mapping definitions, contained in resource files.
        for (int i = 0; i < this.mappingLocations.length; i++) {
          config.addInputStream(this.mappingLocations[i].getInputStream());
        }
      }

      if (this.mappingJarLocations != null) {
        // Register given Hibernate mapping definitions, contained in jar files.
        for (int i = 0; i < this.mappingJarLocations.length; i++) {
          Resource resource = this.mappingJarLocations[i];
          config.addJar(resource.getFile());
        }
      }

      if (this.mappingDirectoryLocations != null) {
        // Register all Hibernate mapping definitions in the given directories.
        for (int i = 0; i < this.mappingDirectoryLocations.length; i++) {
          File file = this.mappingDirectoryLocations[i].getFile();
          if (!file.isDirectory()) {
            throw new IllegalArgumentException(
                "Mapping directory location [" + this.mappingDirectoryLocations[i] +
                "] does not denote a directory");
          }
          config.addDirectory(file);
        }
      }

      // Perform custom post-processing in subclasses.
      postProcessConfiguration(config);
View Full Code Here

   * @return the Configuration instance
   * @throws HibernateException in case of Hibernate initialization errors
   * @see net.sf.hibernate.cfg.Configuration#Configuration()
   */
  protected Configuration newConfiguration() throws HibernateException {
    return new Configuration();
  }
View Full Code Here

    node.setText(url);
    FileWriter w = new FileWriter(hibernateConfigFile);
    w.write(hibCfg.asXML());
    w.close();
    // Create hsqldb schema
    new SchemaExport(new Configuration().configure()).create(false, true);
  }
View Full Code Here

  private SessionFactory factory;

  public void configure(Properties properties) {
    try {
      Configuration config = new Configuration();

      Iterator it = properties.keySet().iterator();
      while (it.hasNext()) {
        String key = (String) it.next();
        String value = (String) properties.get(key);
        if (key.startsWith("class.")) {
          config.addClass(Resources.classForName(value));
        }
        if (key.startsWith("map.")) {
        config.addResource(value);
        }
      }

      Properties props = new Properties();
      props.putAll(properties);
      config.setProperties(props);

      factory = config.buildSessionFactory();

    } catch (Exception e) {
      throw new DaoException("Error configuring Hibernate.  Cause: " + e);
    }
  }
View Full Code Here

        return formatted;
    }

    public static void main(String[] args) {
        try {
            Configuration cfg = HibernateHelper.initializeConfiguration();

            boolean script = true;
            boolean drop = false;
            boolean export = true;
            String outFile = null;
            String propFile = null;
            boolean formatSQL = false;
            String delim = null;

            for (int i = 0; i < args.length; i++) {
                if (args[i].startsWith("--")) {
                    if (args[i].equals("--quiet")) {
                        script = false;
                    } else if (args[i].equals("--drop")) {
                        drop = true;
                    } else if (args[i].equals("--text")) {
                        export = false;
                    } else if (args[i].startsWith("--output=")) {
                        outFile = args[i].substring(9);
                    } else if (args[i].startsWith("--properties=")) {
                        propFile = args[i].substring(13);
                    } else if (args[i].equals("--format")) {
                        formatSQL = true;
                    } else if (args[i].startsWith("--delimiter=")) {
                        delim = args[i].substring(12);
                    } else if (args[i].startsWith("--config=")) {
                        cfg.configure(args[i].substring(9));
                    }
                } else {
                    String filename = args[i];
                    if (filename.endsWith(".jar")) {
                        cfg.addJar(new File(filename));
                    } else {
                        cfg.addFile(filename);
                    }
                }

            }
            if (propFile != null) {
View Full Code Here

public class HibernateHelper {
    private static Logger log = Logger.getLogger(HibernateHelper.class);

    public static void initializeHibernate() throws HibernateException {
        if (GlobalSessionFactory.get() == null) {
            Configuration cfg = initializeConfiguration();
            SessionFactory sessionFactory = cfg.buildSessionFactory();
            // XPlanner uses a custom session factory so that all sessions will be
            // automatically configured with an XPlanner-related Hibernate interceptor.
            GlobalSessionFactory.set(new XPlannerSessionFactory(sessionFactory));
        }
    }
View Full Code Here

TOP

Related Classes of net.sf.hibernate.cfg.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.