📄 abstractgraction.java
字号:
buildEQLRequestMetaInf( mainEql ); // build EQL select clause buildEQLSelectClause( mainEql ); boolean hasFilters = ( eqlFilters != null ) || ( reqFilters != null && reqFilters.getReqFiltersTypeItemCount() > 0 ); if( hasFilters ) { // build EQL where clause StringBuffer whereClause = new StringBuffer( " WHERE " ); buildEQLWhereClause( whereClause ); mainEql.append( whereClause.toString() ); } // build EQL order clause buildEQLOrderClause( mainEql ); // set class variable eqlQuery = mainEql.toString(); } /** * Build EQL select clause * @param eql EQL string */ protected void buildEQLSelectClause( StringBuffer eql ) { // do nothing } /** * Build EQL order clause * @param eql EQL string */ protected void buildEQLOrderClause( StringBuffer eql ) { // do nothing } /** * Build EQL request meta information * @param eql EQL string */ protected void buildEQLRequestMetaInf( StringBuffer eql ) { eql.append( "/* " ); // set PAGE attribute if( page != UNDEFINED_PAGE ) { eql.append( PAGE_PARAM ).append( "=" ).append( page ).append( "," ); } // set PAGESIZE attribute if( pageSize != UNDEFINED_PAGESIZE ) { eql.append( PAGE_SIZE_PARAM ).append( "=" ).append( pageSize ).append( "," ); } eql.append( " */ " ); } /** * Build EQL where clause * @param eql EQL string * @throws UserQueryParseException */ protected void buildEQLWhereClause( StringBuffer eql ) throws UserQueryParseException { if( eqlFilters != null ) { eql.append( eqlFilters ); } else { buildEQLWhereClause( eql, reqFilters ); } } /** * Build EQL where clause * @param eql EQL string * @param reqFilters ReqFilters object * @throws UserQueryParseException */ protected void buildEQLWhereClause( StringBuffer eql, ReqFilters reqFilters ) throws UserQueryParseException { String boolType = reqFilters.getType().toString(); int count = reqFilters.getReqFiltersTypeItemCount(); for( int i = 0; i < count; i++ ) { if( i > 0 ) { eql.append( " " ).append( boolType ).append( " " ); } ReqFiltersTypeItem typeItem = reqFilters.getReqFiltersTypeItem( i ); ReqFilters nextReqFilters = typeItem.getReqFilters(); if( nextReqFilters != null ) { eql.append( "(" ); buildEQLWhereClause( eql, nextReqFilters ); eql.append( ")" ); } else { ReqFilter reqFilter = typeItem.getReqFilter(); String _boolType = reqFilter.getConditiontype().toString(); boolean useTextField = reqFilter.getUsetextfield().booleanValue(); String entityName = reqFilter.getEntity(); String fieldName = reqFilter.getName(); Entity entity = ctx.getEntityViewConfig( entityName ); Efield field = EntityHelper.getEfield( fieldName, entity ); String searchFunction = field.getEqlextSrchfunc(); int _count = reqFilter.getReqFilterValueCount(); if( _count > 0 ) { eql.append( "(" ); for( int j = 0; j < _count; j++ ) { if( j > 0 ) { eql.append( " " ).append( _boolType ).append( " " ); } String userQuery = reqFilter.getReqFilterValue( j ); String eqlQuery; if( searchFunction != null ) { eqlQuery = parseUserQueryInsideSearchFunction( searchFunction, entity, field, useTextField, userQuery ); } else { eqlQuery = parseUserQuery( entity, field, useTextField, userQuery ); } eql.append( eqlQuery ); } eql.append( ")" ); } else { String eqlQuery = parseUserQuery( entity, field, useTextField, StringHelper.EMPTY_VALUE ); eql.append( eqlQuery ); } } } } /** * Parse user input query and put it inside EQL serach function * <code>searchFunc</code>. * @param searchFunc EQL search function name * @param entity Entity object * @param field Efield object * @param useTextField treat field as textfield or not * @param query user query * @return part of EQL query * @throws UserQueryParseException */ protected String parseUserQueryInsideSearchFunction( String searchFunc, Entity entity, Efield field, boolean useTextField, String query ) throws UserQueryParseException { return searchFunc + "(" + field.getId() + ", " + StringHelper.java2sql( query ) + ")"; } /** * Parse user input query * @param entity Entity object * @param field Efield object * @param useTextField treat field as textfield or not * @param query user query * @return part of EQL query * @throws UserQueryParseException */ protected String parseUserQuery( Entity entity, Efield field, boolean useTextField, String query ) throws UserQueryParseException { StringBuffer ret = new StringBuffer(); StringBuffer cond = new StringBuffer(); query = iwDetector.replace( query ); int size = ( query == null ) ? 0 : query.length(); boolean evenEscapes = true; for( int i = 0; i < size; i++ ) { char c = query.charAt( i ); if( c == AND_CHARACTER && evenEscapes ) { parseUserCondition( cond.toString(), entity, field, useTextField, ret ); ret.append( " AND " ); cond.delete( 0, cond.length() ); } else if( c == OR_CHARACTER && evenEscapes ) { parseUserCondition( cond.toString(), entity, field, useTextField, ret ); ret.append( " OR " ); cond.delete( 0, cond.length() ); } else if( c == ESCAPE_CHARACTER ) { cond.append( c ); evenEscapes = !evenEscapes; } else { cond.append( c ); evenEscapes = true; } } parseUserCondition( cond.toString(), entity, field, useTextField, ret ); return ret.toString(); } /** * Parse user query condition * @param cond user query conition * @param entity given entity * @param field given field * @param useTextField treat field as textfield * @param ret result string buffer * @throws UserQueryParseException */ protected void parseUserCondition( String cond, Entity entity, Efield field, boolean useTextField, StringBuffer ret ) throws UserQueryParseException { if( cond == null ) { throw new NullPointerException( "Condition is NULL" ); } String leftMember; if( useTextField ) { // add text field leftMember = "#" + field.getId(); } else { // add field leftMember = field.getId(); } // try to detect condition operation int cond_op; String value; String s = cond.trim(); if( s.indexOf( QUERY_GTEQ_OP ) == 0 ) { cond_op = GTEQ_OP; value = s.substring( 2 ); } else if( s.indexOf( QUERY_LTEQ_OP ) == 0 ) { cond_op = LTEQ_OP; value = s.substring( 2 ); } else if( cond.indexOf( QUERY_GT_OP ) == 0 ) { cond_op = GT_OP; value = cond.substring( 1 ); } else if( s.indexOf( QUERY_LT_OP ) == 0 ) { cond_op = LT_OP; value = s.substring( 1 ); } else if( s.indexOf( QUERY_NE_OP ) == 0 ) { cond_op = NE_OP; value = s.substring( 1 ); } else if( s.indexOf( QUERY_EQ_OP ) == 0 ) { cond_op = EQ_OP; value = s.substring( 1 ); } else { cond_op = NONE_OP; value = cond; } // trim value if operation present if( cond_op != NONE_OP && value != null ) { value = value.trim(); } if( useTextField ) { // Use text field String lrefEntityName = field.getListref().getEntity(); String lrefFieldName = field.getListref().getEfield(); entity = ctx.getEntityViewConfig( lrefEntityName ); field = EntityHelper.getEfield( lrefFieldName, entity ); } ret.append( " " ); if( value == null || value.equalsIgnoreCase( StringHelper.NULL_VALUE ) ) { // // Null condition // ret.append( leftMember ); if( cond_op == NONE_OP || cond_op == EQ_OP ) { ret.append( " IS NULL" ); } else if( cond_op == NE_OP ) { ret.append( " IS NOT NULL" ); } else { throwUserQueryParseException( entity, field, "NULL" ); } } else { // // Not null condition // int datatype = field.getDatatype().getType(); switch( datatype ) { case DataSType.INT_TYPE: case DataSType.LONG_TYPE: case DataSType.FLOAT_TYPE: case DataSType.TIME_TYPE: parseUserSimpleCondition( leftMember, value, cond_op, entity, field, ret ); break; case DataSType.STRING_TYPE: // string type parseUserStringCondition( leftMember, value, cond_op, entity, field, ret ); break; case DataSType.TIMESTAMP_TYPE: case DataSType.DATE_TYPE: // date type parseUserDateCondition( leftMember, value, cond_op, entity, field, ret ); break; case DataSType.MEMO_TYPE: // memo type parseUserMemoCondition( leftMember, cond, entity, field, ret ); break; default: // default behaivor throw new GenericSystemException( "Unsupported datatype '" + datatype + "'" ); } } ret.append( " " ); } /** * Parse user query condition * @param leftMember left member of query * @param rightMember right member of query * @param cond_op number of condition operation * @param entity given entity * @param field given field * @param ret result string buffer * @throws UserQueryParseException */ protected void parseUserSimpleCondition( String leftMember, String rightMember, int cond_op, Entity entity, Efield field, StringBuffer ret ) throws UserQueryParseException { eqlPS.setObject( psCount++, convertString2EQLObject( entity, field, rightMember ) ); ret.append( leftMember ); ret.append( DEFAULT_EQL_OP_MAPPINGS[cond_op] ); ret.append( PS_CHARACTER ); } /** * Parse string user query condition * @param leftMember left member of query * @param rightMember right member of query * @param cond_op number of condition operation * @param entity given entity * @param field given field * @param ret result string buffer * @throws UserQueryParseException */ protected void parseUserStringCondition( String leftMember, String rightMember, int cond_op, Entity entity, Efield field, StringBuffer ret )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -