Java 类net.sf.jasperreports.engine.JRQueryChunk 实例源码

项目:jasperreports    文件:JRBaseObjectFactory.java   
/**
 *
 */
protected JRBaseQueryChunk getQueryChunk(JRQueryChunk queryChunk)
{
    JRBaseQueryChunk baseQueryChunk = null;

    if (queryChunk != null)
    {
        baseQueryChunk = (JRBaseQueryChunk)get(queryChunk);
        if (baseQueryChunk == null)
        {
            baseQueryChunk = new JRBaseQueryChunk(queryChunk, this);
        }
    }

    return baseQueryChunk;
}
项目:jasperreports    文件:JRBaseQueryChunk.java   
/**
 *
 */
protected JRBaseQueryChunk(JRQueryChunk queryChunk, JRBaseObjectFactory factory)
{
    factory.put(queryChunk, this);

    type = queryChunk.getType();
    text = queryChunk.getText();
    tokenSeparator = queryChunk.getTokenSeparator();

    String[] chunkTokens = queryChunk.getTokens();
    if (chunkTokens == null)
    {
        tokens = null;
    }
    else
    {
        tokens = new String[chunkTokens.length];
        System.arraycopy(chunkTokens, 0, tokens, 0, chunkTokens.length);
    }
}
项目:jasperreports    文件:JRBaseQuery.java   
/**
 *
 */
protected JRBaseQuery(JRQuery query, JRBaseObjectFactory factory)
{
    factory.put(query, this);

    /*   */
    JRQueryChunk[] jrChunks = query.getChunks();
    if (jrChunks != null && jrChunks.length > 0)
    {
        chunks = new JRQueryChunk[jrChunks.length];
        for(int i = 0; i < chunks.length; i++)
        {
            chunks[i] = factory.getQueryChunk(jrChunks[i]);
        }
    }

    language = query.getLanguage();
}
项目:jasperreports    文件:JRAbstractQueryExecuter.java   
/**
 * Parses the query and replaces the parameter clauses by the parameter values and
 * the parameters by the return value of {@link #getParameterReplacement(String) getParameterReplacement}.
 *
 */
protected void parseQuery()
{
    parameterClauseStack = new HashSet<String>();

    JRQuery query = dataset.getQuery();

    if (query != null)
    {
        JRQueryChunk[] chunks = query.getChunks();
        if (chunks != null && chunks.length > 0)
        {
            StringBuffer sbuffer = new StringBuffer();
            for(int i = 0; i < chunks.length; i++)
            {
                JRQueryChunk chunk = chunks[i];
                appendQueryChunk(sbuffer, chunk);
            }

            queryString = sbuffer.toString();
        }
    }
}
项目:opennmszh    文件:ResourceQueryFieldsProviderTest.java   
public JRQuery getQuery() {
    JRQuery query = new JRBaseQuery() {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public JRQueryChunk[] getChunks() {
            return null;
        }

        public String getLanguage() {
            return "resourceQuery";
        }

        public String getText() {
            return getQueryText();
        }
    };
    return query;
}
项目:OpenNMS    文件:ResourceQueryFieldsProviderTest.java   
public JRQuery getQuery() {
    JRQuery query = new JRBaseQuery() {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public JRQueryChunk[] getChunks() {
            return null;
        }

        public String getLanguage() {
            return "resourceQuery";
        }

        public String getText() {
            return getQueryText();
        }
    };
    return query;
}
项目:jasperreports    文件:JRAbstractQueryExecuter.java   
protected void appendQueryChunk(StringBuffer sbuffer, JRQueryChunk chunk)
{
    switch (chunk.getType())
    {
        case JRQueryChunk.TYPE_PARAMETER_CLAUSE :
        {
            appendParameterClauseChunk(sbuffer, chunk.getText());
            break;
        }
        case JRQueryChunk.TYPE_PARAMETER :
        {
            appendParameterChunk(sbuffer, chunk.getText());
            break;
        }
        case JRQueryChunk.TYPE_CLAUSE_TOKENS :
        {
            appendClauseChunk(sbuffer, chunk.getTokens());
            break;
        }
        case JRQueryChunk.TYPE_TEXT :
        default :
        {
            appendTextChunk(sbuffer, chunk.getText());
            break;
        }
    }
}
项目:jasperreports    文件:JRDesignQuery.java   
@Override
public JRQueryChunk[] getChunks()
{
    JRQueryChunk[] chunkArray = null;

    if (chunks != null && chunks.size() > 0)
    {
        chunkArray = new JRQueryChunk[chunks.size()];
        chunks.toArray(chunkArray);
    }

    return chunkArray;
}
项目:jasperreports    文件:JRDesignQuery.java   
/**
 *
 */
public void addTextChunk(String text)
{
    JRDesignQueryChunk chunk = new JRDesignQueryChunk();
    chunk.setType(JRQueryChunk.TYPE_TEXT);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignQuery.java   
/**
 *
 */
public void addParameterChunk(String text)
{
    JRDesignQueryChunk chunk = new JRDesignQueryChunk();
    chunk.setType(JRQueryChunk.TYPE_PARAMETER);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignQuery.java   
/**
 *
 */
public void addParameterClauseChunk(String text)
{
    JRDesignQueryChunk chunk = new JRDesignQueryChunk();
    chunk.setType(JRQueryChunk.TYPE_PARAMETER_CLAUSE);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignQuery.java   
/**
 * Adds a {@link JRQueryChunk#TYPE_CLAUSE_TOKENS clause chunk} to the query.
 * 
 * @param tokens the clause tokens
 * @see JRDesignQueryChunk#setTokens(String[])
 * @deprecated Replaced by {@link #addClauseChunk(String[], char)}.
 */
public void addClauseChunk(String[] tokens)
{
    JRDesignQueryChunk chunk = new JRDesignQueryChunk();
    chunk.setType(JRQueryChunk.TYPE_CLAUSE_TOKENS);
    chunk.setTokens(tokens);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignQuery.java   
/**
 * Adds a {@link JRQueryChunk#TYPE_CLAUSE_TOKENS clause chunk} to the query.
 * 
 * @param tokens the clause tokens
 * @param tokenSeparator the token separator character
 * @see JRDesignQueryChunk#setTokens(String[])
 * @see JRQueryChunk#PROPERTY_CHUNK_TOKEN_SEPARATOR
 */
public void addClauseChunk(String[] tokens, char tokenSeparator)
{
    JRDesignQueryChunk chunk = new JRDesignQueryChunk();
    chunk.setType(JRQueryChunk.TYPE_CLAUSE_TOKENS);
    chunk.setTokens(tokens);
    chunk.setTokenSeparator(tokenSeparator);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignQuery.java   
/**
 *
 */
public void setText(String text)
{
    Object old = getText();
    chunks = new ArrayList<JRQueryChunk>();
    JRQueryParser.instance().parse(text, chunkAdder());
    getEventSupport().firePropertyChange(PROPERTY_TEXT, old, getText());
}
项目:openreports    文件:JRQueryExecuter.java   
/**
  *
  */
private void parseQuery() {
    queryString = "";
    parameterNames = new ArrayList();

    if( query != null ) {
        JRQueryChunk[] chunks = query.getChunks();
        if( chunks != null && chunks.length > 0 ) {
            StringBuffer sbuffer = new StringBuffer();
            JRQueryChunk chunk = null;
            for( int i = 0; i < chunks.length; i++ ) {
                chunk = chunks[i];
                switch( chunk.getType() ) {
                case JRQueryChunk.TYPE_PARAMETER_CLAUSE: {
                    String parameterName = chunk.getText();
                    Object parameterValue = parameterValues.get( parameterName );
                    sbuffer.append( String.valueOf( parameterValue ) );
                    // parameterNames.add(parameterName);
                    break;
                }
                case JRQueryChunk.TYPE_PARAMETER: {
                    sbuffer.append( "?" );
                    parameterNames.add( chunk.getText() );
                    break;
                }
                case JRQueryChunk.TYPE_TEXT:
                default: {
                    sbuffer.append( chunk.getText() );
                    break;
                }
                }
            }

            queryString = sbuffer.toString();
        }
    }
}
项目:jasperreports    文件:JRBaseQuery.java   
@Override
public JRQueryChunk[] getChunks()
{
    return this.chunks;
}
项目:jasperreports    文件:JRQueryParser.java   
protected String getTokenSeparators()
{
    return JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance()).getProperty(JRQueryChunk.PROPERTY_CHUNK_TOKEN_SEPARATOR);
}
项目:jasperreports    文件:JRQueryParser.java   
/**
 * (Re)creates the query text from a list of chunks.
 * 
 * @param chunks the chunks
 * @return the recreated query text
 */
public String asText(JRQueryChunk[] chunks)
{
    String text = "";

    if (chunks != null && chunks.length > 0)
    {
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < chunks.length; i++)
        {
            JRQueryChunk queryChunk = chunks[i];
            switch(queryChunk.getType())
            {
                case JRQueryChunk.TYPE_PARAMETER :
                {
                    sb.append("$P{");
                    sb.append( queryChunk.getText() );
                    sb.append("}");
                    break;
                }
                case JRQueryChunk.TYPE_PARAMETER_CLAUSE :
                {
                    sb.append("$P!{");
                    sb.append( queryChunk.getText() );
                    sb.append("}");
                    break;
                }
                case JRQueryChunk.TYPE_CLAUSE_TOKENS :
                {
                    sb.append("$X{");
                    sb.append(queryChunk.getText());
                    sb.append("}");
                    break;
                }
                case JRQueryChunk.TYPE_TEXT :
                default :
                {
                    sb.append( queryChunk.getText() );
                    break;
                }
            }
        }

        text = sb.toString();
    }

    return text;
}
项目:jasperreports    文件:JRVerifier.java   
/**
 *
 */
private void verifyQuery(JRDesignDataset dataset)
{
    JRQuery query = dataset.getQuery();
    if (query != null)
    {
        String language = query.getLanguage();
        QueryExecuterFactory queryExecuterFactory = null;
        if (language == null || language.length() == 0)
        {
            addBrokenRule("Query language not set.", query);
        }
        else
        {
            try
            {
                queryExecuterFactory = JRQueryExecuterUtils.getInstance(jasperReportsContext).getExecuterFactory(query.getLanguage());
            }
            catch (JRException e1)
            {
                addBrokenRule("Query executer factory for " + language + " cannot be created.", query);
            }
        }


        JRQueryChunk[] chunks = query.getChunks();
        if (chunks != null && chunks.length > 0)
        {
            Map<String, JRParameter> parametersMap = dataset.getParametersMap();

            for(int j = 0; j < chunks.length; j++)
            {
                JRQueryChunk queryChunk = chunks[j];
                switch (queryChunk.getType())
                {
                    case JRQueryChunk.TYPE_PARAMETER :
                    {
                        JRParameter parameter = parametersMap.get(queryChunk.getText());
                        if ( parameter == null )
                        {
                            addBrokenRule("Query parameter not found : " + queryChunk.getText(), query);
                        }
                        else if (queryExecuterFactory != null)
                        {
                            String parameterType = null;
                            try
                            {
                                parameterType = parameter.getValueClassName();
                            }
                            catch (JRRuntimeException e)
                            {
                                // ignore, already added when the parameter got verified
                            }
                            if (parameterType != null && !queryExecuterFactory.supportsQueryParameterType(parameterType))
                            {
                                addBrokenRule("Parameter type not supported in query : " + queryChunk.getText() + " class " + parameterType, query);
                            }
                        }

                        break;
                    }
                    case JRQueryChunk.TYPE_PARAMETER_CLAUSE :
                    {
                        if (!parametersMap.containsKey(queryChunk.getText()))
                        {
                            addBrokenRule("Query parameter not found : " + queryChunk.getText(), query);
                        }
                        break;
                    }
                    case JRQueryChunk.TYPE_TEXT :
                    default :
                    {
                    }
                }
            }
        }
    }
}
项目:jasperreports    文件:JRDesignQuery.java   
/**
 *
 */
public void setChunks(List<JRQueryChunk> chunks)
{
    this.chunks = chunks;
}
项目:PDFReporter-Studio    文件:SoapConnection.java   
private void cascadingDependencies(ResourceDescriptor ic, Set<String> icNames) {
    List<ResourceDescriptor> children = ic.getChildren();
    for (ResourceDescriptor sub_ic : children) {
        if (!InputControlsManager.isRDQuery(sub_ic))
            continue;
        String queryString = sub_ic.getSql();
        String lang = sub_ic.getResourceProperty(ResourceDescriptor.PROP_QUERY_LANGUAGE).getValue();
        if (!Misc.isNullOrEmpty(queryString)) {
            List<String> parameters = new ArrayList<String>();
            JRDesignQuery query = new JRDesignQuery();
            query.setText(queryString);
            if (lang != null)
                query.setLanguage(lang);
            for (JRQueryChunk chunk : query.getChunks()) {
                switch (chunk.getType()) {
                case JRQueryChunk.TYPE_TEXT:
                    break;
                case JRQueryChunk.TYPE_PARAMETER_CLAUSE:
                case JRQueryChunk.TYPE_PARAMETER:
                    String paramName = chunk.getText().trim();
                    if (!parameters.contains(paramName) && icNames.contains(paramName))
                        parameters.add(paramName);
                    break;
                case JRQueryChunk.TYPE_CLAUSE_TOKENS:
                    String[] tokens = chunk.getTokens();
                    if (tokens.length > 2) {
                        for (String t : tokens) {
                            t = t.trim();
                            if (!parameters.contains(t) && icNames.contains(t))
                                parameters.add(t);
                        }
                    }
                    break;
                }
            }
            if (!parameters.isEmpty())
                ic.setMasterInputControls(parameters);
        }
        break;
    }
}