org.modeshape.jdbc.JcrDriver Maven / Gradle / Ivy
Go to download
JDBC driver to allow clients to use JCR-SQL2 to query a local or remote ModeShape JCR repository.
The newest version!
/*
* ModeShape (http://www.modeshape.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.modeshape.jdbc;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.jcr.Repository;
import org.modeshape.jdbc.delegate.HttpRepositoryDelegate;
/**
* A JDBC driver implementation that is able to access a JCR repository to query its contents using JCR-SQL2. Connection URLs
*
* The driver accepts several URL formats based on how the repository is configured:
*
* - configured for local access using JNDI
*
*
* jdbc:jcr:jndi:{jndiName}
*
*
* or
*
*
* jdbc:jcr:jndi:{jndiName}?{firstProperty}&{secondProperty}&...
*
*
* where
*
* - {jndiName} is the JNDI name where the {@link Repository} or {@literal org.modeshape.jcr.api.Repositories}
* instance can be found;
* - {firstProperty} consists of the first property name followed by '=' followed by the property's value;
* - {secondProperty} consists of the second property name followed by '=' followed by the property's value;
*
* Note that any use of URL encoding ('%' followed by a two-digit hexadecimal value) will be decoded before being used.
*
*
* Here's an example of a URL that defines a {@link Repository} instance located at "jcr/local
" with a repository
* name of "repository" and a user, password of "secret", and workspace name of "My Workspace":
*
*
* jdbc:jcr:jndi:jcr/local?repositoryName=repository&user=jsmith&password=secret&workspace=My%20Workspace
*
*
* The "repository" property is required only if the object in JNDI is a {@literal org.modeshape.jcr.api.Repositories} object.
*
*
* - configured for remote access using REST interface.
*
*
* jdbc:jcr:http://{hostname}:{port}?{firstProperty}&{secondProperty}&...
*
*
* where
*
* - {hostname} is the host name where the {@link Repository} or {@literal org.modeshape.jcr.api.Repositories}
* instance can be found;
* - {port} is the port to access the {@link Repository} or {@literal org.modeshape.jcr.api.Repositories} on
* the specified hostname;
* - {firstProperty} consists of the first property name followed by '=' followed by the property's value;
* - {secondProperty} consists of the second property name followed by '=' followed by the property's value;
*
*
* Note that any use of URL encoding ('%' followed by a two-digit hexadecimal value) will be decoded before being used.
*
*
*/
public class JcrDriver extends LocalJcrDriver {
/* URL Prefix used for remote access */
public static final String HTTP_URL_PREFIX = "jdbc:jcr:http://";
static {
try {
DriverManager.registerDriver(new JcrDriver(null));
} catch (SQLException e) {
logger.error(JdbcI18n.driverErrorRegistering, e.getMessage());
}
}
/**
* No-arg constructor, required by the {@link DriverManager}.
*/
public JcrDriver() {
this(null);
}
/**
* Create an instance of this driver using the supplied JNDI naming context factory. This is useful for testing, but is
* otherwise not generally recommended.
*
* @param namingContextFactory the naming context factory; may be null if one should be created automatically
*/
protected JcrDriver( JcrContextFactory namingContextFactory ) {
super(HttpRepositoryDelegate.FACTORY, new DriverInfo(JdbcI18n.driverName.text(), JdbcI18n.driverVendor.text(),
JdbcI18n.driverVendorUrl.text(), JdbcI18n.driverVersion.text()),
namingContextFactory);
}
}