-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathRequest.java
More file actions
97 lines (77 loc) · 2.62 KB
/
Request.java
File metadata and controls
97 lines (77 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */
package org.restsql.core;
import java.util.List;
/**
* Represents a single CRUD request on a specific SQL Resource.
*
* @author Mark Sawers
*/
public interface Request {
public static final String PARAM_NAME_LIMIT = "_limit";
public static final String PARAM_NAME_OFFSET = "_offset";
public static final String PARAM_NAME_OUTPUT = "_output";
/** Returns children CUD requests to a single parent for a hierarchical SQL Resource. */
public List<List<RequestValue>> getChildrenParameters();
/** Returns http request attributes. */
public HttpRequestAttributes getHttpRequestAttributes();
/** Returns request logger. */
public RequestLogger getLogger();
/** Returns ordered list of parameters, for example the selection filter for update request. */
public List<RequestValue> getParameters();
/** Returns parent, if any. */
public Request getParent();
/**
* Returns ordered list of primary key values for a CRUD request on a single object (row). On a hierarchical SQL
* Resource, this list identifies the parent and the children are identified by the children parameters.
*/
public List<RequestValue> getResourceIdentifiers();
/** Returns select row limit, if any. */
public Integer getSelectLimit();
/** Returns select row offset, if any. */
public Integer getSelectOffset();
/** Returns SQL Resource name. */
public String getSqlResource();
/** Returns request type. */
public Type getType();
/** Returns true if request has parameter with the given name. */
public boolean hasParameter(String name);
/** Sets parameters for request. Used for cloning requests on child objects. */
public void setParameters(final List<RequestValue> params);
/** Sets parent request. */
public void setParent(Request parentRequest);
/**
* Sets select limit.
*/
public void setSelectLimit(final Integer integer);
/**
* Sets select offset.
*/
public void setSelectOffset(final Integer integer);
/**
* Extract limit and offset.
*
* @throws InvalidRequestException if request is invalid
*/
public void extractParameters() throws InvalidRequestException;
/**
* Represents request types, mapping to CRUD operations.
*
* @author Mark Sawers
*/
public enum Type {
DELETE, INSERT, SELECT, UPDATE;
public static Type fromHttpMethod(final String method) {
Type type;
if (method.equals("DELETE")) {
type = Type.DELETE;
} else if (method.equals("GET")) {
type = Type.SELECT;
} else if (method.equals("POST")) {
type = Type.INSERT;
} else { // method.equals("PUT")
type = Type.UPDATE;
}
return type;
}
}
}