The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services.
This module provides infrastructure components to build repository abstractions for stores dealing with the Connected Data Objects (CDO) model repository of Eclipse.
Version Compatability
Spring Data CDO |
Eclipse Modeling Tools |
CDO Protocol Version |
0.8.0 (latest) |
54 |
|
0.7.5 |
48 |
|
0.7.2 |
48 |
|
0.6.0-SNAPSHOT |
48 |
The standard use case of this framework is to store and read native CDOObject and standard EObject.
To be clear, the framework does not perform a transformation of standard Java POJOs to their Ecore representatives.
Only Java objects of class type CDOObject or EObject (and in legacy mode) are supported.
Legacy mode: Models that are not converted for CDO support.
See also Preparing EMF Models
Your domain models should be defined using the Eclipse EMF Ecore metamodel as usual, or dynamically at runtime. Eclipse EMF also supports the generation of an API from Ecore models. They can also be used afterwards with Spring Data CDO.
Just add the following Maven dependency to your project’s pom.xml:
<dependency>
<groupId>org.bigraphs.springframework.data</groupId>
<artifactId>spring-data-cdo</artifactId>
<version>0.8.0</version>
</dependency>These dependencies are required when you want to start the standalone CDO server that is shipped with this framework:
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
<version>3.34.0</version>
</dependency>The following examples show some possible configuration and usage scenarios.
The framework can handle native EMF models:
// any auto-generated object of an EMF model or native CDO model
interface Person extends EObject {}
interface Person extends CDOObject {}Non-native EMF domain classes (i.e., classes that don’t extend EObject or the CDOObject interface) should be annotated in the following way to provide necessary details:
@CDO(path = "your/repository/resource/path", // CDO resource path
nsUri = "http://www.example.org/personDomainModel", // namespace of the Ecore model
ePackage = PersonDomainModelPackage.class, // the EPackage of the model
ePackageBaseClass = "org.example.ecore.personDomainModel.PersonDomainModelPackage"
)
class PersonWrapper {
// ID is mandatory
@Id
CDOID id;
// Provide here the actual EObject model that the framework can access
// because PersonWrapper does not extend EObject
@EObjectModel(classFor=Person.class)
public Person model; // Person extends from EMF's EObject class
}They effectively work like a wrapper for internal members, which are of class EObject or CDOObject.
Additionally, an ID must be specified of type CDOID using the @Id annotation feature of Spring.
Enable the Spring repository support for CDO repositories:
// Spring Configuration Class
@Configuration
@EnableCdoRepositories(basePackageClasses = PersonRepository.class)
//@EnableCdoRepositories(basePackages = "org.example.repository") // Java package to repository interfaces
public class CDOServerConfig {
// ...
}package org.example.repository;
@Repository
public interface PersonRepository extends CdoRepository<PersonWrapper, CDOID> {
// ...
}With regard to EMF-related programming, the respective EPackage must be registered in the global package registry first (see EPackage.Registry).
The registry provides a mapping from namespace URIs to EPackage instances.
Though, this framework has some internal mechanism to initialize the EPackage in the registry automatically, it may not always find it.
We advise to initialize the corresponding EPackage that is going to be used with this framework by using standard mechanisms of EMF:
@BeforeClass
public static void beforeClass() throws Exception {
PersonDomainModelPackageImpl.init();
// Or: EPackage.Registry.INSTANCE.put("http://www.example.org/personDomainModel", PersonDomainModelPackage.eINSTANCE);
// This statement should not fail:
EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage("http://www.example.org/personDomainModel");
Assert.notNull(ePackage, "Model Package couldn't be found in the EPackage Registry.");
}Especially when working with CDO the package should be registered locally and remotely:
CdoTemplate template = new CdoTemplate(factory);
CDOPackageRegistry.INSTANCE.put(BookstoreDomainModelPackage.eNS_URI, BookstoreDomainModelPackage.eINSTANCE);
CDOPackageRegistry remoteRegistry = template.getCDOPackageRegistry(); //acquire the remote CDO package registry
EPackage ePackage = remoteRegistry.getEPackage(BookstoreDomainModelPackage.eNS_URI);
if (ePackage == null) {
remoteRegistry.put(BookstoreDomainModelPackage.eNS_URI, BookstoreDomainModelPackage.eINSTANCE);
}When required, one can listen to specific events emitted by some repository actions for adding extended behavior. Events are implemented for Delete, Save and Insert operations, including "after" and "before" notions for fine-grained control.
For testing purposes you can start a standalone CDO server like this:
CDOStandaloneServer server = new CDOStandaloneServer("repo1");
CDOStandaloneServer.start(server);This framework includes functionality to launch a standalone CDO server. Use the Eclipse CDO Explorer, which allows you to easily view and interact with Ecore models hosted on the CDO server.
-
Download CDO Explorer or Server via the Eclipse Installer. See table above to see which version of Eclipse to use.
For information about setting up the development environment, building the project, and contribution guidelines, please refer to DEVELOPMENT.adoc.
This library is Open Source software released under the Apache 2.0 license.
Copyright 2023-present Bigraph Toolkit Developers
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.