Author: chathura
Date: Sun Dec 16 20:42:14 2007
New Revision: 11185
Log:
Changed the JDBC registry constructors as discussed in the mailing list.
Added RegistryRealm class and InMemoryRegistryRealm class to be used as realms
for the registry.
Later we need to add registry specific restrictions to these classes.
There are some test failures due to some user manager issue. Working with
Dimuthu to resolve that...
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryJDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryRegistryRealm.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/RegistryRealm.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/RegistryDataSource.java
Modified:
trunk/registry/modules/core/pom.xml
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/TagsTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/secure/SecureRegistryTest.java
trunk/registry/pom.xml
Modified: trunk/registry/modules/core/pom.xml
==============================================================================
--- trunk/registry/modules/core/pom.xml (original)
+++ trunk/registry/modules/core/pom.xml Sun Dec 16 20:42:14 2007
@@ -50,6 +50,10 @@
<artifactId>log4j</artifactId>
</dependency>
<dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryJDBCRegistry.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryJDBCRegistry.java
Sun Dec 16 20:42:14 2007
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.wso2.registry.jdbc;
+
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.i18n.Messages;
+import org.wso2.registry.jdbc.hsql.DBUtils;
+import org.wso2.registry.jdbc.utils.RegistryDataSource;
+import org.wso2.usermanager.Realm;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class InMemoryJDBCRegistry extends JDBCRegistry {
+
+ public static final String INMEMORY_DB_URL = "jdbc:hsqldb:mem:aname";
+ public static final String INMEMORY_DB_DRIVER_NAME =
"org.hsqldb.jdbcDriver";
+ public static final String INMEMORY_DB_USER_NAME = "sa";
+ public static final String INMEMORY_DB_PASSWORD = "";
+
+ /**
+ * Creates an in-memory HSQL database based registry without the support
for authentication and
+ * authorization.
+ *
+ * @throws RegistryException
+ */
+ public InMemoryJDBCRegistry() throws RegistryException {
+
+ RegistryDataSource dataSource = new RegistryDataSource(INMEMORY_DB_URL,
+ INMEMORY_DB_DRIVER_NAME,
+ INMEMORY_DB_USER_NAME,
+ INMEMORY_DB_PASSWORD);
+
+ startInProcessDatabase(dataSource);
+
+ super.configure(dataSource, null);
+ }
+
+ /**
+ * Creates the in-memory HSQL database and creates all tables necessary
for the registry. Then
+ * contructs the registry with a datasource pointing to the HSQL database.
+ *
+ * @param realm User manager realm to use with the registry. It is
strongly recommended to use
+ * a realm configured with a in-memory (transient) database with the
in-memory registry.
+ */
+ public InMemoryJDBCRegistry(Realm realm) throws RegistryException {
+
+ // create a datasource using the HSQL database. jdbc registry should
use this datasource.
+
+ RegistryDataSource dataSource = new RegistryDataSource(INMEMORY_DB_URL,
+ INMEMORY_DB_DRIVER_NAME,
+ INMEMORY_DB_USER_NAME,
+ INMEMORY_DB_PASSWORD);
+
+ startInProcessDatabase(dataSource);
+
+ super.configure(dataSource, realm);
+ }
+
+
+ private void startInProcessDatabase(DataSource dataSource) throws
RegistryException {
+
+ // Create tables
+ try {
+ Connection conn = dataSource.getConnection();
+ new DBUtils().initializeDatabase(conn);
+
+ } catch (SQLException e) {
+ String message = Messages.getMessage("database.error");
+ throw new RegistryException(message);
+ }
+ }
+}
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryRegistryRealm.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryRegistryRealm.java
Sun Dec 16 20:42:14 2007
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.wso2.registry.jdbc;
+
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.jdbc.utils.RegistryDataSource;
+
+public class InMemoryRegistryRealm extends RegistryRealm {
+
+ public static final String INMEMORY_DB_URL = "jdbc:hsqldb:mem:umdb";
+ public static final String INMEMORY_DB_DRIVER_NAME =
"org.hsqldb.jdbcDriver";
+ public static final String INMEMORY_DB_USER_NAME = "sa";
+ public static final String INMEMORY_DB_PASSWORD = "";
+
+ public InMemoryRegistryRealm() throws RegistryException {
+ super();
+
+ RegistryDataSource dataSource = new RegistryDataSource(INMEMORY_DB_URL,
+ INMEMORY_DB_DRIVER_NAME,
+ INMEMORY_DB_USER_NAME,
+ INMEMORY_DB_PASSWORD);
+
+ super.configure(dataSource);
+ }
+}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
Sun Dec 16 20:42:14 2007
@@ -30,8 +30,8 @@
import org.wso2.registry.jdbc.urlhandlers.URLHandlerManager;
import org.wso2.registry.utils.AuthorizationUtil;
import org.wso2.usermanager.Realm;
-import org.wso2.usermanager.UserManagerException;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
@@ -47,7 +47,7 @@
private static final Log log = LogFactory.getLog(JDBCRegistry.class);
- private ConnectionFactory connectionFactory = null;
+ private DataSource dataSource = null;
private URLHandlerManager urlHandlerManager;
private MediaTypeManager mediaTypeManager;
private VersionedResourceDAO resourceDAO = null;
@@ -58,77 +58,63 @@
private Realm defaultRealm = null;
- // database attributes
- private String dataSourceName;
-
- private String driverClassName;
- private String connectionURL;
- private String userName;
- private String password;
-
- private boolean allowInMemoryDatabase = true;
-
- public JDBCRegistry() {
-
- }
+ /**
+ * Default constructor. JDBC registry should be configured using the
configure(...) method, if
+ * it is instantiated using this contructor.
+ */
+ public JDBCRegistry() {}
/**
- * Configure the JDBC registry to work with a jdbc connection obtained
using an URL.
+ * Contructs a JDBC registry to be used without any security
(authorizations on actions). JDBC
+ * registry instances created using this constructor should not be used
with SecureRegisrty
+ * instances.
+ *
+ * @param dataSource Data source to be used to store resources and
metadata.
*
- * @param driverClass Class name of the JDBC driver.
- * @param URL JDBC connection URL.
- * @param userName User name to login to the database.
- * @param password Password for the above user name.
+ * @throws RegistryException
*/
- public void configureDatabase(String driverClass, String URL, String
userName, String password) {
- this.driverClassName = driverClass;
- this.connectionURL = URL;
- this.userName = userName;
- this.password = password;
+ public JDBCRegistry(DataSource dataSource) throws RegistryException {
+ this.dataSource = dataSource;
+ init(null);
}
/**
- * Configure the JDBC registry to work with a datasource with the given
name.
+ * Contructs a JDBC registry to be used with secure registries. Default
authorizations will be
+ * applied on the resources created using this registry.
+ *
+ * @param dataSource Data source to be used to store resources and
metadata. Note that the same
+ * data source may or may not be used as the data source of user manager.
*
- * @param dataSourceName Datasource name to use.
+ * @param realm User manager realm to handle authorizations. It is
strongly recommented to
+ * use a realm instance contructed using the RegistryRealmFactory. All
initail users, roles
+ * and authorizations will be set on realms obtained using the
RegistryRealmFactory.
+ *
+ * @throws RegistryException
*/
- public void configureDatabase(String dataSourceName) {
- this.dataSourceName = dataSourceName;
- }
-
- public boolean isAllowInMemoryDatabase() {
- return allowInMemoryDatabase;
+ public JDBCRegistry(DataSource dataSource, Realm realm) throws
RegistryException {
+ this.dataSource = dataSource;
+ init(realm);
}
- public void setAllowInMemoryDatabase(boolean allowInMemoryDatabase) {
- this.allowInMemoryDatabase = allowInMemoryDatabase;
+ /**
+ * Configures and initiates the JDBC registry with a (new) datasource and
a realm. This is
+ * useful for changing underlying databases at run-time.
+ *
+ * @param dataSource
+ * @param realm
+ * @throws RegistryException
+ */
+ public void configure(DataSource dataSource, Realm realm) throws
RegistryException {
+ this.dataSource = dataSource;
+ init(realm);
}
- public void init(Realm realm) throws RegistryException {
+ private void init(Realm realm) throws RegistryException {
defaultRealm = realm;
- AuthorizationUtil authorizationUtil = new AuthorizationUtil();
-
- try {
- authorizationUtil.populateUserStore(defaultRealm);
- } catch (UserManagerException e) {
- String msg = "Could not add default users and roles to the
Registry Realm. Caused by: " + e.getMessage();
- log.error(msg, e);
- throw new RegistryException(msg);
- }
-
- if (dataSourceName != null) {
- connectionFactory = new ConnectionFactory(dataSourceName);
- } else if (driverClassName != null && connectionURL != null) {
- connectionFactory = new ConnectionFactory(driverClassName,
connectionURL, userName, password);
- } else {
- connectionFactory = new ConnectionFactory();
- }
-
- connectionFactory.setAllowInMemoryDatabase(allowInMemoryDatabase);
- urlHandlerManager = new URLHandlerManager(connectionFactory);
- mediaTypeManager = new MediaTypeManager(connectionFactory, realm);
+ urlHandlerManager = new URLHandlerManager(dataSource);
+ mediaTypeManager = new MediaTypeManager(dataSource, realm);
this.resourceDAO = new VersionedResourceDAO();
this.tagsDAO = new TagsDAO();
@@ -137,7 +123,12 @@
logsDAO = new LogsDAO();
// check if root is added. if not add it.
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
try {
conn.setAutoCommit(false);
@@ -222,11 +213,11 @@
public boolean resourceExists(String path) throws RegistryException {
- Connection conn = connectionFactory.getConnection();
-
boolean resourceExist = false;
+ Connection conn = null;
try {
+ conn = dataSource.getConnection();
resourceExist = resourceDAO.resourceExist(path, conn);
} catch (SQLException e) {
@@ -260,9 +251,10 @@
path = preparePath(path);
mediaTypeManager.put(path, resource);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
try {
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
long resourceID = resourceDAO.getResourceID(path, conn);
@@ -304,9 +296,10 @@
mediaTypeManager.delete(path);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
try {
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
long resourceID = resourceDAO.getResourceID(path, conn);
@@ -338,9 +331,10 @@
String[] versionPaths = null;
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
try {
+ conn = dataSource.getConnection();
long artifactID = resourceDAO.getResourceID(path, conn);
String[] versionIDs = resourceDAO.getVersionNumbers(artifactID,
conn);
@@ -386,9 +380,10 @@
throw new RegistryException(msg);
}
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
try {
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
long artifactID = resourceDAO.getResourceID(plainPath, conn);
@@ -440,7 +435,7 @@
resourcePath = preparePath(resourcePath);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
String userID = User.getCurrentUser();
@@ -448,6 +443,7 @@
String[] tags = tag.split(",");
try {
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
if (!resourceDAO.resourceExist(resourcePath, conn)) {
@@ -515,9 +511,10 @@
//List pathList = new ArrayList();
List taggedPaths = new ArrayList();
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
try {
-
+ conn = dataSource.getConnection();
+
List pathList = tagsDAO.getPathsWithAnyTag(tags, conn);
Iterator iPaths = pathList.iterator();
while (iPaths.hasNext()) {
@@ -564,11 +561,12 @@
resourcePath = preparePath(resourcePath);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
Tag[] tags = null;
try {
+ conn = dataSource.getConnection();
tags = tagsDAO.getTagsWithCount(resourcePath, conn);
} catch (SQLException e) {
@@ -594,9 +592,10 @@
String user = User.getCurrentUser();
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
try {
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
Resource taggedResource = resourceDAO.getLatestVersion(path, conn);
@@ -642,12 +641,12 @@
resourcePath = preparePath(resourcePath);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
String userID = User.getCurrentUser();
try {
-
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
Resource resource = resourceDAO.getLatestVersion(resourcePath,
conn);
@@ -698,11 +697,12 @@
resourcePath = preparePath(resourcePath);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
Comment[] comments = new Comment[0];
try {
+ conn = dataSource.getConnection();
comments = commentsDAO.getComments(resourcePath, conn);
} catch (SQLException e) {
@@ -737,11 +737,12 @@
resourcePath = preparePath(resourcePath);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
String userID = User.getCurrentUser();
try {
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
Resource resource = resourceDAO.getLatestVersion(resourcePath,
conn);
@@ -801,11 +802,12 @@
resourcePath = preparePath(resourcePath);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
float rating = 0;
try {
+ conn = dataSource.getConnection();
rating = ratingsDAO.getAverageRating(resourcePath, conn);
} catch (SQLException e) {
@@ -828,11 +830,12 @@
path = preparePath(path);
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
int rating = 0;
try {
+ conn = dataSource.getConnection();
rating = ratingsDAO.getRating(path, userName, conn);
} catch (SQLException e) {
@@ -858,7 +861,7 @@
public synchronized void defineQuery (String name, String query) throws
RegistryException {
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
String userID = User.getCurrentUser();
@@ -869,7 +872,7 @@
try {
-
+ conn = dataSource.getConnection();
conn.setAutoCommit(false);
Resource queryResource = new Resource();
@@ -912,8 +915,16 @@
}
public Resource executeQuery (String path, Object[] parameters) throws
RegistryException {
- Connection conn = connectionFactory.getConnection();
+
+ Connection conn = null;
try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
+
+ try {
+
Resource query = get(path);
QueryProcessor queryProcessor =
new
QueryProcessorFactory().getQueryProcessor(query.getMediaType());
@@ -929,13 +940,11 @@
}
}
}
+
public void shutdown() throws RegistryException {
- try {
- connectionFactory.shutdown();
- } catch (Exception e) {
- throw new RegistryException("Unable to shutdown the database.");
- }
+
}
+
private String preparePath(String rawPath) {
String path = rawPath;
@@ -953,11 +962,12 @@
String userName,
Date from, Date to, boolean recentFirst) throws
RegistryException {
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
List logEntryList;
try {
+ conn = dataSource.getConnection();
logEntryList =
logsDAO.getLogs(resourcePath, action, userName, from, to,
recentFirst, conn);
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/RegistryRealm.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/RegistryRealm.java
Sun Dec 16 20:42:14 2007
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.wso2.registry.jdbc;
+
+import org.wso2.usermanager.readwrite.DefaultRealm;
+import org.wso2.usermanager.readwrite.DefaultRealmConfig;
+import org.wso2.usermanager.UserManagerException;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.utils.AuthorizationUtil;
+
+import javax.sql.DataSource;
+
+public class RegistryRealm extends DefaultRealm {
+
+ public RegistryRealm(DataSource dataSource) throws RegistryException {
+ super();
+ init(dataSource);
+ }
+
+ protected RegistryRealm() throws RegistryException {}
+
+ protected void configure(DataSource dataSource) throws RegistryException {
+ init(dataSource);
+ }
+
+ private void init(DataSource dataSource) throws RegistryException {
+
+ try {
+ DefaultRealmConfig config =
(DefaultRealmConfig)this.getRealmConfiguration();
+ config.setDataSource(dataSource);
+ this.init(config);
+
+ AuthorizationUtil.populateUserStore(this);
+
+ } catch (UserManagerException e) {
+ String msg = "Could not initiate a user manager realm using the
given data source. " +
+ "Cause by: " + e.getMessage();
+ throw new RegistryException(msg);
+ }
+ }
+}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java
Sun Dec 16 20:42:14 2007
@@ -23,6 +23,8 @@
import org.wso2.registry.utils.AuthorizationUtil;
import org.wso2.usermanager.Realm;
+import javax.sql.DataSource;
+
/**
* Base class of all media type handlers. It defines the three basic methods
to be implemented by
* all media type handlers. This is initialized with the objects required for
handling media type
@@ -32,10 +34,10 @@
public abstract class MediaTypeHandler {
/**
- * Connection factory to obtaining database connections. Media type
handlers need to access the
+ * Data source for obtaining database connections. Media type handlers
need to access the
* database for performing almost all the tasks.
*/
- protected ConnectionFactory connectionFactory;
+ protected DataSource dataSource;
/**
* User manager realm, which can be used to set permissions on resources.
Media type handlers
@@ -68,11 +70,11 @@
*/
protected AuthorizationUtil authorizationUtil = new AuthorizationUtil();
- public MediaTypeHandler(ConnectionFactory connectionFactory,
+ public MediaTypeHandler(DataSource dataSource,
Realm realm,
MediaTypeManager mediaTypeManager) {
- this.connectionFactory = connectionFactory;
+ this.dataSource = dataSource;
this.realm = realm;
this.mediaTypeManager = mediaTypeManager;
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
Sun Dec 16 20:42:14 2007
@@ -31,6 +31,7 @@
import org.wso2.registry.jdbc.mediatypes.builtin.WSDLMediaTypeHandler;
import org.wso2.usermanager.Realm;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
@@ -46,30 +47,31 @@
private static final Log log = LogFactory.getLog(JDBCRegistry.class);
- private ConnectionFactory connectionFactory;
+ private DataSource dataSource = null;
private VersionedResourceDAO resourceDAO = new VersionedResourceDAO();
private Map mediaTypeHandlers = new HashMap();
private DefaultMediaTypeHandler defaultMediaTypeHandler;
- public MediaTypeManager(ConnectionFactory connectionFactory, Realm realm) {
- this.connectionFactory = connectionFactory;
+ public MediaTypeManager(DataSource dataSource, Realm realm) {
- defaultMediaTypeHandler = new
DefaultMediaTypeHandler(connectionFactory, realm, this);
+ this.dataSource = dataSource;
+
+ defaultMediaTypeHandler = new DefaultMediaTypeHandler(dataSource,
realm, this);
mediaTypeHandlers.put(RegistryConstants.DEFAULT_MEDIA_TYPE,
defaultMediaTypeHandler);
MediaTypeHandler sqlMediaTypeHandler =
- new SQLQueryMediaTypeHandler(connectionFactory, realm, this);
+ new SQLQueryMediaTypeHandler(dataSource, realm, this);
mediaTypeHandlers.put(RegistryConstants.SQL_QUERY_MEDIA_TYPE,
sqlMediaTypeHandler);
MediaTypeHandler synRepoMediaTypeHandler =
- new SynapseRepositoryMediaTypeHandler(connectionFactory,
realm, this);
+ new SynapseRepositoryMediaTypeHandler(dataSource, realm, this);
mediaTypeHandlers.put(
RegistryConstants.SYNPASE_REPOSITORY_MEDIA_TYPE,
synRepoMediaTypeHandler);
MediaTypeHandler wsdlMediaTypeHandler =
- new WSDLMediaTypeHandler(connectionFactory, realm, this);
+ new WSDLMediaTypeHandler(dataSource, realm, this);
mediaTypeHandlers.put(RegistryConstants.WSDL_MEDIA_TYPE,
wsdlMediaTypeHandler);
}
@@ -175,7 +177,13 @@
Resource resource;
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
+
try {
resource = resourceDAO.getLatestVersion(path, conn);
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java
Sun Dec 16 20:42:14 2007
@@ -24,13 +24,15 @@
import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
import org.wso2.usermanager.Realm;
+import javax.sql.DataSource;
+
public class Axis2RepositoryMediaTypeHandler extends MediaTypeHandler {
- public Axis2RepositoryMediaTypeHandler(ConnectionFactory connectionFactory,
+ public Axis2RepositoryMediaTypeHandler(DataSource dataSource,
Realm realm,
MediaTypeManager mediaTypeManager) {
- super(connectionFactory, realm, mediaTypeManager);
+ super(dataSource, realm, mediaTypeManager);
}
public Resource get(String path, Resource rawArtifact) throws
RegistryException {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
Sun Dec 16 20:42:14 2007
@@ -22,12 +22,14 @@
import org.wso2.registry.RegistryException;
import org.wso2.registry.Resource;
import org.wso2.registry.User;
+import org.wso2.registry.utils.AuthorizationUtil;
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.jdbc.ConnectionFactory;
import org.wso2.registry.jdbc.mediatypes.MediaTypeHandler;
import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
import org.wso2.usermanager.Realm;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Iterator;
@@ -36,11 +38,11 @@
public class DefaultMediaTypeHandler extends MediaTypeHandler {
private static final Log log =
LogFactory.getLog(DefaultMediaTypeHandler.class);
- public DefaultMediaTypeHandler(ConnectionFactory connectionFactory,
+ public DefaultMediaTypeHandler(DataSource dataSource,
Realm realm,
MediaTypeManager mediaTypeManager) {
- super(connectionFactory, realm, mediaTypeManager);
+ super(dataSource, realm, mediaTypeManager);
}
public Resource get(String path, Resource resource) throws
RegistryException {
@@ -53,7 +55,12 @@
versionNumber = Long.parseLong(parts[1]);
}
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
//if we uncomment following three lines then , no onc access a deleted
resource
// if (!resourceDAO.isResourceActive(plainPath,conn)) {
// throw new RegistryException("Trying to access a deleted
resource");
@@ -88,7 +95,12 @@
String userID = User.getCurrentUser();
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
try {
conn.setAutoCommit(false);
@@ -129,7 +141,7 @@
currentCollection.setLastUpdaterUserName(userID);
resourceDAO.add(currentCollection, conn);
- authorizationUtil.setDefaultAuthorizations(realm,
currentPath, userID);
+ AuthorizationUtil.setDefaultAuthorizations(realm,
currentPath, userID);
// currentCollection =
resourceDAO.getLatestVersion(currentPath, conn);
} else {
@@ -162,7 +174,7 @@
resource.setLastUpdaterUserName(userID);
resourceDAO.add(resource, conn);
- authorizationUtil.setDefaultAuthorizations(realm, path,
userID);
+ AuthorizationUtil.setDefaultAuthorizations(realm, path,
userID);
resource.setId(resourceDAO.getResourceID(path, conn));
resourceDAO.addResourceVersion(resource, conn);
@@ -195,7 +207,14 @@
}
public boolean delete(String path) throws RegistryException {
- Connection conn = connectionFactory.getConnection();
+
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
+
try {
conn.setAutoCommit(false);
Resource resource = resourceDAO.getLatestVersion(path, conn);
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java
Sun Dec 16 20:42:14 2007
@@ -23,13 +23,15 @@
import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
import org.wso2.usermanager.Realm;
+import javax.sql.DataSource;
+
public class SQLQueryMediaTypeHandler extends MediaTypeHandler {
- public SQLQueryMediaTypeHandler(ConnectionFactory connectionFactory,
+ public SQLQueryMediaTypeHandler(DataSource dataSource,
Realm realm,
MediaTypeManager mediaTypeManager) {
- super(connectionFactory, realm, mediaTypeManager);
+ super(dataSource, realm, mediaTypeManager);
}
public Resource get(String path, Resource resource) throws
RegistryException {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java
Sun Dec 16 20:42:14 2007
@@ -24,12 +24,14 @@
import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
import org.wso2.usermanager.Realm;
+import javax.sql.DataSource;
+
public class SynapseRepositoryMediaTypeHandler extends MediaTypeHandler {
- public SynapseRepositoryMediaTypeHandler(ConnectionFactory
connectionFactory,
+ public SynapseRepositoryMediaTypeHandler(DataSource dataSource,
Realm realm,
MediaTypeManager
mediaTypeManager) {
- super(connectionFactory, realm, mediaTypeManager);
+ super(dataSource, realm, mediaTypeManager);
}
public Resource get(String path, Resource resource) throws
RegistryException {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
Sun Dec 16 20:42:14 2007
@@ -25,15 +25,17 @@
import org.wso2.registry.RegistryConstants;
import org.wso2.usermanager.Realm;
+import javax.sql.DataSource;
+
public class WSDLMediaTypeHandler extends MediaTypeHandler {
WSDLFileProcessor wsdlFileProcessor;
- public WSDLMediaTypeHandler(ConnectionFactory connectionFactory,
+ public WSDLMediaTypeHandler(DataSource dataSource,
Realm realm,
MediaTypeManager mediaTypeManager) {
- super(connectionFactory, realm, mediaTypeManager);
+ super(dataSource, realm, mediaTypeManager);
wsdlFileProcessor = new
WSDLFileProcessor(mediaTypeManager.getDefaultMediaTypeHandler());
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
Sun Dec 16 20:42:14 2007
@@ -23,6 +23,7 @@
import org.wso2.registry.jdbc.ConnectionFactory;
import org.wso2.registry.jdbc.dao.CommentsDAO;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -36,8 +37,8 @@
private static final Log log =
LogFactory.getLog(CommentCollectionURLHandler.class);
- public CommentCollectionURLHandler(ConnectionFactory connectionFactory) {
- super(connectionFactory);
+ public CommentCollectionURLHandler(DataSource dataSource) {
+ super(dataSource);
}
public boolean handleURL(String url, Resource resource) throws
RegistryException {
@@ -62,7 +63,13 @@
String resourcePath = parts[0];
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
+
CommentsDAO commentsDAO = new CommentsDAO();
try {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
Sun Dec 16 20:42:14 2007
@@ -22,9 +22,9 @@
import org.wso2.registry.RegistryConstants;
import org.wso2.registry.RegistryException;
import org.wso2.registry.Resource;
-import org.wso2.registry.jdbc.ConnectionFactory;
import org.wso2.registry.jdbc.dao.CommentsDAO;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@@ -34,8 +34,8 @@
private CommentsDAO commentsDAO = new CommentsDAO();
- public CommentURLHandler(ConnectionFactory connectionFactory) {
- super(connectionFactory);
+ public CommentURLHandler(DataSource dataSource) {
+ super(dataSource);
}
/**
@@ -77,7 +77,12 @@
return false;
}
- Connection conn = connectionFactory.getConnection();
+ Connection conn;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
Comment comment = null;
String resourcePath = "";
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
Sun Dec 16 20:42:14 2007
@@ -24,6 +24,7 @@
import org.wso2.registry.jdbc.ConnectionFactory;
import org.wso2.registry.jdbc.dao.RatingsDAO;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
@@ -32,8 +33,8 @@
private static final Log log = LogFactory.getLog(RatingURLHandler.class);
- public RatingURLHandler(ConnectionFactory connectionFactory) {
- super(connectionFactory);
+ public RatingURLHandler(DataSource dataSource) {
+ super(dataSource);
}
public boolean handleURL(String url, Resource resource) throws
RegistryException {
@@ -56,7 +57,13 @@
String resourcePath = parts[0];
String ratedUserName = details[1];
- Connection conn = connectionFactory.getConnection();
+ Connection conn;
+
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
try {
RatingsDAO ratingsDAO = new RatingsDAO();
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
Sun Dec 16 20:42:14 2007
@@ -23,6 +23,7 @@
import org.wso2.registry.jdbc.ConnectionFactory;
import org.wso2.registry.jdbc.dao.RatingsDAO;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -32,8 +33,8 @@
private static final Log log =
LogFactory.getLog(CommentCollectionURLHandler.class);
- public RatingsCollectionURLHandler(ConnectionFactory connectionFactory) {
- super(connectionFactory);
+ public RatingsCollectionURLHandler(DataSource dataSource) {
+ super(dataSource);
}
public boolean handleURL(String url, Resource resource) throws
RegistryException {
@@ -58,7 +59,13 @@
String resourcePath = parts[0];
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
+
RatingsDAO ratingsDAO = new RatingsDAO();
try {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
Sun Dec 16 20:42:14 2007
@@ -23,13 +23,14 @@
import org.wso2.registry.jdbc.dao.TagsDAO;
import org.wso2.registry.jdbc.dataobjects.TaggingDO;
+import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class TagURLHandler extends URLHandler {
- public TagURLHandler(ConnectionFactory connectionFactory) {
- super(connectionFactory);
+ public TagURLHandler(DataSource dataSource) {
+ super(dataSource);
}
/**
@@ -62,7 +63,12 @@
String tagName = queries[1];
String userName = queries[2];
- Connection conn = connectionFactory.getConnection();
+ Connection conn = null;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
try {
TagsDAO tagsDAO = new TagsDAO();
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
Sun Dec 16 20:42:14 2007
@@ -20,6 +20,8 @@
import org.wso2.registry.Resource;
import org.wso2.registry.jdbc.ConnectionFactory;
+import javax.sql.DataSource;
+
/**
* Base class for URL handlers. URL handlers are used support virtual
resources. JDBC registry
* allows users to access some none-resource entities in the same way they
access normal resources
@@ -34,10 +36,10 @@
*/
public abstract class URLHandler {
- protected ConnectionFactory connectionFactory;
+ protected DataSource dataSource;
- public URLHandler(ConnectionFactory connectionFactory) {
- this.connectionFactory = connectionFactory;
+ public URLHandler(DataSource dataSource) {
+ this.dataSource = dataSource;
}
public abstract boolean handleURL(String url, Resource resource) throws
RegistryException;
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
Sun Dec 16 20:42:14 2007
@@ -20,6 +20,7 @@
import org.wso2.registry.Resource;
import org.wso2.registry.jdbc.ConnectionFactory;
+import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -28,13 +29,13 @@
private List urlHandlers = new ArrayList();
- public URLHandlerManager(ConnectionFactory connectionFactory) {
+ public URLHandlerManager(DataSource dataSource) {
- urlHandlers.add(new CommentURLHandler(connectionFactory));
- urlHandlers.add(new CommentCollectionURLHandler(connectionFactory));
- urlHandlers.add(new RatingURLHandler(connectionFactory));
- urlHandlers.add(new RatingsCollectionURLHandler(connectionFactory));
- urlHandlers.add(new TagURLHandler(connectionFactory));
+ urlHandlers.add(new CommentURLHandler(dataSource));
+ urlHandlers.add(new CommentCollectionURLHandler(dataSource));
+ urlHandlers.add(new RatingURLHandler(dataSource));
+ urlHandlers.add(new RatingsCollectionURLHandler(dataSource));
+ urlHandlers.add(new TagURLHandler(dataSource));
}
public Resource handleURL(String url)
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/RegistryDataSource.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/RegistryDataSource.java
Sun Dec 16 20:42:14 2007
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.wso2.registry.jdbc.utils;
+
+import org.apache.commons.dbcp.BasicDataSource;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.io.PrintWriter;
+
+public class RegistryDataSource implements DataSource {
+
+ private DataSource dataSource = null;
+
+ public RegistryDataSource(String dbURL, String driverName, String
userName, String password) {
+
+ BasicDataSource basicDataSource = new BasicDataSource();
+ basicDataSource.setUrl(dbURL);
+ basicDataSource.setDriverClassName(driverName);
+ basicDataSource.setUsername(userName);
+ basicDataSource.setPassword(password);
+
+ this.dataSource = basicDataSource;
+ }
+
+ public Connection getConnection() throws SQLException {
+ return dataSource.getConnection();
+ }
+
+ public Connection getConnection(String username, String password) throws
SQLException {
+ return dataSource.getConnection(username, password);
+ }
+
+ public PrintWriter getLogWriter() throws SQLException {
+ return dataSource.getLogWriter();
+ }
+
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ dataSource.setLogWriter(out);
+ }
+
+ public void setLoginTimeout(int seconds) throws SQLException {
+ dataSource.setLoginTimeout(seconds);
+ }
+
+ public int getLoginTimeout() throws SQLException {
+ return dataSource.getLoginTimeout();
+ }
+}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
Sun Dec 16 20:42:14 2007
@@ -28,6 +28,7 @@
import org.wso2.registry.secure.SecureRegistry;
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.jdbc.InMemoryJDBCRegistry;
import org.wso2.usermanager.Realm;
import javax.servlet.ServletConfig;
@@ -73,9 +74,7 @@
if (coreRegistryTypeParam == null ||
coreRegistryTypeParam.equals(RegistryConstants.JDBC_REGISTRY_TYPE)) {
- JDBCRegistry jdbcRegistry = new JDBCRegistry();
- jdbcRegistry.init(registryRealm);
- coreRegistry = jdbcRegistry;
+ coreRegistry = new InMemoryJDBCRegistry(registryRealm);
} else if
(coreRegistryTypeParam.equals(RegistryConstants.REMOTE_REGISTRY_TYPE)) {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
Sun Dec 16 20:42:14 2007
@@ -30,6 +30,10 @@
public static void setDefaultAuthorizations(Realm realm, String path,
String authorUserName)
throws RegistryException {
+ if (realm == null) {
+ return;
+ }
+
try {
AccessControlAdmin accessControlAdmin =
realm.getAccessControlAdmin();
@@ -68,6 +72,10 @@
public static void populateUserStore(Realm realm) throws
UserManagerException {
+ if (realm == null) {
+ return;
+ }
+
UserStoreReader userStoreReader = realm.getUserStoreReader();
UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
AccessControlAdmin accessControlAdmin = realm.getAccessControlAdmin();
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Sun Dec 16 20:42:14 2007
@@ -37,11 +37,9 @@
public void setUp() {
try {
if (registry == null) {
- Realm registryRealm =
- RegistryRealmFactory.createInMemoryRegistryRealm();
- JDBCRegistry jdbcRegistry = new JDBCRegistry();
- jdbcRegistry.init(registryRealm);
- registry = jdbcRegistry;
+ //Realm registryRealm =
+ // RegistryRealmFactory.createInMemoryRegistryRealm();
+ registry = new InMemoryJDBCRegistry();
}
} catch (RegistryException e) {
fail("Failed to initialize the registry.");
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/TagsTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/TagsTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/TagsTest.java
Sun Dec 16 20:42:14 2007
@@ -37,9 +37,7 @@
if (registry == null) {
realm =
RegistryRealmFactory.createInMemoryRegistryRealm();
- JDBCRegistry jdbcRegistry = new JDBCRegistry();
- jdbcRegistry.init(realm);
- registry = jdbcRegistry;
+ registry = new InMemoryJDBCRegistry(realm);
}
} catch (RegistryException e) {
fail("Failed to initialize the registry.");
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java
Sun Dec 16 20:42:14 2007
@@ -35,9 +35,7 @@
if (registry == null) {
Realm registryRealm =
RegistryRealmFactory.createInMemoryRegistryRealm();
- JDBCRegistry jdbcRegistry = new JDBCRegistry();
- jdbcRegistry.init(registryRealm);
- registry = jdbcRegistry;
+ registry = new InMemoryJDBCRegistry(registryRealm);
}
} catch (RegistryException e) {
fail("Failed to initialize the registry.");
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/secure/SecureRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/secure/SecureRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/secure/SecureRegistryTest.java
Sun Dec 16 20:42:14 2007
@@ -23,6 +23,8 @@
import org.wso2.registry.*;
import org.wso2.registry.servlet.RegistryRealmFactory;
import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.jdbc.InMemoryJDBCRegistry;
+import org.wso2.registry.jdbc.InMemoryRegistryRealm;
import org.wso2.usermanager.Realm;
import java.io.*;
@@ -35,10 +37,9 @@
public void setUp() {
try {
if (registry == null) {
- realm = RegistryRealmFactory.createInMemoryRegistryRealm();
- JDBCRegistry jdbcRegistry = new JDBCRegistry();
- jdbcRegistry.init(realm);
- registry = jdbcRegistry;
+ //realm = RegistryRealmFactory.createInMemoryRegistryRealm();
+ realm = new InMemoryRegistryRealm();
+ registry = new InMemoryJDBCRegistry(realm);
}
} catch (RegistryException e) {
fail("Failed to initialize the registry.");
Modified: trunk/registry/pom.xml
==============================================================================
--- trunk/registry/pom.xml (original)
+++ trunk/registry/pom.xml Sun Dec 16 20:42:14 2007
@@ -88,6 +88,11 @@
<version>${log4j.version}</version>
</dependency>
<dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>${commons.dbcp.version}</version>
+ </dependency>
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons.logging.version}</version>
@@ -330,6 +335,7 @@
<javamail.version>1.4</javamail.version>
<activation.version>1.1</activation.version>
+ <commons.dbcp.version>1.3-SNAPSHOT</commons.dbcp.version>
<commons.logging.version>1.1</commons.logging.version>
<commons.beanutils.version>1.7.0</commons.beanutils.version>
<commons.collections.version>3.2</commons.collections.version>
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev