forked from dork/tarantool-java
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This DSL includes set of request builders that can be used as a public API to construct requests. The main idea here is to provide more natural DSL-like approach to build operations instead of current abstract types like List<?> or List<Object>. Closes: #212
- Loading branch information
1 parent
567851c
commit 63f1dee
Showing
19 changed files
with
1,096 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.tarantool.dsl; | ||
|
||
import org.tarantool.Code; | ||
import org.tarantool.TarantoolRequest; | ||
import org.tarantool.schema.TarantoolSchemaMeta; | ||
|
||
import java.time.Duration; | ||
|
||
public abstract class AbstractRequestSpec<B extends AbstractRequestSpec<B>> | ||
implements TarantoolRequestSpec { | ||
|
||
final Code code; | ||
Duration duration = Duration.ZERO; | ||
boolean useDefaultTimeout = true; | ||
|
||
AbstractRequestSpec(Code code) { | ||
this.code = code; | ||
} | ||
|
||
AbstractRequestSpec(Code code, Duration duration) { | ||
this.code = code; | ||
this.duration = duration; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public B timeout(Duration duration) { | ||
this.duration = duration; | ||
this.useDefaultTimeout = false; | ||
return (B) this; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public B useDefaultTimeout() { | ||
this.duration = Duration.ZERO; | ||
this.useDefaultTimeout = true; | ||
return (B) this; | ||
} | ||
|
||
@Override | ||
public TarantoolRequest toTarantoolRequest(TarantoolSchemaMeta schemaMeta) { | ||
TarantoolRequest request = new TarantoolRequest(code); | ||
request.setTimeout(useDefaultTimeout ? null : duration); | ||
return request; | ||
} | ||
|
||
} |
Oops, something went wrong.