public class Peer
extends java.lang.Object
Main entry point, used to manage connections, submit transactions, and query.
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
administerSystem(java.util.Map options)
Administer a Datomic system.
|
static void |
cancel(java.lang.Object anomaly)
Cancels the current Datomic operation (query or transaction).
|
static Connection |
connect(java.lang.Object uriOrMap)
Connects to the specified database.
|
static boolean |
createDatabase(java.lang.Object uriOrMap)
Creates a database with the given name.
|
static boolean |
deleteDatabase(java.lang.Object uriOrMap)
Deletes a database.
|
static datomic.functions.Fn |
function(java.util.Map m)
Generates a function object given a map of
:lang - clojure or java
:params - a list of parameter names used in the code
:code - a string containing the code of the function body.
|
static java.util.List<java.lang.String> |
getDatabaseNames(java.lang.Object uriOrMap)
Returns a list of database names.
|
static java.lang.Object |
part(java.lang.Object entityId)
Returns the partition of this entity id.
|
static java.util.Collection<java.util.List<java.lang.Object>> |
q(java.lang.Object query,
java.lang.Object... inputs)
Like
query(Object, Object...) , but with a more specific return signature. |
static java.util.stream.Stream<java.lang.Object> |
qseq(java.lang.Object query,
java.lang.Object... inputs)
Performs the query described by
query and inputs (as per query(Object, Object...) ),
Item transformations such as pull are deferred until the Stream is consumed. |
static <T> T |
query(java.lang.Object query,
java.lang.Object... inputs)
Executes a datalog query.
|
static <T> T |
query(QueryRequest queryRequest)
Like
query(Object, Object...) , but accepts a QueryRequest object. |
static boolean |
renameDatabase(java.lang.Object uriOrMap,
java.lang.String newName)
Renames a database.
|
static java.lang.Object |
resolveTempid(Database db,
java.lang.Object tempids,
java.lang.Object tempid)
Resolve a tempid to the actual id assigned in a database.
|
static void |
shutdown(boolean shutdownClojure)
Shutdown all peer resources.
|
static java.util.UUID |
squuid()
Constructs a semi-sequential UUID.
|
static long |
squuidTimeMillis(java.util.UUID squuid)
Get the time component of a squuid.
|
static java.lang.Object |
tempid(java.lang.Object partition)
Generates a temp id in the designated partition.
|
static java.lang.Object |
tempid(java.lang.Object partition,
long idNumber)
Generates a temp id in the designated partition.
|
static long |
toT(java.lang.Object tx)
Returns the t value associated with this tx.
|
static java.lang.Object |
toTx(long t)
Returns the tx associated with this t value.
|
public static Connection connect(java.lang.Object uriOrMap)
URI syntax:
;;dynamo using roles datomic:ddb://{aws-region}/{dynamodb-table}/{db-name} ;;dynamo using keys, use roles if possible datomic:ddb://{aws-region}/{dynamodb-table}/{db-name}?aws_access_key_id={XXX}&aws_secret_key={YYY} ;; dynamo local datomic:ddb-local://{endpoint}:{port}/{dynamodb-table}/{db-name}?aws_access_key_id={XXX}&aws_secret_key={YYY} ;;riak, defaults to protobuf datomic:riak://{host}[:{port}]/{bucket}/{dbname}[?interface=http|https|protobuf] ;; couchbase datomic:couchbase://{host}/{bucket}/{dbname}[?password={xxx}] ;; sql datomic:sql://{db-name}?{jdbc-url} ;; infinispan datomic:inf://{cluster-member-host}:{port}/{db-name} ;; cassandra datomic:cass://{cluster-member-host}[:{port}]/{keyspace}.{table}/{db-name}[?user={user}&password={pwd}][&ssl=true] ;; dev appliance datomic:dev://{transactor-host}:{port}/{db-name}[?password={password}] ;; limited-edition transactor integrated storage datomic:limited-edition://{transactor-host}:{port}/{db-name}[?password={password}] ;; in-process memory datomic:mem://{db-name}
Note that URIs must be percent encoded and db-name cannot contain the following characters: / " * : = ?
The dev, free, and limited-edition protocols use an additional ports to communicate with storage. By default this port is one higher than the specified transactor port. You can override the default by specifying h2-port in the query string, e.g.datomic:limited-edition://localhost:4334/mydb?h2-port=6000&The sql protocol also supports a map format for the connection params. This is to enable communicating objects that can't be embedded in URI strings, like DataSources. The format for the map is:
{ :protocol :sql :db-name "myDb" :data-source aDataSourceObject ;; OR :factory aCallableReturningConnection }Note only one of data-source or factory should be supplied. The keys and protocol name can be keywords or strings. The cass protocol also supports a map format for the connection params. The format for the map is:
{ :protocol :cass :db-name "myDb" :table "myKeyspace.myTable" :cluster aClusterObject }Note aClusterObject must be an instance of type com.datastax.driver.core.Cluster. The keys and protocol name can be keywords or strings. Datomic connections do not adhere to an acquire/use/release pattern. They are thread-safe and long lived. Connections are cached such that calling Peer.connect(uri) multiple times with the same URI value will return the same connection object.
uriOrMap
- a Datomic connection URI string, or parameters map if supported by the protocol.public static boolean createDatabase(java.lang.Object uriOrMap)
uriOrMap
- the uri of the database to create.trueif the database was created,
falseif the database already exists.
public static boolean renameDatabase(java.lang.Object uriOrMap, java.lang.String newName)
uriOrMap
- same as in #connect(Object)newName
- the new name of the database. This is the database name only and should not be a URI.trueif rename succeeded
public static boolean deleteDatabase(java.lang.Object uriOrMap)
uriOrMap
- same as in #connect(Object)trueif delete occurred.
public static java.util.List<java.lang.String> getDatabaseNames(java.lang.Object uriOrMap)
connect(java.lang.Object)
documentation,
but with a '*' where the database name would be. For instance:
datomic:dev://{transactor-host}:{port}/*When using the map form, :db-name should be omitted.
uriOrMap
- same as in #connect(Object), with a '*' where the database name would be, or omitted in the map form.public static java.lang.Object administerSystem(java.util.Map options)
options
- Mappublic static java.util.UUID squuid()
public static long squuidTimeMillis(java.util.UUID squuid)
squuid
- a UUID created by squuid()public static java.lang.Object tempid(java.lang.Object partition)
partition
- a keyword identifying the partition.public static java.lang.Object tempid(java.lang.Object partition, long idNumber)
partition
- - a keyword identifying the partition.idNumber
- - a long in the range (-1000000,-1]public static long toT(java.lang.Object tx)
tx
- a txpublic static java.lang.Object toTx(long t)
t
- a t valuepublic static java.lang.Object part(java.lang.Object entityId)
entityId
- an entityIdpublic static java.util.Collection<java.util.List<java.lang.Object>> q(java.lang.Object query, java.lang.Object... inputs)
query(Object, Object...)
, but with a more specific return signature.
Supports same grammar as query,
except for find-coll
, find-scalar
, and find-tuple
.public static <T> T query(java.lang.Object query, java.lang.Object... inputs)
In addition to basic pattern matching, query supports
Query can be applied to multiple inputs, including both databases and plain old data. See the grammar and documentation for complete details.
Query runs locally in a Peer process. Query is set-based: intermediate
and final result sets must fit in memory.
The query
data structure passed in can be one of
:find
, :with
, :in
, and :where
keysThe inputs
can be any of
If a single database value is provided as input, then no :in
section
is required in the query
.
T
- a type compatible with the find specificationquery
- a data structure describing the queryinputs
- inputs bound to the names in :in
section of query
public static <T> T query(QueryRequest queryRequest)
query(Object, Object...)
, but accepts a QueryRequest
object.public static java.util.stream.Stream<java.lang.Object> qseq(java.lang.Object query, java.lang.Object... inputs)
query
and inputs
(as per query(Object, Object...)
),
Item transformations such as pull are deferred until the Stream is consumed. For queries with
pull(s), this results in:
query
- a data structure describing the queryinputs
- inputs bound to the names in :in
section of query
Stream
of the data structure based on the find specificationpublic static datomic.functions.Fn function(java.util.Map m)
m
- a map defining the functionpublic static java.lang.Object resolveTempid(Database db, java.lang.Object tempids, java.lang.Object tempid)
db
- a databasetempids
- Connection.TEMPIDS
member of a map returned from
Connection.transact(java.util.List)
or Connection.transactAsync
.tempid
- a tempidpublic static void shutdown(boolean shutdownClojure)
shutdownClojure
- set true to shutdown Clojure resourcespublic static void cancel(java.lang.Object anomaly)
anomaly
- Map