2015-11-13 35 views
0

我需要在條件字符串上提取一些值。 的概念是要獲得真正的SQL語句和他的參數(無日誌)在條件中獲取特定值休眠字符串

就目前而言,我用這對獲得選擇:

CriteriaImpl c = (CriteriaImpl) criteria; 
     SessionImpl s = (SessionImpl)c.getSession(); 
     SessionFactoryImplementor factory = s.getFactory(); 
     CriteriaQueryTranslator translator=new CriteriaQueryTranslator(factory,c,c.getEntityOrClassName(),CriteriaQueryTranslator.ROOT_SQL_ALIAS); 
     String[] implementors = factory.getImplementors(c.getEntityOrClassName()); 

     CriteriaJoinWalker walker = new CriteriaJoinWalker((OuterJoinLoadable)factory.getEntityPersister(implementors[0]), 
           translator, 
           factory, 
           c, 
           c.getEntityOrClassName(), 
           s.getLoadQueryInfluencers()); 


     String sql=walker.getSQLString(); 

而結果:

select this_.ID_ELEMENTO as ID1_72_32_, this_2_.ACTIVO as[....]where this_2_.FECHA_BAJA is null and this_2_.ID_TIPO_ELEMENTO=? and this_2_.ACTIVO=? order by this_.ID_ELEMENTO asc 

最接近的獲得參數:

CriteriaQueryTranslator subCriteria= new CriteriaQueryTranslator(factory, c, c.getEntityOrClassName(), CriteriaQueryTranslator.ROOT_SQL_ALIAS); 


     String root =subCriteria.getRootCriteria().toString(); 

而結果:

CriteriaImpl(com.itym.pojo.elementos.antenas.AntenaAnalogicaPojo:elemento[Subcriteria(tipoElemento:tipoElemento)][fechaBaja is null, tipoElemento=ANTENA, activo=true]) 

我需要「TipoElemento」和「activo」值來替換第一個字符串。

我試過定期表達,但不會離開我。

如果有人知道如何,或以其他方式獲得真正的選擇,將非常感激!

+0

你看看這個帖子:http://stackoverflow.com/ a/555192/3698894? – Journeycorner

回答

0

我想這是你想要的,如果不是,指正: 兩個值都awaylable與此正則表達式

/tipoElemento=([A-Za-z]*).*activo=([A-Za-z]*)/ 
+0

是的,使用模式,匹配器和提取兩組。謝謝! – Borz93