Examples of InvalidRequestException


Examples of org.restsql.core.InvalidRequestException

          selectLimit = Integer.valueOf((String) requestValue.getValue());
        } else {
          selectOffset = Integer.valueOf((String) requestValue.getValue());
        }
      } catch (final NumberFormatException exception) {
        throw new InvalidRequestException(paramName + " value " + requestValue.getValue()
            + " is not a number");
      }
    } else {
      throw new InvalidRequestException(paramName + " value " + requestValue.getValue()
          + " is not an Integer");
    }
    return requestValue;
  }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

    final Handler handler = new Handler(httpAttributes, requestType, resIds, sqlResource, requestLogger);
    try {
      final JSONParser parser = new JSONParser();
      parser.parse(requestBody, handler);
    } catch (final ParseException exception) {
      throw new InvalidRequestException("Error parsing request body: " + exception.toString());
    }
    final SqlResourceException handlerException = handler.getHandlerException();
    if (handlerException != null) {
      throw handlerException;
    }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

        break;
      case DELETE:
        sqls = buildDeleteSql(metaData, request, doParent);
        break;
      default:
        throw new InvalidRequestException("SELECT Request provided to SqlBuilder.buildWriteSql()");
    }
    return sqls;
  }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

        sql.compileStatements();
      }
    }

    if (sqls.size() == 0 && doParent) {
      throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
    }
    return sqls;
  }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

        final List<TableMetaData> tables = metaData.getWriteTables(Request.Type.DELETE, doParent);
        for (final TableMetaData table : tables) {
          final ColumnMetaData column = table.getColumns().get(requestParam.getName());
          if (column != null) {
            if (column.isReadOnly()) {
              throw new InvalidRequestException(InvalidRequestException.MESSAGE_READONLY_PARAM,
                  column.getColumnLabel());
            }
            final String qualifiedTableName = column.getQualifiedTableName();
            SqlStruct sql = sqls.get(qualifiedTableName);
            if (sql == null) {
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

      final List<TableMetaData> tables = metaData.getWriteTables(request.getType(), doParent);
      for (final TableMetaData table : tables) {
        final ColumnMetaData column = table.getColumns().get(param.getName());
        if (column != null) {
          if (column.isReadOnly()) {
            throw new InvalidRequestException(InvalidRequestException.MESSAGE_READONLY_PARAM,
                column.getColumnLabel());
          }
          final String qualifiedTableName = column.getQualifiedTableName();
          SqlStruct sql = sqls.get(qualifiedTableName);
          if (sql == null) {
            // Create new sql holder
            sql = new SqlStruct(DEFAULT_INSERT_SIZE, DEFAULT_INSERT_SIZE / 2);
            sqls.put(qualifiedTableName, sql);
            sql.getMain().append("INSERT INTO ");
            sql.getMain().append(qualifiedTableName);
            sql.getMain().append(" (");

            sql.appendToBothClauses(" VALUES (");
          } else {
            sql.getMain().append(',');
            sql.appendToBothClauses(",");
          }
          sql.getMain().append(column.getColumnName()); // since parameter may use column label

          // Begin quote the column value
          if (column.isCharOrDateTimeType()) {
            sql.getClause().append('\'');
          }

          // Convert String to appropriate object
          column.normalizeValue(param);

          // Set the value in the printable clause, the ? in the prepared clause, and prepared clause value
          sql.getClause().append(param.getValue().toString());
          sql.getPreparedClause().append(buildPreparedParameterSql(column));
          sql.getPreparedValues().add(param.getValue());

          // End quote the column value
          if (column.isCharOrDateTimeType()) {
            sql.getClause().append('\'');
          }
        }
      }
    }

    for (final String tableName : sqls.keySet()) {
      final SqlStruct sql = sqls.get(tableName);
      if (sql == null) {
        sqls.remove(tableName);
      } else {
        sql.getMain().append(')');
        sql.appendToBothClauses(")");
        sql.compileStatements();
      }
    }

    if (sqls.size() == 0) {
      throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
    }
    return sqls;
  }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

        for (final TableMetaData table : metaData.getTables()) {
          final ColumnMetaData column = table.getColumns().get(param.getName());
          if (column != null) {
            if (column.isReadOnly()) {
              throw new InvalidRequestException(InvalidRequestException.MESSAGE_READONLY_PARAM,
                  column.getColumnLabel());
            }
            if (!column.isNonqueriedForeignKey()) {
              validParamFound = true;
              setNameValue(Request.Type.SELECT, metaData, column, param, true, sql, false);
            }
          }
        }
      }

      if (sql.getClause().length() > 0 && !validParamFound) {
        throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
      }
    }
  }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

    for (final RequestValue param : request.getParameters()) {
      for (final TableMetaData table : tables) {
        final ColumnMetaData column = table.getColumns().get(param.getName());
        if (column != null) {
          if (column.isReadOnly()) {
            throw new InvalidRequestException(InvalidRequestException.MESSAGE_READONLY_PARAM,
                column.getColumnLabel());
          }
          if (column.isPrimaryKey()) {
            // Add this to the res Ids - assume resIds is non null
            resIds.add(param);
          } else if (!column.isNonqueriedForeignKey()) {
            SqlStruct sql = sqls.get(column.getQualifiedTableName());
            if (sql == null) {
              // Create new sql holder
              sql = new SqlStruct(DEFAULT_UPDATE_SIZE, DEFAULT_UPDATE_SIZE / 2, true);
              sqls.put(column.getQualifiedTableName(), sql);
              sql.appendToBothMains("UPDATE ");
              sql.appendToBothMains(column.getQualifiedTableName());
              sql.appendToBothMains(" SET ");
            } else {
              sql.appendToBothMains(",");
            }

            validParamFound = true;
            setNameValue(request.getType(), metaData, column, param, false, sql, true);
          }
        }
      }
    }

    if (!validParamFound) {
      throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
    }
    validParamFound = false;

    for (final String qualifiedTableName : sqls.keySet()) {
      final SqlStruct sql = sqls.get(qualifiedTableName);
      if (sql == null) {
        sqls.remove(qualifiedTableName);
      } else {
        // Iterate through the resourceIds and build the where clause sql for each table
        for (final RequestValue resId : resIds) {
          final TableMetaData table = metaData.getTableMap().get(qualifiedTableName);
          final ColumnMetaData column = table.getColumns().get(resId.getName());
          if (column != null) {
            if (sql.getClause().length() == 0) {
              sql.appendToBothClauses(" WHERE ");
            } else { // sql.getClause().length() > 0
              sql.appendToBothClauses(" AND ");
            }
            validParamFound = true;
            setNameValue(request.getType(), metaData, column, resId, true, sql, false);
          }
        }
        sql.compileStatements();
      }
    }

    if (!validParamFound) {
      throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
    }
    return sqls;
  }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

          break;
        case GreaterThanOrEqualTo:
          appendToBoth(sql, useMain, " >= ");
          break;
        default: // case Escaped
          throw new InvalidRequestException(
              "SqlBuilder.setNameValue() found unexpected operator of type "
                  + param.getOperator());
      }
    }
View Full Code Here

Examples of org.restsql.core.InvalidRequestException

      parser = SAXParserFactory.newInstance().newSAXParser();
      inputStream = new ByteArrayInputStream(requestBody.getBytes());
      parser.parse(inputStream, handler);
    } catch (final Exception exception) {
      Config.logger.info("Error parsing request body for " + httpAttributes, exception);
      throw new InvalidRequestException("Error parsing request body: " + exception.toString());
    }
    final SqlResourceException handlerException = handler.getHandlerException();
    if (handlerException != null) {
      throw handlerException;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.