/* * JBoss, Home of Professional Open Source. * See the COPYRIGHT.txt file distributed with this work for information * regarding copyright ownership. Some portions may be licensed * to Red Hat, Inc. under one or more contributor license agreements. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. */ package com.metamatrix.connector.metadata.internal; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import org.teiid.connector.api.ConnectorException; import org.teiid.connector.language.ICommand; import org.teiid.connector.language.IMetadataReference; import org.teiid.connector.language.IParameter; import org.teiid.connector.language.IProcedure; import org.teiid.connector.language.IParameter.Direction; import org.teiid.connector.metadata.runtime.Element; import org.teiid.connector.metadata.runtime.MetadataObject; import org.teiid.connector.metadata.runtime.RuntimeMetadata; import com.metamatrix.connector.metadata.MetadataConnectorConstants; import com.metamatrix.connector.metadata.MetadataConnectorPlugin; import com.metamatrix.connector.metadata.index.MetadataLiteralCriteria; import com.metamatrix.core.MetaMatrixRuntimeException; import com.metamatrix.core.util.ArgCheck; import com.metamatrix.core.util.StringUtil; /** * ObjectProcedure * @since 4.2 */ public class ObjectProcedure { private final RuntimeMetadata metadata; private final IProcedure procedure; private IParameter resultSetParameter; // in/inout parameters private Collection inParams; private Map criteriaMap; private Map propValueMap; // column properties of the resultset private String[] columnNames = null; private String[] columnNamesInSource = null; private Class[] columnTypes = null; /** * ObjectProcedure * @since 4.2 */ public ObjectProcedure(final RuntimeMetadata metadata, final ICommand command) throws ConnectorException { ArgCheck.isNotNull(metadata); ArgCheck.isNotNull(command); this.metadata = metadata; this.procedure = (IProcedure) command; initParameters(); initSetProperties(); initCriteria(); } public RuntimeMetadata getMetadata() { return this.metadata; } public Collection getInParameters() { return this.inParams; } /** * Collect inparameters and resultset.. * @since 4.2 */ private void initParameters() throws ConnectorException { Collection parameters = this.procedure.getParameters(); if(parameters != null) { this.inParams = new HashSet(parameters.size()); for(final Iterator iter = parameters.iterator(); iter.hasNext();) { IParameter parameter = (IParameter) iter.next(); // if there is one result set parameter if(parameter.getDirection() == Direction.RESULT_SET) { this.resultSetParameter = parameter; initResultSet(); } if(parameter.getDirection() == Direction.IN || parameter.getDirection() == Direction.INOUT) { inParams.add(parameter); } } } } /** * Collect names, types, nameinsources of all columns in the resultset. * @since 4.2 */ private void initResultSet() throws ConnectorException { List columnMetadata = resultSetParameter.getMetadataObject().getChildren(); int size = columnMetadata.size(); columnNames = new String[size]; columnNamesInSource = new String[size]; columnTypes = new Class[size]; for(int i =0; i