示例#1
0
 /**
  * Create query param list according to table column names
  *
  * @param param -List of column names in the database table
  * @param tableName -
  * @return paramList-List of QueryParam
  * @throws IllegalArgumentException -""
  * @throws SQLException -""
  * @throws DataServiceFault -
  */
 private List<QueryParam> getQueryParamList(
     DatabaseMetaData metaData, String dbName, String schema, String tableName, List<String> param)
     throws IllegalArgumentException, SQLException, DataServiceFault {
   List<QueryParam> paramList = new ArrayList<QueryParam>();
   int ordinal = 1;
   for (String pName : param) {
     /* Get the SQL type of parameter */
     String sqlType = "";
     ResultSet rs = getColumnNames(metaData, schema, dbName, tableName, pName);
     while (rs.next()) {
       int type = rs.getInt(DBConstants.DataServiceGenerator.DATA_TYPE);
       if ((-1 == type) || (-16 == type) || (-15 == type) || (2009 == type)) {
         type = 1;
       }
       sqlType = DSSqlTypes.getDefinedTypes().get(type);
     }
     List<Validator> validator = new ArrayList<Validator>();
     QueryParam queryParam =
         new QueryParam(
             pName,
             sqlType,
             DBConstants.DataServiceGenerator.IN,
             DBConstants.DataServiceGenerator.SCALAR,
             ordinal,
             null,
             null,
             validator);
     paramList.add(queryParam);
     ordinal++; // increase the ordinal value one by one
   }
   return paramList;
 }
示例#2
0
 /** This method construct the result object. */
 private Result getResult(
     DataService dataServiceObject,
     DatabaseMetaData metaData,
     String dbName,
     String schema,
     String tableName)
     throws DataServiceFault, IllegalArgumentException, SQLException {
   // row name is equal to table Name
   String rowElementName = tableName + DBConstants.DataServiceGenerator.ROW_ELEMENT_NAME_SUFFIX;
   Result result = new Result(rowElementName, tableName, null, null, ResultTypes.XML);
   ResultSet columnNames = getColumnNames(metaData, schema, dbName, tableName, null);
   OutputElementGroup defGroup = new OutputElementGroup(null, null, null, null);
   while (columnNames.next()) {
     String columnName = columnNames.getString(DBConstants.DataServiceGenerator.COLUMN_NAME);
     int typeInt = columnNames.getInt("DATA_TYPE");
     if ((-1 == typeInt) || (-16 == typeInt) || (-15 == typeInt) || (2009 == typeInt)) {
       typeInt = 1;
     }
     String type = DSSqlTypes.getQNameType(typeInt);
     QName qName = QueryFactory.getXsdTypeQName(type);
     Set<String> requiredRoles = new HashSet<String>(); // empty set
     StaticOutputElement outputElement =
         new StaticOutputElement(
             dataServiceObject,
             columnName,
             columnName,
             columnName,
             DBConstants.DataServiceGenerator.COLUMN,
             DBConstants.DataServiceGenerator.ELEMENT,
             null,
             qName,
             requiredRoles,
             0,
             0,
             null,
             ParamValue.PARAM_VALUE_SCALAR,
             null);
     defGroup.addAttributeEntry(outputElement);
   }
   result.setDefaultElementGroup(defGroup);
   return result;
 }