[Carbon-commits] [Carbon] svn commit r113876 - in branches/carbon/3.2.0/components/data-services: org.wso2.carbon.dataservices.common/3.2.2/src/main/java/org/wso2/carbon/dataservices/common org.wso2.carbon.dataservices.core/3.2.2 org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/internal org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/script org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans org.ws o2.carbon.dataservices.ui/3.2.2/src/main/resources org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/org/wso2/carbon/dataservices/ui/i18n org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/js
prabatha at wso2.com
prabatha at wso2.com
Fri Oct 14 01:50:59 EDT 2011
Author: prabatha
Date: Thu Oct 13 22:50:58 2011
New Revision: 113876
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=113876
Log:
adding SQL Array support, improving nested UDT functionality and removing Listners that were previously used upon grabbing the carbondatasource and registry declarative services
Added:
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/ResultSetWrapper.java
Removed:
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/TypeMapper.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/UDT.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/DataServiceAdmin.wsdl
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/DataServiceFileUploader.wsdl
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/TaskManagementAdminService.wsdl
Modified:
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.common/3.2.2/src/main/java/org/wso2/carbon/dataservices/common/DBConstants.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/pom.xml
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBDeployer.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBUtils.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DataServices.xsd
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/WSDLToDataService.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/XSLTTransformer.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CSVConfig.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CarbonDataSourceConfig.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/GSpreadConfig.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/ExcelQuery.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/Query.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/QueryFactory.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/SQLQuery.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/CallQuery.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/InternalParam.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/QueryParam.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/StaticOutputElement.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/internal/DataServicesDSComponent.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/script/DSGenerator.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/DataServiceAdminClient.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/UIutils.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Data.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Param.java
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/org/wso2/carbon/dataservices/ui/i18n/Resources.properties
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/addInputMapping.jsp
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/inputMappingProcessor.jsp
branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/js/ui-validations.js
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.common/3.2.2/src/main/java/org/wso2/carbon/dataservices/common/DBConstants.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.common/3.2.2/src/main/java/org/wso2/carbon/dataservices/common/DBConstants.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.common/3.2.2/src/main/java/org/wso2/carbon/dataservices/common/DBConstants.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.common/3.2.2/src/main/java/org/wso2/carbon/dataservices/common/DBConstants.java Thu Oct 13 22:50:58 2011
@@ -131,7 +131,8 @@
public static final String TIME = "TIME";
public static final String TIMESTAMP = "TIMESTAMP";
public static final String ORACLE_REF_CURSOR = "ORACLE_REF_CURSOR";
- public static final String UDT = "UDT";
+ public static final String STRUCT = "STRUCT";
+ public static final String ARRAY = "ARRAY";
}
/**
@@ -529,6 +530,8 @@
public static final String ENABLE_DTP = "enableDTP";
public static final String TRANSACTION_MANAGER_JNDI_NAME = "txManagerJNDIName";
public static final String USE_COLUMN_NUMBERS = "useColumnNumbers";
+ public static final String STRUCT_TYPE = "structType";
+
}
/**
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/pom.xml
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/pom.xml?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/pom.xml (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/pom.xml Thu Oct 13 22:50:58 2011
@@ -198,6 +198,12 @@
</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>
<Axis2Deployer>DataServicesDeployer</Axis2Deployer>
+ <!--<Axis2RequiredServices>-->
+ <!--org.wso2.carbon.datasource.DataSourceInformationRepositoryService,-->
+ <!--org.wso2.carbon.registry.core.service.RegistryService,-->
+ <!--org.wso2.carbon.user.core.service.RealmService,-->
+ <!--org.wso2.carbon.event.core.EventBroker-->
+ <!--</Axis2RequiredServices>-->
</instructions>
</configuration>
</plugin>
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBDeployer.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBDeployer.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBDeployer.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBDeployer.java Thu Oct 13 22:50:58 2011
@@ -124,12 +124,14 @@
RealmService realmService = DataServicesDSComponent.getRealmService();
if (realmService != null) {
try {
- SuperTenantCarbonContext.getCurrentContext().setUserRealm(realmService.getBootstrapRealm());
+ SuperTenantCarbonContext.getCurrentContext().setUserRealm(
+ realmService.getBootstrapRealm());
} catch (UserStoreException e) {
throw new DeploymentException(e);
}
}
- SuperTenantCarbonContext.getCurrentContext().setUsername(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
+ SuperTenantCarbonContext.getCurrentContext().setUsername(
+ CarbonConstants.REGISTRY_SYSTEM_USERNAME);
DBUtils.setDeploymentTimeTenantId(tenantId);
} catch (Error e) {
/* during unit tests, this may occur */
@@ -183,9 +185,11 @@
/* finished deploying successfully */
successfullyDeployed = true;
- /* the following section is to remove a faulty service, if there's one already registered */
+ /* the following section is to remove a faulty service, if there's one already
+ registered */
String faultyServiceFilePath = deploymentFileData.getFile().getAbsolutePath();
- AxisService faultyService = CarbonUtils.getFaultyService(faultyServiceFilePath, this.configCtx);
+ AxisService faultyService = CarbonUtils.getFaultyService(faultyServiceFilePath,
+ this.configCtx);
if (faultyService != null) {
this.axisConfig.removeFaultyService(faultyServiceFilePath);
}
@@ -392,7 +396,8 @@
}
}
}
- Iterator<OMElement> queryElements = configElement.getChildrenWithName(new QName(DBSFields.QUERY));
+ Iterator<OMElement> queryElements =
+ configElement.getChildrenWithName(new QName(DBSFields.QUERY));
while (queryElements.hasNext()) {
OMElement query = queryElements.next();
String useConfig = query.getAttributeValue(new QName(
@@ -508,29 +513,40 @@
AxisMessage inMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
if (inMessage != null) {
inMessage.setName(operationName + Java2WSDLConstants.MESSAGE_SUFFIX);
- createAxisBindingMessage(soap11BindingOperation, inMessage, WSDLConstants.MESSAGE_LABEL_IN_VALUE, false);
- createAxisBindingMessage(soap12BindingOperation, inMessage, WSDLConstants.MESSAGE_LABEL_IN_VALUE, false);
- createAxisBindingMessage(httpBindingOperation, inMessage, WSDLConstants.MESSAGE_LABEL_IN_VALUE, false);
+ createAxisBindingMessage(soap11BindingOperation, inMessage,
+ WSDLConstants.MESSAGE_LABEL_IN_VALUE, false);
+ createAxisBindingMessage(soap12BindingOperation, inMessage,
+ WSDLConstants.MESSAGE_LABEL_IN_VALUE, false);
+ createAxisBindingMessage(httpBindingOperation, inMessage,
+ WSDLConstants.MESSAGE_LABEL_IN_VALUE, false);
}
if (axisOperation instanceof InOutAxisOperation) {
- AxisMessage outMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+ AxisMessage outMessage =
+ axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
if (outMessage != null) {
outMessage.setName(operationName + Java2WSDLConstants.RESPONSE_MESSAGE);
- createAxisBindingMessage(soap11BindingOperation, outMessage, WSDLConstants.MESSAGE_LABEL_OUT_VALUE, false);
- createAxisBindingMessage(soap12BindingOperation, outMessage, WSDLConstants.MESSAGE_LABEL_OUT_VALUE, false);
- createAxisBindingMessage(httpBindingOperation, outMessage, WSDLConstants.MESSAGE_LABEL_OUT_VALUE, false);
+ createAxisBindingMessage(soap11BindingOperation, outMessage,
+ WSDLConstants.MESSAGE_LABEL_OUT_VALUE, false);
+ createAxisBindingMessage(soap12BindingOperation, outMessage,
+ WSDLConstants.MESSAGE_LABEL_OUT_VALUE, false);
+ createAxisBindingMessage(httpBindingOperation, outMessage,
+ WSDLConstants.MESSAGE_LABEL_OUT_VALUE, false);
}
}
AxisMessage faultMessage = new AxisMessage();
faultMessage.setName(DBConstants.DS_FAULT_ELEMENT);
- faultMessage.setElementQName(new QName(DBConstants.WSO2_DS_NAMESPACE, DBConstants.DS_FAULT_ELEMENT));
+ faultMessage.setElementQName(new QName(DBConstants.WSO2_DS_NAMESPACE,
+ DBConstants.DS_FAULT_ELEMENT));
axisOperation.setFaultMessages(faultMessage);
- createAxisBindingMessage(soap11BindingOperation, faultMessage, WSDLConstants.MESSAGE_LABEL_FAULT_VALUE, true);
- createAxisBindingMessage(soap12BindingOperation, faultMessage, WSDLConstants.MESSAGE_LABEL_FAULT_VALUE, true);
- createAxisBindingMessage(httpBindingOperation, faultMessage, WSDLConstants.MESSAGE_LABEL_FAULT_VALUE, true);
+ createAxisBindingMessage(soap11BindingOperation, faultMessage,
+ WSDLConstants.MESSAGE_LABEL_FAULT_VALUE, true);
+ createAxisBindingMessage(soap12BindingOperation, faultMessage,
+ WSDLConstants.MESSAGE_LABEL_FAULT_VALUE, true);
+ createAxisBindingMessage(httpBindingOperation, faultMessage,
+ WSDLConstants.MESSAGE_LABEL_FAULT_VALUE, true);
axisOperation.setDocumentation(description);
return axisOperation;
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBUtils.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBUtils.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBUtils.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DBUtils.java Thu Oct 13 22:50:58 2011
@@ -144,6 +144,7 @@
conversionTypes.put(DBConstants.DataTypes.TIME, "java.sql.Time");
conversionTypes.put(DBConstants.DataTypes.TIMESTAMP, "java.sql.Timestamp");
conversionTypes.put(DBConstants.DataTypes.ANYURI, "java.net.URI");
+ conversionTypes.put(DBConstants.DataTypes.STRUCT, "java.sql.Struct");
xsdSqlTypeMap = new HashMap<String,String>();
xsdSqlTypeMap.put("string", DBConstants.DataTypes.STRING);
@@ -246,51 +247,47 @@
* Retrieves the current user's roles.
*/
public static String[] getUserRoles(MessageContext msgContext)
- throws DataServiceFault, Exception {
- HttpServletRequest request = (HttpServletRequest) msgContext
- .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
-
- HttpSession httpSession = request.getSession(false);
- String userName = DBUtils.getUsername(msgContext);
-
- RealmService realmService = DataServicesDSComponent.getRealmService();
- RegistryService registryService = DataServicesDSComponent.getRegistryService();
-
- /* if session does not exist, return empty array of roles */
- if (httpSession == null) {
- return new String[0];
- }
-
- /* first return the tenant id from the tenant domain */
- SuperTenantCarbonContext carbonContext = SuperTenantCarbonContext.getCurrentContext(httpSession);
+ throws DataServiceFault {
+ HttpServletRequest request = (HttpServletRequest) msgContext.getProperty(
+ HTTPConstants.MC_HTTP_SERVLETREQUEST);
+ HttpSession httpSession = request.getSession(false);
+ String userName = DBUtils.getUsername(msgContext);
+ RealmService realmService = DataServicesDSComponent.getRealmService();
+ RegistryService registryService = DataServicesDSComponent.getRegistryService();
+ /* if session does not exist, return empty array of roles */
+ if (httpSession == null) {
+ return new String[0];
+ }
+ /* first return the tenant id from the tenant domain */
+ SuperTenantCarbonContext carbonContext = SuperTenantCarbonContext
+ .getCurrentContext(httpSession);
String tenantDomain = carbonContext.getTenantDomain();
- int tenantId = carbonContext.getTenantId();
- if (tenantId < 0) {
- tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
- }
- if (tenantId < 0) {
- /* the tenant doesn't exist. */
- log.error("The tenant doesn't exist. Tenant domain:" + tenantDomain);
- throw new DataServiceFault("Access Denied. You are not authorized.");
- }
- if (!realmService.getTenantManager().isTenantActive(tenantId)) {
- /* the tenant is not active. */
- log.error("The tenant is not active. Tenant domain:" + tenantDomain);
- throw new DataServiceFault("The tenant is not active. Tenant domain:" + tenantDomain);
- }
- UserRealm realm;
- String roles[];
- try {
- realm = registryService.getUserRealm(tenantId);
- roles = realm.getUserStoreManager().getRoleListOfUser(userName);
- } catch (Exception e) {
- String msg = "Error in retrieving the realm for the tenant id: " + tenantId
- + ", username: " + userName + ". " + e.getMessage();
- log.error(msg);
- throw new DataServiceFault(msg);
- }
- return roles;
- }
+ int tenantId = carbonContext.getTenantId();
+ try {
+ if (tenantId < 0) {
+ tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
+ }
+ if (tenantId < 0) {
+ /* the tenant doesn't exist. */
+ log.error("The tenant doesn't exist. Tenant domain:" + tenantDomain);
+ throw new DataServiceFault("Access Denied. You are not authorized.");
+ }
+ if (!realmService.getTenantManager().isTenantActive(tenantId)) {
+ /* the tenant is not active. */
+ log.error("The tenant is not active. Tenant domain:" + tenantDomain);
+ throw new DataServiceFault("The tenant is not active. Tenant domain:"
+ + tenantDomain);
+ }
+ UserRealm realm = registryService.getUserRealm(tenantId);
+ String roles[] = realm.getUserStoreManager().getRoleListOfUser(userName);
+ return roles;
+ } catch (Exception e) {
+ String msg = "Error in retrieving the realm for the tenant id: " + tenantId
+ + ", username: " + userName + ". " + e.getMessage();
+ log.error(msg);
+ throw new DataServiceFault(msg);
+ }
+ }
public static boolean isRegistryPath(String path) {
if (path.startsWith(DBConstants.CONF_REGISTRY_PATH_PREFIX) || path.startsWith(DBConstants.GOV_REGISTRY_PATH_PREFIX)) {
@@ -607,6 +604,9 @@
if (typeName.equals("java.net.URI")) {
return new QName(DBConstants.XSD_NAMESPACE, "anyURI");
}
+ if (typeName.equals("java.sql.Struct")) {
+ return new QName (DBConstants.XSD_NAMESPACE, "anyType");
+ }
return typeTable.getSimpleSchemaTypeName(typeName);
}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DataServices.xsd
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DataServices.xsd?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DataServices.xsd (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/DataServices.xsd Thu Oct 13 22:50:58 2011
@@ -33,7 +33,12 @@
<xs:element name="query" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
- <xs:element name="sql"/>
+ <xs:element name="sql" maxOccurs="unbounded" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="dialect" use="optional"/>
+ </xs:complexType>
+ </xs:elemenet>
+ <xs:element name="sparql" maxOccurs="1" minOccurs="0"/>
<xs:element name="properties" maxOccurs="1" minOccurs="0">
<xs:complexType>
<xs:sequence>
@@ -57,6 +62,7 @@
<xs:attribute name="column" use="required"/>
<xs:attribute name="xsdType" use="optional"/>
<xs:attribute name="requiredRoles" use="optional"/>
+ <xs:attribute name="export" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="attribute" maxOccurs="unbounded" minOccurs="0">
@@ -154,6 +160,7 @@
<xs:attribute name="type" use="optional"/>
<xs:attribute name="ordinal" use="optional"/>
<xs:attribute name="defaultValue" use="optional"/>
+ <xs:attribute name="structType" use="optional"/>
</xs:complexType>
</xs:element>
</xs:choice>
@@ -220,6 +227,7 @@
</xs:element>
</xs:choice>
<xs:attribute name="name" use="required"/>
+ <xs:attribute name="disableStreaming" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="resource" maxOccurs="unbounded" minOccurs="0">
@@ -251,6 +259,7 @@
<xs:attribute name="enableBoxcarring" use="optional"/>
<xs:attribute name="serviceStatus" use="optional"/>
<xs:attribute name="baseURI" use="optional"/>
+ <xs:attribute name="enableDTP" use="optional"/>
</xs:complexType>
</xs:element>
-</xs:schema>
\ No newline at end of file
+</xs:schema>
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/WSDLToDataService.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/WSDLToDataService.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/WSDLToDataService.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/WSDLToDataService.java Thu Oct 13 22:50:58 2011
@@ -18,32 +18,9 @@
*/
package org.wso2.carbon.dataservices.core;
-import java.io.BufferedWriter;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
import org.apache.axiom.om.util.AXIOMUtil;
import org.apache.axis2.AxisFault;
-import org.apache.axis2.description.AxisMessage;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
-import org.apache.axis2.description.WSDL20ToAxisServiceBuilder;
+import org.apache.axis2.description.*;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.schema.CompilerOptions;
import org.apache.axis2.schema.SchemaCompilationException;
@@ -51,15 +28,7 @@
import org.apache.axis2.util.XMLPrettyPrinter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.ws.commons.schema.XmlSchemaAttribute;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaObject;
-import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
-import org.apache.ws.commons.schema.XmlSchemaParticle;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
-import org.apache.ws.commons.schema.XmlSchemaSimpleType;
-import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -69,18 +38,19 @@
import org.wso2.carbon.dataservices.core.description.config.RDBMSConfig;
import org.wso2.carbon.dataservices.core.description.operation.Operation;
import org.wso2.carbon.dataservices.core.description.query.SQLQuery;
-import org.wso2.carbon.dataservices.core.engine.CallQuery;
+import org.wso2.carbon.dataservices.core.engine.*;
import org.wso2.carbon.dataservices.core.engine.CallQuery.WithParam;
-import org.wso2.carbon.dataservices.core.engine.CallQueryGroup;
-import org.wso2.carbon.dataservices.core.engine.DataService;
-import org.wso2.carbon.dataservices.core.engine.DataServiceSerializer;
-import org.wso2.carbon.dataservices.core.engine.OutputElementGroup;
-import org.wso2.carbon.dataservices.core.engine.ParamValue;
-import org.wso2.carbon.dataservices.core.engine.QueryParam;
-import org.wso2.carbon.dataservices.core.engine.Result;
-import org.wso2.carbon.dataservices.core.engine.StaticOutputElement;
import org.wso2.carbon.dataservices.core.validation.Validator;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.*;
+import java.net.URL;
+import java.util.*;
+
/**
* This class is used to create a data service using a given WSDL (create
* contract first data services).
@@ -363,7 +333,7 @@
prop.isArray() ? DBConstants.QueryParamTypes.ARRAY :
DBConstants.QueryParamTypes.SCALAR,
i + 1, // ordinal
- null, new ArrayList<Validator>()));
+ null, null, new ArrayList<Validator>()));
}
return queryParams;
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/XSLTTransformer.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/XSLTTransformer.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/XSLTTransformer.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/XSLTTransformer.java Thu Oct 13 22:50:58 2011
@@ -18,17 +18,12 @@
*/
package org.wso2.carbon.dataservices.core;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.jaxp.OMSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.dataservices.common.DBConstants;
-import org.wso2.carbon.dataservices.core.internal.DataServicesDSComponent;
import org.wso2.carbon.dataservices.core.listeners.RegistryServiceListener;
import org.wso2.carbon.registry.core.service.RegistryService;
@@ -40,6 +35,9 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
/**
* This class is used in transforming data services result using XSLT.
@@ -63,7 +61,6 @@
this.tenantId = DBUtils.getDeploymentTimeTenantId();
if (xsltPath.startsWith(DBConstants.CONF_REGISTRY_PATH_PREFIX) ||
xsltPath.startsWith(DBConstants.GOV_REGISTRY_PATH_PREFIX)) {
- DataServicesDSComponent.registerRegistryServiceListener(this);
} else {
TransformerFactory tFactory = TransformerFactory.newInstance();
this.transformer = tFactory.newTransformer(
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CSVConfig.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CSVConfig.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CSVConfig.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CSVConfig.java Thu Oct 13 22:50:58 2011
@@ -18,11 +18,7 @@
*/
package org.wso2.carbon.dataservices.core.description.config;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Map;
-
+import au.com.bytecode.opencsv.CSVReader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.dataservices.common.DBConstants;
@@ -30,11 +26,13 @@
import org.wso2.carbon.dataservices.core.DBUtils;
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.engine.DataService;
-import org.wso2.carbon.dataservices.core.internal.DataServicesDSComponent;
import org.wso2.carbon.dataservices.core.listeners.RegistryServiceListener;
import org.wso2.carbon.registry.core.service.RegistryService;
-import au.com.bytecode.opencsv.CSVReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Map;
/**
* This class represents a CSV based data source configuration.
@@ -86,16 +84,13 @@
this.hasHeader = false;
}
- if (DBUtils.isRegistryPath(this.getCsvDataSourcePath())) {
- /* register registry service listener */
- DataServicesDSComponent.registerRegistryServiceListener(this);
- } else {
+ if (!DBUtils.isRegistryPath(this.getCsvDataSourcePath())) {
try {
this.columnMappings = DBUtils.createColumnMappings(this.getHeader());
} catch (IOException e) {
throw new DataServiceFault("Error in creating CSV column mappings.");
- }
- }
+ }
+ }
}
private char extractColumnSeparator(String value) {
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CarbonDataSourceConfig.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CarbonDataSourceConfig.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CarbonDataSourceConfig.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/CarbonDataSourceConfig.java Thu Oct 13 22:50:58 2011
@@ -18,13 +18,6 @@
*/
package org.wso2.carbon.dataservices.core.description.config;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.commons.datasource.DataSourceInformation;
@@ -38,6 +31,12 @@
import org.wso2.carbon.dataservices.core.listeners.CarbonDataSourceServiceListener;
import org.wso2.carbon.datasource.DataSourceInformationRepositoryService;
+import javax.sql.DataSource;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/**
* This class represents a Carbon Data Source based data source configuration.
*/
@@ -53,7 +52,6 @@
Map<String, String> properties) throws DataServiceFault {
super(dataService, configId, DataSourceTypes.CARBON, properties);
this.dataSourceName = properties.get(DBConstants.CarbonDatasource.NAME);
- DataServicesDSComponent.registerCarbonDataSourceServiceListener(this);
}
@Override
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/GSpreadConfig.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/GSpreadConfig.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/GSpreadConfig.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/config/GSpreadConfig.java Thu Oct 13 22:50:58 2011
@@ -18,9 +18,9 @@
*/
package org.wso2.carbon.dataservices.core.description.config;
-import java.net.URL;
-import java.util.Map;
-
+import com.google.gdata.client.GoogleAuthTokenFactory.UserToken;
+import com.google.gdata.client.spreadsheet.SpreadsheetService;
+import com.google.gdata.data.IFeed;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.dataservices.common.DBConstants;
@@ -36,9 +36,8 @@
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.service.RegistryService;
-import com.google.gdata.client.GoogleAuthTokenFactory.UserToken;
-import com.google.gdata.client.spreadsheet.SpreadsheetService;
-import com.google.gdata.data.IFeed;
+import java.net.URL;
+import java.util.Map;
/**
* This class represents a Google Spreadsheet based data source configuration.
@@ -73,8 +72,6 @@
this.service = new SpreadsheetService(this.getDataService().getName() +
":" + this.getConfigId());
}
- /* register registry service listener */
- DataServicesDSComponent.registerRegistryServiceListener(this);
}
private void initRegistryService(RegistryService registryService) {
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/ExcelQuery.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/ExcelQuery.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/ExcelQuery.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/ExcelQuery.java Thu Oct 13 22:50:58 2011
@@ -30,7 +30,6 @@
import org.wso2.carbon.dataservices.core.description.config.ExcelConfig;
import org.wso2.carbon.dataservices.core.description.event.EventTrigger;
import org.wso2.carbon.dataservices.core.engine.*;
-import org.wso2.carbon.dataservices.core.internal.DataServicesDSComponent;
import org.wso2.carbon.dataservices.core.listeners.RegistryServiceListener;
import org.wso2.carbon.registry.core.service.RegistryService;
@@ -75,18 +74,13 @@
this.hasHeader = hasHeader;
this.startingRow = startingRow;
this.maxRowCount = maxRowCount;
- if (DBUtils.isRegistryPath(config.getExcelDataSourcePath())) {
- /* register registry service listener */
- DataServicesDSComponent.registerRegistryServiceListener(this);
- } else {
- try {
+ if (!DBUtils.isRegistryPath(config.getExcelDataSourcePath())) {
+ try {
this.columnMappings = DBUtils.createColumnMappings(this.getHeader());
} catch (Exception e) {
throw new DataServiceFault(e, "Error in creating Excel column mappings.");
- }
-
+ }
}
-
}
public Map<Integer, String> getColumnMappings() {
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/Query.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/Query.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/Query.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/Query.java Thu Oct 13 22:50:58 2011
@@ -178,10 +178,9 @@
}
}
}
- ipc.addParam(new InternalParam(queryParam.getName(),
- tmpParamValue, queryParam.getSqlType(),
- queryParam.getType(), queryParam.getOrdinal()));
-
+ ipc.addParam(new InternalParam(queryParam.getName(), tmpParamValue,
+ queryParam.getSqlType(), queryParam.getType(), queryParam.getStructType(),
+ queryParam.getOrdinal()));
}
return ipc;
}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/QueryFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/QueryFactory.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/QueryFactory.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/QueryFactory.java Thu Oct 13 22:50:58 2011
@@ -29,7 +29,6 @@
import org.wso2.carbon.dataservices.core.description.event.EventTrigger;
import org.wso2.carbon.dataservices.core.engine.*;
import org.wso2.carbon.dataservices.core.engine.CallQuery.WithParam;
-import org.wso2.carbon.dataservices.core.internal.DataServicesDSComponent;
import org.wso2.carbon.dataservices.core.validation.Validator;
import org.wso2.carbon.dataservices.core.validation.standard.*;
@@ -130,7 +129,10 @@
/**
* This method returns the input and output event triggers in a query.
* Returns [0] - Input EventTrigger, [1] - Output EventTrigger.
- * @see EventTrigger
+ * @param dataService corresponding dataservice object
+ * @param queryEl dataservices query element
+ * @see EventTrigger
+ * @return array of Event Trigger objects
*/
private static EventTrigger[] getEventTriggers(DataService dataService, OMElement queryEl) {
EventTrigger inputEventTrigger = null;
@@ -303,17 +305,12 @@
} catch (Exception e) {
throw new DataServiceFault(e, "Error in parsing SQL query element");
}
- Config config = dataService.getConfig(configId);
SQLQuery query = new SQLQuery(dataService, queryId, configId,
returnGeneratedKeys, keyColumns, sql, getQueryParamsFromQueryElement(queryEl),
result, eventTriggers[0], eventTriggers[1],
extractAdvancedProps(queryEl), inputNamespace);
if (sql == null) {
- String carbonDataSource = config.getProperty(CarbonDatasource.NAME);
- if (carbonDataSource != null) {
- DataServicesDSComponent.registerCarbonDataSourceServiceListener(
- new SQLQueryDialectCarbonDSListener(query, queryEl, carbonDataSource));
- }
+ throw new DataServiceFault("Unable to retrieve SQL query string");
}
return query;
}
@@ -603,7 +600,7 @@
Iterator<OMElement> paramItr = queryEl.getChildrenWithName(new QName(DBSFields.PARAM));
OMElement paramEl;
- String name, sqlType, type, paramType, ordinalStr, defaultValue;
+ String name, sqlType, type, paramType, ordinalStr, defaultValue, structType;
int ordinal, currentTmpOrdinal = 0;
while (paramItr.hasNext()) {
@@ -629,8 +626,11 @@
}
/* retrieve validators */
List<Validator> validators = getValidators(paramType, paramEl);
+ /* retrieve struct type */
+ structType = paramEl.getAttributeValue(new QName(DBSFields.STRUCT_TYPE));
queryParams.add(new QueryParam(name, sqlType, type, paramType, ordinal,
- defaultValue == null ? null : new ParamValue(defaultValue), validators));
+ defaultValue == null ? null : new ParamValue(defaultValue), structType,
+ validators));
}
return queryParams;
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/SQLQuery.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/SQLQuery.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/SQLQuery.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/description/query/SQLQuery.java Thu Oct 13 22:50:58 2011
@@ -51,241 +51,249 @@
* This class represents an SQL query in a data service.
*/
public class SQLQuery extends Query implements BatchRequestParticipant {
-
- private static final Log log = LogFactory.getLog(SQLQuery.class);
-
- public static final int DS_QUERY_TYPE_NORMAL = 0x01;
-
- public static final int DS_QUERY_TYPE_STORED_PROC = 0x02;
-
- public static final int ORACLE_REF_CURSOR_TYPE = -10;
-
- private String query;
-
- private SQLConfig config;
-
- private int queryType;
-
- private List<QueryParam> outQueryParams;
-
- private List<QueryParam> onlyOutQueryParams;
-
- private boolean hasOutParams;
-
- private boolean resultOnlyOutParams;
-
- private int[] namedParamIndices;
-
- private List<String> namedParamNames;
-
- private boolean hasOrdinalOffsets;
-
- private QueryParam currentRefCursor;
-
- private boolean hasRefCursor;
+
+ private static final Log log = LogFactory.getLog(SQLQuery.class);
+
+ public static final int DS_QUERY_TYPE_NORMAL = 0x01;
+
+ public static final int DS_QUERY_TYPE_STORED_PROC = 0x02;
+
+ public static final int ORACLE_REF_CURSOR_TYPE = -10;
+
+ private String query;
+
+ private SQLConfig config;
+
+ private int queryType;
+
+ private List<QueryParam> outQueryParams;
+
+ private List<QueryParam> onlyOutQueryParams;
+
+ private boolean hasOutParams;
+
+ private boolean resultOnlyOutParams;
+
+ private int[] namedParamIndices;
+
+ private List<String> namedParamNames;
+
+ private QueryParam currentRefCursor;
+
+ private boolean hasRefCursor;
+
+ private QueryParam currentSqlArray;
+
+ private boolean hasSqlArrayType;
private int prevRefCursorOrdinal;
private boolean arrayTypesEnabled = false;
-
- private String sql;
-
- private int paramCount;
-
- private int optimalRSFetchSize;
-
- private boolean hasFetchDirection;
-
- private boolean hasFetchSize;
-
- private boolean hasMaxFieldSize;
-
- private boolean hasMaxRows;
-
- private boolean hasQueryTimeout;
-
- private int fetchDirection;
-
- private int fetchSize;
-
- private int maxFieldSize;
-
- private int maxRows;
-
- private int queryTimeout;
-
- private boolean returnGeneratedKeys;
-
- private String[] keyColumns;
-
- private boolean hasBatchQuerySupport;
-
- private AutoCommit autoCommit;
-
- private boolean forceStoredProc;
-
- private boolean forceJDBCBatchReqs;
-
- private boolean inited;
-
- /** thread local variable to keep a PreparedStatement in batch processing */
- private ThreadLocal<PreparedStatement> batchPreparedStatement = new ThreadLocal<PreparedStatement>() {
- protected synchronized PreparedStatement initialValue() {
- return null;
- }
- };
-
- public SQLQuery(DataService dataService, String queryId, String configId, boolean returnGeneratedKeys,
- String[] keyColumns, String query, List<QueryParam> queryParams, Result result,
- EventTrigger inputEventTrigger, EventTrigger outputEventTrigger,
- Map<String, String> advancedProperties, String inputNamespace)
- throws DataServiceFault {
- super(dataService, queryId, queryParams, result, configId,
- inputEventTrigger, outputEventTrigger, advancedProperties, inputNamespace);
- this.returnGeneratedKeys = returnGeneratedKeys;
- this.keyColumns = keyColumns;
- this.query = query;
- try {
- this.config = (SQLConfig) this.getDataService().getConfig(this.getConfigId());
- } catch (ClassCastException e) {
- throw new DataServiceFault(e, "Configuration is not an SQL config:" +
- this.getConfigId());
- }
- /* only if this has a query, it can be that the query is null, because it came from a
- * dialect related to a carbon data source, where it may not be available yet */
- if (this.getQuery() != null) {
- init();
- }
- }
-
- public void init () throws DataServiceFault {
- /* process the advanced/additional properties */
- this.processAdvancedProps(this.getAdvancedProperties());
- this.queryType = this.retrieveQueryType(this.getQuery());
- this.outQueryParams = this.extractOutQueryParams(this.getQueryParams());
- this.onlyOutQueryParams = this.extractOnlyOutQueryParams(this.getOutQueryParams());
- this.processNamedParams();
- /* re-format sql query with named params */
- this.sql = this.createSqlFromQueryString(this.getQuery());
- this.paramCount = this.calculateParamCount(this.getSql());
- /* check for existence of any ref cursors */
- this.checkRefCursor(this.getQueryParams());
- this.hasOutParams = this.getOutQueryParams().size() > 0;
- /* first a result should be available and then check the other necessary conditions */
- this.resultOnlyOutParams = this.calculateResultOnlyOutParams();
- /* set the optimal JDBC result set fetch size */
- this.optimalRSFetchSize = DBUtils.getOptimalRSFetchSizeForRDBMS(
- this.getConfig().getProperty(RDBMS.PROTOCOL));
- /* set batch update support for this query */
- try {
- this.hasBatchQuerySupport = this.getDataService().isBatchRequestsEnabled() &&
+
+ private String sql;
+
+ private int paramCount;
+
+ private int optimalRSFetchSize;
+
+ private boolean hasFetchDirection;
+
+ private boolean hasFetchSize;
+
+ private boolean hasMaxFieldSize;
+
+ private boolean hasMaxRows;
+
+ private boolean hasQueryTimeout;
+
+ private int fetchDirection;
+
+ private int fetchSize;
+
+ private int maxFieldSize;
+
+ private int maxRows;
+
+ private int queryTimeout;
+
+ private boolean returnGeneratedKeys;
+
+ private String[] keyColumns;
+
+ private boolean hasBatchQuerySupport;
+
+ private AutoCommit autoCommit;
+
+ private boolean forceStoredProc;
+
+ private boolean forceJDBCBatchReqs;
+
+ private boolean inited;
+
+
+ /**
+ * thread local variable to keep a PreparedStatement in batch processing
+ */
+ private ThreadLocal<PreparedStatement> batchPreparedStatement = new ThreadLocal<PreparedStatement>() {
+ protected synchronized PreparedStatement initialValue() {
+ return null;
+ }
+ };
+
+ public SQLQuery(DataService dataService, String queryId, String configId, boolean returnGeneratedKeys,
+ String[] keyColumns, String query, List<QueryParam> queryParams, Result result,
+ EventTrigger inputEventTrigger, EventTrigger outputEventTrigger,
+ Map<String, String> advancedProperties, String inputNamespace)
+ throws DataServiceFault {
+ super(dataService, queryId, queryParams, result, configId,
+ inputEventTrigger, outputEventTrigger, advancedProperties, inputNamespace);
+ this.returnGeneratedKeys = returnGeneratedKeys;
+ this.keyColumns = keyColumns;
+ this.query = query;
+ try {
+ this.config = (SQLConfig) this.getDataService().getConfig(this.getConfigId());
+ } catch (ClassCastException e) {
+ throw new DataServiceFault(e, "Configuration is not an SQL config:" +
+ this.getConfigId());
+ }
+ /* only if this has a query, it can be that the query is null, because it came from a
+ * dialect related to a carbon data source, where it may not be available yet */
+ if (this.getQuery() != null) {
+ init();
+ }
+ }
+
+ public void init() throws DataServiceFault {
+ /* process the advanced/additional properties */
+ this.processAdvancedProps(this.getAdvancedProperties());
+ this.queryType = this.retrieveQueryType(this.getQuery());
+ this.outQueryParams = this.extractOutQueryParams(this.getQueryParams());
+ this.onlyOutQueryParams = this.extractOnlyOutQueryParams(this.getOutQueryParams());
+ this.processNamedParams();
+ /* re-format sql query with named params */
+ this.sql = this.createSqlFromQueryString(this.getQuery());
+ this.paramCount = this.calculateParamCount(this.getSql());
+ /* check for existence of any ref cursors */
+ this.checkRefCursor(this.getQueryParams());
+ /* check for existence of any SQL Arrays */
+ this.checkSqlArrayType(this.getQueryParams());
+ this.hasOutParams = this.getOutQueryParams().size() > 0;
+ /* first a result should be available and then check the other necessary conditions */
+ this.resultOnlyOutParams = this.calculateResultOnlyOutParams();
+ /* set the optimal JDBC result set fetch size */
+ this.optimalRSFetchSize = DBUtils.getOptimalRSFetchSizeForRDBMS(
+ this.getConfig().getProperty(RDBMS.PROTOCOL));
+ /* set batch update support for this query */
+ try {
+ this.hasBatchQuerySupport = this.getDataService().isBatchRequestsEnabled() &&
(this.isForceJDBCBatchReqs() || this.calculateBatchQuerySupport());
- } catch (DataServiceFault e) {
- this.hasBatchQuerySupport = false;
- log.warn("Unable to determine batch query support for query '" + this.getQueryId() +
- "' : " + e.getMessage() + " - batch query support is disabled.");
- }
-
- this.setInited(true);
- }
-
- private boolean calculateResultOnlyOutParams() {
- return (this.getResult() != null) && (this.hasRefCursor() ||
- (this.hasOutParams() &&
- ((this.getResult().getDefaultElementGroup().getAllElements().size() +
- this.getResult().getDefaultElementGroup().getAttributeEntries().size()) ==
- this.getOutQueryParams().size())));
- }
-
- /**
- * Extract the stored proc name from the SQL.
- * @param skipFirstWord If the first word should be considered the name or not,
- * if this is true, the second word will be considered as the stored proc name
- * @return The stored procedure name
- */
- private String extractStoredProcName(boolean skipFirstWord) {
- String sql = this.getSql();
- String[] tokens = removeSpaces(sql.split("\\s|\\(|\\["));
- if (skipFirstWord) {
- if (tokens.length < 2) {
- return null;
- }
- return tokens[1];
- } else {
- if (tokens.length < 1) {
- return null;
- }
- return tokens[0];
- }
- }
-
- private static String[] removeSpaces(String[] vals) {
- List<String> result = new ArrayList<String>();
- for (String val : vals) {
- if (val.trim().length() > 0) {
- result.add(val);
- }
- }
- return result.toArray(new String[result.size()]);
- }
-
- private Object[] getStoredProcFuncProps(String name) throws DataServiceFault, SQLException {
- Connection conn = this.getConfig().createConnection();
- DatabaseMetaData md = conn.getMetaData();
- ResultSet rs = md.getProcedureColumns(null, null, name, "%");
+ } catch (DataServiceFault e) {
+ this.hasBatchQuerySupport = false;
+ log.warn("Unable to determine batch query support for query '" + this.getQueryId() +
+ "' : " + e.getMessage() + " - batch query support is disabled.");
+ }
+
+ this.setInited(true);
+ }
+
+ private boolean calculateResultOnlyOutParams() {
+ return (this.getResult() != null) && (this.hasRefCursor() || this.hasSqlArrayType() ||
+ (this.hasOutParams() &&
+ ((this.getResult().getDefaultElementGroup().getAllElements().size() +
+ this.getResult().getDefaultElementGroup().getAttributeEntries().size()) ==
+ this.getOutQueryParams().size())));
+ }
+
+ /**
+ * Extract the stored proc name from the SQL.
+ *
+ * @param skipFirstWord If the first word should be considered the name or not,
+ * if this is true, the second word will be considered as the stored proc name
+ * @return The stored procedure name
+ */
+ private String extractStoredProcName(boolean skipFirstWord) {
+ String sql = this.getSql();
+ String[] tokens = removeSpaces(sql.split("\\s|\\(|\\["));
+ if (skipFirstWord) {
+ if (tokens.length < 2) {
+ return null;
+ }
+ return tokens[1];
+ } else {
+ if (tokens.length < 1) {
+ return null;
+ }
+ return tokens[0];
+ }
+ }
+
+ private static String[] removeSpaces(String[] vals) {
+ List<String> result = new ArrayList<String>();
+ for (String val : vals) {
+ if (val.trim().length() > 0) {
+ result.add(val);
+ }
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
+ private Object[] getStoredProcFuncProps(String name) throws DataServiceFault, SQLException {
+ Connection conn = this.getConfig().createConnection();
+ DatabaseMetaData md = conn.getMetaData();
+ ResultSet rs = md.getProcedureColumns(null, null, name, "%");
Object[] resultMap = new Object[2];
- if (!rs.next()) {
+ if (!rs.next()) {
rs.close();
- rs = md.getFunctionColumns(null, null, name, "%");
- } else {
+ rs = md.getFunctionColumns(null, null, name, "%");
+ } else {
rs.close();
rs = md.getProcedureColumns(null, null, name, "%");
}
resultMap[0] = conn;
resultMap[1] = rs;
- return resultMap;
- }
-
- private boolean calculateBatchQuerySupport() throws DataServiceFault {
- Object[] resultMap ;
+ return resultMap;
+ }
+
+ private boolean calculateBatchQuerySupport() throws DataServiceFault {
+ Object[] resultMap;
List<Connection> connections = new ArrayList<Connection>();
- if (this.getConfig().hasJDBCBatchUpdateSupport()) {
- if (this.getQueryType() == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
- try {
+ if (this.getConfig().hasJDBCBatchUpdateSupport()) {
+ if (this.getQueryType() == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
+ try {
resultMap = this.getStoredProcFuncProps(this.extractStoredProcName(true));
- ResultSet rs = (ResultSet) resultMap[1];
+ ResultSet rs = (ResultSet) resultMap[1];
connections.add((Connection) resultMap[0]);
if (!rs.next()) {
resultMap = this.getStoredProcFuncProps(this.extractStoredProcName(false));
- rs = (ResultSet) resultMap[1];
+ rs = (ResultSet) resultMap[1];
connections.add((Connection) resultMap[0]);
- if (!rs.next()) {
- throw new DataServiceFault(
- "Cannot find metadata for the stored procedure");
- }
- }
- /* stored procedures here can only have IN params and results which only
- * returns an integer, which has the update count,
- * all other situations are not supported for batch updates */
- StoredProcMetadataCollection mdCollection = new StoredProcMetadataCollection(rs);
- for (StoredProcMetdataEntry entry : mdCollection.getEntries()) {
- switch (entry.getColumnReturn()) {
- case DatabaseMetaData.procedureColumnIn:
- break;
- case DatabaseMetaData.procedureColumnReturn:
- if (!(entry.getColumnDataType() == Types.INTEGER ||
- entry.getColumnDataType() == Types.BIGINT
- || entry.getColumnDataType() == Types.DECIMAL)) {
- return false;
- }
- break;
- default:
- return false;
- }
- }
- return true;
- } catch (Throwable e) {
+ if (!rs.next()) {
+ throw new DataServiceFault(
+ "Cannot find metadata for the stored procedure");
+ }
+ }
+ /* stored procedures here can only have IN params and results which only
+ * returns an integer, which has the update count,
+ * all other situations are not supported for batch updates */
+ StoredProcMetadataCollection mdCollection = new StoredProcMetadataCollection(rs);
+ for (StoredProcMetdataEntry entry : mdCollection.getEntries()) {
+ switch (entry.getColumnReturn()) {
+ case DatabaseMetaData.procedureColumnIn:
+ break;
+ case DatabaseMetaData.procedureColumnReturn:
+ if (!(entry.getColumnDataType() == Types.INTEGER ||
+ entry.getColumnDataType() == Types.BIGINT
+ || entry.getColumnDataType() == Types.DECIMAL)) {
+ return false;
+ }
+ break;
+ default:
+ return false;
+ }
+ }
+ return true;
+ } catch (Throwable e) {
throw new DataServiceFault("Error in retrieving database metadata.");
} finally {
for (Connection aCon : connections) {
@@ -295,1046 +303,1079 @@
}
}
}
- } else {
- return true;
- }
- } else {
- return false;
- }
- }
-
- public boolean isInited() {
- return inited;
- }
-
- public void setInited(boolean inited) {
- this.inited = inited;
- }
-
- public AutoCommit getAutoCommit() {
- return autoCommit;
- }
-
- public boolean hasBatchQuerySupport() {
- return hasBatchQuerySupport;
- }
-
- public int getParamCount() {
- return paramCount;
- }
-
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isInited() {
+ return inited;
+ }
+
+ public void setInited(boolean inited) {
+ this.inited = inited;
+ }
+
+ public AutoCommit getAutoCommit() {
+ return autoCommit;
+ }
+
+ public boolean hasBatchQuerySupport() {
+ return hasBatchQuerySupport;
+ }
+
+ public int getParamCount() {
+ return paramCount;
+ }
+
private PreparedStatement getBatchPreparedStatement() {
- return batchPreparedStatement.get();
+ return batchPreparedStatement.get();
}
-
+
private void setBatchPreparedStatement(PreparedStatement val) {
- batchPreparedStatement.set(val);
+ batchPreparedStatement.set(val);
+ }
+
+ public String[] getKeyColumns() {
+ return keyColumns;
+ }
+
+ public boolean isReturnGeneratedKeys() {
+ return returnGeneratedKeys;
+ }
+
+ public boolean isForceStoredProc() {
+ return forceStoredProc;
+ }
+
+ public boolean isForceJDBCBatchReqs() {
+ return forceJDBCBatchReqs;
+ }
+
+
+ private void processAdvancedProps(Map<String, String> props) throws DataServiceFault {
+ if (props == null) {
+ return;
+ }
+ /* process fetch direction */
+ String fetchDirectionProp = props.get(RDBMS.FETCH_DIRECTION);
+ if (!DBUtils.isEmptyString(fetchDirectionProp)) {
+ fetchDirectionProp = fetchDirectionProp.trim();
+ if (AdvancedSQLProps.FETCH_DIRECTION_FORWARD.equals(fetchDirectionProp)) {
+ this.fetchDirection = ResultSet.FETCH_FORWARD;
+ } else if (AdvancedSQLProps.FETCH_DIRECTION_REVERSE.equals(fetchDirectionProp)) {
+ this.fetchDirection = ResultSet.FETCH_REVERSE;
+ } else {
+ throw new DataServiceFault("Invalid fetch direction: " + fetchDirectionProp +
+ ", valid values are {'" + AdvancedSQLProps.FETCH_DIRECTION_FORWARD +
+ "', '" + AdvancedSQLProps.FETCH_DIRECTION_REVERSE + "'}");
+ }
+ this.hasFetchDirection = true;
+ } else {
+ this.hasFetchDirection = false;
+ }
+ /* process fetch size */
+ String fetchSizeProp = props.get(RDBMS.FETCH_SIZE);
+ if (!DBUtils.isEmptyString(fetchSizeProp)) {
+ fetchSizeProp = fetchSizeProp.trim();
+ try {
+ this.fetchSize = Integer.parseInt(fetchSizeProp);
+ } catch (NumberFormatException e) {
+ throw new DataServiceFault(e, "Invalid fetch size: " + fetchSizeProp +
+ ", fetch size should be an integer");
+ }
+ this.hasFetchSize = true;
+ } else {
+ this.hasFetchSize = false;
+ }
+ /* process max field size */
+ String maxFieldSizeProp = props.get(RDBMS.MAX_FIELD_SIZE);
+ if (!DBUtils.isEmptyString(maxFieldSizeProp)) {
+ maxFieldSizeProp = maxFieldSizeProp.trim();
+ try {
+ this.maxFieldSize = Integer.parseInt(maxFieldSizeProp);
+ if (this.maxFieldSize <= 0) {
+ throw new DataServiceFault("Invalid maximum field size: " + maxFieldSizeProp +
+ ", maximum field size should be a positive integer");
+ }
+ } catch (NumberFormatException e) {
+ throw new DataServiceFault(e, "Invalid maximum field size: " + maxFieldSizeProp +
+ ", maximum field size should be a positive integer");
+ }
+ this.hasMaxFieldSize = true;
+ } else {
+ this.hasMaxFieldSize = false;
+ }
+ /* process max rows */
+ String maxRowsProp = props.get(RDBMS.MAX_ROWS);
+ if (!DBUtils.isEmptyString(maxRowsProp)) {
+ maxRowsProp = maxRowsProp.trim();
+ try {
+ this.maxRows = Integer.parseInt(maxRowsProp);
+ if (this.maxRows <= 0) {
+ throw new DataServiceFault("Invalid maximum rows: " + maxRowsProp +
+ ", maximum rows should be a positive integer");
+ }
+ } catch (NumberFormatException e) {
+ throw new DataServiceFault(e, "Invalid maximum rows: " + maxRowsProp +
+ ", maximum rows should be a positive integer");
+ }
+ this.hasMaxRows = true;
+ } else {
+ this.hasMaxRows = false;
+ }
+ /* process query timeout */
+ String queryTimeoutProp = props.get(RDBMS.QUERY_TIMEOUT);
+ if (!DBUtils.isEmptyString(queryTimeoutProp)) {
+ queryTimeoutProp = queryTimeoutProp.trim();
+ try {
+ this.queryTimeout = Integer.parseInt(queryTimeoutProp);
+ if (this.queryTimeout <= 0) {
+ throw new DataServiceFault("Invalid query timeout: " + queryTimeoutProp +
+ ", query timeout be a positive integer");
+ }
+ } catch (NumberFormatException e) {
+ throw new DataServiceFault(e, "Invalid query timeout: " + queryTimeoutProp +
+ ", query timeout be a positive integer");
+ }
+ this.hasQueryTimeout = true;
+ } else {
+ this.hasQueryTimeout = false;
+ }
+ /* auto commit */
+ /* first check local auto commit setting */
+ String autoCommitProp = props.get(RDBMS.AUTO_COMMIT);
+ if (!DBUtils.isEmptyString(autoCommitProp)) {
+ autoCommitProp = autoCommitProp.trim();
+ try {
+ boolean acBool = Boolean.parseBoolean(autoCommitProp);
+ if (acBool) {
+ this.autoCommit = AutoCommit.AUTO_COMMIT_ON;
+ } else {
+ this.autoCommit = AutoCommit.AUTO_COMMIT_OFF;
+ }
+ } catch (Exception e) {
+ throw new DataServiceFault(e, "Invalid autocommit value: " + autoCommitProp +
+ ", autocommit should be a boolean value");
+ }
+ } else {
+ /* global auto commit setting */
+ this.autoCommit = this.getConfig().getAutoCommit();
+ }
+ /* force stored procedure */
+ String forceStoredProc = props.get(RDBMS.FORCE_STORED_PROC);
+ if (!DBUtils.isEmptyString(forceStoredProc)) {
+ this.forceStoredProc = Boolean.parseBoolean(forceStoredProc);
+ }
+ /* force JDBC batch requests */
+ String forceJDBCBatchRequests = props.get(RDBMS.FORCE_JDBC_BATCH_REQUESTS);
+ if (!DBUtils.isEmptyString(forceJDBCBatchRequests)) {
+ this.forceJDBCBatchReqs = Boolean.parseBoolean(forceJDBCBatchRequests);
+ }
+ }
+
+ public List<String> getNamedParamNames() {
+ return namedParamNames;
+ }
+
+ public boolean isHasFetchDirection() {
+ return hasFetchDirection;
+ }
+
+ public boolean isHasFetchSize() {
+ return hasFetchSize;
+ }
+
+ public boolean isHasMaxFieldSize() {
+ return hasMaxFieldSize;
+ }
+
+ public boolean isHasMaxRows() {
+ return hasMaxRows;
+ }
+
+ public boolean isHasQueryTimeout() {
+ return hasQueryTimeout;
+ }
+
+ public int getFetchDirection() {
+ return fetchDirection;
+ }
+
+ public int getFetchSize() {
+ return fetchSize;
+ }
+
+ public int getMaxFieldSize() {
+ return maxFieldSize;
+ }
+
+ public int getMaxRows() {
+ return maxRows;
}
-
- public String[] getKeyColumns() {
- return keyColumns;
- }
-
- public boolean isReturnGeneratedKeys() {
- return returnGeneratedKeys;
- }
-
- public boolean isForceStoredProc() {
- return forceStoredProc;
- }
-
- public boolean isForceJDBCBatchReqs() {
- return forceJDBCBatchReqs;
- }
-
- private void processAdvancedProps(Map<String, String> props) throws DataServiceFault {
- if (props == null) {
- return;
- }
- /* process fetch direction */
- String fetchDirectionProp = props.get(RDBMS.FETCH_DIRECTION);
- if (!DBUtils.isEmptyString(fetchDirectionProp)) {
- fetchDirectionProp = fetchDirectionProp.trim();
- if (AdvancedSQLProps.FETCH_DIRECTION_FORWARD.equals(fetchDirectionProp)) {
- this.fetchDirection = ResultSet.FETCH_FORWARD;
- } else if (AdvancedSQLProps.FETCH_DIRECTION_REVERSE.equals(fetchDirectionProp)) {
- this.fetchDirection = ResultSet.FETCH_REVERSE;
- } else {
- throw new DataServiceFault("Invalid fetch direction: " + fetchDirectionProp +
- ", valid values are {'" + AdvancedSQLProps.FETCH_DIRECTION_FORWARD +
- "', '" + AdvancedSQLProps.FETCH_DIRECTION_REVERSE + "'}");
- }
- this.hasFetchDirection = true;
- } else {
- this.hasFetchDirection = false;
- }
- /* process fetch size */
- String fetchSizeProp = props.get(RDBMS.FETCH_SIZE);
- if (!DBUtils.isEmptyString(fetchSizeProp)) {
- fetchSizeProp = fetchSizeProp.trim();
- try {
- this.fetchSize = Integer.parseInt(fetchSizeProp);
- } catch (NumberFormatException e) {
- throw new DataServiceFault(e, "Invalid fetch size: " + fetchSizeProp +
- ", fetch size should be an integer");
- }
- this.hasFetchSize = true;
- } else {
- this.hasFetchSize = false;
- }
- /* process max field size */
- String maxFieldSizeProp = props.get(RDBMS.MAX_FIELD_SIZE);
- if (!DBUtils.isEmptyString(maxFieldSizeProp)) {
- maxFieldSizeProp = maxFieldSizeProp.trim();
- try {
- this.maxFieldSize = Integer.parseInt(maxFieldSizeProp);
- if (this.maxFieldSize <= 0) {
- throw new DataServiceFault("Invalid maximum field size: " + maxFieldSizeProp +
- ", maximum field size should be a positive integer");
- }
- } catch (NumberFormatException e) {
- throw new DataServiceFault(e, "Invalid maximum field size: " + maxFieldSizeProp +
- ", maximum field size should be a positive integer");
- }
- this.hasMaxFieldSize = true;
- } else {
- this.hasMaxFieldSize = false;
- }
- /* process max rows */
- String maxRowsProp = props.get(RDBMS.MAX_ROWS);
- if (!DBUtils.isEmptyString(maxRowsProp)) {
- maxRowsProp = maxRowsProp.trim();
- try {
- this.maxRows = Integer.parseInt(maxRowsProp);
- if (this.maxRows <= 0) {
- throw new DataServiceFault("Invalid maximum rows: " + maxRowsProp +
- ", maximum rows should be a positive integer");
- }
- } catch (NumberFormatException e) {
- throw new DataServiceFault(e, "Invalid maximum rows: " + maxRowsProp +
- ", maximum rows should be a positive integer");
- }
- this.hasMaxRows = true;
- } else {
- this.hasMaxRows = false;
- }
- /* process query timeout */
- String queryTimeoutProp = props.get(RDBMS.QUERY_TIMEOUT);
- if (!DBUtils.isEmptyString(queryTimeoutProp)) {
- queryTimeoutProp = queryTimeoutProp.trim();
- try {
- this.queryTimeout = Integer.parseInt(queryTimeoutProp);
- if (this.queryTimeout <= 0) {
- throw new DataServiceFault("Invalid query timeout: " + queryTimeoutProp +
- ", query timeout be a positive integer");
- }
- } catch (NumberFormatException e) {
- throw new DataServiceFault(e, "Invalid query timeout: " + queryTimeoutProp +
- ", query timeout be a positive integer");
- }
- this.hasQueryTimeout = true;
- } else {
- this.hasQueryTimeout = false;
- }
- /* auto commit */
- /* first check local auto commit setting */
- String autoCommitProp = props.get(RDBMS.AUTO_COMMIT);
- if (!DBUtils.isEmptyString(autoCommitProp)) {
- autoCommitProp = autoCommitProp.trim();
- try {
- boolean acBool = Boolean.parseBoolean(autoCommitProp);
- if (acBool) {
- this.autoCommit = AutoCommit.AUTO_COMMIT_ON;
- } else {
- this.autoCommit = AutoCommit.AUTO_COMMIT_OFF;
- }
- } catch (Exception e) {
- throw new DataServiceFault(e, "Invalid autocommit value: " + autoCommitProp +
- ", autocommit should be a boolean value");
- }
- } else {
- /* global auto commit setting */
- this.autoCommit = this.getConfig().getAutoCommit();
- }
- /* force stored procedure */
- String forceStoredProc = props.get(RDBMS.FORCE_STORED_PROC);
- if (!DBUtils.isEmptyString(forceStoredProc)) {
- this.forceStoredProc = Boolean.parseBoolean(forceStoredProc);
- }
- /* force JDBC batch requests */
- String forceJDBCBatchRequests = props.get(RDBMS.FORCE_JDBC_BATCH_REQUESTS);
- if (!DBUtils.isEmptyString(forceJDBCBatchRequests)) {
- this.forceJDBCBatchReqs = Boolean.parseBoolean(forceJDBCBatchRequests);
- }
- }
-
- public List<String> getNamedParamNames() {
- return namedParamNames;
- }
-
- public boolean isHasFetchDirection() {
- return hasFetchDirection;
- }
-
- public boolean isHasFetchSize() {
- return hasFetchSize;
- }
-
- public boolean isHasMaxFieldSize() {
- return hasMaxFieldSize;
- }
-
- public boolean isHasMaxRows() {
- return hasMaxRows;
- }
-
- public boolean isHasQueryTimeout() {
- return hasQueryTimeout;
- }
-
- public int getFetchDirection() {
- return fetchDirection;
- }
-
- public int getFetchSize() {
- return fetchSize;
- }
-
- public int getMaxFieldSize() {
- return maxFieldSize;
- }
-
- public int getMaxRows() {
- return maxRows;
- }
-
- public int getQueryTimeout() {
- return queryTimeout;
- }
-
- public int getOptimalRSFetchSize() {
- return optimalRSFetchSize;
- }
-
- private void checkRefCursor(List<QueryParam> queryParams) {
- for (QueryParam queryParam : queryParams) {
- if (queryParam.getSqlType().equals(DBConstants.DataTypes.ORACLE_REF_CURSOR)) {
- this.currentRefCursor = queryParam;
- this.hasRefCursor = true;
- return;
- }
- }
- }
-
- private String createSqlFromQueryString(String query) {
- List<String> values = this.getNamedParamNames();
- for (String val : values) {
- /* replace named params with ?'s */
- query = query.replaceAll(":" + val, "?");
- }
- return query;
- }
-
- public String getSql() {
- return sql;
- }
-
- private List<String> extractParamNames(String query, Set<String> queryParams) {
- List<String> paramNames = new ArrayList<String>();
- String tmpParam;
- for (int i = 0; i < query.length(); i++) {
- if (query.charAt(i) == '?') {
- paramNames.add("?");
- } else if (query.charAt(i) == ':') {
- /* check if the string is at the end */
- if (i + 1 < query.length()) {
- /* split params in situations like ":a,:b", ":a :b", ":a:b", "(:a,:b)" */
- tmpParam = query.substring(i + 1, query.length()).split(" |,|\\)|\\(|:")[0];
- if (queryParams.contains(tmpParam)) {
- /* only consider this as a parameter if it's in input mappings */
- paramNames.add(tmpParam);
- }
- }
- }
- }
- return paramNames;
- }
-
- private void processNamedParams() {
- Map<String, Integer> paramMap = new HashMap<String, Integer>();
- for (QueryParam param : this.getQueryParams()) {
- paramMap.put(param.getName(), param.getOrdinal());
- }
- List<String> paramNames = this.extractParamNames(this.getQuery(), paramMap.keySet());
- this.namedParamIndices = new int[paramNames.size()];
- this.namedParamNames = new ArrayList<String>();
- String tmpParamName;
- for (int i = 0; i < this.namedParamIndices.length; i++) {
- if (paramNames.get(i).equals("?")) {
- this.namedParamIndices[i] = i + 1;
- } else {
- tmpParamName = paramNames.get(i);
- this.namedParamNames.add(tmpParamName);
- this.namedParamIndices[i] = paramMap.get(tmpParamName);
- }
- }
- }
-
- public int[] getNamedParamIndices() {
- return namedParamIndices;
- }
-
- private InternalParamCollection createProcessedNamedParams(
- InternalParamCollection params) throws DataServiceFault {
- InternalParamCollection newParams = new InternalParamCollection();
- int[] indices = this.getNamedParamIndices();
- Set<InternalParam> remainingParams = new HashSet<InternalParam>(params.getParams());
- InternalParam tmpParam;
- int i;
- for (i = 0; i < indices.length; i++) {
- tmpParam = params.getParam(indices[i]);
- remainingParams.remove(tmpParam);
- if (tmpParam == null) {
- throw new DataServiceFault(
- "A parameter is expected at position '" + (i + 1)
- + "' for the SQL query '" + this.getQuery() + "'");
- }
- if (indices[i] >= 0) {
- newParams.addParam(new InternalParam(tmpParam, i + 1));
- }
- }
- /* add the remaining params, which are not referenced by the sql query itself */
- for (InternalParam rparam : remainingParams) {
- newParams.addParam(new InternalParam(rparam, i + 1));
- i++;
- }
- return newParams;
- }
-
- public boolean hasOutParams() {
- return hasOutParams;
- }
-
- public boolean isResultOnlyOutParams() {
- return resultOnlyOutParams;
- }
-
- private List<QueryParam> extractOutQueryParams(List<QueryParam> queryParams) {
- List<QueryParam> inOutQueryParams = new ArrayList<QueryParam>();
- for (QueryParam queryParam : queryParams) {
- if (queryParam.getType().endsWith(QueryTypes.OUT) && !queryParam.getSqlType().equals(
- DBConstants.DataTypes.ORACLE_REF_CURSOR)) {
- inOutQueryParams.add(queryParam);
- }
- }
- return inOutQueryParams;
- }
-
- private List<QueryParam> extractOnlyOutQueryParams(List<QueryParam> queryParams) {
- List<QueryParam> outQueryParams = new ArrayList<QueryParam>();
- for (QueryParam queryParam : queryParams) {
- if (queryParam.getType().equals(QueryTypes.OUT)) {
- outQueryParams.add(queryParam);
- }
- }
- return outQueryParams;
- }
-
- public List<QueryParam> getOutQueryParams() {
- return outQueryParams;
- }
-
- public String getQuery() {
- return query;
- }
-
- public void setQuery(String query) {
- this.query = query;
- }
-
- public int getQueryType() {
- return queryType;
- }
-
- public SQLConfig getConfig() {
- return config;
- }
-
- /**
- * Creates a new connection and return it.
- * @see Connection
- */
- private Connection createConnection() throws DataServiceFault {
- try {
- Connection connection = null;
- DataService dataService = this.getDataService();
- if (dataService.isInTransaction() && !dataService.isEnableXA()) {
- /* if in a transaction, and not XA transactions */
- connection = TLConnectionStore.getConnection(this.getConfigId());
- if (connection == null) {
- connection = this.getConfig().createConnection();
- /* disable autocommit, and add to the connection list */
- connection.setAutoCommit(false);
- TLConnectionStore.addConnection(this.getConfigId(), connection);
- }
- } else {
- /* for normal operations and XA-transactions */
- connection = this.getConfig().createConnection();
- /* set auto commit, but don't mess with XA-transactions */
- if (!(dataService.isInTransaction() && dataService.isEnableXA())) {
- switch (this.getAutoCommit()) {
- case AUTO_COMMIT_ON:
- connection.setAutoCommit(true);
- case AUTO_COMMIT_OFF:
- connection.setAutoCommit(false);
- break;
- }
- }
- }
- return connection;
- } catch (SQLException e) {
- throw new DataServiceFault(e, "Error in opening DBMS connection.");
- }
- }
-
- /**
- * Post actions after a connection is used.
- */
- public void finalizeConnection(Connection connection, boolean force) throws DataServiceFault {
- try {
- if (connection == null || connection.isClosed()) {
- return;
- }
- DataService dataService = this.getDataService();
- if (dataService.isEnableXA() && dataService.isInTransaction()) {
- /* just close it */
- connection.close();
- } else if (!dataService.isInTransaction()) {
- if (!connection.getAutoCommit()) {
- connection.commit();
- }
- connection.close();
- } else if (force) {
- connection.close();
- }
- } catch (SQLException e) {
- throw new DataServiceFault(e, "Error in DBMS connection finalize.");
- }
- }
-
- private int retrieveQueryType(String query) {
- if (this.isForceStoredProc()) {
- return SQLQuery.DS_QUERY_TYPE_STORED_PROC;
- } else {
- return inferQueryType(query);
- }
- }
-
- private int inferQueryType(String query) {
- query = query.trim().toUpperCase();
- /* check if this query starts with SELECT, INSERT etc.. */
- for (String normalQueryType : DBConstants.SQL_NORMAL_QUERY_TYPES) {
- if (query.startsWith(normalQueryType)) {
- return SQLQuery.DS_QUERY_TYPE_NORMAL;
- }
- }
- /* else, this has to be a stored procedure */
- return SQLQuery.DS_QUERY_TYPE_STORED_PROC;
- }
-
- private boolean isJDBCBatchRequest() {
- return (DBUtils.isBatchProcessing() && this.hasBatchQuerySupport());
- }
-
- private boolean isJDBCFirstBatchRequest() {
- return (this.isJDBCBatchRequest() && DBUtils.getBatchRequestNumber() == 0);
- }
-
- private boolean isJDBCLastBatchRequest() {
- return (this.isJDBCBatchRequest() &&
- (DBUtils.getBatchRequestNumber() + 1 >= DBUtils.getBatchRequestCount()));
- }
-
- private void writeOutGeneratedKeys(Statement stmt, XMLStreamWriter xmlWriter,
- InternalParamCollection params, int queryLevel) throws DataServiceFault, SQLException {
- ResultSet krs = stmt.getGeneratedKeys();
- DataEntry dataEntry;
- while (krs.next()) {
- dataEntry = this.getDataEntryFromRS(krs);
- this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
- }
- }
-
- private void processNormalQuery(XMLStreamWriter xmlWriter,
- InternalParamCollection params,
- int queryLevel)
- throws DataServiceFault {
- Connection conn = null;
- boolean isError = false;
- try {
- conn = this.createConnection();
- PreparedStatement stmt = this.createProcessedPreparedStatement(
- SQLQuery.DS_QUERY_TYPE_NORMAL, params, conn);
- /* check if this is a batch request */
- if (this.isJDBCFirstBatchRequest()) {
- this.setBatchPreparedStatement(stmt);
- /* add this to cleanup this query after batch request */
- BatchDataServiceRequest.addParticipant(this);
- }
- /* if updating/inserting stuff, go inside here */
- if (!this.hasResult() || (this.hasResult() && this.isReturnGeneratedKeys())) {
- /* if we are in the middle of a batch request, don't execute it */
- if (this.isJDBCBatchRequest()) {
- /* if this is the last one, execute the full batch */
- if (this.isJDBCLastBatchRequest()) {
- stmt.executeBatch();
- if (this.isReturnGeneratedKeys()) {
- /* handle generated keys, i.e. SQL INSERT etc.. */
- this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
- }
- stmt.close();
- }
- } else {
- /* normal update operation */
- stmt.executeUpdate();
- if (this.isReturnGeneratedKeys()) {
- this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
- }
- stmt.close();
- }
- } else {
- ResultSet rs = stmt.executeQuery();
- DataEntry dataEntry;
- while (rs.next()) {
- dataEntry = this.getDataEntryFromRS(rs);
- this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
- }
- /* close the result set */
- rs.close();
- }
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- isError = true;
- throw new DataServiceFault(e, FaultCodes.DATABASE_ERROR,
- "Error in 'SQLQuery.processNormalQuery'");
- } finally {
- /* finalize the DB connection, close it if possible etc.. */
- this.finalizeConnection(conn, isError);
- }
- }
-
- private void processStoredProcQuery(XMLStreamWriter xmlWriter,
- InternalParamCollection params, int queryLevel)
- throws DataServiceFault {
- Connection conn = null;
- boolean isError = false;
- try {
- conn = this.createConnection();
- CallableStatement stmt = (CallableStatement) this.createProcessedPreparedStatement(
- SQLQuery.DS_QUERY_TYPE_STORED_PROC, params, conn);
- /* check if this is a batch request */
- if (this.isJDBCFirstBatchRequest()) {
- this.setBatchPreparedStatement(stmt);
- /* add this to cleanup this query after batch request */
- BatchDataServiceRequest.addParticipant(this);
- }
- if (!this.hasResult() || (this.hasResult() && this.isReturnGeneratedKeys())) {
- /* if we are in the middle of a batch request, don't execute it */
- if (this.isJDBCBatchRequest()) {
- /* if this is the last one, execute the full batch */
- if (this.isJDBCLastBatchRequest()) {
- stmt.executeBatch();
- if (this.isReturnGeneratedKeys()) {
- this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
- }
- stmt.close();
- }
- } else {
- stmt.executeUpdate();
- if (this.isReturnGeneratedKeys()) {
- this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
- }
- stmt.close();
- }
- } else {
- ResultSet rs = null;
- /* check if all the result elements are out params; if so, no result set */
- if (this.isResultOnlyOutParams()) {
- stmt.execute();
- /* if there's a ref cursor, get the result set */
- if (this.hasRefCursor()) {
- rs = (ResultSet) stmt.getObject(this.getCurrentRefCursor().getOrdinal());
- if (this.arrayTypesEnabled) {
- this.getCurrentRefCursor().setOrdinal(this.prevRefCursorOrdinal);
- }
- }
- } else {
- rs = this.getFirstRSOfStoredProc(stmt);
- }
-
- if (rs == null || rs.isClosed() || !rs.next()) {
- if (this.hasOutParams()) {
- DataEntry outParamDataEntry = this.getDataEntryFromOutParams(stmt);
- if (outParamDataEntry != null) {
- this.writeResultEntry(xmlWriter, outParamDataEntry, params, queryLevel);
- }
- }
- if (rs != null && !rs.isClosed()) {
- rs.close();
- }
- } else {
- if (this.hasOutParams()) {
- /*
- * so if someone mixes up OUT parameters with normal results, this will
- * effectively turn off streaming
- */
- List<DataEntry> entries = this.getAllDataEntriesFromRS(rs, true);
- rs.close();
- /* result sets must be processed before extracting out params */
- DataEntry outParamDataEntry = this.getDataEntryFromOutParams(stmt);
- for (DataEntry dataEntry : entries) {
- this.mergeDataEntries(dataEntry, outParamDataEntry);
- this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
- }
- } else {
- /* do-while loop since, 'rs.next()' has already been called once */
- DataEntry dataEntry;
- do {
- dataEntry = this.getDataEntryFromRS(rs);
- this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
- } while (rs.next());
- /* close result set */
- rs.close();
- }
- }
- }
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- isError = true;
- throw new DataServiceFault(e, FaultCodes.DATABASE_ERROR,
- "Error in 'SQLQuery.processStoredProcQuery'");
- } finally {
- /* close the DB connection */
- this.finalizeConnection(conn, isError);
- }
- }
-
- private List<DataEntry> getAllDataEntriesFromRS(ResultSet rs,
- boolean rsNextAlreadyCalled) throws SQLException {
- List<DataEntry> entries = new ArrayList<DataEntry>();
- if (!rsNextAlreadyCalled) {
- if (!rs.next()) {
- return entries;
- }
- }
- do {
- entries.add(this.getDataEntryFromRS(rs));
- } while (rs.next());
- return entries;
- }
-
- private ResultSet getFirstRSOfStoredProc(CallableStatement stmt) throws SQLException {
- boolean resultAndNoUpdateCount = stmt.execute();
- ResultSet result = null;
- while (true) {
- if (!resultAndNoUpdateCount) {
- if (stmt.getUpdateCount() == -1) {
- break;
- }
- } else {
- result = stmt.getResultSet();
- break;
- }
- try {
- resultAndNoUpdateCount = stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT);
- } catch (SQLException e) {
- /* for some DBMS, this will throw an unsupported feature exception, even when after a valid result set is
- * retrieved first, so if there's a valid result set existing, we will ignore the eventual unsupported feature
- * exception */
- if (result == null) {
- throw e;
- }
- break;
- }
- }
- return result;
- }
-
- /*
- * merge data entry objects from rhs -> lhs.
- */
- private void mergeDataEntries(DataEntry lhs, DataEntry rhs) {
- lhs.getData().putAll(rhs.getData());
- }
-
- private DataEntry getDataEntryFromOutParams(CallableStatement stmt) throws DataServiceFault {
- DataEntry dataEntry = new DataEntry();
- String name;
- ParamValue value;
- for (QueryParam queryParam : this.getOutQueryParams()) {
- name = queryParam.getName();
- value = this.getOutparameterValue(stmt, queryParam.getSqlType(),
- queryParam.getOrdinal());
- dataEntry.addValue(name, value);
- }
- return dataEntry;
- }
-
- private DataEntry getDataEntryFromRS(ResultSet rs) throws SQLException {
- DataEntry dataEntry = new DataEntry();
- ResultSetMetaData metaData = rs.getMetaData();
- int columnCount = metaData.getColumnCount();
- int columnType;
- String value;
- ParamValue paramValue;
- Time sqlTime;
- Date sqlDate;
- Timestamp sqlTimestamp;
- Blob sqlBlob;
- BigDecimal bigDecimal;
- InputStream binInStream;
- boolean useColumnNumbers = this.isUsingColumnNumbers();
- for (int i = 1; i <= columnCount; i++) {
- /* retrieve values according to the column type */
- columnType = metaData.getColumnType(i);
- switch (columnType) {
- /* handle string types */
- case Types.VARCHAR:
- /* fall through */
- case Types.LONGVARCHAR:
- /* fall through */
- case Types.CHAR:
- /* fall through */
- case Types.CLOB:
- /* fall through */
- case Types.NCHAR:
- /* fall through */
- case Types.NCLOB:
- /* fall through */
- case Types.NVARCHAR:
- /* fall through */
- case Types.LONGNVARCHAR:
- value = rs.getString(i);
- paramValue = new ParamValue(value);
- break;
- /* handle numbers */
- case Types.INTEGER:
- /* fall through */
- case Types.TINYINT:
- /* fall through */
- case Types.SMALLINT:
- value = ConverterUtil.convertToString(rs.getInt(i));
- paramValue = new ParamValue(value);
- break;
- case Types.DOUBLE:
- value = ConverterUtil.convertToString(rs.getDouble(i));
- paramValue = new ParamValue(value);
- break;
- case Types.FLOAT:
- value = ConverterUtil.convertToString(rs.getFloat(i));
- paramValue = new ParamValue(value);
- break;
- case Types.BOOLEAN:
- /* fall through */
- case Types.BIT:
- value = ConverterUtil.convertToString(rs.getBoolean(i));
- paramValue = new ParamValue(value);
- break;
- case Types.DECIMAL:
- bigDecimal = rs.getBigDecimal(i);
- if (bigDecimal != null) {
- value = ConverterUtil.convertToString(bigDecimal);
- } else {
- value = null;
- }
- paramValue = new ParamValue(value);
- break;
- /* handle data/time values */
- case Types.TIME:
- /* handle time data type */
- sqlTime = rs.getTime(i);
- if (sqlTime != null) {
- value = this.convertToTimeString(sqlTime);
- } else {
- value = null;
- }
- paramValue = new ParamValue(value);
- break;
- case Types.DATE:
- /* handle date data type */
- sqlDate = rs.getDate(i);
- if (sqlDate != null) {
- value = ConverterUtil.convertToString(sqlDate);
- } else {
- value = null;
- }
- paramValue = new ParamValue(value);
- break;
- case Types.TIMESTAMP:
- sqlTimestamp = rs.getTimestamp(i);
- if (sqlTimestamp != null) {
- value = this.convertToTimestampString(sqlTimestamp);
- } else {
- value = null;
- }
- paramValue = new ParamValue(value);
- break;
- /* handle binary types */
- case Types.BLOB:
- sqlBlob = rs.getBlob(i);
- if (sqlBlob != null) {
- value = this.getBase64StringFromInputStream(sqlBlob.getBinaryStream());
- } else {
- value = null;
- }
- paramValue = new ParamValue(value);
- break;
- case Types.BINARY:
- /* fall through */
- case Types.LONGVARBINARY:
- /* fall through */
- case Types.VARBINARY:
- binInStream = rs.getBinaryStream(i);
- if (binInStream != null) {
- value = this.getBase64StringFromInputStream(binInStream);
- } else {
- value = null;
- }
- paramValue = new ParamValue(value);
- break;
- /* handling User Defined Types */
- case Types.STRUCT:
- Struct udt = (Struct) rs.getObject(i);
- paramValue = new ParamValue(udt);
+
+ public int getQueryTimeout() {
+ return queryTimeout;
+ }
+
+ public QueryParam getCurrentSqlArray() {
+ return currentSqlArray;
+ }
+
+ public int getOptimalRSFetchSize() {
+ return optimalRSFetchSize;
+ }
+
+ private void checkRefCursor(List<QueryParam> queryParams) {
+ for (QueryParam queryParam : queryParams) {
+ if (queryParam.getSqlType().equals(DBConstants.DataTypes.ORACLE_REF_CURSOR)) {
+ this.currentRefCursor = queryParam;
+ this.hasRefCursor = true;
+ return;
+ }
+ }
+ }
+
+ private void checkSqlArrayType(List<QueryParam> queryParams) {
+ for (QueryParam queryParam : queryParams) {
+ if (queryParam.getSqlType().equals(DBConstants.DataTypes.ARRAY)) {
+ this.currentSqlArray = queryParam;
+ this.hasSqlArrayType = true;
+ return;
+ }
+ }
+ }
+
+ private String createSqlFromQueryString(String query) {
+ List<String> values = this.getNamedParamNames();
+ for (String val : values) {
+ /* replace named params with ?'s */
+ query = query.replaceAll(":" + val, "?");
+ }
+ return query;
+ }
+
+ public String getSql() {
+ return sql;
+ }
+
+ private List<String> extractParamNames(String query, Set<String> queryParams) {
+ List<String> paramNames = new ArrayList<String>();
+ String tmpParam;
+ for (int i = 0; i < query.length(); i++) {
+ if (query.charAt(i) == '?') {
+ paramNames.add("?");
+ } else if (query.charAt(i) == ':') {
+ /* check if the string is at the end */
+ if (i + 1 < query.length()) {
+ /* split params in situations like ":a,:b", ":a :b", ":a:b", "(:a,:b)" */
+ tmpParam = query.substring(i + 1, query.length()).split(" |,|\\)|\\(|:")[0];
+ if (queryParams.contains(tmpParam)) {
+ /* only consider this as a parameter if it's in input mappings */
+ paramNames.add(tmpParam);
+ }
+ }
+ }
+ }
+ return paramNames;
+ }
+
+ private void processNamedParams() {
+ Map<String, Integer> paramMap = new HashMap<String, Integer>();
+ for (QueryParam param : this.getQueryParams()) {
+ paramMap.put(param.getName(), param.getOrdinal());
+ }
+ List<String> paramNames = this.extractParamNames(this.getQuery(), paramMap.keySet());
+ this.namedParamIndices = new int[paramNames.size()];
+ this.namedParamNames = new ArrayList<String>();
+ String tmpParamName;
+ for (int i = 0; i < this.namedParamIndices.length; i++) {
+ if (paramNames.get(i).equals("?")) {
+ this.namedParamIndices[i] = i + 1;
+ } else {
+ tmpParamName = paramNames.get(i);
+ this.namedParamNames.add(tmpParamName);
+ this.namedParamIndices[i] = paramMap.get(tmpParamName);
+ }
+ }
+ }
+
+ public int[] getNamedParamIndices() {
+ return namedParamIndices;
+ }
+
+ private InternalParamCollection createProcessedNamedParams(
+ InternalParamCollection params) throws DataServiceFault {
+ InternalParamCollection newParams = new InternalParamCollection();
+ int[] indices = this.getNamedParamIndices();
+ Set<InternalParam> remainingParams = new HashSet<InternalParam>(params.getParams());
+ InternalParam tmpParam;
+ int i;
+ for (i = 0; i < indices.length; i++) {
+ tmpParam = params.getParam(indices[i]);
+ remainingParams.remove(tmpParam);
+ if (tmpParam == null) {
+ throw new DataServiceFault(
+ "A parameter is expected at position '" + (i + 1)
+ + "' for the SQL query '" + this.getQuery() + "'");
+ }
+ if (indices[i] >= 0) {
+ newParams.addParam(new InternalParam(tmpParam, i + 1));
+ }
+ }
+ /* add the remaining params, which are not referenced by the sql query itself */
+ for (InternalParam rparam : remainingParams) {
+ newParams.addParam(new InternalParam(rparam, i + 1));
+ i++;
+ }
+ return newParams;
+ }
+
+ public boolean hasOutParams() {
+ return hasOutParams;
+ }
+
+ public boolean isResultOnlyOutParams() {
+ return resultOnlyOutParams;
+ }
+
+ private List<QueryParam> extractOutQueryParams(List<QueryParam> queryParams) {
+ List<QueryParam> inOutQueryParams = new ArrayList<QueryParam>();
+ for (QueryParam queryParam : queryParams) {
+ if (queryParam.getType().endsWith(QueryTypes.OUT) && !queryParam.getSqlType().equals(
+ DBConstants.DataTypes.ORACLE_REF_CURSOR) &&
+ !queryParam.getSqlType().equals(DBConstants.DataTypes.ARRAY)) {
+ inOutQueryParams.add(queryParam);
+ }
+ }
+ return inOutQueryParams;
+ }
+
+ private List<QueryParam> extractOnlyOutQueryParams(List<QueryParam> queryParams) {
+ List<QueryParam> outQueryParams = new ArrayList<QueryParam>();
+ for (QueryParam queryParam : queryParams) {
+ if (queryParam.getType().equals(QueryTypes.OUT)) {
+ outQueryParams.add(queryParam);
+ }
+ }
+ return outQueryParams;
+ }
+
+ public List<QueryParam> getOutQueryParams() {
+ return outQueryParams;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+ public int getQueryType() {
+ return queryType;
+ }
+
+ public SQLConfig getConfig() {
+ return config;
+ }
+
+ /**
+ * Creates a new connection and return it.
+ *
+ * @see Connection
+ */
+ private Connection createConnection() throws DataServiceFault {
+ try {
+ Connection connection = null;
+ DataService dataService = this.getDataService();
+ if (dataService.isInTransaction() && !dataService.isEnableXA()) {
+ /* if in a transaction, and not XA transactions */
+ connection = TLConnectionStore.getConnection(this.getConfigId());
+ if (connection == null) {
+ connection = this.getConfig().createConnection();
+ /* disable autocommit, and add to the connection list */
+ connection.setAutoCommit(false);
+ TLConnectionStore.addConnection(this.getConfigId(), connection);
+ }
+ } else {
+ /* for normal operations and XA-transactions */
+ connection = this.getConfig().createConnection();
+ /* set auto commit, but don't mess with XA-transactions */
+ if (!(dataService.isInTransaction() && dataService.isEnableXA())) {
+ switch (this.getAutoCommit()) {
+ case AUTO_COMMIT_ON:
+ connection.setAutoCommit(true);
+ case AUTO_COMMIT_OFF:
+ connection.setAutoCommit(false);
+ break;
+ }
+ }
+ }
+ return connection;
+ } catch (SQLException e) {
+ throw new DataServiceFault(e, "Error in opening DBMS connection.");
+ }
+ }
+
+ /**
+ * Post actions after a connection is used.
+ */
+ public void finalizeConnection(Connection connection, boolean force) throws DataServiceFault {
+ try {
+ if (connection == null || connection.isClosed()) {
+ return;
+ }
+ DataService dataService = this.getDataService();
+ if (dataService.isEnableXA() && dataService.isInTransaction()) {
+ /* just close it */
+ connection.close();
+ } else if (!dataService.isInTransaction()) {
+ if (!connection.getAutoCommit()) {
+ connection.commit();
+ }
+ connection.close();
+ } else if (force) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ throw new DataServiceFault(e, "Error in DBMS connection finalize.");
+ }
+ }
+
+ private int retrieveQueryType(String query) {
+ if (this.isForceStoredProc()) {
+ return SQLQuery.DS_QUERY_TYPE_STORED_PROC;
+ } else {
+ return inferQueryType(query);
+ }
+ }
+
+ private int inferQueryType(String query) {
+ query = query.trim().toUpperCase();
+ /* check if this query starts with SELECT, INSERT etc.. */
+ for (String normalQueryType : DBConstants.SQL_NORMAL_QUERY_TYPES) {
+ if (query.startsWith(normalQueryType)) {
+ return SQLQuery.DS_QUERY_TYPE_NORMAL;
+ }
+ }
+ /* else, this has to be a stored procedure */
+ return SQLQuery.DS_QUERY_TYPE_STORED_PROC;
+ }
+
+ private boolean isJDBCBatchRequest() {
+ return (DBUtils.isBatchProcessing() && this.hasBatchQuerySupport());
+ }
+
+ private boolean isJDBCFirstBatchRequest() {
+ return (this.isJDBCBatchRequest() && DBUtils.getBatchRequestNumber() == 0);
+ }
+
+ private boolean isJDBCLastBatchRequest() {
+ return (this.isJDBCBatchRequest() &&
+ (DBUtils.getBatchRequestNumber() + 1 >= DBUtils.getBatchRequestCount()));
+ }
+
+ private void writeOutGeneratedKeys(Statement stmt, XMLStreamWriter xmlWriter,
+ InternalParamCollection params,
+ int queryLevel) throws DataServiceFault, SQLException {
+ ResultSet krs = stmt.getGeneratedKeys();
+ DataEntry dataEntry;
+ while (krs.next()) {
+ dataEntry = this.getDataEntryFromRS(new ResultSetWrapper(krs));
+ this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
+ }
+ }
+
+ private void processNormalQuery(XMLStreamWriter xmlWriter,
+ InternalParamCollection params,
+ int queryLevel)
+ throws DataServiceFault {
+ Connection conn = null;
+ boolean isError = false;
+ try {
+ conn = this.createConnection();
+ PreparedStatement stmt = this.createProcessedPreparedStatement(
+ SQLQuery.DS_QUERY_TYPE_NORMAL, params, conn);
+ /* check if this is a batch request */
+ if (this.isJDBCFirstBatchRequest()) {
+ this.setBatchPreparedStatement(stmt);
+ /* add this to cleanup this query after batch request */
+ BatchDataServiceRequest.addParticipant(this);
+ }
+ /* if updating/inserting stuff, go inside here */
+ if (!this.hasResult() || (this.hasResult() && this.isReturnGeneratedKeys())) {
+ /* if we are in the middle of a batch request, don't execute it */
+ if (this.isJDBCBatchRequest()) {
+ /* if this is the last one, execute the full batch */
+ if (this.isJDBCLastBatchRequest()) {
+ stmt.executeBatch();
+ if (this.isReturnGeneratedKeys()) {
+ /* handle generated keys, i.e. SQL INSERT etc.. */
+ this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
+ }
+ stmt.close();
+ }
+ } else {
+ /* normal update operation */
+ stmt.executeUpdate();
+ if (this.isReturnGeneratedKeys()) {
+ this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
+ }
+ stmt.close();
+ }
+ } else {
+ ResultSet rs = stmt.executeQuery();
+ DataEntry dataEntry;
+ while (rs.next()) {
+ dataEntry = this.getDataEntryFromRS(new ResultSetWrapper(rs));
+ this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
+ }
+ /* close the result set */
+ rs.close();
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ isError = true;
+ throw new DataServiceFault(e, FaultCodes.DATABASE_ERROR,
+ "Error in 'SQLQuery.processNormalQuery'");
+ } finally {
+ /* finalize the DB connection, close it if possible etc.. */
+ this.finalizeConnection(conn, isError);
+ }
+ }
+
+ private void processStoredProcQuery(XMLStreamWriter xmlWriter,
+ InternalParamCollection params, int queryLevel)
+ throws DataServiceFault {
+ Connection conn = null;
+ boolean isError = false;
+ try {
+ conn = this.createConnection();
+ CallableStatement stmt = (CallableStatement) this.createProcessedPreparedStatement(
+ SQLQuery.DS_QUERY_TYPE_STORED_PROC, params, conn);
+ /* check if this is a batch request */
+ if (this.isJDBCFirstBatchRequest()) {
+ this.setBatchPreparedStatement(stmt);
+ /* add this to cleanup this query after batch request */
+ BatchDataServiceRequest.addParticipant(this);
+ }
+ if (!this.hasResult() || (this.hasResult() && this.isReturnGeneratedKeys())) {
+ /* if we are in the middle of a batch request, don't execute it */
+ if (this.isJDBCBatchRequest()) {
+ /* if this is the last one, execute the full batch */
+ if (this.isJDBCLastBatchRequest()) {
+ stmt.executeBatch();
+ if (this.isReturnGeneratedKeys()) {
+ this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
+ }
+ stmt.close();
+ }
+ } else {
+ stmt.executeUpdate();
+ if (this.isReturnGeneratedKeys()) {
+ this.writeOutGeneratedKeys(stmt, xmlWriter, params, queryLevel);
+ }
+ stmt.close();
+ }
+ } else {
+ ResultSet rs = null;
+ /* check if all the result elements are out params; if so, no result set */
+ if (this.isResultOnlyOutParams()) {
+ stmt.execute();
+ /* if there's a ref cursor, get the result set */
+ if (this.hasRefCursor()) {
+ rs = (ResultSet) stmt.getObject(this.getCurrentRefCursor().getOrdinal());
+ if (this.arrayTypesEnabled()) {
+ this.getCurrentRefCursor().setOrdinal(this.getPrevRefCusorOrdinal());
+ }
+ }
+ if (this.hasSqlArrayType()) {
+ rs = stmt.getArray(this.getCurrentSqlArray().getOrdinal()).getResultSet();
+ }
+ } else {
+ rs = this.getFirstRSOfStoredProc(stmt);
+ }
+
+ if (rs == null || rs.isClosed() || !rs.next()) {
+ if (this.hasOutParams()) {
+ DataEntry outParamDataEntry = this.getDataEntryFromOutParams(stmt);
+ if (outParamDataEntry != null) {
+ this.writeResultEntry(xmlWriter, outParamDataEntry, params, queryLevel);
+ }
+ }
+ if (rs != null && !rs.isClosed()) {
+ rs.close();
+ }
+ } else {
+ if (this.hasOutParams()) {
+ /*
+ * so if someone mixes up OUT parameters with normal results, this will
+ * effectively turn off streaming
+ */
+ List<DataEntry> entries = this.getAllDataEntriesFromRS(rs, true);
+ rs.close();
+ /* result sets must be processed before extracting out params */
+ DataEntry outParamDataEntry = this.getDataEntryFromOutParams(stmt);
+ for (DataEntry dataEntry : entries) {
+ this.mergeDataEntries(dataEntry, outParamDataEntry);
+ this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
+ }
+ } else {
+ /* do-while loop since, 'rs.next()' has already been called once */
+ DataEntry dataEntry;
+ do {
+ dataEntry = this.getDataEntryFromRS(new ResultSetWrapper(rs));
+ this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
+ } while (rs.next());
+ /* close result set */
+ rs.close();
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ isError = true;
+ throw new DataServiceFault(e, FaultCodes.DATABASE_ERROR,
+ "Error in 'SQLQuery.processStoredProcQuery'");
+ } finally {
+ /* close the DB connection */
+ this.finalizeConnection(conn, isError);
+ }
+ }
+
+ private List<DataEntry> getAllDataEntriesFromRS(ResultSet rs,
+ boolean rsNextAlreadyCalled) throws SQLException {
+ List<DataEntry> entries = new ArrayList<DataEntry>();
+ if (!rsNextAlreadyCalled) {
+ if (!rs.next()) {
+ return entries;
+ }
+ }
+ do {
+ entries.add(this.getDataEntryFromRS(new ResultSetWrapper(rs)));
+ } while (rs.next());
+ return entries;
+ }
+
+ private ResultSet getFirstRSOfStoredProc(CallableStatement stmt) throws SQLException {
+ boolean resultAndNoUpdateCount = stmt.execute();
+ ResultSet result = null;
+ while (true) {
+ if (!resultAndNoUpdateCount) {
+ if (stmt.getUpdateCount() == -1) {
+ break;
+ }
+ } else {
+ result = stmt.getResultSet();
+ break;
+ }
+ try {
+ resultAndNoUpdateCount = stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT);
+ } catch (SQLException e) {
+ /* for some DBMS, this will throw an unsupported feature exception, even when after a valid result set is
+ * retrieved first, so if there's a valid result set existing, we will ignore the eventual unsupported feature
+ * exception */
+ if (result == null) {
+ throw e;
+ }
break;
- /* handle all other types as strings */
- default:
- value = rs.getString(i);
- paramValue = new ParamValue(value);
- break;
- }
- dataEntry.addValue(useColumnNumbers ? Integer.toString(i) : metaData.getColumnLabel(i),
- paramValue);
- }
- return dataEntry;
- }
-
- private String convertToTimeString(Time sqlTime) {
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(sqlTime.getTime());
- return new org.apache.axis2.databinding.types.Time(cal).toString();
- }
-
- private String convertToTimestampString(Timestamp sqlTimestamp) {
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(sqlTimestamp.getTime());
- return ConverterUtil.convertToString(cal);
- }
-
- private String getBase64StringFromInputStream(InputStream in) throws SQLException {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- String strData;
- try {
- byte[] buff = new byte[512];
- int i = 0;
- while ((i = in.read(buff)) > 0) {
- byteOut.write(buff, 0, i);
- }
- in.close();
- byte[] base64Data = Base64.encodeBase64(byteOut.toByteArray());
- strData = new String(base64Data, DBConstants.DEFAULT_CHAR_SET_TYPE);
- } catch (Exception e) {
- throw new SQLException(e.getMessage());
- }
- return strData;
- }
-
- private byte[] getBytesFromBase64String(String base64Str) throws SQLException {
- try {
- byte[] data = Base64.decodeBase64(base64Str.getBytes(DBConstants.DEFAULT_CHAR_SET_TYPE));
- return data;
- } catch (Exception e) {
- throw new SQLException(e.getMessage());
- }
- }
-
- /**
- * Returns the SQL manipulated to suite the given parameters,
- * e.g. adding additional "?"'s for array types.
- */
- public String createProcessedSql(String sql, InternalParamCollection params, int paramCount) {
- String currentSql = sql;
- int start = 0;
- Object[] vals = null;
- InternalParam param = null;
- ParamValue value = null;
- int count;
- for (int i = 1; i <= paramCount; i++) {
- param = params.getParam(i);
- value = param.getValue();
- /* value can be null in stored proc OUT params, so it is simply treated as a
- * single param, because the number of elements in an array cannot be
- * calculated, since there's no actual value passed in */
- if (value != null && (value.getValueType() == ParamValue.PARAM_VALUE_ARRAY)) {
- count = (value.getArrayValue()).size();
- if (this.hasRefCursor) {
+ }
+ }
+ return result;
+ }
+
+ /*
+ * merge data entry objects from rhs -> lhs.
+ */
+
+ private void mergeDataEntries(DataEntry lhs, DataEntry rhs) {
+ lhs.getData().putAll(rhs.getData());
+ }
+
+ private DataEntry getDataEntryFromOutParams(CallableStatement stmt) throws DataServiceFault {
+ DataEntry dataEntry = new DataEntry();
+ String name;
+ ParamValue value;
+ for (QueryParam queryParam : this.getOutQueryParams()) {
+ name = queryParam.getName();
+ value = this.getOutparameterValue(stmt, queryParam.getSqlType(),
+ queryParam.getOrdinal());
+ dataEntry.addValue(name, value);
+ }
+ return dataEntry;
+ }
+
+ private DataEntry getDataEntryFromRS(ResultSet rs) throws SQLException {
+ //rs = new DSResultSet(rs);
+ DataEntry dataEntry = new DataEntry();
+ ResultSetMetaData metaData = rs.getMetaData();
+ int columnCount = metaData.getColumnCount();
+ int columnType;
+ String value;
+ ParamValue paramValue;
+ Time sqlTime;
+ Date sqlDate;
+ Timestamp sqlTimestamp;
+ Blob sqlBlob;
+ BigDecimal bigDecimal;
+ InputStream binInStream;
+ boolean useColumnNumbers = this.isUsingColumnNumbers();
+ for (int i = 1; i <= columnCount; i++) {
+ /* retrieve values according to the column type */
+ columnType = metaData.getColumnType(i);
+ switch (columnType) {
+ /* handle string types */
+ case Types.VARCHAR:
+ /* fall through */
+ case Types.LONGVARCHAR:
+ /* fall through */
+ case Types.CHAR:
+ /* fall through */
+ case Types.CLOB:
+ /* fall through */
+ case Types.NCHAR:
+ /* fall through */
+ case Types.NCLOB:
+ /* fall through */
+ case Types.NVARCHAR:
+ /* fall through */
+ case Types.LONGNVARCHAR:
+ value = rs.getString(i);
+ paramValue = new ParamValue(value);
+ break;
+ /* handle numbers */
+ case Types.INTEGER:
+ /* fall through */
+ case Types.TINYINT:
+ /* fall through */
+ case Types.SMALLINT:
+ value = ConverterUtil.convertToString(rs.getInt(i));
+ paramValue = new ParamValue(value);
+ break;
+ case Types.DOUBLE:
+ value = ConverterUtil.convertToString(rs.getDouble(i));
+ paramValue = new ParamValue(value);
+ break;
+ case Types.FLOAT:
+ value = ConverterUtil.convertToString(rs.getFloat(i));
+ paramValue = new ParamValue(value);
+ break;
+ case Types.BOOLEAN:
+ /* fall through */
+ case Types.BIT:
+ value = ConverterUtil.convertToString(rs.getBoolean(i));
+ paramValue = new ParamValue(value);
+ break;
+ case Types.DECIMAL:
+ bigDecimal = rs.getBigDecimal(i);
+ if (bigDecimal != null) {
+ value = ConverterUtil.convertToString(bigDecimal);
+ } else {
+ value = null;
+ }
+ paramValue = new ParamValue(value);
+ break;
+ /* handle data/time values */
+ case Types.TIME:
+ /* handle time data type */
+ sqlTime = rs.getTime(i);
+ if (sqlTime != null) {
+ value = this.convertToTimeString(sqlTime);
+ } else {
+ value = null;
+ }
+ paramValue = new ParamValue(value);
+ break;
+ case Types.DATE:
+ /* handle date data type */
+ sqlDate = rs.getDate(i);
+ if (sqlDate != null) {
+ value = ConverterUtil.convertToString(sqlDate);
+ } else {
+ value = null;
+ }
+ paramValue = new ParamValue(value);
+ break;
+ case Types.TIMESTAMP:
+ sqlTimestamp = rs.getTimestamp(i);
+ if (sqlTimestamp != null) {
+ value = this.convertToTimestampString(sqlTimestamp);
+ } else {
+ value = null;
+ }
+ paramValue = new ParamValue(value);
+ break;
+ /* handle binary types */
+ case Types.BLOB:
+ sqlBlob = rs.getBlob(i);
+ if (sqlBlob != null) {
+ value = this.getBase64StringFromInputStream(sqlBlob.getBinaryStream());
+ } else {
+ value = null;
+ }
+ paramValue = new ParamValue(value);
+ break;
+ case Types.BINARY:
+ /* fall through */
+ case Types.LONGVARBINARY:
+ /* fall through */
+ case Types.VARBINARY:
+ binInStream = rs.getBinaryStream(i);
+ if (binInStream != null) {
+ value = this.getBase64StringFromInputStream(binInStream);
+ } else {
+ value = null;
+ }
+ paramValue = new ParamValue(value);
+ break;
+ /* handling User Defined Types */
+ case Types.STRUCT:
+ Struct udt = (Struct) rs.getObject(i);
+ paramValue = new ParamValue(udt);
+ break;
+ /* handle all other types as strings */
+ default:
+ value = rs.getString(i);
+ paramValue = new ParamValue(value);
+ break;
+ }
+ dataEntry.addValue(useColumnNumbers ? Integer.toString(i) : metaData.getColumnLabel(i),
+ paramValue);
+ }
+ return dataEntry;
+ }
+
+ private String convertToTimeString(Time sqlTime) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(sqlTime.getTime());
+ return new org.apache.axis2.databinding.types.Time(cal).toString();
+ }
+
+ private String convertToTimestampString(Timestamp sqlTimestamp) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(sqlTimestamp.getTime());
+ return ConverterUtil.convertToString(cal);
+ }
+
+ private String getBase64StringFromInputStream(InputStream in) throws SQLException {
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ String strData;
+ try {
+ byte[] buff = new byte[512];
+ int i = 0;
+ while ((i = in.read(buff)) > 0) {
+ byteOut.write(buff, 0, i);
+ }
+ in.close();
+ byte[] base64Data = Base64.encodeBase64(byteOut.toByteArray());
+ strData = new String(base64Data, DBConstants.DEFAULT_CHAR_SET_TYPE);
+ } catch (Exception e) {
+ throw new SQLException(e.getMessage());
+ }
+ return strData;
+ }
+
+ private byte[] getBytesFromBase64String(String base64Str) throws SQLException {
+ try {
+ byte[] data = Base64.decodeBase64(base64Str.getBytes(DBConstants.DEFAULT_CHAR_SET_TYPE));
+ return data;
+ } catch (Exception e) {
+ throw new SQLException(e.getMessage());
+ }
+ }
+
+ /**
+ * Returns the SQL manipulated to suite the given parameters,
+ * e.g. adding additional "?"'s for array types.
+ */
+ public String createProcessedSql(String sql, InternalParamCollection params, int paramCount) {
+ String currentSql = sql;
+ int start = 0;
+ Object[] vals;
+ InternalParam param;
+ ParamValue value;
+ int count;
+ for (int i = 1; i <= paramCount; i++) {
+ param = params.getParam(i);
+ value = param.getValue();
+ /* value can be null in stored proc OUT params, so it is simply treated as a
+ * single param, because the number of elements in an array cannot be
+ * calculated, since there's no actual value passed in */
+ if (value != null && (value.getValueType() == ParamValue.PARAM_VALUE_ARRAY)) {
+ count = (value.getArrayValue()).size();
+ if (this.hasRefCursor()) {
this.arrayTypesEnabled = true;
- int currentRefCursorOrdinal = this.currentRefCursor.getOrdinal();
+ int currentRefCursorOrdinal = this.getCurrentRefCursor().getOrdinal();
if (i < currentRefCursorOrdinal) {
this.prevRefCursorOrdinal = currentRefCursorOrdinal;
- this.currentRefCursor.setOrdinal(currentRefCursorOrdinal + count - 1);
+ this.getCurrentRefCursor().setOrdinal(currentRefCursorOrdinal + count - 1);
+ }
+ } else if (this.hasSqlArrayType()) {
+ this.arrayTypesEnabled = true;
+ int currentSqlArrayOrdinal = this.getCurrentSqlArray().getOrdinal();
+ if (i < currentSqlArrayOrdinal) {
+ this.prevRefCursorOrdinal = currentSqlArrayOrdinal;
+ this.getCurrentSqlArray().setOrdinal(currentSqlArrayOrdinal + count - 1);
+ }
+ }
+ } else {
+ count = 1;
+ }
+ vals = this.expandSQL(start, count, currentSql);
+ start = (Integer) vals[0];
+ currentSql = (String) vals[1];
+ }
+ return currentSql;
+ }
+
+ /**
+ * Given the starting position, this method searches for the first occurence of "?"
+ * and replace it with `count` "?"'s.
+ * Returns [0] - end position of "?"'s, [1] - modified sql.
+ */
+ private Object[] expandSQL(int start, int count, String sql) {
+ StringBuilder result = new StringBuilder();
+ int n = sql.length();
+ int end = n;
+ for (int i = start; i < n; i++) {
+ if (sql.charAt(i) == '?') {
+ result.append(sql.substring(0, i));
+ result.append(this.generateQuestionMarks(count));
+ end = result.length() + 1;
+ if (i + 1 < n) {
+ result.append(sql.substring(i + 1));
+ }
+ break;
+ }
+ }
+ return new Object[]{end, result.toString()};
+ }
+
+ private String generateQuestionMarks(int n) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < n; i++) {
+ builder.append("?");
+ if (i + 1 < n) {
+ builder.append(",");
+ }
+ }
+ return builder.toString();
+ }
+
+ private int calculateParamCount(String sql) {
+ int n = 0;
+ for (char ch : sql.toCharArray()) {
+ if (ch == '?') {
+ n++;
+ }
+ }
+ return n;
+ }
+
+ private PreparedStatement createProcessedPreparedStatement(
+ int queryType, InternalParamCollection params, Connection conn) throws DataServiceFault {
+ try {
+ /* lets see first if there's already a batch prepared statement created */
+ boolean inTheMiddleOfABatch = false;
+ PreparedStatement stmt = this.getBatchPreparedStatement();
+
+ /* create a new prepared statement */
+ if (stmt == null) {
+ String processedSQL = this.createProcessedSql(this.getSql(), params, this.getParamCount());
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (this.isReturnGeneratedKeys()) {
+ if (this.getKeyColumns() != null) {
+ stmt = conn.prepareStatement(processedSQL, this.getKeyColumns());
+ } else {
+ stmt = conn.prepareStatement(processedSQL,
+ Statement.RETURN_GENERATED_KEYS);
+ }
+ } else {
+ stmt = conn.prepareStatement(processedSQL);
+ }
+ } else if (queryType == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
+ stmt = conn.prepareCall(processedSQL);
+ } else {
+ throw new DataServiceFault("Unsupported query type: " + queryType);
+ }
+ } else {
+ inTheMiddleOfABatch = true;
+ }
+
+ if (!inTheMiddleOfABatch) {
+ /* set query timeout */
+ if (this.isHasQueryTimeout()) {
+ stmt.setQueryTimeout(this.getQueryTimeout());
+ }
+ /* set fetch direction */
+ if (this.isHasFetchDirection()) {
+ stmt.setFetchDirection(this.getFetchDirection());
+ }
+ /* set fetch size - user's setting */
+ if (this.isHasFetchSize()) {
+ stmt.setFetchSize(this.getFetchSize());
+ } else {
+ /* stream data by sections - avoid the full result set to be loaded to memory,
+ * and only stream if there aren't any OUT parameters, MySQL fails in the scenario
+ * of streaming and OUT parameters, so the possibility is there for other DBMSs */
+ if (!this.hasOutParams()) {
+ stmt.setFetchSize(this.getOptimalRSFetchSize());
+ }
+ }
+ /* set max field size */
+ if (this.isHasMaxFieldSize()) {
+ stmt.setMaxFieldSize(this.getMaxFieldSize());
+ }
+ /* set max rows */
+ if (this.isHasMaxRows()) {
+ stmt.setMaxRows(this.getMaxRows());
+ }
+ }
+
+ int currentOrdinal = 0;
+ InternalParam param = null;
+ ParamValue value = null;
+ int count = this.getParamCount();
+ for (int i = 1; i <= count; i++) {
+ param = params.getParam(i);
+ value = param.getValue();
+ /* handle array values, if value is null, this param has to be an OUT param */
+ if (value != null && value.getValueType() == ParamValue.PARAM_VALUE_ARRAY) {
+ for (String arrayElement : value.getArrayValue()) {
+ this.setParamInPreparedStatement(stmt, param, arrayElement, queryType,
+ currentOrdinal);
+ currentOrdinal++;
}
+ } else { /* scalar value */
+ this.setParamInPreparedStatement(stmt, param,
+ value != null ? value.getScalarValue() : null, queryType, currentOrdinal);
+ currentOrdinal++;
}
- } else {
- count = 1;
- }
- vals = this.expandSQL(start, count, currentSql);
- start = (Integer) vals[0];
- currentSql = (String) vals[1];
- }
- return currentSql;
- }
-
- /**
- * Given the starting position, this method searches for the first occurence of "?"
- * and replace it with `count` "?"'s.
- * Returns [0] - end position of "?"'s, [1] - modified sql.
- */
- private Object[] expandSQL(int start, int count, String sql) {
- StringBuilder result = new StringBuilder();
- int n = sql.length();
- int end = n;
- for (int i = start; i < n; i++) {
- if (sql.charAt(i) == '?') {
- result.append(sql.substring(0, i));
- result.append(this.generateQuestionMarks(count));
- end = result.length() + 1;
- if (i + 1 < n) {
- result.append(sql.substring(i + 1));
- }
- break;
- }
- }
- return new Object[] { end, result.toString() };
- }
-
- private String generateQuestionMarks(int n) {
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < n; i++) {
- builder.append("?");
- if (i + 1 < n) {
- builder.append(",");
- }
- }
- return builder.toString();
- }
-
- private int calculateParamCount(String sql) {
- int n = 0;
- for (char ch : sql.toCharArray()) {
- if (ch == '?') {
- n++;
- }
- }
- return n;
- }
-
- private PreparedStatement createProcessedPreparedStatement(int queryType,
- InternalParamCollection params, Connection conn) throws DataServiceFault {
- try {
- /* lets see first if there's already a batch prepared statement created */
- boolean inTheMiddleOfABatch = false;
- PreparedStatement stmt = this.getBatchPreparedStatement();
-
- /* create a new prepared statement */
- if (stmt == null) {
- String processedSQL = this.createProcessedSql(this.getSql(), params, this.getParamCount());
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (this.isReturnGeneratedKeys()) {
- if (this.getKeyColumns() != null) {
- stmt = conn.prepareStatement(processedSQL, this.getKeyColumns());
- } else {
- stmt = conn.prepareStatement(processedSQL,
- Statement.RETURN_GENERATED_KEYS);
- }
- } else {
- stmt = conn.prepareStatement(processedSQL);
- }
- } else if (queryType == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
- stmt = conn.prepareCall(processedSQL);
- } else {
- throw new DataServiceFault("Unsupported query type: " + queryType);
- }
- } else {
- inTheMiddleOfABatch = true;
- }
-
- if (!inTheMiddleOfABatch) {
- /* set query timeout */
- if (this.isHasQueryTimeout()) {
- stmt.setQueryTimeout(this.getQueryTimeout());
- }
- /* set fetch direction */
- if (this.isHasFetchDirection()) {
- stmt.setFetchDirection(this.getFetchDirection());
- }
- /* set fetch size - user's setting */
- if (this.isHasFetchSize()) {
- stmt.setFetchSize(this.getFetchSize());
- } else {
- /* stream data by sections - avoid the full result set to be loaded to memory,
- * and only stream if there aren't any OUT parameters, MySQL fails in the scenario
- * of streaming and OUT parameters, so the possibility is there for other DBMSs */
- if (!this.hasOutParams()) {
- stmt.setFetchSize(this.getOptimalRSFetchSize());
- }
- }
- /* set max field size */
- if (this.isHasMaxFieldSize()) {
- stmt.setMaxFieldSize(this.getMaxFieldSize());
- }
- /* set max rows */
- if (this.isHasMaxRows()) {
- stmt.setMaxRows(this.getMaxRows());
- }
- }
-
- int currentOrdinal = 0;
- InternalParam param = null;
- ParamValue value = null;
- int count = this.getParamCount();
- for (int i = 1; i <= count; i++) {
- param = params.getParam(i);
- value = param.getValue();
- /* handle array values, if value is null, this param has to be an OUT param */
- if (value != null && value.getValueType() == ParamValue.PARAM_VALUE_ARRAY) {
- for (String arrayElement : value.getArrayValue()) {
- this.setParamInPreparedStatement(stmt, param.getName(), arrayElement,
- param.getSqlType(), param.getType(), queryType, currentOrdinal);
- currentOrdinal++;
- }
- } else { /* scalar value */
- this.setParamInPreparedStatement(stmt, param.getName(),
- value != null ? value.getScalarValue() : null,
- param.getSqlType(), param.getType(), queryType, currentOrdinal);
- currentOrdinal++;
- }
- }
-
- /* if we are in JDBC batch processing mode, batch it! */
- if (this.isJDBCBatchRequest()) {
- stmt.addBatch();
- }
-
- return stmt;
- } catch (SQLException e) {
- throw new DataServiceFault(e, "Error in 'createProcessedPreparedStatement'");
- }
- }
-
- private void setParamInPreparedStatement(PreparedStatement stmt, String paramName,
- String value, String sqlType, String paramType,
- int queryType, int index) throws SQLException, DataServiceFault {
+ }
+
+ /* if we are in JDBC batch processing mode, batch it! */
+ if (this.isJDBCBatchRequest()) {
+ stmt.addBatch();
+ }
+
+ return stmt;
+ } catch (SQLException e) {
+ throw new DataServiceFault(e, "Error in 'createProcessedPreparedStatement'");
+ }
+ }
+
+ private void setParamInPreparedStatement(PreparedStatement stmt, InternalParam param,
+ String value, int queryType,
+ int index) throws SQLException, DataServiceFault {
+ String paramName = param.getName();
+ String sqlType = param.getSqlType();
+ String paramType = param.getType();
+ String structType = param.getStructType();
if (sqlType == null) {
/* defaults to string */
setDefaultStringValue(value, paramType, stmt, index);
@@ -1362,760 +1403,780 @@
} else if (DBConstants.DataTypes.TIMESTAMP.equals(sqlType)) {
setTimestampValue(queryType, paramName, value, paramType, stmt, index);
} else if (DBConstants.DataTypes.TIME.equals(sqlType)) {
- setTimeValue(queryType, paramName, value, paramType, stmt, index);
+ setTimeValue(queryType, paramName, value, paramType, stmt, index);
} else if (DBConstants.DataTypes.BINARY.equals(sqlType)) {
setBinaryValue(queryType, paramName, value, paramType, stmt, index);
} else if (DBConstants.DataTypes.ORACLE_REF_CURSOR.equals(sqlType)) {
setOracleRefCusor(stmt, index);
- } else if (DBConstants.DataTypes.UDT.equals(sqlType)){
- setUserDefinedType(stmt, index, paramName, paramType);
- } else{
- throw new DataServiceFault("[" + this.getDataService().getName() +
- "] Found Unsupported data type : " + sqlType + " as input parameter.");
+ } else if (DBConstants.DataTypes.STRUCT.equals(sqlType)) {
+ setUserDefinedType(stmt, index, paramType, structType);
+ } else if (DBConstants.DataTypes.ARRAY.equals(sqlType)) {
+ setArrayValue(stmt, index, paramType, structType);
+ } else {
+ throw new DataServiceFault("[" + this.getDataService().getName() +
+ "] Found Unsupported data type : " + sqlType + " as input parameter.");
}
- }
-
+ }
+
+ private void setArrayValue(PreparedStatement sqlQuery, int i, String paramType,
+ String structType) throws SQLException, DataServiceFault {
+ if (QueryTypes.OUT.equals(paramType)) {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1, Types.ARRAY, structType);
+ } else {
+ throw new DataServiceFault("IN or INOUT operations are not supported for SQL Arrays");
+ }
+ }
+
private void setDefaultStringValue(String value, String paramType,
- PreparedStatement sqlQuery, int i) throws SQLException {
- if (QueryTypes.IN.equals(paramType)) {
- sqlQuery.setString(i + 1, value);
- } else if (QueryTypes.INOUT.equals(paramType)) {
- sqlQuery.setString(i + 1, value);
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.VARCHAR);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.VARCHAR);
- }
- }
-
- private void setTimeValue(int queryType, String paramName,
- String value, String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException, DataServiceFault {
- Time time = null;
- try {
- if (value != null) {
- time = DBUtils.getTime(value);
- }
- } catch (ParseException e) {
- throw new DataServiceFault(e,
- "Incorrect Time format for parameter : " + paramName
- + ". Time should be in the format hh:mm:ss");
- }
- if ("IN".equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.TIME);
- } else {
- sqlQuery.setTime(i + 1, time);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.TIME);
- } else {
- ((CallableStatement) sqlQuery).setTime(i + 1, time);
- }
- }
- } else if ("INOUT".equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.TIME);
- } else {
- ((CallableStatement) sqlQuery).setTime(i + 1, time);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.TIME);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.TIME);
- }
- }
-
- private void setBinaryValue(int queryType, String paramName,
- String value, String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException, DataServiceFault {
- if ("IN".equals(paramType)) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.BINARY);
- } else {
- byte[] data = this.getBytesFromBase64String(value);
- sqlQuery.setBinaryStream(i + 1, new ByteArrayInputStream(data), data.length);
- }
- } else if ("INOUT".equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.BINARY);
- } else {
- byte[] data = this.getBytesFromBase64String(value);
- ((CallableStatement) sqlQuery).setBinaryStream(i + 1,
- new ByteArrayInputStream(data), data.length);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.BINARY);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.BINARY);
- }
- }
-
- private void setOracleRefCusor(PreparedStatement sqlQuery, int i)
- throws SQLException, DataServiceFault {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1, ORACLE_REF_CURSOR_TYPE);
- }
+ PreparedStatement sqlQuery, int i) throws SQLException {
+ if (QueryTypes.IN.equals(paramType)) {
+ sqlQuery.setString(i + 1, value);
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ sqlQuery.setString(i + 1, value);
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.VARCHAR);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.VARCHAR);
+ }
+ }
+
+ private void setTimeValue(int queryType, String paramName,
+ String value, String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException, DataServiceFault {
+ Time time = null;
+ try {
+ if (value != null) {
+ time = DBUtils.getTime(value);
+ }
+ } catch (ParseException e) {
+ throw new DataServiceFault(e,
+ "Incorrect Time format for parameter : " + paramName
+ + ". Time should be in the format hh:mm:ss");
+ }
+ if ("IN".equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.TIME);
+ } else {
+ sqlQuery.setTime(i + 1, time);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.TIME);
+ } else {
+ ((CallableStatement) sqlQuery).setTime(i + 1, time);
+ }
+ }
+ } else if ("INOUT".equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.TIME);
+ } else {
+ ((CallableStatement) sqlQuery).setTime(i + 1, time);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.TIME);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.TIME);
+ }
+ }
+
+ private void setBinaryValue(int queryType, String paramName,
+ String value, String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException, DataServiceFault {
+ if ("IN".equals(paramType)) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.BINARY);
+ } else {
+ byte[] data = this.getBytesFromBase64String(value);
+ sqlQuery.setBinaryStream(i + 1, new ByteArrayInputStream(data), data.length);
+ }
+ } else if ("INOUT".equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.BINARY);
+ } else {
+ byte[] data = this.getBytesFromBase64String(value);
+ ((CallableStatement) sqlQuery).setBinaryStream(i + 1,
+ new ByteArrayInputStream(data), data.length);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.BINARY);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.BINARY);
+ }
+ }
+
+ private void setOracleRefCusor(PreparedStatement sqlQuery, int i)
+ throws SQLException, DataServiceFault {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1, ORACLE_REF_CURSOR_TYPE);
+ }
/**
* This method sets the parameters to be passed to/from an oracle stored procedure that
* deals with User Defined Types.
- * @param sqlQuery Prepared Statement
+ *
+ * @param sqlQuery Prepared Statement
* @param parameterIndex current parameter index
- * @param udtName Name of the User Defined Type
- * @param paramType Whether the parameter is IN or OUT
- * @throws SQLException Throws an SQL Exception
+ * @param structType Name of the User Defined Type
+ * @param paramType Whether the parameter is IN or OUT
+ * @throws SQLException Throws an SQL Exception
+ * @throws DataServiceFault DataServiceFault
*/
- private void setUserDefinedType(PreparedStatement sqlQuery, int parameterIndex,
- String udtName, String paramType) throws SQLException {
- if (QueryTypes.OUT.equals(paramType)) {
- ((CallableStatement) sqlQuery).registerOutParameter(parameterIndex + 1, Types.STRUCT,
- udtName);
- } else if (QueryTypes.IN.equals(paramType)) {
- // ((CallableStatement)sqlQuery).setObject(parameterIndex+1,new
- // UserDefinedType(udtName));
- }
- }
-
- private void setTimestampValue(int queryType, String paramName,
- String value, String paramType, PreparedStatement sqlQuery, int i)
- throws DataServiceFault, SQLException {
- Timestamp timestamp = null;
- try {
- if (value != null) {
- timestamp = DBUtils.getTimestamp(value);
- }
- } catch (ParseException e) {
- throw new DataServiceFault(e,
- "Incorrect Timestamp format for parameter : "
- + paramName
- + ". Timestamp should be in one of following formats "
- + "yyyy-MM-dd'T'hh:mm:ss.sss'+'hh:mm, "
- + "yyyy-MM-dd'T'hh:mm:ss.sss'-'hh:mm, "
- + "yyyy-MM-dd'T'hh:mm:ss.sss'Z', "
- + "yyyy-MM-dd hh:mm:ss.SSSSSS or "
- + "yyyy-MM-dd hh:mm:ss");
- }
- if ("IN".equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.TIMESTAMP);
- } else {
- sqlQuery.setTimestamp(i + 1, timestamp);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.TIMESTAMP);
- } else {
- ((CallableStatement) sqlQuery).setTimestamp(i + 1,
- timestamp);
- }
- }
- } else if ("INOUT".equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.TIMESTAMP);
- } else {
- ((CallableStatement) sqlQuery).setTimestamp(i + 1, timestamp);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.TIMESTAMP);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.TIMESTAMP);
- }
- }
-
- private void setDateValue(int queryType, String paramName,
- String value, String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException, DataServiceFault {
- Date val = null;
- if (value != null) {
- val = DBUtils.getDate(value);
- }
- try {
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.DATE);
- } else {
- sqlQuery.setDate(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.DATE);
- } else {
- ((CallableStatement) sqlQuery).setDate(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.DATE);
- } else {
- ((CallableStatement) sqlQuery).setDate(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.DATE);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.DATE);
- }
- } catch (IllegalArgumentException e) {
- throw new DataServiceFault(e, "Incorrect date format for parameter : "
- + paramName + ". Date should be in yyyy-mm-dd format.");
- }
- }
-
- private void setRealValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- Float val = null;
- if (value != null) {
- val = new Float(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.FLOAT);
- } else {
- sqlQuery.setFloat(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.FLOAT);
- } else {
- ((CallableStatement) sqlQuery).setFloat(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.FLOAT);
- } else {
- ((CallableStatement) sqlQuery).setFloat(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.FLOAT);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.FLOAT);
- }
- }
-
- private void setBigIntValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- Long val = null;
- if (value != null) {
- val = new Long(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.BIGINT);
- } else {
- sqlQuery.setLong(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.BIGINT);
- } else {
- ((CallableStatement) sqlQuery).setLong(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.BIGINT);
- } else {
- ((CallableStatement) sqlQuery).setLong(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.BIGINT);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.BIGINT);
- }
- }
-
- private void setSmallIntValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- Short val = null;
- if (value != null) {
- val = new Short(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.SMALLINT);
- } else {
- sqlQuery.setShort(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.SMALLINT);
- } else {
- ((CallableStatement) sqlQuery).setShort(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.SMALLINT);
- } else {
- ((CallableStatement) sqlQuery).setShort(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.SMALLINT);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.SMALLINT);
- }
- }
-
- private void setTinyIntValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- Byte val = null;
- if (value != null) {
- val = new Byte(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.TINYINT);
- } else {
- sqlQuery.setByte(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.TINYINT);
- } else {
- ((CallableStatement) sqlQuery).setByte(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.TINYINT);
- } else {
- ((CallableStatement) sqlQuery).setByte(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.TINYINT);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.TINYINT);
- }
- }
-
- private void setBitValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- Boolean val = null;
- if (value != null) {
- val = Boolean.valueOf(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.BIT);
- } else {
- sqlQuery.setBoolean(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.BIT);
- } else {
- ((CallableStatement) sqlQuery).setBoolean(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.BIT);
- } else {
- ((CallableStatement) sqlQuery).setBoolean(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.BIT);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.BIT);
- }
- }
-
- private void setNumericValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- BigDecimal val = null;
- if (value != null) {
- val = new BigDecimal(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.NUMERIC);
- } else {
- sqlQuery.setBigDecimal(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.NUMERIC);
- } else {
- ((CallableStatement) sqlQuery).setBigDecimal(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.NUMERIC);
- } else {
- ((CallableStatement) sqlQuery).setBigDecimal(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.NUMERIC);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.NUMERIC);
- }
- }
-
- private void setDoubleValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- Double val = null;
- if (value != null) {
- val = Double.parseDouble(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.DOUBLE);
- } else {
- sqlQuery.setDouble(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.DOUBLE);
- } else {
- ((CallableStatement) sqlQuery).setDouble(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.DOUBLE);
- } else {
- ((CallableStatement) sqlQuery).setDouble(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.DOUBLE);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.DOUBLE);
- }
- }
-
- private void setStringValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.VARCHAR);
- } else {
- sqlQuery.setString(i + 1, value);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.VARCHAR);
- } else {
- ((CallableStatement) sqlQuery).setString(i + 1, value);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.VARCHAR);
- } else {
- ((CallableStatement) sqlQuery).setString(i + 1, value);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.VARCHAR);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.VARCHAR);
- }
- }
-
- private void setIntValue(int queryType, String value,
- String paramType, PreparedStatement sqlQuery, int i)
- throws SQLException {
- Integer val = null;
- if (value != null) {
- val = Integer.parseInt(value);
- }
- if (QueryTypes.IN.equals(paramType)) {
- if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- if (value == null) {
- sqlQuery.setNull(i + 1, java.sql.Types.INTEGER);
- } else {
- sqlQuery.setInt(i + 1, val);
- }
- } else {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.INTEGER);
- } else {
- ((CallableStatement) sqlQuery).setInt(i + 1, val);
- }
- }
- } else if (QueryTypes.INOUT.equals(paramType)) {
- if (value == null) {
- ((CallableStatement) sqlQuery).setNull(i + 1,
- java.sql.Types.INTEGER);
- } else {
- ((CallableStatement) sqlQuery).setInt(i + 1, val);
- }
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.INTEGER);
- } else {
- ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
- java.sql.Types.INTEGER);
- }
- }
-
- private ParamValue getOutparameterValue(CallableStatement cs,
- String type, int ordinal)
- throws DataServiceFault {
- try {
+ private void setUserDefinedType(PreparedStatement sqlQuery,
+ int parameterIndex,
+ String paramType,
+ String structType) throws SQLException, DataServiceFault {
+ if (QueryTypes.OUT.equals(paramType)) {
+ ((CallableStatement) sqlQuery).registerOutParameter(parameterIndex + 1, Types.STRUCT,
+ structType);
+ } else {
+ throw new DataServiceFault("IN or INOUT operations are not supported for User " +
+ "Defined Types");
+ }
+ }
+
+ private void setTimestampValue(int queryType, String paramName,
+ String value, String paramType, PreparedStatement sqlQuery, int i)
+ throws DataServiceFault, SQLException {
+ Timestamp timestamp = null;
+ try {
+ if (value != null) {
+ timestamp = DBUtils.getTimestamp(value);
+ }
+ } catch (ParseException e) {
+ throw new DataServiceFault(e,
+ "Incorrect Timestamp format for parameter : "
+ + paramName
+ + ". Timestamp should be in one of following formats "
+ + "yyyy-MM-dd'T'hh:mm:ss.sss'+'hh:mm, "
+ + "yyyy-MM-dd'T'hh:mm:ss.sss'-'hh:mm, "
+ + "yyyy-MM-dd'T'hh:mm:ss.sss'Z', "
+ + "yyyy-MM-dd hh:mm:ss.SSSSSS or "
+ + "yyyy-MM-dd hh:mm:ss");
+ }
+ if ("IN".equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.TIMESTAMP);
+ } else {
+ sqlQuery.setTimestamp(i + 1, timestamp);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.TIMESTAMP);
+ } else {
+ ((CallableStatement) sqlQuery).setTimestamp(i + 1,
+ timestamp);
+ }
+ }
+ } else if ("INOUT".equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.TIMESTAMP);
+ } else {
+ ((CallableStatement) sqlQuery).setTimestamp(i + 1, timestamp);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.TIMESTAMP);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.TIMESTAMP);
+ }
+ }
+
+ private void setDateValue(int queryType, String paramName,
+ String value, String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException, DataServiceFault {
+ Date val = null;
+ if (value != null) {
+ val = DBUtils.getDate(value);
+ }
+ try {
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.DATE);
+ } else {
+ sqlQuery.setDate(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.DATE);
+ } else {
+ ((CallableStatement) sqlQuery).setDate(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.DATE);
+ } else {
+ ((CallableStatement) sqlQuery).setDate(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.DATE);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.DATE);
+ }
+ } catch (IllegalArgumentException e) {
+ throw new DataServiceFault(e, "Incorrect date format for parameter : "
+ + paramName + ". Date should be in yyyy-mm-dd format.");
+ }
+ }
+
+ private void setRealValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ Float val = null;
+ if (value != null) {
+ val = new Float(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.FLOAT);
+ } else {
+ sqlQuery.setFloat(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.FLOAT);
+ } else {
+ ((CallableStatement) sqlQuery).setFloat(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.FLOAT);
+ } else {
+ ((CallableStatement) sqlQuery).setFloat(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.FLOAT);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.FLOAT);
+ }
+ }
+
+ private void setBigIntValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ Long val = null;
+ if (value != null) {
+ val = new Long(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.BIGINT);
+ } else {
+ sqlQuery.setLong(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.BIGINT);
+ } else {
+ ((CallableStatement) sqlQuery).setLong(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.BIGINT);
+ } else {
+ ((CallableStatement) sqlQuery).setLong(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.BIGINT);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.BIGINT);
+ }
+ }
+
+ private void setSmallIntValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ Short val = null;
+ if (value != null) {
+ val = new Short(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.SMALLINT);
+ } else {
+ sqlQuery.setShort(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.SMALLINT);
+ } else {
+ ((CallableStatement) sqlQuery).setShort(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.SMALLINT);
+ } else {
+ ((CallableStatement) sqlQuery).setShort(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.SMALLINT);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.SMALLINT);
+ }
+ }
+
+ private void setTinyIntValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ Byte val = null;
+ if (value != null) {
+ val = new Byte(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.TINYINT);
+ } else {
+ sqlQuery.setByte(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.TINYINT);
+ } else {
+ ((CallableStatement) sqlQuery).setByte(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.TINYINT);
+ } else {
+ ((CallableStatement) sqlQuery).setByte(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.TINYINT);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.TINYINT);
+ }
+ }
+
+ private void setBitValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ Boolean val = null;
+ if (value != null) {
+ val = Boolean.valueOf(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.BIT);
+ } else {
+ sqlQuery.setBoolean(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.BIT);
+ } else {
+ ((CallableStatement) sqlQuery).setBoolean(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.BIT);
+ } else {
+ ((CallableStatement) sqlQuery).setBoolean(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.BIT);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.BIT);
+ }
+ }
+
+ private void setNumericValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ BigDecimal val = null;
+ if (value != null) {
+ val = new BigDecimal(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.NUMERIC);
+ } else {
+ sqlQuery.setBigDecimal(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.NUMERIC);
+ } else {
+ ((CallableStatement) sqlQuery).setBigDecimal(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.NUMERIC);
+ } else {
+ ((CallableStatement) sqlQuery).setBigDecimal(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.NUMERIC);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.NUMERIC);
+ }
+ }
+
+ private void setDoubleValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ Double val = null;
+ if (value != null) {
+ val = Double.parseDouble(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.DOUBLE);
+ } else {
+ sqlQuery.setDouble(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.DOUBLE);
+ } else {
+ ((CallableStatement) sqlQuery).setDouble(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.DOUBLE);
+ } else {
+ ((CallableStatement) sqlQuery).setDouble(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.DOUBLE);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.DOUBLE);
+ }
+ }
+
+ private void setStringValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.VARCHAR);
+ } else {
+ sqlQuery.setString(i + 1, value);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.VARCHAR);
+ } else {
+ ((CallableStatement) sqlQuery).setString(i + 1, value);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.VARCHAR);
+ } else {
+ ((CallableStatement) sqlQuery).setString(i + 1, value);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.VARCHAR);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.VARCHAR);
+ }
+ }
+
+ private void setIntValue(int queryType, String value,
+ String paramType, PreparedStatement sqlQuery, int i)
+ throws SQLException {
+ Integer val = null;
+ if (value != null) {
+ val = Integer.parseInt(value);
+ }
+ if (QueryTypes.IN.equals(paramType)) {
+ if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ if (value == null) {
+ sqlQuery.setNull(i + 1, java.sql.Types.INTEGER);
+ } else {
+ sqlQuery.setInt(i + 1, val);
+ }
+ } else {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.INTEGER);
+ } else {
+ ((CallableStatement) sqlQuery).setInt(i + 1, val);
+ }
+ }
+ } else if (QueryTypes.INOUT.equals(paramType)) {
+ if (value == null) {
+ ((CallableStatement) sqlQuery).setNull(i + 1,
+ java.sql.Types.INTEGER);
+ } else {
+ ((CallableStatement) sqlQuery).setInt(i + 1, val);
+ }
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.INTEGER);
+ } else {
+ ((CallableStatement) sqlQuery).registerOutParameter(i + 1,
+ java.sql.Types.INTEGER);
+ }
+ }
+
+ private ParamValue getOutparameterValue(CallableStatement cs,
+ String type, int ordinal)
+ throws DataServiceFault {
+ try {
Object elementValue;
if (type.equals(DBConstants.DataTypes.STRING)) {
- elementValue = cs.getString(ordinal);
- return new ParamValue(elementValue == null ? null :
- elementValue.toString());
- } else if (type.equals(DBConstants.DataTypes.DOUBLE)) {
- elementValue = cs.getDouble(ordinal);
- return new ParamValue(elementValue == null ? null :
- ConverterUtil.convertToString((Double) elementValue));
- } else if (type.equals(DBConstants.DataTypes.BIGINT)) {
- elementValue = cs.getLong(ordinal);
- return new ParamValue(elementValue == null ? null :
- ConverterUtil.convertToString((Long) elementValue));
- } else if (type.equals(DBConstants.DataTypes.INTEGER)) {
- elementValue = cs.getInt(ordinal);
- return new ParamValue(elementValue == null ? null :
- ConverterUtil.convertToString((Integer) elementValue));
- } else if (type.equals(DBConstants.DataTypes.TIME)) {
- elementValue = cs.getTime(ordinal);
- return new ParamValue(elementValue == null ? null :
- this.convertToTimeString((Time) elementValue));
- } else if (type.equals(DBConstants.DataTypes.DATE)) {
- elementValue = cs.getDate(ordinal);
+ elementValue = cs.getString(ordinal);
+ return new ParamValue(elementValue == null ? null :
+ elementValue.toString());
+ } else if (type.equals(DBConstants.DataTypes.DOUBLE)) {
+ elementValue = cs.getDouble(ordinal);
+ return new ParamValue(elementValue == null ? null :
+ ConverterUtil.convertToString((Double) elementValue));
+ } else if (type.equals(DBConstants.DataTypes.BIGINT)) {
+ elementValue = cs.getLong(ordinal);
return new ParamValue(elementValue == null ? null :
- ConverterUtil.convertToString((Date) elementValue));
- } else if (type.equals(DBConstants.DataTypes.TIMESTAMP)) {
- elementValue = cs.getTimestamp(ordinal);
- return new ParamValue(elementValue == null ? null :
- this.convertToTimestampString((Timestamp) elementValue));
- } else if(type.equals(DBConstants.DataTypes.UDT)){
+ ConverterUtil.convertToString((Long) elementValue));
+ } else if (type.equals(DBConstants.DataTypes.INTEGER)) {
+ elementValue = cs.getInt(ordinal);
+ return new ParamValue(elementValue == null ? null :
+ ConverterUtil.convertToString((Integer) elementValue));
+ } else if (type.equals(DBConstants.DataTypes.TIME)) {
+ elementValue = cs.getTime(ordinal);
+ return new ParamValue(elementValue == null ? null :
+ this.convertToTimeString((Time) elementValue));
+ } else if (type.equals(DBConstants.DataTypes.DATE)) {
+ elementValue = cs.getDate(ordinal);
+ return new ParamValue(elementValue == null ? null :
+ ConverterUtil.convertToString((Date) elementValue));
+ } else if (type.equals(DBConstants.DataTypes.TIMESTAMP)) {
+ elementValue = cs.getTimestamp(ordinal);
+ return new ParamValue(elementValue == null ? null :
+ this.convertToTimestampString((Timestamp) elementValue));
+ } else if (type.equals(DBConstants.DataTypes.STRUCT)) {
elementValue = cs.getObject(ordinal);
- return new ParamValue(elementValue == null ? null :
- (Struct) elementValue);
+ return new ParamValue(elementValue == null ? null : (Struct) elementValue);
+ } else if (type.equals(DBConstants.DataTypes.ARRAY)) {
+ elementValue = cs.getArray(ordinal);
+ return new ParamValue(elementValue == null ? null : elementValue.toString());
} else {
- throw new DataServiceFault("Unsupported data type: " + type);
- }
- } catch (SQLException e) {
- throw new DataServiceFault(e, "Error in getting sql output parameter values.");
- }
- }
-
- public List<QueryParam> getOnlyOutQueryParams() {
- return onlyOutQueryParams;
- }
-
- public boolean isHasOrdinalOffsets() {
- return hasOrdinalOffsets;
- }
-
- public QueryParam getCurrentRefCursor() {
- return currentRefCursor;
- }
-
- public boolean hasRefCursor() {
- return hasRefCursor;
- }
-
- public void runQuery(XMLStreamWriter xmlWriter,
- InternalParamCollection params, int queryLevel)
- throws DataServiceFault {
- if (!this.isInited()) {
- throw new DataServiceFault("The data service query has not been initialised, the data source not available?");
- }
- /* process named parameters */
- params = this.createProcessedNamedParams(params);
-
- int type = this.getQueryType();
- if (type == SQLQuery.DS_QUERY_TYPE_NORMAL) {
- this.processNormalQuery(xmlWriter, params, queryLevel);
- } else if (type == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
- this.processStoredProcQuery(xmlWriter, params, queryLevel);
- } else {
- throw new DataServiceFault("Unsupported query type: " + type);
- }
- }
-
- @Override
- public void releaseBatchRequestResources() {
- /* clear the TL batch prepared statement */
- this.batchPreparedStatement.set(null);
- }
-
- /**
- * This class contains the stored procedure metadata collection.
- */
- private class StoredProcMetadataCollection {
-
- private List<StoredProcMetdataEntry> entries;
-
- public StoredProcMetadataCollection(ResultSet rs) throws SQLException {
- entries = new ArrayList<StoredProcMetdataEntry>();
- do { // use do-while loop since rs.next has already called once previously
- entries.add(new StoredProcMetdataEntry(rs.getString(1), rs.getString(2),
- rs.getString(3), rs.getString(4), rs.getShort(5), rs.getInt(6),
- rs.getString(7), rs.getInt(8), rs.getInt(9), rs.getShort(10),
- rs.getShort(11), rs.getShort(12), rs.getString(13)));
- } while (rs.next());
- }
-
- public List<StoredProcMetdataEntry> getEntries() {
- return entries;
- }
-
- }
-
- /**
- * This class represents a information on a single stored procedure parameter/result element.
- */
- public class StoredProcMetdataEntry {
-
- private String procedureCatalog;
-
- private String procedureSchema;
-
- private String procedureName;
-
- private String columnName;
-
- private short columnReturn;
-
- private int columnDataType;
-
- private String columnReturnTypeName;
-
- private int columnPrecision;
-
- private int columnByteLength;
-
- private short columnScale;
-
- private short columnRadix;
-
- private short columnNullable;
-
- private String columnRemarks;
-
- public StoredProcMetdataEntry(String procedureCatalog, String procedureSchema, String procedureName,
- String columnName, short columnReturn, int columnDataType, String columnReturnTypeName,
- int columnPrecision, int columnByteLength, short columnScale, short columnRadix,
- short columnNullable, String columnRemarks) {
- this.procedureCatalog = procedureCatalog;
- this.procedureSchema = procedureSchema;
- this.procedureName = procedureName;
- this.columnName = columnName;
- this.columnReturn = columnReturn;
- this.columnDataType = columnDataType;
- this.columnReturnTypeName = columnReturnTypeName;
- this.columnPrecision = columnPrecision;
- this.columnByteLength = columnByteLength;
- this.columnScale = columnScale;
- this.columnRadix = columnRadix;
- this.columnNullable = columnNullable;
- this.columnRemarks = columnRemarks;
- }
-
- public String getProcedureCatalog() {
- return procedureCatalog;
- }
-
- public String getProcedureSchema() {
- return procedureSchema;
- }
-
- public String getProcedureName() {
- return procedureName;
- }
-
- public String getColumnName() {
- return columnName;
- }
-
- public short getColumnReturn() {
- return columnReturn;
- }
-
- public int getColumnDataType() {
- return columnDataType;
- }
-
- public String getColumnReturnTypeName() {
- return columnReturnTypeName;
- }
-
- public int getColumnPrecision() {
- return columnPrecision;
- }
-
- public int getColumnByteLength() {
- return columnByteLength;
- }
-
- public short getColumnScale() {
- return columnScale;
- }
-
- public short getColumnRadix() {
- return columnRadix;
- }
-
- public short getColumnNullable() {
- return columnNullable;
- }
-
- public String getColumnRemarks() {
- return columnRemarks;
- }
-
- }
+ throw new DataServiceFault("Unsupported data type: " + type);
+ }
+ } catch (SQLException e) {
+ throw new DataServiceFault(e, "Error in getting sql output parameter values.");
+ }
+ }
+
+ public QueryParam getCurrentRefCursor() {
+ return currentRefCursor;
+ }
+
+ public boolean hasRefCursor() {
+ return hasRefCursor;
+ }
+
+ public boolean hasSqlArrayType() {
+ return hasSqlArrayType;
+ }
+
+ public boolean arrayTypesEnabled() {
+ return arrayTypesEnabled;
+ }
+
+ public int getPrevRefCusorOrdinal() {
+ return prevRefCursorOrdinal;
+ }
+
+ public void runQuery(XMLStreamWriter xmlWriter,
+ InternalParamCollection params, int queryLevel)
+ throws DataServiceFault {
+ if (!this.isInited()) {
+ throw new DataServiceFault("The data service query has not been initialised, the data source not available?");
+ }
+ /* process named parameters */
+ params = this.createProcessedNamedParams(params);
+
+ int type = this.getQueryType();
+ if (type == SQLQuery.DS_QUERY_TYPE_NORMAL) {
+ this.processNormalQuery(xmlWriter, params, queryLevel);
+ } else if (type == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
+ this.processStoredProcQuery(xmlWriter, params, queryLevel);
+ } else {
+ throw new DataServiceFault("Unsupported query type: " + type);
+ }
+ }
+
+ @Override
+ public void releaseBatchRequestResources() {
+ /* clear the TL batch prepared statement */
+ this.batchPreparedStatement.set(null);
+ }
+
+ /**
+ * This class contains the stored procedure metadata collection.
+ */
+ private class StoredProcMetadataCollection {
+
+ private List<StoredProcMetdataEntry> entries;
+
+ public StoredProcMetadataCollection(ResultSet rs) throws SQLException {
+ entries = new ArrayList<StoredProcMetdataEntry>();
+ do { // use do-while loop since rs.next has already called once previously
+ entries.add(new StoredProcMetdataEntry(rs.getString(1), rs.getString(2),
+ rs.getString(3), rs.getString(4), rs.getShort(5), rs.getInt(6),
+ rs.getString(7), rs.getInt(8), rs.getInt(9), rs.getShort(10),
+ rs.getShort(11), rs.getShort(12), rs.getString(13)));
+ } while (rs.next());
+ }
+
+ public List<StoredProcMetdataEntry> getEntries() {
+ return entries;
+ }
+
+ }
+
+ /**
+ * This class represents a information on a single stored procedure parameter/result element.
+ */
+ public class StoredProcMetdataEntry {
+
+ private String procedureCatalog;
+
+ private String procedureSchema;
+
+ private String procedureName;
+
+ private String columnName;
+
+ private short columnReturn;
+
+ private int columnDataType;
+
+ private String columnReturnTypeName;
+
+ private int columnPrecision;
+
+ private int columnByteLength;
+
+ private short columnScale;
+
+ private short columnRadix;
+
+ private short columnNullable;
+
+ private String columnRemarks;
+
+ public StoredProcMetdataEntry(String procedureCatalog, String procedureSchema, String procedureName,
+ String columnName, short columnReturn, int columnDataType, String columnReturnTypeName,
+ int columnPrecision, int columnByteLength, short columnScale, short columnRadix,
+ short columnNullable, String columnRemarks) {
+ this.procedureCatalog = procedureCatalog;
+ this.procedureSchema = procedureSchema;
+ this.procedureName = procedureName;
+ this.columnName = columnName;
+ this.columnReturn = columnReturn;
+ this.columnDataType = columnDataType;
+ this.columnReturnTypeName = columnReturnTypeName;
+ this.columnPrecision = columnPrecision;
+ this.columnByteLength = columnByteLength;
+ this.columnScale = columnScale;
+ this.columnRadix = columnRadix;
+ this.columnNullable = columnNullable;
+ this.columnRemarks = columnRemarks;
+ }
+
+ public String getProcedureCatalog() {
+ return procedureCatalog;
+ }
+
+ public String getProcedureSchema() {
+ return procedureSchema;
+ }
+
+ public String getProcedureName() {
+ return procedureName;
+ }
+
+ public String getColumnName() {
+ return columnName;
+ }
+
+ public short getColumnReturn() {
+ return columnReturn;
+ }
+
+ public int getColumnDataType() {
+ return columnDataType;
+ }
+
+ public String getColumnReturnTypeName() {
+ return columnReturnTypeName;
+ }
+
+ public int getColumnPrecision() {
+ return columnPrecision;
+ }
+
+ public int getColumnByteLength() {
+ return columnByteLength;
+ }
+
+ public short getColumnScale() {
+ return columnScale;
+ }
+
+ public short getColumnRadix() {
+ return columnRadix;
+ }
+
+ public short getColumnNullable() {
+ return columnNullable;
+ }
+
+ public String getColumnRemarks() {
+ return columnRemarks;
+ }
+ }
-}
+}
\ No newline at end of file
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/CallQuery.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/CallQuery.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/CallQuery.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/CallQuery.java Thu Oct 13 22:50:58 2011
@@ -21,12 +21,16 @@
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.databinding.types.NCName;
import org.wso2.carbon.core.multitenancy.SuperTenantCarbonContext;
+import org.wso2.carbon.dataservices.common.DBConstants;
import org.wso2.carbon.dataservices.common.DBConstants.DBSFields;
import org.wso2.carbon.dataservices.common.DBConstants.FaultCodes;
+import org.wso2.carbon.dataservices.core.DBUtils;
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.description.query.Query;
import javax.xml.stream.XMLStreamWriter;
+
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -92,22 +96,27 @@
/**
* This method returns the system variable's value given the property name.
*/
- private String evaluateGetProperty(String propName) {
- MessageContext context = MessageContext.getCurrentMessageContext();
- if (context != null) {
- /* so far we only evaluate the "USERNAME" value */
- if ("USERNAME".equals(propName)) {
- Object val = context.getProperty("username");
+ private Object evaluateGetProperty(String propName) throws DataServiceFault {
+ /* so far we only evaluate the "USERNAME" value */
+ if ("USERNAME".equals(propName)) {
+ MessageContext context = MessageContext.getCurrentMessageContext();
+ if (context != null) {
+ Object val = context.getProperty("username");
if (val != null) {
return val.toString();
}
- } else if ("TENANT_ID".equals(propName)) {
- return String.valueOf(SuperTenantCarbonContext.getCurrentContext().getTenantId());
- } else if ("NULL".equals(propName)) {
- /* represent the special null value (not empty string) */
- return null;
}
- }
+ } else if ("TENANT_ID".equals(propName)) {
+ return String.valueOf(SuperTenantCarbonContext.getCurrentContext().getTenantId());
+ } else if ("USER_ROLES".equals(propName)) {
+ MessageContext context = MessageContext.getCurrentMessageContext();
+ if (context != null) {
+ return DBUtils.getUserRoles(context);
+ }
+ } else if ("NULL".equals(propName)) {
+ /* represent the special null value (not empty string) */
+ return null;
+ }
return null;
}
@@ -117,32 +126,56 @@
* contain a reference to an system variable such as the current user's username,
* e.g. #{USERNAME}.
*/
- private ParamValue evaluateDefaultValue(ParamValue paramValue) {
+ private ParamValue evaluateDefaultValue(ParamValue paramValue, String paramType)
+ throws DataServiceFault {
if (paramValue.getValueType() != ParamValue.PARAM_VALUE_SCALAR) {
return paramValue;
}
String value = paramValue.getScalarValue();
- String evaluatedValue;
+ Object evaluatedValue;
if (value != null && value.startsWith("#{") && value.endsWith("}")) {
String propName = value.substring(2, value.length() - 1).trim();
evaluatedValue = this.evaluateGetProperty(propName);
} else {
evaluatedValue = value;
}
- return new ParamValue(evaluatedValue);
+ ParamValue result;
+ if (DBConstants.QueryParamTypes.ARRAY.equals(paramType)) {
+ result = new ParamValue(ParamValue.PARAM_VALUE_ARRAY);
+ if (evaluatedValue instanceof String[]) {
+ result.setArrayValue(Arrays.asList((String[]) evaluatedValue));
+ } else {
+ result.addArrayValue(evaluatedValue == null ? null : evaluatedValue.toString());
+ }
+ } else {
+ result = new ParamValue(ParamValue.PARAM_VALUE_SCALAR);
+ /* if the expected value is a scalar, and we have an array,
+ only set the first element as the value */
+ if (evaluatedValue instanceof String[]) {
+ String[] tmpArray = (String[]) evaluatedValue;
+ String tmpVal = null;
+ if (tmpArray.length > 0) {
+ tmpVal = tmpArray[0];
+ }
+ result.setScalarValue(tmpVal);
+ } else {
+ result.setScalarValue(evaluatedValue == null ? null : evaluatedValue.toString());
+ }
+ }
+ return result;
}
- private void processDefaultValues(ExternalParamCollection params) {
+ private void processDefaultValues(ExternalParamCollection params) throws DataServiceFault {
List<QueryParam> queryParams = this.getQuery().getQueryParams();
for (QueryParam queryParam : queryParams) {
if (queryParam.getDefaultValue() != null) {
params.addTempParam(queryParam.getName(),
- this.evaluateDefaultValue(queryParam.getDefaultValue()));
+ this.evaluateDefaultValue(queryParam.getDefaultValue(), queryParam.getParamType()));
}
}
}
- public void execute(XMLStreamWriter xmlWriter, ExternalParamCollection params,
+public void execute(XMLStreamWriter xmlWriter, ExternalParamCollection params,
int queryLevel) throws DataServiceFault {
/* handle default values */
this.processDefaultValues(params);
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/InternalParam.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/InternalParam.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/InternalParam.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/InternalParam.java Thu Oct 13 22:50:58 2011
@@ -36,12 +36,15 @@
private int ordinal;
+ private String structType;
+
public InternalParam(String name, ParamValue value, String sqlType,
- String type, int ordinal) {
+ String type, String structType, int ordinal) {
this.name = name;
this.value = value;
this.sqlType = sqlType;
this.type = type;
+ this.structType = structType;
this.ordinal = ordinal;
}
@@ -50,9 +53,10 @@
this.value = param.value;
this.sqlType = param.sqlType;
this.type = param.type;
+ this.structType = param.structType;
this.ordinal = ordinal;
}
-
+
public String getName() {
return name;
}
@@ -72,5 +76,9 @@
public int getOrdinal() {
return ordinal;
}
+
+ public String getStructType() {
+ return structType;
+ }
}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/QueryParam.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/QueryParam.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/QueryParam.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/QueryParam.java Thu Oct 13 22:50:58 2011
@@ -18,9 +18,6 @@
*/
package org.wso2.carbon.dataservices.core.engine;
-import java.lang.reflect.Field;
-import java.util.List;
-
import org.wso2.carbon.dataservices.common.DBConstants;
import org.wso2.carbon.dataservices.common.DBConstants.DataTypes;
import org.wso2.carbon.dataservices.common.DBConstants.QueryParamTypes;
@@ -29,6 +26,9 @@
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.validation.Validator;
+import java.lang.reflect.Field;
+import java.util.List;
+
/**
* Query param is an input parameter associated with a query,
* e.g. INTEGER, STRING.
@@ -55,9 +55,11 @@
/** validators assigned to this param */
private List<Validator> validators;
+
+ private String structType;
public QueryParam(String name, String sqlType, String type, String paramType,
- int ordinal, ParamValue defaultValue,
+ int ordinal, ParamValue defaultValue, String structType,
List<Validator> validators) throws DataServiceFault {
this.name = name;
this.sqlType = sqlType;
@@ -65,6 +67,7 @@
this.paramType = paramType;
this.ordinal = ordinal;
this.defaultValue = defaultValue;
+ this.structType = structType;
this.validators = validators;
/* validate the current query param */
this.validateQueryParam();
@@ -106,6 +109,13 @@
throw new DataServiceFault("Invalid query param type: '" +
this.getParamType() + "'.");
}
+ /* validate SQL Type struct. Here, if the SQL type is defined as STRUCT, it should
+ * carry the mandatory attribute named structType*/
+ if (DBConstants.DataTypes.STRUCT.equals(this.getSqlType()) &&
+ ("".equals(this.getStructType()) || this.getStructType() == null)) {
+ throw new DataServiceFault("Unable to find SQL type name corresponding to the " +
+ "specified Struct");
+ }
} catch (Exception e) {
throw new DataServiceFault(e);
}
@@ -138,6 +148,10 @@
public ParamValue getDefaultValue() {
return defaultValue;
}
+
+ public String getStructType() {
+ return structType;
+ }
public boolean hasDefaultValue() {
return this.getDefaultValue() != null;
Added: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/ResultSetWrapper.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/ResultSetWrapper.java?pathrev=113876
==============================================================================
--- (empty file)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/ResultSetWrapper.java Thu Oct 13 22:50:58 2011
@@ -0,0 +1,1167 @@
+/*
+ * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you 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.wso2.carbon.dataservices.core.engine;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.*;
+import java.util.Calendar;
+import java.util.Map;
+
+public class ResultSetWrapper implements ResultSet {
+
+ private ResultSet rs;
+
+ public ResultSetWrapper (ResultSet rs) {
+ this.rs = rs;
+ }
+
+ public ResultSet getResultSet() {
+ return rs;
+ }
+
+ @Override
+ public boolean next() throws SQLException {
+ return this.getResultSet().next();
+ }
+
+ @Override
+ public void close() throws SQLException {
+ this.getResultSet().close();
+ }
+
+ @Override
+ public boolean wasNull() throws SQLException {
+ return this.getResultSet().wasNull();
+ }
+
+ @Override
+ public String getString(int columnIndex) throws SQLException {
+ return this.getResultSet().getString(columnIndex);
+ }
+
+ @Override
+ public boolean getBoolean(int columnIndex) throws SQLException {
+ return this.getResultSet().getBoolean(columnIndex);
+ }
+
+ @Override
+ public byte getByte(int columnIndex) throws SQLException {
+ return this.getResultSet().getByte(columnIndex);
+ }
+
+ @Override
+ public short getShort(int columnIndex) throws SQLException {
+ return this.getResultSet().getShort(columnIndex);
+ }
+
+ @Override
+ public int getInt(int columnIndex) throws SQLException {
+ return this.getResultSet().getInt(columnIndex);
+ }
+
+ @Override
+ public long getLong(int columnIndex) throws SQLException {
+ return this.getResultSet().getLong(columnIndex);
+ }
+
+ @Override
+ public float getFloat(int columnIndex) throws SQLException {
+ return this.getResultSet().getFloat(columnIndex);
+ }
+
+ @Override
+ public double getDouble(int columnIndex) throws SQLException {
+ return this.getResultSet().getDouble(columnIndex);
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+ return this.getResultSet().getBigDecimal(columnIndex, scale);
+ }
+
+ @Override
+ public byte[] getBytes(int columnIndex) throws SQLException {
+ return this.getResultSet().getBytes(columnIndex);
+ }
+
+ @Override
+ public Date getDate(int columnIndex) throws SQLException {
+ return this.getResultSet().getDate(columnIndex);
+ }
+
+ @Override
+ public Time getTime(int columnIndex) throws SQLException {
+ return this.getResultSet().getTime(columnIndex);
+ }
+
+ @Override
+ public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ return this.getResultSet().getTimestamp(columnIndex);
+ }
+
+ @Override
+ public InputStream getAsciiStream(int columnIndex) throws SQLException {
+ return this.getResultSet().getAsciiStream(columnIndex);
+ }
+
+ @Override
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+ return this.getResultSet().getUnicodeStream(columnIndex);
+ }
+
+ @Override
+ public InputStream getBinaryStream(int columnIndex) throws SQLException {
+ return this.getResultSet().getBinaryStream(columnIndex);
+ }
+
+ @Override
+ public String getString(String columnLabel) throws SQLException {
+ return this.getResultSet().getString(columnLabel);
+ }
+
+ @Override
+ public boolean getBoolean(String columnLabel) throws SQLException {
+ return this.getResultSet().getBoolean(columnLabel);
+ }
+
+ @Override
+ public byte getByte(String columnLabel) throws SQLException {
+ return this.getResultSet().getByte(columnLabel);
+ }
+
+ @Override
+ public short getShort(String columnLabel) throws SQLException {
+ return this.getResultSet().getShort(columnLabel);
+ }
+
+ @Override
+ public int getInt(String columnLabel) throws SQLException {
+ return this.getResultSet().getInt(columnLabel);
+ }
+
+ @Override
+ public long getLong(String columnLabel) throws SQLException {
+ return this.getResultSet().getLong(columnLabel);
+ }
+
+ @Override
+ public float getFloat(String columnLabel) throws SQLException {
+ return this.getResultSet().getFloat(columnLabel);
+ }
+
+ @Override
+ public double getDouble(String columnLabel) throws SQLException {
+ return this.getResultSet().getDouble(columnLabel);
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
+ return this.getResultSet().getBigDecimal(columnLabel, scale);
+ }
+
+ @Override
+ public byte[] getBytes(String columnLabel) throws SQLException {
+ return this.getResultSet().getBytes(columnLabel);
+ }
+
+ @Override
+ public Date getDate(String columnLabel) throws SQLException {
+ return this.getResultSet().getDate(columnLabel);
+ }
+
+ @Override
+ public Time getTime(String columnLabel) throws SQLException {
+ return this.getResultSet().getTime(columnLabel);
+ }
+
+ @Override
+ public Timestamp getTimestamp(String columnLabel) throws SQLException {
+ return this.getResultSet().getTimestamp(columnLabel);
+ }
+
+ @Override
+ public InputStream getAsciiStream(String columnLabel) throws SQLException {
+ return this.getResultSet().getAsciiStream(columnLabel);
+ }
+
+ @Override
+ public InputStream getUnicodeStream(String columnLabel) throws SQLException {
+ return this.getResultSet().getUnicodeStream(columnLabel);
+ }
+
+ @Override
+ public InputStream getBinaryStream(String columnLabel) throws SQLException {
+ return this.getResultSet().getBinaryStream(columnLabel);
+ }
+
+ @Override
+ public SQLWarning getWarnings() throws SQLException {
+ return this.getResultSet().getWarnings();
+ }
+
+ @Override
+ public void clearWarnings() throws SQLException {
+ this.getResultSet().clearWarnings();
+ }
+
+ @Override
+ public String getCursorName() throws SQLException {
+ return this.getResultSet().getCursorName();
+ }
+
+ @Override
+ public ResultSetMetaData getMetaData() throws SQLException {
+ ResultSetMetaData rsMedata;
+ try {
+ rsMedata = this.getResultSet().getMetaData();
+ return rsMedata;
+ } catch (SQLException e) {
+ rsMedata = new ResultSetMetadataWrapper(this.getResultSet());
+ return rsMedata;
+ }
+ }
+
+ @Override
+ public Object getObject(int columnIndex) throws SQLException {
+ return this.getResultSet().getObject(columnIndex);
+ }
+
+ @Override
+ public Object getObject(String columnLabel) throws SQLException {
+ return this.getResultSet().getObject(columnLabel);
+ }
+
+ @Override
+ public int findColumn(String columnLabel) throws SQLException {
+ return this.getResultSet().findColumn(columnLabel);
+ }
+
+ @Override
+ public Reader getCharacterStream(int columnIndex) throws SQLException {
+ return this.getResultSet().getCharacterStream(columnIndex);
+ }
+
+ @Override
+ public Reader getCharacterStream(String columnLabel) throws SQLException {
+ return this.getResultSet().getCharacterStream(columnLabel);
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+ return this.getResultSet().getBigDecimal(columnIndex);
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
+ return this.getResultSet().getBigDecimal(columnLabel);
+ }
+
+ @Override
+ public boolean isBeforeFirst() throws SQLException {
+ return this.getResultSet().isBeforeFirst();
+ }
+
+ @Override
+ public boolean isAfterLast() throws SQLException {
+ return this.getResultSet().isAfterLast();
+ }
+
+ @Override
+ public boolean isFirst() throws SQLException {
+ return this.getResultSet().isFirst();
+ }
+
+ @Override
+ public boolean isLast() throws SQLException {
+ return this.getResultSet().isLast();
+ }
+
+ @Override
+ public void beforeFirst() throws SQLException {
+ this.getResultSet().beforeFirst();
+ }
+
+ @Override
+ public void afterLast() throws SQLException {
+ this.getResultSet().afterLast();
+ }
+
+ @Override
+ public boolean first() throws SQLException {
+ return this.getResultSet().first();
+ }
+
+ @Override
+ public boolean last() throws SQLException {
+ return this.getResultSet().last();
+ }
+
+ @Override
+ public int getRow() throws SQLException {
+ return this.getResultSet().getRow();
+ }
+
+ @Override
+ public boolean absolute(int row) throws SQLException {
+ return this.getResultSet().absolute(row);
+ }
+
+ @Override
+ public boolean relative(int rows) throws SQLException {
+ return this.getResultSet().relative(rows);
+ }
+
+ @Override
+ public boolean previous() throws SQLException {
+ return this.getResultSet().previous();
+ }
+
+ @Override
+ public void setFetchDirection(int direction) throws SQLException {
+ this.getResultSet().setFetchDirection(direction);
+ }
+
+ @Override
+ public int getFetchDirection() throws SQLException {
+ return this.getResultSet().getFetchDirection();
+ }
+
+ @Override
+ public void setFetchSize(int rows) throws SQLException {
+ this.getResultSet().setFetchSize(rows);
+ }
+
+ @Override
+ public int getFetchSize() throws SQLException {
+ return this.getResultSet().getFetchSize();
+ }
+
+ @Override
+ public int getType() throws SQLException {
+ return this.getResultSet().getType();
+ }
+
+ @Override
+ public int getConcurrency() throws SQLException {
+ return this.getResultSet().getConcurrency();
+ }
+
+ @Override
+ public boolean rowUpdated() throws SQLException {
+ return this.getResultSet().rowUpdated();
+ }
+
+ @Override
+ public boolean rowInserted() throws SQLException {
+ return this.getResultSet().rowInserted();
+ }
+
+ @Override
+ public boolean rowDeleted() throws SQLException {
+ return this.getResultSet().rowDeleted();
+ }
+
+ @Override
+ public void updateNull(int columnIndex) throws SQLException {
+ this.getResultSet().updateNull(columnIndex);
+ }
+
+ @Override
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+ this.getResultSet().updateBoolean(columnIndex, x);
+ }
+
+ @Override
+ public void updateByte(int columnIndex, byte x) throws SQLException {
+ this.getResultSet().updateByte(columnIndex, x);
+ }
+
+ @Override
+ public void updateShort(int columnIndex, short x) throws SQLException {
+ this.getResultSet().updateShort(columnIndex, x);
+ }
+
+ @Override
+ public void updateInt(int columnIndex, int x) throws SQLException {
+ this.getResultSet().updateInt(columnIndex, x);
+ }
+
+ @Override
+ public void updateLong(int columnIndex, long x) throws SQLException {
+ this.getResultSet().updateLong(columnIndex, x);
+ }
+
+ @Override
+ public void updateFloat(int columnIndex, float x) throws SQLException {
+ this.getResultSet().updateFloat(columnIndex, x);
+ }
+
+ @Override
+ public void updateDouble(int columnIndex, double x) throws SQLException {
+ this.getResultSet().updateDouble(columnIndex, x);
+ }
+
+ @Override
+ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
+ this.getResultSet().updateBigDecimal(columnIndex, x);
+ }
+
+ @Override
+ public void updateString(int columnIndex, String x) throws SQLException {
+ this.getResultSet().updateString(columnIndex, x);
+ }
+
+ @Override
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+ this.getResultSet().updateBytes(columnIndex, x);
+ }
+
+ @Override
+ public void updateDate(int columnIndex, Date x) throws SQLException {
+ this.getResultSet().updateDate(columnIndex, x);
+ }
+
+ @Override
+ public void updateTime(int columnIndex, Time x) throws SQLException {
+ this.getResultSet().updateTime(columnIndex, x);
+ }
+
+ @Override
+ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
+ this.getResultSet().updateTimestamp(columnIndex, x);
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
+ this.getResultSet().updateAsciiStream(columnIndex, x);
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
+ this.getResultSet().updateBinaryStream(columnIndex, x);
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
+ this.getResultSet().updateCharacterStream(columnIndex, x);
+ }
+
+ @Override
+ public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
+ this.getResultSet().updateObject(columnIndex, x, scaleOrLength);
+ }
+
+ @Override
+ public void updateObject(int columnIndex, Object x) throws SQLException {
+ this.getResultSet().updateObject(columnIndex, x);
+ }
+
+ @Override
+ public void updateNull(String columnLabel) throws SQLException {
+ this.getResultSet().updateNull(columnLabel);
+ }
+
+ @Override
+ public void updateBoolean(String columnLabel, boolean x) throws SQLException {
+ this.getResultSet().updateBoolean(columnLabel, x);
+ }
+
+ @Override
+ public void updateByte(String columnLabel, byte x) throws SQLException {
+ this.getResultSet().updateByte(columnLabel, x);
+ }
+
+ @Override
+ public void updateShort(String columnLabel, short x) throws SQLException {
+ this.getResultSet().updateShort(columnLabel, x);
+ }
+
+ @Override
+ public void updateInt(String columnLabel, int x) throws SQLException {
+ this.getResultSet().updateInt(columnLabel, x);
+ }
+
+ @Override
+ public void updateLong(String columnLabel, long x) throws SQLException {
+ this.getResultSet().updateLong(columnLabel, x);
+ }
+
+ @Override
+ public void updateFloat(String columnLabel, float x) throws SQLException {
+ this.getResultSet().updateFloat(columnLabel, x);
+ }
+
+ @Override
+ public void updateDouble(String columnLabel, double x) throws SQLException {
+ this.getResultSet().updateDouble(columnLabel, x);
+ }
+
+ @Override
+ public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
+ this.getResultSet().updateBigDecimal(columnLabel, x);
+ }
+
+ @Override
+ public void updateString(String columnLabel, String x) throws SQLException {
+ this.getResultSet().updateString(columnLabel, x);
+ }
+
+ @Override
+ public void updateBytes(String columnLabel, byte[] x) throws SQLException {
+ this.getResultSet().updateBytes(columnLabel, x);
+ }
+
+ @Override
+ public void updateDate(String columnLabel, Date x) throws SQLException {
+ this.getResultSet().updateDate(columnLabel, x);
+ }
+
+ @Override
+ public void updateTime(String columnLabel, Time x) throws SQLException {
+ this.getResultSet().updateTime(columnLabel, x);
+ }
+
+ @Override
+ public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
+ this.getResultSet().updateTimestamp(columnLabel, x);
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
+ this.getResultSet().updateAsciiStream(columnLabel, x);
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
+ this.getResultSet().updateBinaryStream(columnLabel, x);
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
+ this.getResultSet().updateCharacterStream(columnLabel, reader, length);
+ }
+
+ @Override
+ public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
+ this.getResultSet().updateObject(columnLabel, x, scaleOrLength);
+ }
+
+ @Override
+ public void updateObject(String columnLabel, Object x) throws SQLException {
+ this.getResultSet().updateObject(columnLabel, x);
+ }
+
+ @Override
+ public void insertRow() throws SQLException {
+ this.getResultSet().insertRow();
+ }
+
+ @Override
+ public void updateRow() throws SQLException {
+ this.getResultSet().updateRow();
+ }
+
+ @Override
+ public void deleteRow() throws SQLException {
+ this.getResultSet().deleteRow();
+ }
+
+ @Override
+ public void refreshRow() throws SQLException {
+ this.getResultSet().deleteRow();
+ }
+
+ @Override
+ public void cancelRowUpdates() throws SQLException {
+ this.getResultSet().cancelRowUpdates();
+ }
+
+ @Override
+ public void moveToInsertRow() throws SQLException {
+ this.getResultSet().moveToInsertRow();
+ }
+
+ @Override
+ public void moveToCurrentRow() throws SQLException {
+ this.getResultSet().moveToCurrentRow();
+ }
+
+ @Override
+ public Statement getStatement() throws SQLException {
+ return this.getResultSet().getStatement();
+ }
+
+ @Override
+ public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
+ return this.getResultSet().getObject(columnIndex, map);
+ }
+
+ @Override
+ public Ref getRef(int columnIndex) throws SQLException {
+ return this.getResultSet().getRef(columnIndex);
+ }
+
+ @Override
+ public Blob getBlob(int columnIndex) throws SQLException {
+ return this.getResultSet().getBlob(columnIndex);
+ }
+
+ @Override
+ public Clob getClob(int columnIndex) throws SQLException {
+ return this.getResultSet().getClob(columnIndex);
+ }
+
+ @Override
+ public Array getArray(int columnIndex) throws SQLException {
+ return this.getResultSet().getArray(columnIndex);
+ }
+
+ @Override
+ public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
+ return this.getResultSet().getObject(columnLabel, map);
+ }
+
+ @Override
+ public Ref getRef(String columnLabel) throws SQLException {
+ return this.getResultSet().getRef(columnLabel);
+ }
+
+ @Override
+ public Blob getBlob(String columnLabel) throws SQLException {
+ return this.getResultSet().getBlob(columnLabel);
+ }
+
+ @Override
+ public Clob getClob(String columnLabel) throws SQLException {
+ return this.getResultSet().getClob(columnLabel);
+ }
+
+ @Override
+ public Array getArray(String columnLabel) throws SQLException {
+ return this.getResultSet().getArray(columnLabel);
+ }
+
+ @Override
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+ return this.getResultSet().getDate(columnIndex, cal);
+ }
+
+ @Override
+ public Date getDate(String columnLabel, Calendar cal) throws SQLException {
+ return this.getResultSet().getDate(columnLabel, cal);
+ }
+
+ @Override
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+ return this.getResultSet().getTime(columnIndex, cal);
+ }
+
+ @Override
+ public Time getTime(String columnLabel, Calendar cal) throws SQLException {
+ return this.getResultSet().getTime(columnLabel, cal);
+ }
+
+ @Override
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+ return this.getResultSet().getTimestamp(columnIndex, cal);
+ }
+
+ @Override
+ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
+ return this.getResultSet().getTimestamp(columnLabel, cal);
+ }
+
+ @Override
+ public URL getURL(int columnIndex) throws SQLException {
+ return this.getResultSet().getURL(columnIndex);
+ }
+
+ @Override
+ public URL getURL(String columnLabel) throws SQLException {
+ return this.getResultSet().getURL(columnLabel);
+ }
+
+ @Override
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
+ this.getResultSet().updateRef(columnIndex, x);
+ }
+
+ @Override
+ public void updateRef(String columnLabel, Ref x) throws SQLException {
+ this.getResultSet().updateRef(columnLabel, x);
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, Blob x) throws SQLException {
+ this.getResultSet().updateBlob(columnIndex, x);
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, Blob x) throws SQLException {
+ this.getResultSet().updateBlob(columnLabel, x);
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Clob x) throws SQLException {
+ this.getResultSet().updateClob(columnIndex, x);
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Clob x) throws SQLException {
+ this.getResultSet().updateClob(columnLabel, x);
+ }
+
+ @Override
+ public void updateArray(int columnIndex, Array x) throws SQLException {
+ this.getResultSet().updateArray(columnIndex, x);
+ }
+
+ @Override
+ public void updateArray(String columnLabel, Array x) throws SQLException {
+ this.getResultSet().updateArray(columnLabel, x);
+ }
+
+ @Override
+ public RowId getRowId(int columnIndex) throws SQLException {
+ return this.getResultSet().getRowId(columnIndex);
+ }
+
+ @Override
+ public RowId getRowId(String columnLabel) throws SQLException {
+ return this.getResultSet().getRowId(columnLabel);
+ }
+
+ @Override
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
+ this.getResultSet().updateRowId(columnIndex, x);
+ }
+
+ @Override
+ public void updateRowId(String columnLabel, RowId x) throws SQLException {
+ this.getResultSet().updateRowId(columnLabel, x);
+ }
+
+ @Override
+ public int getHoldability() throws SQLException {
+ return this.getResultSet().getHoldability();
+ }
+
+ @Override
+ public boolean isClosed() throws SQLException {
+ return this.getResultSet().isClosed();
+ }
+
+ @Override
+ public void updateNString(int columnIndex, String nString) throws SQLException {
+ this.getResultSet().updateNString(columnIndex, nString);
+ }
+
+ @Override
+ public void updateNString(String columnLabel, String nString) throws SQLException {
+ this.getResultSet().updateNString(columnLabel, nString);
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
+ this.getResultSet().updateNClob(columnIndex, nClob);
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
+ this.getResultSet().updateNClob(columnLabel, nClob);
+ }
+
+ @Override
+ public NClob getNClob(int columnIndex) throws SQLException {
+ return this.getResultSet().getNClob(columnIndex);
+ }
+
+ @Override
+ public NClob getNClob(String columnLabel) throws SQLException {
+ return this.getResultSet().getNClob(columnLabel);
+ }
+
+ @Override
+ public SQLXML getSQLXML(int columnIndex) throws SQLException {
+ return this.getResultSet().getSQLXML(columnIndex);
+ }
+
+ @Override
+ public SQLXML getSQLXML(String columnLabel) throws SQLException {
+ return this.getResultSet().getSQLXML(columnLabel);
+ }
+
+ @Override
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
+ this.getResultSet().updateSQLXML(columnIndex, xmlObject);
+ }
+
+ @Override
+ public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
+ this.getResultSet().updateSQLXML(columnLabel, xmlObject);
+ }
+
+ @Override
+ public String getNString(int columnIndex) throws SQLException {
+ return this.getResultSet().getNString(columnIndex);
+ }
+
+ @Override
+ public String getNString(String columnLabel) throws SQLException {
+ return this.getResultSet().getNString(columnLabel);
+ }
+
+ @Override
+ public Reader getNCharacterStream(int columnIndex) throws SQLException {
+ return this.getResultSet().getNCharacterStream(columnIndex);
+ }
+
+ @Override
+ public Reader getNCharacterStream(String columnLabel) throws SQLException {
+ return this.getResultSet().getNCharacterStream(columnLabel);
+ }
+
+ @Override
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+ this.getResultSet().updateNCharacterStream(columnIndex, x, length);
+ }
+
+ @Override
+ public void updateNCharacterStream(String columnLabel, Reader reader,
+ long length) throws SQLException {
+ this.getResultSet().updateNCharacterStream(columnLabel, reader, length);
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
+ this.getResultSet().updateAsciiStream(columnIndex, x, length);
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x,
+ long length) throws SQLException {
+ this.getResultSet().updateBinaryStream(columnIndex, x, length);
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x,
+ long length) throws SQLException {
+ this.getResultSet().updateCharacterStream(columnIndex, x, length);
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x,
+ long length) throws SQLException {
+ this.getResultSet().updateAsciiStream(columnLabel, x, length);
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x,
+ long length) throws SQLException {
+ this.getResultSet().updateBinaryStream(columnLabel, x, length);
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader,
+ long length) throws SQLException {
+ this.getResultSet().updateCharacterStream(columnLabel, reader, length);
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, InputStream inputStream,
+ long length) throws SQLException {
+ this.getResultSet().updateBlob(columnIndex, inputStream, length);
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, InputStream inputStream,
+ long length) throws SQLException {
+ this.getResultSet().updateBlob(columnLabel, inputStream, length);
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
+ this.getResultSet().updateClob(columnIndex, reader, length);
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
+ this.getResultSet().updateClob(columnLabel, reader, length);
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
+ this.getResultSet().updateNClob(columnIndex, reader, length);
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
+ this.getResultSet().updateNClob(columnLabel, reader, length);
+ }
+
+ @Override
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
+ this.getResultSet().updateNCharacterStream(columnIndex, x);
+ }
+
+ @Override
+ public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
+ this.getResultSet().updateNCharacterStream(columnLabel, reader);
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
+ this.getResultSet().updateAsciiStream(columnIndex, x);
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
+ this.getResultSet().updateBinaryStream(columnIndex, x);
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
+ this.getResultSet().updateCharacterStream(columnIndex, x);
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
+ this.getResultSet().updateAsciiStream(columnLabel, x);
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
+ this.getResultSet().updateBinaryStream(columnLabel, x);
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
+ this.getResultSet().updateCharacterStream(columnLabel, reader);
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
+ this.getResultSet().updateBlob(columnIndex, inputStream);
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
+ this.getResultSet().updateBlob(columnLabel, inputStream);
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
+ this.getResultSet().updateClob(columnIndex, reader);
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Reader reader) throws SQLException {
+ this.getResultSet().updateClob(columnLabel, reader);
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+ this.getResultSet().updateNClob(columnIndex, reader);
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
+ this.getResultSet().updateNClob(columnLabel, reader);
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return this.getResultSet().unwrap(iface);
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return this.getResultSet().isWrapperFor(iface);
+ }
+
+ /* Custom ResultSetMetadata implementation to support SQL Array type */
+
+ private class ResultSetMetadataWrapper implements ResultSetMetaData {
+
+ private ResultSet rs;
+
+ public ResultSetMetadataWrapper(ResultSet rs) {
+ this.rs = rs;
+ }
+
+ public ResultSet getResultSet() {
+ return rs;
+ }
+
+ @Override
+ public int getColumnCount() throws SQLException {
+ return 2;
+ }
+
+ @Override
+ public boolean isAutoIncrement(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isCaseSensitive(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isSearchable(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isCurrency(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public int isNullable(int column) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean isSigned(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public int getColumnDisplaySize(int column) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public String getColumnLabel(int column) throws SQLException {
+ return String.valueOf(column - 1);
+ }
+
+ @Override
+ public String getColumnName(int column) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getSchemaName(int column) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int getPrecision(int column) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getScale(int column) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public String getTableName(int column) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getCatalogName(int column) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int getColumnType(int column) throws SQLException {
+ Object o = this.getResultSet().getObject(column);
+ if (o instanceof Integer) {
+ return Types.INTEGER;
+ } else if (o instanceof String) {
+ return Types.VARCHAR;
+ } else if (o instanceof Array) {
+ return Types.ARRAY;
+ } else if (o instanceof BigDecimal) {
+ return Types.INTEGER;
+ } else if (o instanceof Blob) {
+ return Types.BLOB;
+ } else if (o instanceof Boolean) {
+ return Types.BOOLEAN;
+ } else if (o instanceof Clob) {
+ return Types.CLOB;
+ } else if (o instanceof Date) {
+ return Types.DATE;
+ } else if (o instanceof Double) {
+ return Types.DOUBLE;
+ } else if (o instanceof Float) {
+ return Types.FLOAT;
+ } else if (o instanceof Ref) {
+ return Types.REF;
+ } else if (o instanceof RowId) {
+ return Types.ROWID;
+ } else if (o instanceof Short) {
+ return Types.INTEGER;
+ } else if (o instanceof SQLXML) {
+ return Types.SQLXML;
+ } else if (o instanceof Struct) {
+ return Types.STRUCT;
+ } else if (o instanceof Time) {
+ return Types.TIME;
+ } else if (o instanceof Timestamp) {
+ return Types.TIMESTAMP;
+ }
+ return Types.OTHER;
+ }
+
+ @Override
+ public String getColumnTypeName(int column) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isWritable(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isDefinitelyWritable(int column) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getColumnClassName(int column) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return false;
+ }
+ }
+
+}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/StaticOutputElement.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/StaticOutputElement.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/StaticOutputElement.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/StaticOutputElement.java Thu Oct 13 22:50:58 2011
@@ -30,6 +30,9 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.sql.SQLException;
+import java.sql.Struct;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
/**
@@ -37,227 +40,303 @@
*/
public class StaticOutputElement extends XMLWriterHelper implements OutputElement {
- /** name of element/attribute */
- private String name;
-
- /** param value */
- private String param;
-
- /** original param value, without any modifications: toLowerCase */
- private String originalParam;
-
- /** i.e. column, query-param, value */
- private String paramType;
-
- /** i.e. element, attribute */
- private String elementType;
-
- /** i.e. xs:string, xs:decimal, etc.. */
- private QName xsdType;
-
- /** user roles required to access this element */
- private Set<String> requiredRoles;
-
- /** i.e. XML, RDF etc.. */
- private int resultType;
-
- /** i.e. VALUE, REFERENCE etc.. */
- private int dataCategory;
-
- /** Exports the values in this element,
- * these will be saved in a thread local storage,
- * which can be re-used later by other queries */
- private String export;
-
- /** The type of value to be exported, i.e. SCALAR, ARRAY */
- private int exportType;
-
- /** A flag to keep if this output element's value is a constant,
- * i.e. paramType = 'value' */
- private boolean hasConstantValue;
-
- public StaticOutputElement(DataService dataService, String name,
- String param, String originalParam, String paramType,
- String elementType, String namespace, QName xsdType,
- Set<String> requiredRoles, int dataCategory, int resultType,
- String export, int exportType) throws DataServiceFault {
- super(namespace);
- this.name = name;
- this.param = param;
- this.originalParam = originalParam;
- this.paramType = paramType;
- this.elementType = elementType;
- this.xsdType = xsdType;
- this.requiredRoles = requiredRoles;
- this.dataCategory = dataCategory;
- this.resultType = resultType;
- this.export = export;
- this.exportType = exportType;
- this.hasConstantValue = DBSFields.VALUE.equals(paramType);
-
- /* validate element/attribute name */
- if (!NCName.isValid(this.name)) {
- throw new DataServiceFault("Invalid output " + this.elementType + " name: '" +
- this.name + "', must be an NCName.");
- }
- }
-
- public boolean hasConstantValue() {
- return hasConstantValue;
- }
-
- public String getExport() {
- return export;
- }
-
- public int getExportType() {
- return exportType;
- }
-
- public int getDataCategory() {
- return dataCategory;
- }
-
- public int getResultType() {
- return resultType;
- }
-
- public String getOriginalParam() {
- return originalParam;
- }
-
- public Set<String> getRequiredRoles() {
- return requiredRoles;
- }
-
- public boolean isOptional() {
- return this.getRequiredRoles() != null && this.getRequiredRoles().size() > 0;
- }
-
- public QName getXsdType() {
- return xsdType;
- }
-
- public String getName() {
- return name;
- }
-
- public String getParam() {
- return param;
- }
-
- public String getParamType() {
- return paramType;
- }
-
- public String getElementType() {
- return elementType;
- }
-
- private String getParamValue(ExternalParamCollection params) throws DataServiceFault {
- if (this.getParamType().equals(DBConstants.DBSFields.RDF_REF_URI)) {
- return this.getParam();
- } else {
+ /**
+ * name of element/attribute
+ */
+ private String name;
+
+ /**
+ * param value
+ */
+ private String param;
+
+ /**
+ * original param value, without any modifications: toLowerCase
+ */
+ private String originalParam;
+
+ /**
+ * i.e. column, query-param, value
+ */
+ private String paramType;
+
+ /**
+ * i.e. element, attribute
+ */
+ private String elementType;
+
+ /**
+ * i.e. xs:string, xs:decimal, etc..
+ */
+ private QName xsdType;
+
+ /**
+ * user roles required to access this element
+ */
+ private Set<String> requiredRoles;
+
+ /**
+ * i.e. XML, RDF etc..
+ */
+ private int resultType;
+
+ /**
+ * i.e. VALUE, REFERENCE etc..
+ */
+ private int dataCategory;
+
+ /**
+ * Exports the values in this element,
+ * these will be saved in a thread local storage,
+ * which can be re-used later by other queries
+ */
+ private String export;
+
+ /**
+ * The type of value to be exported, i.e. SCALAR, ARRAY
+ */
+ private int exportType;
+
+ /**
+ * A flag to keep if this output element's value is a constant,
+ * i.e. paramType = 'value'
+ */
+ private boolean hasConstantValue;
+
+ public StaticOutputElement(DataService dataService, String name,
+ String param, String originalParam, String paramType,
+ String elementType, String namespace, QName xsdType,
+ Set<String> requiredRoles, int dataCategory, int resultType,
+ String export, int exportType) throws DataServiceFault {
+ super(namespace);
+ this.name = name;
+ this.param = param;
+ this.originalParam = originalParam;
+ this.paramType = paramType;
+ this.elementType = elementType;
+ this.xsdType = xsdType;
+ this.requiredRoles = requiredRoles;
+ this.dataCategory = dataCategory;
+ this.resultType = resultType;
+ this.export = export;
+ this.exportType = exportType;
+ this.hasConstantValue = DBSFields.VALUE.equals(paramType);
+
+ /* validate element/attribute name */
+ if (!NCName.isValid(this.name)) {
+ throw new DataServiceFault("Invalid output " + this.elementType + " name: '" +
+ this.name + "', must be an NCName.");
+ }
+ }
+
+ public boolean hasConstantValue() {
+ return hasConstantValue;
+ }
+
+ public String getExport() {
+ return export;
+ }
+
+ public int getExportType() {
+ return exportType;
+ }
+
+ public int getDataCategory() {
+ return dataCategory;
+ }
+
+ public int getResultType() {
+ return resultType;
+ }
+
+ public String getOriginalParam() {
+ return originalParam;
+ }
+
+ public Set<String> getRequiredRoles() {
+ return requiredRoles;
+ }
+
+ public boolean isOptional() {
+ return this.getRequiredRoles() != null && this.getRequiredRoles().size() > 0;
+ }
+
+ public QName getXsdType() {
+ return xsdType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getParam() {
+ return param;
+ }
+
+ public String getParamType() {
+ return paramType;
+ }
+
+ public String getElementType() {
+ return elementType;
+ }
+
+ private String getParamValue(ExternalParamCollection params) throws DataServiceFault {
+ if (this.getParamType().equals(DBConstants.DBSFields.RDF_REF_URI)) {
+ return this.getParam();
+ } else {
ExternalParam paramObj = this.getParamObj(params);
//ExternalParam paramObj = params.getParam(this.getParamType(), this.getParam());
- /* workaround for 'column', 'query-param' mix up */
- if (paramObj == null) {
- if (this.getParamType().equals(DBSFields.COLUMN)) {
- paramObj = params.getParam(DBSFields.QUERY_PARAM, this.getParam());
- } else if (this.getParamType().equals(DBSFields.QUERY_PARAM)) {
- paramObj = params.getParam(DBSFields.COLUMN, this.getParam());
- }
- }
- if (paramObj != null) {
- return paramObj.getValue().getValueAsString();
- } else {
- throw new DataServiceFault(FaultCodes.INCOMPATIBLE_PARAMETERS_ERROR,
- "Error in 'StaticOutputElement.execute', " +
- "cannot find parameter with type:"
- + this.getParamType() + " name:" + this.getOriginalParam());
- }
- }
- }
-
- /**
- * Exports the given parameter.
- * @param exportName The name of the variable to store the exported value
- * @param value The exported value
- */
- private void exportParam(String exportName, String value, int type) {
- ParamValue paramVal = TLParamStore.getParam(exportName);
- if (paramVal == null || paramVal.getValueType() != type) {
- paramVal = new ParamValue(type);
- TLParamStore.addParam(exportName, paramVal);
- }
- if (type == ParamValue.PARAM_VALUE_ARRAY) {
- paramVal.addToArrayValue(value);
- } else if (type == ParamValue.PARAM_VALUE_SCALAR){
- paramVal.setScalarValue(value);
- }
- }
-
- /**
- * Checks the ExternalParam collection, and finds the record that describes this
- * output element, retrieves its value and output it.
- */
- public void execute(XMLStreamWriter xmlWriter,
- ExternalParamCollection params, int queryLevel)
- throws DataServiceFault {
- String paramValue;
- if (this.hasConstantValue()) {
- paramValue = this.getParam();
- } else {
- paramValue = this.getParamValue(params);
- }
- /* export it if told, and only if it's boxcarring */
- if (this.getExport() != null && DSSessionManager.isBoxcarring()) {
- this.exportParam(this.getExport(), paramValue, this.getExportType());
- }
- try {
- /* write element */
- if (this.getElementType().equals(DBSFields.ELEMENT)) {
- this.writeResultElement(xmlWriter, this.getName(),
- paramValue, this.getXsdType(),
- this.getDataCategory(), this.getResultType(), params);
- } else if (this.getElementType().equals(DBSFields.ATTRIBUTE)) { /* write attribute */
- this.addAttribute(xmlWriter, this.getName(),
- paramValue, this.getXsdType(), this.getResultType());
- }
- } catch (XMLStreamException e) {
- throw new DataServiceFault(e, "Error in XML generation at StaticOutputElement.execute");
- }
- }
+ /* workaround for 'column', 'query-param' mix up */
+ if (paramObj == null) {
+ if (this.getParamType().equals(DBSFields.COLUMN)) {
+ paramObj = params.getParam(DBSFields.QUERY_PARAM, this.getParam());
+ } else if (this.getParamType().equals(DBSFields.QUERY_PARAM)) {
+ paramObj = params.getParam(DBSFields.COLUMN, this.getParam());
+ }
+ }
+ if (paramObj != null) {
+ return paramObj.getValue().getValueAsString();
+ } else {
+ throw new DataServiceFault(FaultCodes.INCOMPATIBLE_PARAMETERS_ERROR,
+ "Error in 'StaticOutputElement.execute', " +
+ "cannot find parameter with type:"
+ + this.getParamType() + " name:" + this.getOriginalParam());
+ }
+ }
+ }
+
+ /**
+ * Exports the given parameter.
+ *
+ * @param exportName The name of the variable to store the exported value
+ * @param value The exported value
+ */
+ private void exportParam(String exportName, String value, int type) {
+ ParamValue paramVal = TLParamStore.getParam(exportName);
+ if (paramVal == null || paramVal.getValueType() != type) {
+ paramVal = new ParamValue(type);
+ TLParamStore.addParam(exportName, paramVal);
+ }
+ if (type == ParamValue.PARAM_VALUE_ARRAY) {
+ paramVal.addToArrayValue(value);
+ } else if (type == ParamValue.PARAM_VALUE_SCALAR) {
+ paramVal.setScalarValue(value);
+ }
+ }
+
+ /**
+ * Checks the ExternalParam collection, and finds the record that describes this
+ * output element, retrieves its value and output it.
+ */
+ public void execute(XMLStreamWriter xmlWriter,
+ ExternalParamCollection params, int queryLevel)
+ throws DataServiceFault {
+ String paramValue;
+ if (this.hasConstantValue()) {
+ paramValue = this.getParam();
+ } else {
+ paramValue = this.getParamValue(params);
+ }
+ /* export it if told, and only if it's boxcarring */
+ if (this.getExport() != null && DSSessionManager.isBoxcarring()) {
+ this.exportParam(this.getExport(), paramValue, this.getExportType());
+ }
+ try {
+ /* write element */
+ if (this.getElementType().equals(DBSFields.ELEMENT)) {
+ this.writeResultElement(xmlWriter, this.getName(),
+ paramValue, this.getXsdType(),
+ this.getDataCategory(), this.getResultType(), params);
+ } else if (this.getElementType().equals(DBSFields.ATTRIBUTE)) { /* write attribute */
+ this.addAttribute(xmlWriter, this.getName(),
+ paramValue, this.getXsdType(), this.getResultType());
+ }
+ } catch (XMLStreamException e) {
+ throw new DataServiceFault(e, "Error in XML generation at StaticOutputElement.execute");
+ }
+ }
private ExternalParam getParamObj(ExternalParamCollection params) throws DataServiceFault {
- if(this.getParam().contains("[")) {
- String paramValue = this.getParam();
- String columnName = paramValue.substring(0, paramValue.indexOf("["));
- int index = Integer.parseInt(paramValue.substring(
- paramValue.indexOf("[") + 1,
- paramValue.indexOf("]")));
+ String param = this.getParam();
+ if (this.getParam().contains("[")) {
+ String columnName = param.substring(0, param.indexOf("["));
ExternalParam paramObj = params.getParam(this.getParamType(), columnName);
+ if (paramObj == null) {
+ throw new DataServiceFault("Unable to extract value of the UDT " +
+ this.getParam());
+ }
try {
- Object[] udtAttributes = paramObj.getValue().getUdt().getAttributes();
- for(int i = 0; i < udtAttributes.length; i++){
- if (index == i) {
- return new ExternalParam(this.getName(),new ParamValue(
- udtAttributes[i].toString()), this.getParamType());
- }
- }
+ String indexString = param.substring(param.indexOf("["), param.length());
+ List<Integer> indices = getNestedIndices(indexString);
+ Object value = this.getUdtAttributeValue(indices, paramObj.getValue().getUdt(), 0);
+
+ return new ExternalParam(this.getName(), new ParamValue(value.toString()),
+ this.getParamType());
} catch (SQLException e) {
- throw new DataServiceFault(e, "Error while extracting UDT attribute values");
+ throw new DataServiceFault(e, "Unable to retrieve UDT attribute value");
}
}
return params.getParam(this.getParamType(), this.getParam());
}
- public boolean equals(Object o) {
- if ((o instanceof StaticOutputElement) && (((StaticOutputElement) o).getName().equals(this.getName()))) {
- return true;
- } else {
- return false;
+ /**
+ * This method traverse through the specified indices and recursively retrieves the value of
+ * the UDT attribute.
+ *
+ * @param indices Index pointing to the desired attribute of the UDT.
+ * @param value Value of the UDT attribute.
+ * @param i Index to keep track of the number of items process in the index list.
+ * @return Final value of the desired UDT attribute
+ * @throws SQLException SQLException
+ * @throws DataServiceFault DataServiceFault.
+ */
+ private Object getUdtAttributeValue(List<Integer> indices, Object value,
+ int i) throws SQLException, DataServiceFault {
+ if (!(value instanceof Struct)) {
+ return null;
+ }
+ Struct udt = (Struct) value;
+ try {
+ value = udt.getAttributes()[indices.get(i)];
+ i++;
+ } catch (Exception e) {
+ throw new DataServiceFault("Unable to retrieve UDT attribute value referred by the " +
+ "given index");
+ }
+
+ if (indices.size() > i) {
+ return this.getUdtAttributeValue(indices, value, i);
}
+ return value;
+ }
+
+ /**
+ * Util method to parse index string and produce the list of nested indices.
+ *
+ * @param indexString Index String.
+ * @return The list of nested indices.
+ * @throws DataServiceFault DataServiceFault.
+ */
+ private static List<Integer> getNestedIndices(String indexString) throws DataServiceFault {
+ List<Integer> indices = new ArrayList<Integer>();
+ String[] temp = indexString.split("\\[");
+ for (String s : temp) {
+ if (!"".equals(s)) {
+ try {
+ indices.add(Integer.parseInt(s.substring(0, s.indexOf("]"))));
+ } catch (NumberFormatException e) {
+ throw new DataServiceFault("Unable to determine nested indices. Incompatible " +
+ "value specified for the attribute index");
+ }
+ }
+ }
+ return indices;
+ }
+
+ public boolean equals(Object o) {
+ return (o instanceof StaticOutputElement) &&
+ (((StaticOutputElement) o).getName().equals(this.getName()));
}
}
Deleted: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/TypeMapper.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=113875
Deleted: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/engine/UDT.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=113875
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/internal/DataServicesDSComponent.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/internal/DataServicesDSComponent.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/internal/DataServicesDSComponent.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/internal/DataServicesDSComponent.java Thu Oct 13 22:50:58 2011
@@ -18,27 +18,21 @@
*/
package org.wso2.carbon.dataservices.core.internal;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.commons.datasource.DataSourceInformationRepository;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.core.multitenancy.SuperTenantCarbonContext;
-import org.wso2.carbon.dataservices.core.listeners.CarbonDataSourceServiceListener;
import org.wso2.carbon.dataservices.core.listeners.EventBrokerServiceListener;
-import org.wso2.carbon.dataservices.core.listeners.RegistryServiceListener;
import org.wso2.carbon.datasource.DataSourceInformationRepositoryService;
-import org.wso2.carbon.datasource.multitenancy.DataSourceInitializer;
-import org.wso2.carbon.datasource.multitenancy.DataSourceRepositoryListener;
import org.wso2.carbon.event.core.EventBroker;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* @scr.component name="dataservices.component" immediate="true"
@@ -60,12 +54,8 @@
private static RealmService realmService = null;
private static DataSourceInformationRepositoryService dataSourceService;
-
- private static EventBroker eventBroker;
-
- private static List<CarbonDataSourceServiceListener> carbonDataSourceServiceListeners = new ArrayList<CarbonDataSourceServiceListener>();
- private static List<RegistryServiceListener> registryServiceListeners = new ArrayList<RegistryServiceListener>();
+ private static EventBroker eventBroker;
private static List<EventBrokerServiceListener> eventBrokerServiceListeners = new ArrayList<EventBrokerServiceListener>();
@@ -94,28 +84,17 @@
}
protected void setRegistryService(RegistryService registryService) {
- synchronized (dsComponentLock) {
- if (log.isDebugEnabled()) {
- log.debug("Setting the Registry Service");
- }
- DataServicesDSComponent.registryService = registryService;
- for (RegistryServiceListener listener : registryServiceListeners) {
- SuperTenantCarbonContext.startTenantFlow();
- SuperTenantCarbonContext.getCurrentContext().setTenantId(listener.getTenantId());
- listener.setRegistryService(registryService);
- SuperTenantCarbonContext.endTenantFlow();
- }
- registryServiceListeners.clear();
+ if (log.isDebugEnabled()) {
+ log.debug("Setting the Registry Service");
}
+ DataServicesDSComponent.registryService = registryService;
}
protected void unsetRegistryService(RegistryService registryService) {
- synchronized (dsComponentLock) {
- if (log.isDebugEnabled()) {
- log.debug("Unsetting the Registry Service");
- }
- DataServicesDSComponent.registryService = null;
+ if (log.isDebugEnabled()) {
+ log.debug("Unsetting the Registry Service");
}
+ DataServicesDSComponent.registryService = null;
}
protected void setRealmService(RealmService realmService) {
@@ -125,7 +104,7 @@
}
DataServicesDSComponent.realmService = realmService;
if (DataServicesDSComponent.eventBroker != null) {
- this.doEventRealmInitiliased();
+ this.doEventRealmInitiliased();
}
}
}
@@ -149,29 +128,12 @@
protected void setCarbonDataSourceService(
DataSourceInformationRepositoryService dataSourceService) {
- synchronized (dsComponentLock) {
- if (log.isDebugEnabled()) {
- log.debug("Setting the Carbon Data Sources Service");
- }
- DataServicesDSComponent.dataSourceService = dataSourceService;
- for (CarbonDataSourceServiceListener listener : carbonDataSourceServiceListeners) {
- SuperTenantCarbonContext.startTenantFlow();
- SuperTenantCarbonContext.getCurrentContext().setTenantId(listener.getTenantId());
- listener.setCarbonDataSourceService(dataSourceService);
- SuperTenantCarbonContext.endTenantFlow();
- }
- carbonDataSourceServiceListeners.clear();
- }
+ DataServicesDSComponent.dataSourceService = dataSourceService;
}
protected void unsetCarbonDataSourceService(
DataSourceInformationRepositoryService dataSourceService) {
- synchronized (dsComponentLock) {
- if (log.isDebugEnabled()) {
- log.debug("Unsetting the Carbon Data Sources Service");
- }
- DataServicesDSComponent.dataSourceService = null;
- }
+ DataServicesDSComponent.dataSourceService = null;
}
public static DataSourceInformationRepositoryService getCarbonDataSourceService() {
@@ -186,26 +148,26 @@
DataServicesDSComponent.eventBroker = eventBroker;
/* event functionality depends on realm service */
if (DataServicesDSComponent.realmService != null) {
- this.doEventRealmInitiliased();
+ this.doEventRealmInitiliased();
}
}
}
-
+
private void doEventRealmInitiliased() {
- RealmService realmService = DataServicesDSComponent.getRealmService();
- try {
+ RealmService realmService = DataServicesDSComponent.getRealmService();
+ try {
SuperTenantCarbonContext.getCurrentContext().setUserRealm(realmService.getBootstrapRealm());
SuperTenantCarbonContext.getCurrentContext().setUsername(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- }
- this.notifyEventServiceListeners();
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ this.notifyEventServiceListeners();
}
-
+
private void notifyEventServiceListeners() {
- for (EventBrokerServiceListener listener : eventBrokerServiceListeners) {
- SuperTenantCarbonContext.startTenantFlow();
- SuperTenantCarbonContext.getCurrentContext().setTenantId(listener.getTenantId());
+ for (EventBrokerServiceListener listener : eventBrokerServiceListeners) {
+ SuperTenantCarbonContext.startTenantFlow();
+ SuperTenantCarbonContext.getCurrentContext().setTenantId(listener.getTenantId());
listener.setEventBroker(eventBroker);
SuperTenantCarbonContext.endTenantFlow();
}
@@ -237,52 +199,4 @@
}
}
- public static void registerCarbonDataSourceServiceListener(
- CarbonDataSourceServiceListener listener) {
- synchronized (dsComponentLock) {
- int listenerTenantId = listener.getTenantId();
- if (listenerTenantId == MultitenantConstants.SUPER_TENANT_ID) {
- DataSourceInformationRepositoryService dataSourceService = getCarbonDataSourceService();
- if (dataSourceService == null) {
- carbonDataSourceServiceListeners.add(listener);
- } else {
- listener.setCarbonDataSourceService(dataSourceService);
- }
- } else {
- DataSourceInitializer.addDataSourceRepositoryListener(listener.getTenantId(),
- new CarbonDataSourceServiceRepositoryListenerAdapter(listener));
- }
- }
- }
-
- public static void registerRegistryServiceListener(RegistryServiceListener listener) {
- synchronized (dsComponentLock) {
- RegistryService registryService = getRegistryService();
- if (registryService == null) {
- registryServiceListeners.add(listener);
- } else {
- listener.setRegistryService(registryService);
- }
- }
- }
-
- private static class CarbonDataSourceServiceRepositoryListenerAdapter implements DataSourceRepositoryListener {
-
- private CarbonDataSourceServiceListener listener;
-
- public CarbonDataSourceServiceRepositoryListenerAdapter(CarbonDataSourceServiceListener listener) {
- this.listener = listener;
- }
-
- public CarbonDataSourceServiceListener getListener() {
- return listener;
- }
-
- @Override
- public void setDataSourceRepository(DataSourceInformationRepository repo) {
- /* In this situation, the data source repository service will be available */
- this.getListener().setCarbonDataSourceService(DataServicesDSComponent.getCarbonDataSourceService());
- }
-
- }
}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/script/DSGenerator.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/script/DSGenerator.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/script/DSGenerator.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.core/3.2.2/src/main/java/org/wso2/carbon/dataservices/core/script/DSGenerator.java Thu Oct 13 22:50:58 2011
@@ -716,7 +716,7 @@
}
List<Validator> validator = new ArrayList<Validator>();
QueryParam queryParam = new QueryParam(pName, sqlType, DBConstants.DataServiceGenerator.IN,
- DBConstants.DataServiceGenerator.SCALAR, ordinal, null, validator);
+ DBConstants.DataServiceGenerator.SCALAR, ordinal, null, null, validator);
paramList.add(queryParam);
ordinal++; // increase the ordinal value one by one
}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/DataServiceAdminClient.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/DataServiceAdminClient.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/DataServiceAdminClient.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/DataServiceAdminClient.java Thu Oct 13 22:50:58 2011
@@ -28,16 +28,16 @@
public class DataServiceAdminClient {
+
private DataServiceAdminStub stub = null;
- private String serviceEndPoint = null;
private static Log log = LogFactory.getLog(DataServiceAdminClient.class);
-
public DataServiceAdminClient(String cookie, String url, ConfigurationContext configContext)
throws AxisFault {
+ String serviceEndPoint = null;
try {
- this.serviceEndPoint = url + "DataServiceAdmin";
+ serviceEndPoint = url + "DataServiceAdmin";
stub = new DataServiceAdminStub(configContext, serviceEndPoint);
ServiceClient client = stub._getServiceClient();
@@ -45,47 +45,49 @@
option.setManageSession(true);
option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
} catch (AxisFault e) {
- log.error("Error occurred while connecting via stub to :"+serviceEndPoint,e);
+ log.error("Error occurred while connecting via stub to :"+ serviceEndPoint,e);
throw e;
}
}
public String getDataServiceContents(String serviceId) throws RemoteException {
- String contents = stub.getDataServiceContentAsString(serviceId);
- return contents;
+ return stub.getDataServiceContentAsString(serviceId);
}
public String[] getCarbonDataSourceNames() throws RemoteException {
- String[] names = stub.getCarbonDataSourceNames();
- return names;
+ return stub.getCarbonDataSourceNames();
}
- public void saveDataService(String serviceName, String serviceGroup, String serviceContents) throws AxisFault {
+ public void saveDataService(String serviceName, String serviceGroup, String serviceContents)
+ throws AxisFault {
try {
stub.saveDataService(serviceName, serviceGroup, serviceContents);
} catch (RemoteException e) {
- log.error("Error occurred while saving dataservice : "+serviceName,e);
- throw new AxisFault("Saving "+serviceName+" failed.",e);
+ log.error("Error occurred while saving dataservice : " + serviceName, e);
+ throw new AxisFault("Saving "+ serviceName+ " failed.", e);
}
}
/**
*
- * @param driverClass
- * @param jdbcURL
- * @param username
- * @param password
- * @throws AxisFault
+ * @param driverClass JDBC driver class name
+ * @param jdbcURL JDBC Url
+ * @param username username
+ * @param password password
+ * @param protectedTokens password tokens
+ * @param passwordProvider password provider
+ * @throws AxisFault axisFault
+ * @return a string representing success or the failure of the JDBC connection
*/
- public String testJDBCConnection(String driverClass,
- String jdbcURL,
- String username,
- String password,String protectedTokens,String passwordProvider )throws AxisFault {
+ public String testJDBCConnection(String driverClass, String jdbcURL, String username,
+ String password, String protectedTokens, String passwordProvider) throws AxisFault {
String response = "";
try {
- response = stub.testJDBCConnection(driverClass, jdbcURL, username, password,protectedTokens,passwordProvider);
+ response = stub.testJDBCConnection(driverClass, jdbcURL, username, password,
+ protectedTokens, passwordProvider);
} catch (RemoteException e) {
- throw new AxisFault("Error connecting to "+jdbcURL+". Message from the service is : ",e);
+ throw new AxisFault("Error connecting to " + jdbcURL +
+ ". Message from the service is : ", e);
}
return response;
}
@@ -96,9 +98,11 @@
String documentURL,String protectedTokens,String passwordProvider)throws AxisFault {
String response = "";
try {
- response = stub.testGSpreadConnection(userName, password, visibility, documentURL,protectedTokens,passwordProvider);
+ response = stub.testGSpreadConnection(userName, password, visibility, documentURL,
+ protectedTokens, passwordProvider);
} catch (RemoteException e) {
- throw new AxisFault("Error connecting to "+documentURL+". Message from the service is : ",e);
+ throw new AxisFault("Error connecting to " + documentURL +
+ ". Message from the service is : ", e);
}
return response;
}
@@ -107,16 +111,19 @@
return stub.getColumnNames(query);
}
- public PaginatedTableInfo getPaginatedTableInfo(int pageNumber, String datasourceId, String dbName,
- String[] schemas )throws Exception {
+ public PaginatedTableInfo getPaginatedTableInfo(int pageNumber,
+ String datasourceId, String dbName,
+ String[] schemas) throws Exception {
return stub.getPaginatedTableInfo(pageNumber,datasourceId, dbName,schemas);
}
- public PaginatedTableInfo getPaginatedSchemaInfo(int pageNumber, String datasourceId) throws Exception {
+ public PaginatedTableInfo getPaginatedSchemaInfo(int pageNumber,
+ String datasourceId) throws Exception {
return stub.getPaginatedSchemaInfo(pageNumber,datasourceId);
}
- public String[] getTableInfo(String datasourceId, String dbName, String[] schemas) throws Exception {
+ public String[] getTableInfo(String datasourceId, String dbName,
+ String[] schemas) throws Exception {
return stub.getTableList(datasourceId, dbName, schemas);
}
@@ -131,19 +138,21 @@
public String[] getDSServiceList(String dataSourceId, String dbName, String[] schemas,
String[] tableNames,String serviceNamespace) {
try {
- return stub.getDSServiceList(dataSourceId, dbName, schemas, tableNames, false,serviceNamespace);
+ return stub.getDSServiceList(dataSourceId, dbName, schemas, tableNames, false,
+ serviceNamespace);
} catch (Exception e) {
return null;
}
}
public String getDSService(String dataSourceId, String dbName, String[] schemas,
- String[] tableNames,String serviceName, String serviceNamespace) {
+ String[] tableNames, String serviceName, String serviceNamespace) {
try {
- return stub.getDSService(dataSourceId, dbName, schemas, tableNames, true,serviceName,serviceNamespace);
+ return stub.getDSService(dataSourceId, dbName, schemas, tableNames, true, serviceName,
+ serviceNamespace);
} catch (Exception e) {
return null;
}
-
}
+
}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/UIutils.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/UIutils.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/UIutils.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/UIutils.java Thu Oct 13 22:50:58 2011
@@ -34,4 +34,5 @@
System.arraycopy(childPaths, start, resultChildPaths, 0, pageLength);
return resultChildPaths;
}
+
}
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Data.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Data.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Data.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Data.java Thu Oct 13 22:50:58 2011
@@ -1118,6 +1118,7 @@
paramElement.getAttributeValue(new QName("type")),
userSetOrdinalValue,
paramElement.getAttributeValue(new QName("defaultValue")),
+ paramElement.getAttributeValue(new QName("structType")),
this.getValidators(paramElement.getChildElements())
);
paramList.add(param);
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Param.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Param.java?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Param.java (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/java/org/wso2/carbon/dataservices/ui/beans/Param.java Thu Oct 13 22:50:58 2011
@@ -42,6 +42,8 @@
private String defaultValue;
+ private String structType;
+
private List<Validator> validators;
public String getName() {
@@ -100,7 +102,16 @@
return defaultValue;
}
- public Param(String name, String paramType, String sqlType, String type, String ordinal, String defaultValue, List<Validator> validators){
+ public String getStructType() {
+ return structType;
+ }
+
+ public void setStructType(String structType) {
+ this.structType = structType;
+ }
+
+ public Param(String name, String paramType, String sqlType, String type, String ordinal,
+ String defaultValue, String structType, List<Validator> validators){
this.name = name;
this.sqlType = sqlType;
this.type = type;
@@ -115,12 +126,15 @@
}
this.ordinal = Integer.parseInt(ordinal);
this.defaultValue = defaultValue;
+ this.structType = structType;
this.validators = validators;
}
- public Param(String name, String paramType, String sqlType, String type, String defaultValue, List<Validator> validators){
- this(name, paramType, sqlType, type, "0", defaultValue, validators);
+ public Param(String name, String paramType, String sqlType, String type, String defaultValue,
+ List<Validator> validators){
+ this(name, paramType, sqlType, type, "0", defaultValue, null, validators);
}
+
public Param(){
}
@@ -162,6 +176,9 @@
if (this.getDefaultValue() != null) {
paramEl.addAttribute("defaultValue", this.getDefaultValue(), null);
}
+ if (this.getStructType() != null) {
+ paramEl.addAttribute("structType", this.getStructType(), null);
+ }
if (this.getValidators() != null) {
for (Validator val : this.getValidators()) {
paramEl.addChild(val.buildXML());
Deleted: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/DataServiceAdmin.wsdl
URL: http://wso2.org/svn/browse/wso2/None?pathrev=113875
Deleted: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/DataServiceFileUploader.wsdl
URL: http://wso2.org/svn/browse/wso2/None?pathrev=113875
Deleted: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/TaskManagementAdminService.wsdl
URL: http://wso2.org/svn/browse/wso2/None?pathrev=113875
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/org/wso2/carbon/dataservices/ui/i18n/Resources.properties
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/org/wso2/carbon/dataservices/ui/i18n/Resources.properties?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/org/wso2/carbon/dataservices/ui/i18n/Resources.properties (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/org/wso2/carbon/dataservices/ui/i18n/Resources.properties Thu Oct 13 22:50:58 2011
@@ -7,6 +7,7 @@
dataservices.new.ui.text=Tree Wizard
service.create.heading=Create Data Service
service.edit.heading=Edit Data Service
+dataservices.input.struct.type=Struct Type
service.details=Service Details
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/addInputMapping.jsp
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/addInputMapping.jsp?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/addInputMapping.jsp (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/addInputMapping.jsp Thu Oct 13 22:50:58 2011
@@ -18,7 +18,6 @@
<%@ page import="org.wso2.carbon.dataservices.ui.beans.Param" %>
<%@ page import="org.wso2.carbon.dataservices.ui.beans.Query" %>
<%@ page import="org.wso2.carbon.dataservices.ui.beans.Validator" %>
-<%@ page import="java.util.Map" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
@@ -39,6 +38,7 @@
String paramName = request.getParameter("paramName");
String paramType = request.getParameter("paramType");
String defaultValue = request.getParameter("defaultValue");
+ String structType = request.getParameter("structType");
String ordinalVal = request.getParameter("inputMappingOrdinalId");
String caption;
boolean isEdit = false;
@@ -72,6 +72,7 @@
paramName = (paramName == null) ? "" : paramName;
paramType = (paramType == null) ? "" : paramType;
defaultValue = (defaultValue == null) ? "" : defaultValue;
+ structType = (structType == null) ? "" : structType;
disable = (paramName != null);
sqlType = (sqlType == null) ? "" : sqlType;
inOutType = (inOutType == null) ? "" : inOutType;
@@ -156,7 +157,7 @@
</tr>
<tr>
<td class="leftCol-small"><fmt:message key="datasources.sql.type"/><font color="red">*</font></td>
- <td><select id="inputMappingSqlTypeId" name="inputMappingSqlType">
+ <td><select id="inputMappingSqlTypeId" name="inputMappingSqlType" onchange="changeVisiblityOnTypeSelection(this, document)">
<% if (sqlType.equals("")) { %>
<option value="" selected="selected">--SELECT--</option>
<% } else { %>
@@ -232,15 +233,32 @@
<option value="BINARY" selected="selected">BINARY</option>
<% } else { %>
<option value="BINARY">BINARY</option>
+ <% }
+ if (sqlType.equals("STRUCT")) { %>
+ <option value="STRUCT" selected="selected">STRUCT</option>
+ <% } else { %>
+ <option value="STRUCT">STRUCT</option>
+ <% } if (sqlType.equals("ARRAY")) { %>
+ <option value="ARRAY" selected="selected">ARRAY</option>
+ <% } else { %>
+ <option value="ARRAY">ARRAY</option>
<% } %>
- </select></td>
+ </select>
+ </td>
</tr>
-<tr style="<%=paramType.equals("SCALAR") || paramType.equals("") ? "" : "display:none"%>"
+<tr style="<%=(paramType.equals("SCALAR") && (!"STRUCT".equals(sqlType)) || !"ARRAY".equals(sqlType)) ||
+paramType.equals("") ? "" : "display:none"%>"
id="defaultValueRow">
<td class="leftCol-small"><fmt:message key="dataservices.default.value"/></td>
<td><input type="text" size="30" value="<%=defaultValue%>" name="defaultValue"
id="defaultValue"/></td>
</tr>
+<tr id="structTypeRow" style="<%=("STRUCT".equals(sqlType)) && !"".equals(structType) && (structType != null) ? "" :
+"display:none"%>">
+ <td class="leftCol-small"><fmt:message key="dataservices.input.struct.type"/><font color="red">*</font></td>
+ <td><input type="text" size="30" value="<%=structType%>" name="structType"
+ id="structType"/></td>
+</tr>
<tr>
<td class="leftCol-small"><fmt:message key="datasources.in.out.type"/></td>
<td><select id="inputMappingInOutTypeId" name="inputMappingInOutType"
@@ -356,7 +374,7 @@
</td>
<td>
<a class="icon-link" style="background-image:url(../admin/images/delete.gif);"
- href="inputMappingProcessor.jsp?queryId=<%=queryId%>&validatorList=<%=valObj.getElementName()%>&inputMappingId=<%=paramName%>&inputMappingSqlType=<%=sqlType%>&defaultValue=<%=defaultValue%>&flag=deleteValidator&origin=add">
+ href="inputMappingProcessor.jsp?queryId=<%=queryId%>&validatorList=<%=valObj.getElementName()%>&inputMappingId=<%=paramName%>&inputMappingSqlType=<%=sqlType%>&defaultValue=<%=defaultValue%>&structType=<%=structType%>&flag=deleteValidator&origin=add">
<fmt:message key="delete"/></a>
</td>
</tr>
@@ -407,7 +425,7 @@
</td>
<td>
<a class="icon-link" style="background-image:url(../admin/images/edit.gif);"
- href="addInputMapping.jsp?paramName=<%=params[a].getName()%>&queryId=<%=queryId%>¶mType=<%=params[a].getParamType()%>"><fmt:message
+ href="addInputMapping.jsp?paramName=<%=params[a].getName()%>&queryId=<%=queryId%>¶mType=<%=params[a].getParamType()%>&structType=<%=params[a].getStructType()%>"><fmt:message
key="edit"/></a>
<a class="icon-link" style="background-image:url(../admin/images/delete.gif);"
href="#"
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/inputMappingProcessor.jsp
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/inputMappingProcessor.jsp?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/inputMappingProcessor.jsp (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/inputMappingProcessor.jsp Thu Oct 13 22:50:58 2011
@@ -15,14 +15,14 @@
~ specific language governing permissions and limitations
~ under the License.
-->
-<%@ page import="org.wso2.carbon.dataservices.ui.beans.Query" %>
<%@ page import="org.wso2.carbon.dataservices.ui.beans.Param" %>
-<%@ page import="java.util.ArrayList" %>
+<%@ page import="org.wso2.carbon.dataservices.ui.beans.Query" %>
<%@ page import="org.wso2.carbon.dataservices.ui.beans.Validator" %>
-<%@ page import="java.util.Map" %>
-<%@ page import="java.util.HashMap" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Iterator" %>
+<%@ page import="java.util.Map" %>
<jsp:useBean id="dataService" class="org.wso2.carbon.dataservices.ui.beans.Data" scope="session"/>
<jsp:useBean id="validators" class="java.util.ArrayList" scope="session" />
<%
@@ -42,12 +42,14 @@
String valMax = request.getParameter("max");
String valPattern = request.getParameter("pattern");
String valCustomClass = request.getParameter("customClass");
+ String structType = request.getParameter("structType");
paramType = (paramType == null ) ? "SCALAR" : paramType;
sqlType = (sqlType == null) ? "" : sqlType;
paramName = (paramName == null) ? "" : paramName;
oldParamName = (oldParamName == null) ? "": oldParamName;
flag = (flag == null) ? "" : flag;
origin = (origin == null) ? "" : origin;
+ structType = (structType == null) ? "" : structType;
Query query = dataService.getQuery(queryId);
boolean addValidation = true;
@@ -136,6 +138,9 @@
if(defaultValue != null && defaultValue.trim().length() > 0){
param.setDefaultValue(defaultValue);
}
+ if(structType != null && structType.trim().length() > 0){
+ param.setStructType(structType);
+ }
if (ordinalStr != null && ordinalStr.trim().length() > 0) {
param.setOrdinal(Integer.parseInt(ordinalStr));
};
@@ -151,6 +156,9 @@
if(defaultValue != null && defaultValue.trim().length() > 0){
param.setDefaultValue(defaultValue);
}
+ if(structType != null && structType.trim().length() > 0){
+ param.setStructType(structType);
+ }
if (ordinalStr != null && ordinalStr.trim().length() > 0) {
param.setOrdinal(Integer.parseInt(ordinalStr));
}
@@ -178,7 +186,8 @@
<input type="hidden" id="origin" name="origin" value="<%=origin%>" />
<input type="hidden" id="paramName" name="paramName" value="<%=paramName%>"/>
<input type ="hidden" id="paramType" name="paramType" value="<%=paramType%>"/>
- <input type ="hidden" id="defaultValue" name="defaultValue" value="<%=defaultValue%>" />
+ <input type ="hidden" id="defaultValue" name="defaultValue" value="<%=defaultValue%>" />
+ <input type="hidden" id="structType" name="structType" value="<%=structType%>"/>
<input type ="hidden" id="sqlType" name="sqlType" value="<%=sqlType%>"/>
<input type ="hidden" id="inoutType" name="inoutType" value="<%=inOutType%>"/>
</form>
@@ -199,10 +208,10 @@
if(document.getElementById('origin').value == 'add'){
location.href= "addInputMapping.jsp?queryId=<%=queryId%>";
}else if(document.getElementById('origin').value == 'save'){
- location.href= "addQuery.jsp?queryId="+document.getElementById('queryId').value;
+ location.href= "addQuery.jsp?queryId=" + document.getElementById('queryId').value;
}
} else if(document.getElementById('flag').value == 'validate' || document.getElementById('flag').value == 'deleteValidator'){
- location.href= "addInputMapping.jsp?queryId="+document.getElementById('queryId').value+"¶mName="+document.getElementById('paramName').value+"¶mType="+document.getElementById('paramType').value+"&defaultValue="+document.getElementById('defaultValue').value+"&sqlType="+document.getElementById('sqlType').value+"&inOutType="+document.getElementById('inoutType').value;
+ location.href= "addInputMapping.jsp?queryId=" + document.getElementById('queryId').value + "¶mName=" + document.getElementById('paramName').value + "¶mType=" + document.getElementById('paramType').value + "&defaultValue=" + document.getElementById('defaultValue').value + "&structType=" + document.getElementById('structType') + "&sqlType=" + document.getElementById('sqlType').value + "&inOutType=" + document.getElementById('inoutType').value;
}
</script>
\ No newline at end of file
Modified: branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/js/ui-validations.js
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/js/ui-validations.js?rev=113876&r1=113875&r2=113876&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/js/ui-validations.js (original)
+++ branches/carbon/3.2.0/components/data-services/org.wso2.carbon.dataservices.ui/3.2.2/src/main/resources/web/ds/js/ui-validations.js Thu Oct 13 22:50:58 2011
@@ -419,7 +419,7 @@
document.getElementById('propertyTable').style.display = propTable;
document.getElementById('inputHeading').style.display = inputHeading;
document.getElementById('scraperRow').style.display = webConfig;
- document.getElementById('autoResponseRow').style.display = autoResponse;
+ //document.getElementById('autoResponseRow').style.display = autoResponse;
}
@@ -469,17 +469,16 @@
return true;
}
-
function manageXADataService(obj){
document.getElementById('dataForm').action ='manageXADS.jsp?flag=manageXADS';
return true;
}
-
function validateInputMappings(){
var name = document.getElementById('inputMappingNameId').value;
var sqlType = document.getElementById('inputMappingSqlTypeId').value;
var ordinal = document.getElementById('inputMappingOrdinalId').value;
+ var structType = document.getElementById('structType').value;
if(name == ''){
CARBON.showWarningDialog('Enter value to the Mapping Name');
@@ -488,6 +487,9 @@
if(sqlType == ''){
CARBON.showWarningDialog('Select SQL Type');
return false;
+ } else if (sqlType == 'STRUCT' && structType == '') {
+ CARBON.showWarningDialog('Enter name of the SQL struct type');
+ return false;
}
if(ordinal.match(/^[a-zA-Z]+$/)){
CARBON.showWarningDialog('Enter numeric values to Ordinal');
@@ -1044,9 +1046,9 @@
function inOutVisibilityOnChange(obj, document) {
var selectedValue = obj[obj.selectedIndex].value;
if(selectedValue == 'OUT'){
- document.getElementById('validatorRow').style.display = 'none';
+ //document.getElementById('validatorRow').style.display = 'none';
}else{
- document.getElementById('validatorRow').style.display = '';
+ //document.getElementById('validatorRow').style.display = '';
}
}
@@ -1406,6 +1408,17 @@
return true;
}
+function changeVisiblityOnTypeSelection(obj, document) {
+ var selectedSqlType = obj[obj.selectedIndex].value;
+ if (selectedSqlType == 'STRUCT' || selectedSqlType == 'ARRAY') {
+ document.getElementById('defaultValueRow').style.display = 'none';
+ document.getElementById('structTypeRow').style.display = ''
+ } else {
+ document.getElementById('defaultValueRow').style.display = '';
+ document.getElementById('structTypeRow').style.display = 'none'
+ }
+}
+
More information about the Carbon-commits
mailing list