Datomic/datomic-java-examples — pull request #2 by rondagostino (2013-12-10 05:45:52+00:00)
Title: Java version of ensure-schema from day-of-datomic

Added a simple DSL for creating schemas and ensureSchema() methods. Output of the main() method appears below.

Database has a :db.part/db partition?
true
Database has a :db.part/user partition?
true
Database has a :db.part/tx partition?
true
Database has a :foo partition?
false
Ensure that there is a :foo partition
Database has a :foo partition now?
true
Ensure that there is a :foo partition -- idempotent
Database has a :foo partition now?
true
Here is what the transaction of (a single) partition looks like when you invoke toString():
[{:db/id #db/id[:db.part/db]
:db/ident :geography
:db.install/_partition :db.part/db}
]
Here is what the list of elements in a transaction looks like when you invoke toString():
[;; community
, {:db/id #db/id[:db.part/db]
:db/ident :community/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A community's name"
:db/fulltext true
:db.install/_attribute :db.part/db}
, {:db/id #db/id[:db.part/db]
:db/ident :community/url
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A community's url"
:db.install/_attribute :db.part/db}
, {:db/id #db/id[:db.part/db]
:db/ident :community/neighborhood
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A community's neighborhood"
:db.install/_attribute :db.part/db}
, {:db/id #db/id[:db.part/db]
:db/ident :community/category
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "All community categories"
:db/fulltext true
:db.install/_attribute :db.part/db}
, {:db/id #db/id[:db.part/db]
:db/ident :community/orgtype
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A community orgtype enum value"
:db.install/_attribute :db.part/db}
, {:db/id #db/id[:db.part/db]
:db/ident :community/type
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A community type enum value"
:db.install/_attribute :db.part/db}
, ;; community/orgtype enum values
, [:db/add #db/id[:geography] :db/ident :community.orgtype/community]
, [:db/add #db/id[:geography] :db/ident :community.orgtype/commercial]
, [:db/add #db/id[:geography] :db/ident :community.orgtype/nonprofit]
, [:db/add #db/id[:geography] :db/ident :community.orgtype/personal]
, ;; community/type enum values
, [:db/add #db/id[:geography] :db/ident :community.type/email-list]
, [:db/add #db/id[:geography] :db/ident :community.type/twitter]
, [:db/add #db/id[:geography] :db/ident :community.type/facebook-page]
, [:db/add #db/id[:geography] :db/ident :community.type/blog]
, [:db/add #db/id[:geography] :db/ident :community.type/website]
, [:db/add #db/id[:geography] :db/ident :community.type/wiki]
, [:db/add #db/id[:geography] :db/ident :community.type/myspace]
, [:db/add #db/id[:geography] :db/ident :community.type/ning]
, ;; neighborhood
, {:db/id #db/id[:db.part/db]
:db/ident :neighborhood/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A unique neighborhood name (upsertable)"
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
, {:db/id #db/id[:db.part/db]
:db/ident :neighborhood/district
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A neighborhood's district"
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
, ;; district
, {:db/id #db/id[:db.part/db]
:db/ident :district/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A unique district name (upsertable)"
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
, {:db/id #db/id[:db.part/db]
:db/ident :district/region
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A district region enum value"
:db.install/_attribute :db.part/db}
, ;; district/region enum values
, [:db/add #db/id[:geography] :db/ident :region/n]
, [:db/add #db/id[:geography] :db/ident :region/ne]
, [:db/add #db/id[:geography] :db/ident :region/e]
, [:db/add #db/id[:geography] :db/ident :region/se]
, [:db/add #db/id[:geography] :db/ident :region/s]
, [:db/add #db/id[:geography] :db/ident :region/sw]
, [:db/add #db/id[:geography] :db/ident :region/w]
, [:db/add #db/id[:geography] :db/ident :region/nw]
]
Here is what the two transactions look like when you convert them to edn:
[
{:db/id #db/id[:db.part/db]
:db/ident :geography
:db.install/_partition :db.part/db}
]
[
;; community
{:db/id #db/id[:db.part/db]
:db/ident :community/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A community's name"
:db/fulltext true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :community/url
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A community's url"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :community/neighborhood
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A community's neighborhood"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :community/category
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "All community categories"
:db/fulltext true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :community/orgtype
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A community orgtype enum value"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :community/type
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A community type enum value"
:db.install/_attribute :db.part/db}
;; community/orgtype enum values
[:db/add #db/id[:geography] :db/ident :community.orgtype/community]
[:db/add #db/id[:geography] :db/ident :community.orgtype/commercial]
[:db/add #db/id[:geography] :db/ident :community.orgtype/nonprofit]
[:db/add #db/id[:geography] :db/ident :community.orgtype/personal]
;; community/type enum values
[:db/add #db/id[:geography] :db/ident :community.type/email-list]
[:db/add #db/id[:geography] :db/ident :community.type/twitter]
[:db/add #db/id[:geography] :db/ident :community.type/facebook-page]
[:db/add #db/id[:geography] :db/ident :community.type/blog]
[:db/add #db/id[:geography] :db/ident :community.type/website]
[:db/add #db/id[:geography] :db/ident :community.type/wiki]
[:db/add #db/id[:geography] :db/ident :community.type/myspace]
[:db/add #db/id[:geography] :db/ident :community.type/ning]
;; neighborhood
{:db/id #db/id[:db.part/db]
:db/ident :neighborhood/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A unique neighborhood name (upsertable)"
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :neighborhood/district
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A neighborhood's district"
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
;; district
{:db/id #db/id[:db.part/db]
:db/ident :district/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A unique district name (upsertable)"
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :district/region
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A district region enum value"
:db.install/_attribute :db.part/db}
;; district/region enum values
[:db/add #db/id[:geography] :db/ident :region/n]
[:db/add #db/id[:geography] :db/ident :region/ne]
[:db/add #db/id[:geography] :db/ident :region/e]
[:db/add #db/id[:geography] :db/ident :region/se]
[:db/add #db/id[:geography] :db/ident :region/s]
[:db/add #db/id[:geography] :db/ident :region/sw]
[:db/add #db/id[:geography] :db/ident :region/w]
[:db/add #db/id[:geography] :db/ident :region/nw]
]
Has schema?
false
Has schema?
false
Has schema?
true
Database has a :community/name attribute?
true; cardinality = :db.cardinality/one
Database has a :community/category attribute?
true; cardinality = :db.cardinality/many
Database has a :bar attribute?
false
Database has a :community.orgtype/community enum entity?
true
Database has a :foobar enum entity?
false