Package railo.runtime.orm

Examples of railo.runtime.orm.ORMConfiguration


     ormconfig
     sqlscript
     useDBForMapping
     */
   
    ORMConfiguration ormConf = data.getORMConfiguration();
   
    // dialect
    DataSource ds = dc.getDatasource();
    String dialect=null;
    try  {
      if (Class.forName(ormConf.getDialect()) != null) {
        dialect = ormConf.getDialect();
      }
    }
    catch (Exception e) {
      // MZ: The dialect value could not be bound to a classname or instantiation causes an exception - ignore and use the default dialect entries
    }
    if (dialect == null) {
      dialect = Dialect.getDialect(ormConf.getDialect());
      if(Util.isEmpty(dialect)) dialect=Dialect.getDialect(ds);
    }
    if(Util.isEmpty(dialect))
      throw ExceptionUtil.createException(data,null,"A valid dialect definition inside the "+Constants.APP_CFC+"/"+Constants.CFAPP_NAME+" is missing. The dialect cannot be determinated automatically",null);
   
    // Cache Provider
    String cacheProvider = ormConf.getCacheProvider();
    Class<? extends RegionFactory> regionFactory=null;
   
    if(Util.isEmpty(cacheProvider) || "EHCache".equalsIgnoreCase(cacheProvider)) {
      regionFactory=net.sf.ehcache.hibernate.EhCacheRegionFactory.class;
      cacheProvider=regionFactory.getName();//"org.hibernate.cache.EhCacheProvider";
         
    }
    else if("JBossCache".equalsIgnoreCase(cacheProvider))   cacheProvider="org.hibernate.cache.TreeCacheProvider";
    else if("HashTable".equalsIgnoreCase(cacheProvider))   cacheProvider="org.hibernate.cache.HashtableCacheProvider";
    else if("SwarmCache".equalsIgnoreCase(cacheProvider))   cacheProvider="org.hibernate.cache.SwarmCacheProvider";
    else if("OSCache".equalsIgnoreCase(cacheProvider))     cacheProvider="org.hibernate.cache.OSCacheProvider";
 
    Resource cacheConfig = ormConf.getCacheConfig();
    Configuration configuration = new Configuration();
   
    // ormConfig
    Resource conf = ormConf.getOrmConfig();
    if(conf!=null){
      try {
        Document doc = CommonUtil.toDocument(conf);
        configuration.configure(doc);
      }
      catch (Throwable t) {
        ORMUtil.printError(t);
       
      }
    }
   
    try{
      configuration.addXML(mappings);
    }
    catch(MappingException me){
      throw ExceptionUtil.createException(data,null, me);
    }
   
    configuration
       
        // Database connection settings
        .setProperty("hibernate.connection.driver_class", ds.getClazz().getName())
      .setProperty("hibernate.connection.url", ds.getDsnTranslated())
      .setProperty("hibernate.connection.username", ds.getUsername())
      .setProperty("hibernate.connection.password", ds.getPassword())
      //.setProperty("hibernate.connection.release_mode", "after_transaction")
      .setProperty("hibernate.transaction.flush_before_completion", "false")
      .setProperty("hibernate.transaction.auto_close_session", "false")
     
      // JDBC connection pool (use the built-in)
      //.setProperty("hibernate.connection.pool_size", "2")//MUST
     
     
      // SQL dialect
      .setProperty("hibernate.dialect", dialect)
      // Enable Hibernate's current session context
      .setProperty("hibernate.current_session_context_class", "thread")
     
      // Echo all executed SQL to stdout
      .setProperty("hibernate.show_sql", CommonUtil.toString(ormConf.logSQL()))
      .setProperty("hibernate.format_sql", CommonUtil.toString(ormConf.logSQL()))
      // Specifies whether secondary caching should be enabled
      .setProperty("hibernate.cache.use_second_level_cache", CommonUtil.toString(ormConf.secondaryCacheEnabled()))
    // Drop and re-create the database schema on startup
      .setProperty("hibernate.exposeTransactionAwareSessionFactory", "false")
    //.setProperty("hibernate.hbm2ddl.auto", "create")
    .setProperty("hibernate.default_entity_mode", "dynamic-map");
   
    if(!Util.isEmpty(ormConf.getCatalog()))
      configuration.setProperty("hibernate.default_catalog", ormConf.getCatalog());
    if(!Util.isEmpty(ormConf.getSchema()))
      configuration.setProperty("hibernate.default_schema",ormConf.getSchema());
   
   
    if(ormConf.secondaryCacheEnabled()){
      if(cacheConfig!=null && cacheConfig.isFile())
        configuration.setProperty("hibernate.cache.provider_configuration_file_resource_path",cacheConfig.getAbsolutePath());
      if(regionFactory!=null || Reflector.isInstaneOf(cacheProvider, RegionFactory.class))
        configuration.setProperty("hibernate.cache.region.factory_class", cacheProvider);
      else
View Full Code Here


   
    return configuration;
  }

  private static void schemaExport(Configuration configuration, DatasourceConnection dc, SessionFactoryData data) throws PageException, SQLException, IOException {
    ORMConfiguration ormConf = data.getORMConfiguration();
   
    if(ORMConfiguration.DBCREATE_NONE==ormConf.getDbCreate()) {
      return;
    }
    else if(ORMConfiguration.DBCREATE_DROP_CREATE==ormConf.getDbCreate()) {
      SchemaExport export = new SchemaExport(configuration);
      export.setHaltOnError(true);
             
      export.execute(false,true,false,false);
            printError(data,export.getExceptions(),false);
            executeSQLScript(ormConf,dc);
    }
    else if(ORMConfiguration.DBCREATE_UPDATE==ormConf.getDbCreate()) {
      SchemaUpdate update = new SchemaUpdate(configuration);
            update.setHaltOnError(true);
            update.execute(false, true);
            printError(data,update.getExceptions(),false);
        }
View Full Code Here

      throw ExceptionUtil.createException((ORMSession)null,null,"ORM is not enabled","");
   
   
    // datasource
    DataSource ds = ORMUtil.getDataSource(pc);
    ORMConfiguration ormConf=appContext.getORMConfiguration();
    String key = hash(ormConf,ds);
    SessionFactoryData data = factories.get(key);
    if(initType==INIT_ALL && data!=null) {
      data.reset();
      data=null;
    }
    if(data==null) {
      data=new SessionFactoryData(this,ormConf,ds);
      factories.put(key, data);
    }
   
   
    // config
    try{
      //arr=null;
      if(initType!=INIT_NOTHING){
        synchronized (data) {
         
          if(ormConf.autogenmap()){
            data.tmpList=HibernateSessionFactory.loadComponents(pc, this, ormConf);
           
            data.cfcs.clear();
          }
          else
View Full Code Here

      if(cfc!=null)return cfc;
    }
   
   
   
    ORMConfiguration ormConf = pc.getApplicationContext().getORMConfiguration();
    Resource[] locations = ormConf.getCfcLocations();
   
    throw ExceptionUtil.createException(data,null,
        "No entity (persitent component) with name ["+entityName+"] found, available entities are ["+CommonUtil.toList(data.getEntityNames(), ", ")+"] ",
        "component are searched in the following directories ["+toString(locations)+"]");
   
View Full Code Here

    // ORM
        if(ormSession!=null){
          // flush orm session
          try {
        ORMEngine engine=ormSession.getEngine();
            ORMConfiguration config=engine.getConfiguration(this);
            if(config==null || (config.flushAtRequestEnd() && config.autoManageSession())){
          ormSession.flush(this);
          //ormSession.close(this);
          //print.err("2orm flush:"+Thread.currentThread().getId());
        }
        ormSession.close(this);
      }
          catch (Throwable t) {
            //print.printST(t);
          }
          ormSession=null;
        }
       
   
    close();
        thread=null;
        base=null;
        //RequestImpl r = request;
       
        // Scopes
        if(hasFamily) {
          if(!isChild){
            req.disconnect();
          }
         
          request=null;
          _url=null;
          _form=null;
            urlForm=null;
            undefined=null;
            variables=null;
            variablesRoot=null;
            if(threads!=null && threads.size()>0) threads.clear();
           
        }
        else {
            if(variables.isBind()) {
              variables=null;
              variablesRoot=null;
            }
            else {
              variables=variablesRoot;
              variables.release(this);
            }
            undefined.release(this);
            urlForm.release(this);
          request.release();
        }
        cgi.release();
        argument.release(this);
        local=localUnsupportedScope;
       
        cookie.release();
    //if(cluster!=null)cluster.release();
       
        //client=null;
        //session=null;
       
   
       
       
    application=null;// not needed at the moment -> application.releaseAfterRequest();
    applicationContext=null;
   
    // Properties
        requestTimeout=-1;
        outputState=0;
        cfid=null;
        cftoken=null;
        locale=null;
        timeZone=null;
        url=null;
        form=null;
       
       
        // Pools
        errorPagePool.clear();

        // transaction connection
        if(!conns.isEmpty()){
          java.util.Iterator<Entry<String, DatasourceConnection>> it = conns.entrySet().iterator();
          DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
          while(it.hasNext())  {
            pool.releaseDatasourceConnection((it.next().getValue()));
          }
          conns.clear();
        }
View Full Code Here

        pageContext.setVariable(getString("admin",action,"returnVariable"),config.getORMEngineClass().getName());
    }
   

    private void doUpdateORMSetting() throws SecurityException, PageException {
      ORMConfiguration oc = config.getORMConfig();
      Struct settings=new StructImpl();
     
      settings.set(ORMConfigurationImpl.AUTO_GEN_MAP, getBool("admin",action,"autogenmap"));
      settings.set(ORMConfigurationImpl.EVENT_HANDLING, getBool("admin",action,"eventHandling"));
      settings.set(ORMConfigurationImpl.FLUSH_AT_REQUEST_END, getBool("admin",action,"flushatrequestend"));
View Full Code Here

    config.setORMEngineClass(clazz);

    // config
    if (orm == null)
      orm = doc.createElement("orm"); // this is just a dummy
    ORMConfiguration def = hasCS ? ((ConfigServerImpl) configServer).getORMConfig() : null;
    ORMConfiguration ormConfig = ORMConfigurationImpl.load(config, null, orm, config.getRootDirectory(), def);
    config.setORMConfig(ormConfig);

  }
View Full Code Here

    Resource src = ac.getSource();
    if(src!=null)sct.setEL(KeyConstants._source,src.getAbsolutePath());
   
    // orm
    if(ac.isORMEnabled()){
      ORMConfiguration conf = ac.getORMConfiguration();
      if(conf!=null)sct.setEL(KeyConstants._orm, conf.toStruct());
    }
    // s3
    Properties props = ac.getS3();
    if(props!=null) {
      sct.setEL(KeyConstants._s3, props.toStruct());
View Full Code Here

  public static String call(PageContext pc) throws PageException {
   
    // flush and close session
    ORMSession session = ORMUtil.getSession(pc,false);
    if(session!=null) {// MUST do the same with all sesson using the same engine
      ORMConfiguration config = session.getEngine().getConfiguration(pc);
      if(config.autoManageSession()) {
        session.flush(pc);
        session.close(pc);
      }
    }
    pc.getApplicationContext().reinitORM(pc);
View Full Code Here

TOP

Related Classes of railo.runtime.orm.ORMConfiguration

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.