Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Corona CC New Approach"

(only one connection active AND rest of headers defined)
Line 57: Line 57:
  
 
== Stackable repositories ==
 
== Stackable repositories ==
 +
There are some simple repositories, like CVS, where its connection definition is enough. But some repositories require access to other repositories. It is usually that something needs to get some file and parse it. For instance team xml file. It is kept either on disc, but can be kept in CVS or Jackrabbit as well. To abstract the real access to file, the team xml repository adapter requires an other repository adapter which would give it the file to parse.
 +
 +
The interface for such adapter would be an extended version of IRepositoryAdapter to return resources of a given type. In order to have it implemented easily, there need to be a factory that obtains a IRepositoryAdapter for a connection configuration. The description of such repository in later section [[#IAdapterManager instead of RepositoryAdapterFactory]].
  
 
=== Reference between repositories ===
 
=== Reference between repositories ===
 +
  
 
== Multiple repository adapter interfaces for a single repository ==
 
== Multiple repository adapter interfaces for a single repository ==

Revision as of 12:56, 7 March 2007

This page is intended to describe and summarize a new approach, a better approach we believe, that could be used for CC and repository adapters. It doesn't provide in fact much changes to the model and repositories, but rather supplements current state.

Some background

The main programming issue with repositories is repository adapter. The repository adapter should allow us to access repositories in some standardized way. For this purpose the repository adapter was introduced. But it had several weaknesses:

  • All arguments and return types are objects. This provides a problem that you cannot work with repository without knowledge of the repository. You always need to know that the object will be. This kind of interface cannot provide a generic API.
  • The repository adapter interface fits only to repositories that keeps entities of any kind. Even now not all repositories fit into this model!
  • Difficulties with reusing existing repository adapters by other repositories.
  • ...

Only one connection configuration active

CC allows to have several connection configurations. The semantic of this wasn't well defined. The possibilities are:

  1. Alternative ways of connecting that software automatically picks one by its preferences or which connection it is able to handle.
  2. Alternative ways of connecting but one is default and user is able to select other if the default doesn't work for him.

The first approach makes things very difficult, inconsistent and error prone. The second one, although gives a bit less power, is acceptably simple. From logic point of view, the repository definition is flat then, because there are no several possible ways of connection. But this means that repository descriptor object should have a method like "getConnectionConfig()", which would check user's preferences and if not available, it would take the default connection.

Parametrize IRepositoryAdapter

Without breaking background compatibility we can slightly modify IReposiotyAdapter and introduce ID and resource types through generics. So the IRepositoryAdapter would now look like this:

interface IRepositoryAdapter<I,T> {
    List<I> listIds(I parentId);
    boolean resourceExists(I id);
    T fetchResource(I id);
    I addResource(T res);
    void removeResource(I id);
    void updateResource(T);
}

Obviously, event though a given repository adapter implementation provides its types, it cannot be detected in runtime! So this doesn't give much, since we are using repository factory, which would loose the type declarations. To overcome it we can simply create a new repository interface extending the IRepositoryAdapter with definition of I and T types.

Some example. CVS, WebDAV, file system, Jackrabbit, FTP, etc. can be threated as a virtual file system. The key is some kind of path, value is a virtual file. So we should have a single interface IVfsRepositoryAdapter for those that we can use them interchangeable.

interface IVfsRepositoryAdapter<I extends IPath, T extends IFile> extends IRepositoryAdapter<I,T> {
}

This declaration creates a new interface but all I in IRepositoryAdapter must be of class IPath, while T of IFile. In addition, the IVfsRepositoryAdapter can be detected in runtime with instanceof. Note also that that you can still build more specialized interfaces that extend IVfsRepositoryAdapter and put even strong constraint for the ID and resource types.

Advantages:

  • Provides type check for a repository adapter which reduces number of problems with class cast exception.
  • Allows to build API by providing specialized interfaces for given repository types. Repository adapters for different repositories may/should implement the same interface in order to have it easily replaceable.
  • The type check can be performed also at runtime by instanceof<code>
  • You can still work only at IRepositoryAdapter level with objects.
DO NOT IMPLEMENT IRepositoryAdapter DIRECTLY

For instance:

class FileSystemAdapter implements IRepositoryAdapter<IPath, IFile> {
  // ... implementation here ...
}

In compilation time the result is exactly the same as implementing IVfsRepositoryAdapter. The problem is that it cannot be detected in runtime.

Stackable repositories

There are some simple repositories, like CVS, where its connection definition is enough. But some repositories require access to other repositories. It is usually that something needs to get some file and parse it. For instance team xml file. It is kept either on disc, but can be kept in CVS or Jackrabbit as well. To abstract the real access to file, the team xml repository adapter requires an other repository adapter which would give it the file to parse.

The interface for such adapter would be an extended version of IRepositoryAdapter to return resources of a given type. In order to have it implemented easily, there need to be a factory that obtains a IRepositoryAdapter for a connection configuration. The description of such repository in later section #IAdapterManager instead of RepositoryAdapterFactory.

Reference between repositories

Multiple repository adapter interfaces for a single repository

IAdapterManager instead of RepositoryAdapterFactory

== Not only IRepositoryAdapter ==

Back to the top