Package org.restsql.core

Examples of org.restsql.core.InvalidRequestException


    String uri;
    try {
      uri = URLDecoder.decode(httpAttributes.getUri(), "UTF-8");
    } catch (final UnsupportedEncodingException exception) {
      throw new InvalidRequestException("Problem decoding uri: " + httpAttributes.getUri() + " - "
          + exception.getMessage());
    }

    final int queryIndex = uri.indexOf('?');
    if (queryIndex > 0) {
View Full Code Here


      final String sqlResource, final List<RequestValue> resIds, final List<RequestValue> params,
      final List<List<RequestValue>> childrenParams, final RequestLogger requestLogger)
      throws InvalidRequestException {
    // Verify expectations
    if (sqlResource == null) {
      throw new InvalidRequestException(InvalidRequestException.MESSAGE_SQLRESOURCE_REQUIRED);
    }

    switch (type) {
      case INSERT:
        if (params == null && childrenParams == null) {
          throw new InvalidRequestException(InvalidRequestException.MESSSAGE_INSERT_MISSING_PARAMS);
        }
        break;
      case UPDATE:
        if (params == null && childrenParams == null) {
          throw new InvalidRequestException(InvalidRequestException.MESSSAGE_UPDATE_MISSING_PARAMS);
        }
        break;
      default:
    }
    RequestUtil.checkForInvalidMultipleParameters(params);
View Full Code Here

          case Types.JAVA_OBJECT:
          case Types.LONGVARBINARY:
            if (BinaryObject.isStringBase64((String) value)) {
              value = BinaryObject.fromString((String) value);
            } else {
              throw new InvalidRequestException(
                  InvalidRequestException.MESSAGE_CANNOT_BASE64DECODE,
                  requestValue.getName());
            }

          case Types.DATE:
          case Types.TIME:
          case Types.TIMESTAMP:
          default:
            // do nothing
        }
      } catch (final NumberFormatException e) {
        throw new InvalidRequestException("Could not convert " + requestValue.getName() + " value " + value + " to number");
      }
    }

    requestValue.setValue(value);
  }
View Full Code Here

      }

      // Validate both limit and offset provided
      if (type == Type.SELECT) {
        if (selectLimit != null && selectOffset == null) {
          throw new InvalidRequestException(InvalidRequestException.MESSAGE_OFFSET_REQUIRED);
        } else if (selectOffset != null && selectLimit == null) {
          throw new InvalidRequestException(InvalidRequestException.MESSAGE_LIMIT_REQUIRED);
        } else if (selectLimit != null && selectOffset != null) {
          params.remove(selectLimitRequestValue);
          params.remove(selectOffsetRequestValue);
        }
      }
View Full Code Here

          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

    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

        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

        sql.compileStatements();
      }
    }

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

        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

      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

TOP

Related Classes of org.restsql.core.InvalidRequestException

Copyright © 2018 www.massapicom. 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.