All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ws.jaxme.PMParams Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2003, 2004  The Apache Software Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.

 */
package org.apache.ws.jaxme;

import java.io.Serializable;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;


/** 

Implementation of a parameter object for use in * {@link PM#select(Observer, String, PMParams)}.

* * @author Jochen Wiedmann */ public class PMParams implements Serializable { /**

A single parameter.

*/ public static class Param { private int type; private Object value; /**

Creates a new parameter with the given type and value.

*/ public Param(int pType, Object pValue) { type = pType; value = pValue; } public int getType() { return type; } public Object getValue() { return value; } } private List params; private int max, start; private boolean distinct; /**

Adds a new parameter.

*/ public void addParam(Param pParam) { if (params == null) { params = new ArrayList(); } params.add(pParam); } /**

Adds a String parameter.

*/ public void addParam(String pParam) { addParam(new Param(Types.VARCHAR, pParam)); } /**

Adds a Long parameter.

*/ public void addParam(Long pParam) { addParam(new Param(Types.BIGINT, pParam)); } /**

Adds a long parameter.

*/ public void addParam(long pParam) { addParam(new Param(Types.BIGINT, new Long(pParam))); } /**

Adds an Integer parameter.

*/ public void addParam(Integer pParam) { addParam(new Param(Types.INTEGER, pParam)); } /**

Adds an int parameter.

*/ public void addParam(int pParam) { addParam(new Param(Types.INTEGER, new Integer(pParam))); } /**

Adds a Short parameter.

*/ public void addParam(Short pParam) { addParam(new Param(Types.SMALLINT, pParam)); } /**

Adds a short parameter.

*/ public void addParam(short pParam) { addParam(new Param(Types.SMALLINT, new Short(pParam))); } /**

Adds a Byte parameter.

*/ public void addParam(Byte pParam) { addParam(new Param(Types.TINYINT, pParam)); } /**

Adds a byte parameter.

*/ public void addParam(byte pParam) { addParam(new Param(Types.TINYINT, new Byte(pParam))); } /**

Adds a DateTime parameter.

*/ public void addDateTimeParam(Calendar pParam) { addParam(new Param(Types.TIMESTAMP, pParam)); } /**

Adds a VARBINARY parameter.

*/ public void addParam(byte[] pParam) { addParam(new Param(Types.VARBINARY, pParam)); } /**

Adds a Date parameter.

*/ public void addDateParam(Calendar pParam) { addParam(new Param(Types.DATE, pParam)); } /**

Adds a Time parameter.

*/ public void addTimeParam(Calendar pParam) { addParam(new Param(Types.TIME, pParam)); } /**

Sets the maximum number of result documents.

*/ public void setMaxResultDocuments(int pMax) { max = pMax; } /**

Returns the maximum number of result documents * or 0 (default) for an unlimited number.

*/ public int getMaxResultDocuments() { return max; } /**

Sets the maximum number of documents to skip * at the beginning (soft cursoring).

*/ public void setSkippedResultDocuments(int pStart) { start = pStart; } /**

Sets the maximum number of documents to skip * at the beginning or 0 (default) to skip no documents.

*/ public int getSkippedResultDocuments() { return start; } /**

Returns the number of parameters added with * addParam().

*/ public int getNumParams() { return (params == null) ? 0 : params.size()/2; } /**

Returns an {@link Iterator} to the list of parameters. Any * element in the list is an instance of {@link PMParams.Param}.

*/ public Iterator getParams() { return params.iterator(); } /**

Sets whether the query should guarantee to return only * distinct objects by activating the DISTINCT clause.

*/ public void setDistinct(boolean pDistinct) { distinct = pDistinct; } /**

Returns whether the query should guarantee to return only * distinct objects by activating the DISTINCT clause.

*/ public boolean isDistinct() { return distinct; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy