java.lang.Object
io.github.mmm.orm.source.DbSource
A
From a logical point-of-view a
When you configure database settings, you will always include the
DbSource identifies a database to connect to as a tenant. It is just a wrapper for a String used as
identifier. Most applications only need to talk to a single database and schema. There is always a
default DbSource. However, to support multi-tenancy and connecting to multiple
different databases the DbSource is used to identify the tenant. From a logical point-of-view a
DbSource is similar to a DataSource. However, it is a much
higher abstraction. Only in case a DbSource points to an RDBMS and you are using JDBC to connect then there
will be a DataSource associated under the hood to talk to that database.When you configure database settings, you will always include the
DbSource identifier in the
property names:
db.default.url=jdbc:postgresql://db.company.com:5432/db db.default.dialect=postgresql db.default.user=admin db.default.password=top$ecret db.default.pool=hikariSo in order to define a secondary database you can simply use a
identifier other than "default":
db.h2.url=jdbc:h2:mem:db db.h2.dialect=h2 db.h2.user=sa db.h2.password= db.h2.pool=hikariNow, in your
repository implementation you may override the
DbSource to DbSource.of("h2") to work on the secondary database.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKeyfor the database name.static final Stringstatic final StringKeyfor the database host name.static final StringKeyfor the kind of database connection (e.g.static final StringKeyfor the user password of the database connection.static final StringKeyfor the ID of the connection pool to use (e.g.static final StringKeyfor the database port number.static final StringKeyfor the type of database.static final StringKeyfor the database connection URL.static final StringKeyfor the user login of the database connection.static final StringThe static part of theproperty prefix.The standard keys for the database connection. -
Method Summary
-
Field Details
-
PROPERTY_PREFIX_DB
The static part of theproperty prefix.- See Also:
-
KEY_URL
Keyfor the database connection URL.- See Also:
-
KEY_HOST
Keyfor the database host name.- See Also:
-
KEY_PORT
Keyfor the database port number.- See Also:
-
KEY_USER
Keyfor the user login of the database connection.- See Also:
-
KEY_PASSWORD
Keyfor the user password of the database connection.- See Also:
-
KEY_DATABASE
Keyfor the database name.- See Also:
-
KEY_DIALECT
- See Also:
-
KEY_TYPE
Keyfor the type of database. This is very similar to thedialectbut for the same database type potentially different dialects may exist (e.g. due to different versions of the database product). Will be auto-configured if undefined.- See Also:
-
KEY_POOL
Keyfor the ID of the connection pool to use (e.g. "hikari", "c3po", or "dbcp"). Will be auto-configured if undefined.- See Also:
-
KEY_KIND
Keyfor the kind of database connection (e.g. "jdbc" or "r2dbc"). Will be auto-configured if undefined.- See Also:
-
STANDARD_KEYS
The standard keys for the database connection. Other keys will be specific for particular implementations (e.g. connection pools).
-
-
Method Details
-
getId
- Returns:
- the identifier of the database as tenant.
-
getPropertyPrefix
- Returns:
- the property prefix as "db.«id»." (e.g. "db.default." for the
default source). - See Also:
-
getPropertyKey
- Parameters:
key- the unqualified property key.- Returns:
- the
qualifiedproperty key.
-
get
- Returns:
- the default
DbSourcefor the "primary" database. It has theidentifier"default".
-
of
- Parameters:
id- theidentifierto wrap asDbSource.- Returns:
- a
DbSourcewith the givenid. Will be thedefaultDbSourceifidisnullor "default".
-