" hibernate.connection.provider_class" + multitenant用于hibernate搜索集成

时间:2016-04-27 15:31:14

标签: hibernate multi-tenant hibernate-search hibernate-4.x

我们使用" hibernate.connection.provider_class"在与hibernate 4.0的多租户连接中,我们尝试将hibernate搜索4.1.1.Final集成到我们的应用程序中,但问题是当我们尝试清除所有数据库时,我们无法使用此代码获取具有完全tenantid的会话#34; FullTextSession fullTextSession = org.hibernate.search.Search.getFullTextSession(hibernateManagement.getHibernateSession());"

因为"" hibernateManagement.getHibernateSession()"没有去调用" connection.provider_class"获取具有租户ID的确切会话,以便我们清除所有提供者而不是客户端数据库

因此,通过" hibernate.connection.provider_class"可以获得与tenantid的会话。因为我们无法整合这样的代码?

DATABASE  factory.MultiTenantIdentifierResolver factory.MultiTenantConnectionProvider 因为它对应用程序的其余部分有很大的影响。

那么我们可以通过获取此属性的会话来做到这一点""建立 FullTextSession? 我们的com.application.resources.controller.ConnectionProvider连接方法是:

public Connection getConnection() throws SQLException {
 try {


        String tenantId = null;


    Connection connection;
      GestionAffichageBean gestionAffichageBean=null;
   String host="";
  boolean distantConnection =false;


  if (FacesContext.getCurrentInstance() != null) {


   HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);


            if (session != null && session.getAttribute("tenantId") != null) {


   tenantId = (String) session.getAttribute("tenantId");
   }
  } else if (InjectionService.getBeanManager() != null) {
  if(gestionAffichageBean==null) {
  gestionAffichageBean = (GestionAffichageBean) InjectionService.getBeanByName("gestionaffichage");
   }

   tenantId = gestionAffichageBean.getTenantId();
  } else {
   tenantId = AppUtil.threadTenantId.get(Thread.currentThread().getId());
  }


  if (gestionAffichageBean!=null && InjectionService.getBeanManager() != null){

  distantConnection=gestionAffichageBean.isDistantConnection();
  if(gestionAffichageBean.getHostIP()!=null)
  host=gestionAffichageBean.getHostIP();

   }

   if(distantConnection && !host.equals("") && !(host.equals("localhost")|| host.equals("127.0.0.1"))  ){


   System.out.println("getConnection() distantConnection => " + tenantId);


   Class.forName("com.mysql.jdbc.Driver");
   Properties prop = new Properties();


   String jdbcUrl;


   prop.put("user", "");
    prop.put("password", "");
  jdbcUrl="jdbc:mysql://"+host+":3306/";


   connection = DriverManager.getConnection(jdbcUrl, prop);
    connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);


     }else{
   javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:jboss/datasources/" + dataSourceNameDefault);
   connection = ds.getConnection();
    }



   if (tenantId != null) {
   connection.setCatalog(tenantId);
  }

   tenantId = null;

  return connection;



  } catch (Exception e) {
  throw new SQLException(e.getMessage());
   }
   }

0 个答案:

没有答案