Package org.hibernate.cfg

Examples of org.hibernate.cfg.AnnotationConfiguration$ExtendedMappingsImpl


    public HibernateSessionSourceImpl(Logger logger, List<HibernateConfigurer> hibernateConfigurers)
    {
        long startTime = System.currentTimeMillis();

        configuration = new AnnotationConfiguration();

        for (HibernateConfigurer configurer : hibernateConfigurers)
            configurer.configure(configuration);

        long configurationComplete = System.currentTimeMillis();
View Full Code Here


  private boolean isConfigurationProcessed = false;


  public Ejb3Configuration() {
    settingsFactory = new InjectionSettingsFactory();
    cfg = new AnnotationConfiguration( settingsFactory );
    cfg.setEntityNotFoundDelegate( ejb3EntityNotFoundDelegate );
    listenerConfigurator = new EventListenerConfigurator( this );
  }
View Full Code Here

        logger.info("Configuring persistence extension.");
    }

    public void configure(Map<Class, Provider> bindings, Map<String, Provider> resourceProviders) {
        final AnnotationConfiguration cfg = new AnnotationConfiguration();
        if (!config.hasProperty("errai.prototyping.persistence.connection.driver_class")) {
            return;
        }

        cfg.setProperty("hibernate.connection.driver_class", config.getProperty("errai.prototyping.persistence.connection.driver_class"));
        cfg.setProperty("hibernate.connection.url", config.getProperty("errai.prototyping.persistence.connection.url"));
        cfg.setProperty("hibernate.connection.username", config.getProperty("errai.prototyping.persistence.connection.username"));
        cfg.setProperty("hibernate.connection.password", config.getProperty("errai.prototyping.persistence.connection.password"));
        cfg.setProperty("hibernate.connection.pool_size", config.getProperty("errai.prototyping.persistence.connection.pool_size"));

        cfg.setProperty("hibernate.dialect", config.getProperty("errai.prototyping.persistence.dialect"));
        cfg.setProperty("hibernate.current_session_context_class", "thread");
        cfg.setProperty("hibernate.cache.use_second_level_cache", "false");
        cfg.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");


        cfg.setProperty("hibernate.show_sql", "true");
        cfg.setProperty("hibernate.hbm2ddl.auto", "update");

        List<File> roots = config.getConfigurationRoots();

        logger.info("Begin scan for annotated classes.");
        ConfigUtil.visitAllTargets(roots, new ConfigVisitor() {
            public void visit(Class<?> clazz) {
                if (clazz.isAnnotationPresent(Entity.class)) {
                    cfg.addAnnotatedClass(clazz);
                }
            }
        });

        final SessionFactory sessionFactory = cfg.buildSessionFactory();

        Provider<Session> sessionProvider = new Provider<Session>() {
            public Session get() {
                return sessionFactory.openSession();
            }
View Full Code Here

    final String dropScriptFileName = args[0] + File.separator + "drop-tables-ejbca4-" + args[1] + ".sql";
      final String createScriptFileName = args[0] + File.separator + "create-tables-ejbca4-" + args[1] + ".sql";
      final String createScriptFileNameNdb = args[0] + File.separator + "create-tables-ejbca4-" + args[1] + "-ndbcluster.sql";
      // Configure with our current persistence unit
      final Ejb3Configuration ejb3Configuration = new Ejb3Configuration().configure("ejbca-pu", null);
      final AnnotationConfiguration hibernateConfiguration = ejb3Configuration.getHibernateConfiguration();
    try {
      // Create drop script
        final String[] dropScript = hibernateConfiguration.generateDropSchemaScript(Dialect.getDialect(ejb3Configuration.getProperties()));
      StringBuilder sb = new StringBuilder();
      for (String line : dropScript) {
        sb.append(line);
        sb.append(";\n");
      }
      System.out.println("Writing drop script to " + dropScriptFileName);
      new FileOutputStream(dropScriptFileName).write(sb.toString().getBytes());
      // Create create script(s)
      final String[] createScript = hibernateConfiguration.generateSchemaCreationScript(Dialect.getDialect(ejb3Configuration.getProperties()));
      sb = new StringBuilder();
      for (String line : createScript) {
        // Format nicely, so it looks more like the old, manually created ones.
        if (line.startsWith("create")) {
          line = line.replaceAll("create table", "CREATE TABLE");
View Full Code Here

    this.dialectName = dialectName;
    this.fileName = fileName;
  }

  public void export() throws Exception {
    AnnotationConfiguration configuration = new AnnotationConfiguration();
    configuration.setProperty("hibernate.hbm2ddl.auto","create");
    PersistenceLoader persistenceLoader = PersistenceLoader.getInstance();
    Persistence persistence = persistenceLoader.getPersistence();
    for (String className : persistence.getPersistenceUnit().getClassNames()) {
      Class<?> c = Class.forName(className);
      configuration.addAnnotatedClass(c);
    }
   
    configuration.setProperty("hibernate.dialect", dialectName);
    SchemaExport exporter = new SchemaExport(configuration);
    exporter.setDelimiter(";");
    exporter.setOutputFile(fileName);
   
    boolean script = true;
View Full Code Here

    ClassNameLocator classNameLocator)
    {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        long startTime = System.currentTimeMillis();

        AnnotationConfiguration configuration = new AnnotationConfiguration();

        // Perform normal configuration.

        configuration.configure();

        for (String packageName : packageNames)
        {
            configuration.addPackage(packageName);

            for (String className : classNameLocator.locateClassNames(packageName))
            {
                try
                {
                    Class entityClass = contextClassLoader.loadClass(className);

                    configuration.addAnnotatedClass(entityClass);
                }
                catch (ClassNotFoundException ex)
                {
                    throw new RuntimeException(ex);
                }
            }
        }

        long configurationComplete = System.currentTimeMillis();

        _sessionFactory = configuration.buildSessionFactory();

        long factoryCreated = System.currentTimeMillis();

        log.info(HibernateMessages.startupTiming(configurationComplete - startTime, factoryCreated
                - startTime));
View Full Code Here

     * @param export If the database should have the SQL executed agaisnt it
     * @param drop If existing database objects should be dropped before creating new objects
     * @param outputFile Optional file to write out the SQL to.
     */
    public void hbm2ddl(boolean export, boolean create, boolean drop, String outputFile) {
        final AnnotationConfiguration configuration = new AnnotationConfiguration();
        try {
            configuration.configure(this.configuration.getURL());
        }
        catch (IOException e) {
            throw new IllegalArgumentException("Could not load configuration file '" + this.configuration + "'", e);
        }
       
        configuration.setProperty("hibernate.dialect", this.dialect);
        configuration.buildMappings();
       
        final Connection connection = DataSourceUtils.getConnection(this.dataSource);
        try {
            final SchemaExport exporter = new SchemaExport(configuration, connection);
            exporter.setFormat(false);
View Full Code Here

  }
 
  public void testTypeDefWithoutNameAndDefaultForTypeAttributes() {
   
    try {
      AnnotationConfiguration config = new AnnotationConfiguration();
      config.addAnnotatedClass(LocalContactDetails.class);
      config.buildSessionFactory();
      fail("Did not throw expected exception");
    }
    catch( AnnotationException ex ) {
      assertEquals(
          "Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType",
View Full Code Here

        Configuration configuration = null;
        if (configurationType.equalsIgnoreCase("xml")) {
          configuration = new Configuration();
        }
        if (configurationType.equalsIgnoreCase("annotation")) {
          configuration = new AnnotationConfiguration();
        }
        if (configuration==null) {
          String errorMessage = getText("hibernateplugin.configurationType_error");
          throw new Exception(errorMessage);
        }
View Full Code Here

  }

  public void testBlownPrecision() throws Exception {
   
    try {
      AnnotationConfiguration config = new AnnotationConfiguration();
      config.addAnnotatedClass(Bunny.class);
      config.addAnnotatedClass(PointyTooth.class);
      config.addAnnotatedClass(TwinkleToes.class);
      config.buildSessionFactory();
      String[] schema = config
          .generateSchemaCreationScript(new SQLServerDialect());
      for (String s : schema) {
        log.debug(s);
      }
      String expectedSqlPointyTooth = "create table PointyTooth (id numeric(128,0) not null, " +
View Full Code Here

TOP

Related Classes of org.hibernate.cfg.AnnotationConfiguration$ExtendedMappingsImpl

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.