You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2015/10/09 17:35:18 UTC
karaf git commit: [KARAF-3976] Update the jdbc section in the user
guide
Repository: karaf
Updated Branches:
refs/heads/master 48a4a8c0e -> 90d60088b
[KARAF-3976] Update the jdbc section in the user guide
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/90d60088
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/90d60088
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/90d60088
Branch: refs/heads/master
Commit: 90d60088b5736729ffdd869004e6182d52f5af63
Parents: 48a4a8c
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Fri Oct 9 17:34:37 2015 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Fri Oct 9 17:34:37 2015 +0200
----------------------------------------------------------------------
manual/src/main/webapp/users-guide/jdbc.conf | 114 +++++++++++-----------
1 file changed, 56 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/90d60088/manual/src/main/webapp/users-guide/jdbc.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/users-guide/jdbc.conf b/manual/src/main/webapp/users-guide/jdbc.conf
index 302a9fc..850172d 100644
--- a/manual/src/main/webapp/users-guide/jdbc.conf
+++ b/manual/src/main/webapp/users-guide/jdbc.conf
@@ -2,114 +2,112 @@ h1. DataSources (JDBC)
The Apache Karaf DataSources (JDBC) is an optional enterprise feature.
-You have to install the {{jdbc}} feature first:
+You have to install the following features first:
{code}
+karaf@root()> feature:repo-add pax-jdbc
+karaf@root()> feature:install pax-jdbc
+karaf@root()> feature:install pax-jdbc-config
karaf@root()> feature:install jdbc
{code}
+Pax JDBC provides ready to use adapters for different databases:
+
+* pax-jdbc-derby
+* pax-jdbc-derbyclient
+* pax-jdbc-h2
+* pax-jdbc-mariadb
+* pax-jdbc-mysql
+* pax-jdbc-oracle
+* pax-jdbc-postgresql
+* pax-jdbc-sqlite
+* pax-jdbc-mssql
+
This feature provides an OSGi service to create/delete JDBC datasources in the container and perform database operations (SQL queries).
This JDBC OSGi service can be manipulated programmatically (see the developer guide for details), using the {{jdbc:*}} commands, or using the JDBC MBean.
h2. Commands
-h3. {{jdbc:create}}
+h3. {{jdbc:ds-create}}
+
+The {{jdbc:ds-create}} command automatically creates a datasource definition file by leveraging pax-jdbc.
-The {{jdbc:create}} command automatically creates a datasource definition file in the Apache Karaf {{deploy}} folder.
+The {{jdbc:ds-create}} command requires either:
-The {{jdbc:create}} accepts a set of options and the name argument:
+* the {{--driverName}} containing the JDBC driver name
+* or the {{--driverClass}} containing the JDBC driver class name
+
+The {{jdbc:ds-create}} accepts a set of options and the name argument:
{code}
-karaf@root()> jdbc:create --help
DESCRIPTION
- jdbc:create
+ jdbc:ds-create
- Create a JDBC datasource
+ Create a JDBC datasource config for pax-jdbc-config from a DataSourceFactory
SYNTAX
- jdbc:create [options] name
+ jdbc:ds-create [options] name
ARGUMENTS
name
The JDBC datasource name
OPTIONS
+ -dbName
+ Database name to use
+ --help
+ Display this help message
+ -dn, --driverName
+ org.osgi.driver.name property of the DataSourceFactory
-u, --username
The database username
- -v, --version
- The version of the driver to use
- -t, --type
- The JDBC datasource type (generic, MySQL, Oracle, Postgres, H2, HSQL, Derby, MSSQL)
- -url
- The JDBC URL to use
+ -dc, --driverClass
+ org.osgi.driver.class property of the DataSourceFactory
-p, --password
The database password
- -i, --install-bundles
- Try to install the bundles providing the JDBC driver
- -d, --driver
- The classname of the JDBC driver to use. NB: this option is used only the type generic
- --help
- Display this help message
-
+ -url
+ The JDBC URL to use
{code}
* the {{name}} argument is required. It's the name of the datasource. The name is used to identify the datasource, and to create the datasource definition file ({{deploy/datasource-[name].xml}}).
* the {{-u}} option is optional. It defines the database username.
-* the {{-v}} option is optional. It "forces" a given JDBC driver version (only used with the {{-i}} option).
-* the {{-t}} option is required. It defines the JDBC datasource type. Accepted values are: MySQL, Oracle, Postgres, Derby, H2, HSQL, MSSQL, Generic. Generic is a generic configuration file using DBCP to create a pooled datasource. When using generic, it's up to you to install the JDBC driver and configure the {{deploy/datasource-[name].xml}} datasource file.
* the {{-url}} option is optional. It defines the JDBC URL to access to the database.
* the {{-p}} option is optional. It defines the database password.
-* the {{-d}} option is optional. It defines the JDBC driver classname to use (only used with the generic type).
-* the {{-i}} option is optional. If specified, the command will try to automatically install the OSGi bundles providing the JDBC driver (depending of the datasource type specified by the {{-t}} option).
For instance, to create an embedded Apache Derby database in Apache Karaf, you can do:
{code}
-karaf@root()> jdbc:create -t derby -u test -i test
+karaf@root()> jdbc:ds-create -dn derby -dbName test -url jdbc:derby:test test
{code}
-We can note that the Derby bundle has been installed automatically, and the datasource has been created:
+We can see that this command created a configuration PID containing the datasource properties.
-{code}
-karaf@root()> la
-...
-87 | Active | 80 | 10.8.2000002.1181258 | Apache Derby 10.8
-88 | Active | 80 | 0.0.0 | datasource-test.xml
-{code}
+h2. {{jdbc:ds-delete}}
-We can see the {{deploy/datasource-test.xml}} datasource file.
-
-h2. {{jdbc:delete}}
-
-The {{jdbc:delete}} command deletes a datasource by removing the {{deploy/datasource-[name].xml}} datasource file:
+The {{jdbc:ds-delete}} command deletes a datasource.
{code}
-karaf@root()> jdbc:delete test
+karaf@root()> jdbc:ds-delete test
{code}
-{warning}
-The {{jdbc:delete}} does not uninstall the JDBC driver bundles and does not remove the files created by the JDBC driver (or the database in case of embedded database).
-It's up to you to remove it.
-{warning}
+h2. {{jdbc:ds-list}}
-h2. {{jdbc:datasources}}
-
-The {{jdbc:datasources}} command lists the JDBC datasources:
+The {{jdbc:ds-list}} command lists the JDBC datasources:
{code}
-karaf@root()> jdbc:datasources
-Name | Product | Version | URL
-------------------------------------------------------------------
-/jdbc/test | Apache Derby | 10.8.2.2 - (1181258) | jdbc:derby:test
+karaf@root()> jdbc:ds-list
+Name | Product | Version | URL | Status
+---------------------------------------
+
{code}
-h2. {{jdbc:info}}
+h2. {{jdbc:ds-info}}
-The {{jdbc:info}} command provides details about a JDBC datasource:
+The {{jdbc:ds-info}} command provides details about a JDBC datasource:
{code}
-karaf@root()> jdbc:info /jdbc/test
+karaf@root()> jdbc:ds-info test
Property | Value
--------------------------------------------------
driver.version | 10.8.2.2 - (1181258)
@@ -129,14 +127,14 @@ Typically, you can use the {{jdbc:execute}} command to create tables, insert val
For instance, we can create a {{person}} table on our {{test}} datasource:
{code}
-karaf@root()> jdbc:execute /jdbc/test "create table person(name varchar(100), nick varchar(100))"
+karaf@root()> jdbc:execute test "create table person(name varchar(100), nick varchar(100))"
{code}
And we can insert some records in the {{person}} table:
{code}
-karaf@root()> jdbc:execute /jdbc/test "insert into person(name, nick) values('foo','bar')"
-karaf@root()> jdbc:execute /jdbc/test "insert into person(name, nick) values('test','test')"
+karaf@root()> jdbc:execute test "insert into person(name, nick) values('foo','bar')"
+karaf@root()> jdbc:execute test "insert into person(name, nick) values('test','test')"
{code}
h2. {{jdbc:query}}
@@ -146,7 +144,7 @@ The {{jdbc:query}} command is similar to the {{jdbc:execute}} one but it display
For instance, to display the content of the {{person}} table, we can do:
{code}
-karaf@root()> jdbc:query /jdbc/test "select * from person"
+karaf@root()> jdbc:query test "select * from person"
NICK | NAME
--------------------------------
bar | foo
@@ -158,7 +156,7 @@ h2. {{jdbc:tables}}
The {{jdbc:tables}} command displays all tables available on a given JDBC datasource:
{code}
-karaf@root()> jdbc:tables /jdbc/test
+karaf@root()> jdbc:tables test
REF_GENERATION | TYPE_NAME | TABLE_NAME | TYPE_CAT | REMARKS | TYPE_SCHEM | TABLE_TYPE | TABLE_SCHEM | TABLE_CAT | SELF_REFERENCING_COL_NAME
----------------------------------------------------------------------------------------------------------------------------------------------------
| | SYSALIASES | | | | SYSTEM TABLE | SYS | |