diff --git a/README.md b/README.md index c15561292..048381aa9 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,4 @@ Grails Datastore API === -[Grails][Grails] is a framework used to build web applications with the [Groovy][Groovy] programming language. This project provides the plumbings for the GORM API both for Hibernate and for new implementations of GORM ontop of NoSQL datastores. -[Grails]: http://grails.org/ -[Groovy]: http://groovy.codehaus.org/ - - -Getting Started ---- - -For further information on the project see the comprehensive [developer guide][Developer Guide]. -[Developer Guide]: http://springsource.github.com/grails-data-mapping/ - -License ---- - -Grails and Groovy are licensed under the terms of the [Apache License, Version 2.0][Apache License, Version 2.0]. -[Apache License, Version 2.0]: http://www.apache.org/licenses/LICENSE-2.0.html +This repository has moved to https://github.com/grails/grails-data-mapping \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 8d0bd1cf4..000000000 --- a/build.gradle +++ /dev/null @@ -1,425 +0,0 @@ -project.ext { - springVersion = "3.2.3.RELEASE" - grailsVersion = "2.3.0" - slf4jVersion = "1.7.2" - groovyVersion = System.getProperty('groovyVersion') ?: '2.1.5' -} - -def groovyMajorVersion = groovyVersion[0..2] -def spockDependency = "org.spockframework:spock-core:0.7-groovy-2.0" - -def groovyProjects() { - subprojects.findAll { project -> isGroovyProject(project) } -} - -def isGroovyProject(project) { - def isGrailsPlugin = project.name.contains("grails-plugins") - def isDocumentation = project.name.contains("documentation") - !isGrailsPlugin && !isDocumentation -} - -configurations { - all*.exclude group: "commons-logging" -} - -apply plugin: 'idea' -apply plugin: 'project-report' - - -ext { - isCiBuild = project.hasProperty("isCiBuild") -} -allprojects { - repositories { - if(!isCiBuild) { - mavenLocal() - } - mavenCentral() - maven { url "http://repo.grails.org/grails/core" } - } - - configurations { - all { - resolutionStrategy { -// def cacheHours = isCiBuild ? 1 : 24 -// cacheDynamicVersionsFor cacheHours, 'hours' -// cacheChangingModulesFor cacheHours, 'hours' - } - } - } -} - -task wrapper(type: Wrapper) { - gradleVersion = '1.5' -} - -subprojects { - ext { - releaseType = "RELEASE" -// releaseType = "BUILD-SNAPSHOT" - // releaseType = "RC2" - isCiBuild = project.hasProperty("isCiBuild") - isBuildSnapshot = releaseType == "BUILD-SNAPSHOT" - } - - version = "2.0.1.${releaseType}" - group = "org.grails" - - - def isStandardGroovyMavenProject = isGroovyProject(project) - - if (isStandardGroovyMavenProject) { - apply plugin: 'groovy' - apply plugin: 'eclipse' - apply plugin: 'maven' - apply plugin: 'idea' - apply plugin: 'signing' - sourceCompatibility = "1.6" - targetCompatibility = "1.6" - -/* apply from: "file:${rootDir}/clover.gradle"*/ - - install.doLast { - def gradleArtifactCache = new File(gradle.gradleUserHomeDir, "cache") - configurations.archives.artifacts.findAll { it.type == "jar" && !it.classifier }.each { artifact -> - - // Gradle's cache layout is internal and may change in future versions, this is written for gradle 1.0-milestone-3 - def artifactInCache = file("${gradleArtifactCache}/${project.group}/${project.name}/jars/${project.name}-${version}.jar") - if (artifactInCache.parentFile.mkdirs()) { - artifactInCache.withOutputStream { destination -> artifact.file.withInputStream { destination << it } } - } - } - } - } - - def isGormDatasource = project.name.startsWith("grails-datastore-gorm-") && - !project.name.endsWith("tck") && - !project.name.endsWith("plugin-support") && - project.name != 'grails-datastore-gorm-hibernate-core'&& - project.name != 'grails-datastore-gorm-rest-client' - def isDocumentationProject = project.name.startsWith("grails-documentation") - - dependencies { - if (isStandardGroovyMavenProject) { - groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: groovyVersion - - testCompile 'junit:junit:4.8.2' - testCompile (spockDependency) { - transitive = false - } - } - - if (project.name == "grails-datastore-gorm-tck") { - compile spockDependency - } - } - - if (isDocumentationProject) { - configurations { - documentation - } - dependencies { - documentation group: 'org.grails', name: 'grails-docs', version: '2.0.0' - project(":grails-datastore-core") - documentation "org.slf4j:jcl-over-slf4j:$slf4jVersion" - documentation "org.slf4j:slf4j-api:$slf4jVersion" - documentation "org.slf4j:slf4j-simple:$slf4jVersion" - } - task docs << { - ant.taskdef (name: 'docs', classname : 'grails.doc.ant.DocPublisherTask') { - classpath { - configurations.documentation.resolve().each { f -> - pathelement(location:f) - } - } - - } - ant.docs(src:"src/docs", dest:destinationDir, properties:"src/docs/doc.properties") - } - docs.ext.destinationDir = "${buildDir}/docs" - - - task clean << { - ant.delete(dir:buildDir) - } - } - - if (isGormDatasource) { - dependencies { - testCompile project(":grails-datastore-gorm-tck") - } - - // We need to test against the TCK. Gradle cannot find/run tests from jars - // without a lot of plumbing, so here we copy the class files from the TCK - // project into this project's test classes dir so Gradle can find the test - // classes and run them. See grails.gorm.tests.GormDatastoreSpec for on the TCK. - - // helper, used below. - def toBaseClassRelativePathWithoutExtension = { String base, String classFile -> - if (classFile.startsWith(base)) { - def sansClass = classFile[0 .. classFile.size() - ".class".size() - 1] - def dollarIndex = sansClass.indexOf('$') - def baseClass = dollarIndex > 0 ? sansClass[0..dollarIndex - 1] : sansClass - def relative = baseClass - base - '/' - relative - } - else { - null - } - } - - test { - maxHeapSize = '2048m' - } - test.doFirst { - def tckClassesDir = project(":grails-datastore-gorm-tck").sourceSets.main.output.classesDir - def thisProjectsTests = // surely there is a less hardcoded way to do this - copy { - from tckClassesDir - into sourceSets.test.output.classesDir - include "**/*.class" - exclude { details -> - // Do not copy across any TCK class (or nested classes of that class) - // If there is a corresponding source file in the particular modules - // test source tree. Allows a module to override a test/helper. - - def candidatePath = details.file.absolutePath - def relativePath = toBaseClassRelativePathWithoutExtension(tckClassesDir.absolutePath, candidatePath) - - if (relativePath == null) { - throw new IllegalStateException("$candidatePath does not appear to be in the TCK") - } - - project.file("src/test/groovy/${relativePath}.groovy").exists() - } - } - } - } - - if (isStandardGroovyMavenProject) { - - task sourcesJar(type: Jar, dependsOn:classes) { - classifier = 'sources' - from sourceSets.main.allSource - } - - task javadocJar(type: Jar, dependsOn:javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir - } - - artifacts { - archives jar - archives sourcesJar - archives javadocJar - } - - signing { - sign configurations.archives - required { !isBuildSnapshot && gradle.taskGraph.hasTask(uploadArchives) } - } - - configure(install.repositories.mavenInstaller) { - pom.whenConfigured { pom -> - def dependency = pom.dependencies.find { dep -> dep.artifactId == 'slf4j-simple' } - dependency?.optional = true - } - pom.project { - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'http://github.com/SpringSource/grails-data-mapping/' - } - } - } - } - - uploadArchives { - description = "Does a maven deploy of archives artifacts" - - // add a configuration with a classpath that includes our s3 maven deployer - configurations { deployerJars } - dependencies { - deployerJars "org.springframework.build.aws:org.springframework.build.aws.maven:3.0.0.RELEASE" - } - - repositories.mavenDeployer { - beforeDeployment { MavenDeployment deployment -> - signing.signPom(deployment) - } - - repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: project.hasProperty("sonatypeUsername") ? project.sonatypeUsername : null, - password: project.hasProperty("sonatypePassword") ? project.sonatypePassword : null) - } - snapshotRepository(url: "http://repo.grails.org/grails/libs-snapshots-local") { - authentication(userName: project.hasProperty("artifactoryPublishUsername") ? project.artifactoryPublishUsername : null, - password: project.hasProperty("artifactoryPublishPassword") ? project.artifactoryPublishPassword : null) - } - - pom.project { - name 'Grails GORM' - packaging 'jar' - description 'GORM - Grails Data Access Framework' - delegate.url 'http://grails.org/' - - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - - scm { - delegate.url 'scm:git@github.com:SpringSource/grails-data-mapping.git' - connection 'scm:git@github.com:SpringSource/grails-data-mapping.git' - developerConnection 'scm:git@github.com:SpringSource/grails-data-mapping.git' - } - - licenses { - license { - name 'The Apache Software License, Version 2.0' - delegate.url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - - developers { - developer { - id 'graemerocher' - name 'Graeme Rocher' - } - developer { - id 'jeffscottbrown' - name 'Jeff Brown' - } - developer { - id 'burtbeckwith' - name 'Burt Beckwith' - } - } - } - } - } - } -} - -configurations { - build -} - -repositories { - mavenCentral() -} - -dependencies { - build "com.cenqua.clover:clover:3.0.2" - build "org.apache.ant:ant-junit:1.8.1" - build "org.apache.ant:ant-nodeps:1.8.1" -} - -task allDocs(dependsOn: getTasksByName("docs", true)) << { - def docTasks = getTasksByName("docs", true) - def groovydocTasks = getTasksByName("groovydoc", true) - allDocsDir = "$buildDir/docs" - mkdir allDocsDir - def stores = [] - for(task in docTasks) { - def dir = task.destinationDir - def projectName = task.project.name - if (projectName.endsWith("core")) { - mkdir "$allDocsDir/manual" - fileTree { from dir }.copy { into "$allDocsDir/manual" } - def groovydocTask = groovydocTasks.find { it.project.name.endsWith "core" } - if (groovydocTask != null) { - mkdir "$allDocsDir/api" - groovydocTask.actions.each { it.execute(groovydocTask) } - - fileTree { from groovydocTask.destinationDir }.copy { into "$allDocsDir/api"} - } - } - else { - def storeName = projectName["grails-documentation-".size()..-1] - stores << storeName - def docsDir = "$allDocsDir/$storeName" - mkdir docsDir - def groovydocTask = groovydocTasks.find { it.project.name == "grails-datastore-$storeName" } - if (groovydocTask == null) groovydocTask = groovydocTasks.find { it.project.name == "grails-datastore-gorm-$storeName" } - if (groovydocTask != null) { - mkdir "$docsDir/api" - groovydocTask.actions.each { it.execute(groovydocTask) } - fileTree { from groovydocTask.destinationDir }.copy { into "$docsDir/api"} - } - mkdir "$docsDir/manual" - fileTree { from dir }.copy { into "$docsDir/manual" } - } - - def engine = new groovy.text.SimpleTemplateEngine() - def binding = [ - datastores:stores.collect { "
TPCacheAdapter
true
Datastore
This is the getSession method used by typical data access code, - * in combination with releaseSession called when done with - * the Session. - * - * @param datastore Datastore to create the session with - * @param allowCreate whether a non-transactional Session should be created - * when no transactional Session can be found for the current thread - * @return the Datastore Session - * @throws org.springframework.dao.DataAccessResourceFailureException if the Session couldn't be created - * @throws IllegalStateException if no thread-bound Session found and - * "allowCreate" is false - */ - public static Session getSession(Datastore datastore, boolean allowCreate) - throws DataAccessResourceFailureException, IllegalStateException { - - try { - return doGetSession(datastore, allowCreate); - } - catch (Exception ex) { - throw new DataAccessResourceFailureException("Could not open Datastore Session", ex); - } - } - - /** - * Get a Datastore Session for the given Datastore. Is aware of and will - * return any existing corresponding Session bound to the current thread, for - * example when using {@link org.grails.datastore.mapping.transactions.DatastoreTransactionManager}. Will create a new - * Session otherwise, if "allowCreate" is true. - * - * @param datastore Datastore to create the session with - * Session on transaction synchronization (may be null) - * @param allowCreate whether a non-transactional Session should be created - * when no transactional Session can be found for the current thread - * @return the Datastore Session - * @throws IllegalStateException if no thread-bound Session found and - * "allowCreate" is false - */ - public static Session doGetSession(Datastore datastore, boolean allowCreate) { - - Assert.notNull(datastore, "No Datastore specified"); - - SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(datastore); - - if (sessionHolder != null && !sessionHolder.isEmpty()) { - // pre-bound Datastore Session - Session session; - if (TransactionSynchronizationManager.isSynchronizationActive() && - sessionHolder.doesNotHoldNonDefaultSession()) { - // Spring transaction management is active -> - // register pre-bound Session with it for transactional flushing. - session = sessionHolder.getValidatedSession(); - if (session != null && !sessionHolder.isSynchronizedWithTransaction()) { - logger.debug("Registering Spring transaction synchronization for existing Datastore Session"); - TransactionSynchronizationManager.registerSynchronization( - new SpringSessionSynchronization(sessionHolder, datastore, false)); - sessionHolder.setSynchronizedWithTransaction(true); - - } - if (session != null) { - return session; - } - } - else { - session = sessionHolder.getValidatedSession(); - if (session != null) { - return session; - } - } - } - - logger.debug("Opening Datastore Session"); - Session session = datastore.connect(); - - // Use same Session for further Datastore actions within the transaction. - // Thread object will get removed by synchronization at transaction completion. - if (TransactionSynchronizationManager.isSynchronizationActive()) { - // We're within a Spring-managed transaction, possibly from JtaTransactionManager. - logger.debug("Registering Spring transaction synchronization for new Datastore Session"); - SessionHolder holderToUse = sessionHolder; - if (holderToUse == null) { - holderToUse = new SessionHolder(session); - } - else { - holderToUse.addSession(session); - } - TransactionSynchronizationManager.registerSynchronization( - new SpringSessionSynchronization(holderToUse, datastore, true)); - holderToUse.setSynchronizedWithTransaction(true); - if (holderToUse != sessionHolder) { - TransactionSynchronizationManager.bindResource(datastore, holderToUse); - } - } - - // Check whether we are allowed to return the Session. - if (!allowCreate && !isSessionTransactional(session, datastore)) { - closeSession(session); - throw new IllegalStateException("No Datastore Session bound to thread, " + - "and configuration does not allow creation of non-transactional one here"); - } - - return session; - } - - /** - * Return whether the given Datastore Session is transactional, that is, - * bound to the current thread by Spring's transaction facilities. - * @param session the Datastore Session to check - * @param datastore Datastore that the Session was created with - * (may be null) - * @return whether the Session is transactional - */ - public static boolean isSessionTransactional(Session session, Datastore datastore) { - if (datastore == null) { - return false; - } - SessionHolder sessionHolder = - (SessionHolder) TransactionSynchronizationManager.getResource(datastore); - return (sessionHolder != null && sessionHolder.containsSession(session)); - } - - /** - * Perform actual closing of the Session, - * catching and logging any cleanup exceptions thrown. - * @param session The Session instance - */ - public static void closeSession(Session session) { - if (session == null) { - return; - } - - logger.debug("Closing Datastore Session"); - try { - session.disconnect(); - } - catch (Throwable ex) { - logger.debug("Unexpected exception on closing Datastore Session", ex); - } - } - - /** - * Close the given Session, created via the given factory, - * if it is not managed externally (i.e. not bound to the thread). - * @param session the Datastore Session to close (may be null) - * @param datastore Datastore that the Session was created with - * (may be null) - */ - public static void releaseSession(Session session, Datastore datastore) { - if (session == null) { - return; - } - // Only close non-transactional Sessions. - if (!isSessionTransactional(session, datastore)) { - closeSessionOrRegisterDeferredClose(session, datastore); - } - } - - /** - * Process all Datastore Sessions that have been registered for deferred close - * for the given SessionFactory. - * @param datastore the Datastore to process deferred close for - * @see #initDeferredClose - * @see #releaseSession - */ - public static void processDeferredClose(Datastore datastore) { - Assert.notNull(datastore, "No Datastore specified"); - Map> holderMap = deferredCloseHolder.get(); - if (holderMap == null || !holderMap.containsKey(datastore)) { - throw new IllegalStateException("Deferred close not active for Datastore [" + datastore + "]"); - } - logger.debug("Processing deferred close of Datastore Sessions"); - Set sessions = holderMap.remove(datastore); - for (Session session : sessions) { - closeSession(session); - } - if (holderMap.isEmpty()) { - deferredCloseHolder.set(null); - } - } - - /** - * Initialize deferred close for the current thread and the given Datastore. - * Sessions will not be actually closed on close calls then, but rather at a - * {@link #processDeferredClose} call at a finishing point (like request completion). - * - * @param datastore the Datastore to initialize deferred close for - * @see #processDeferredClose - * @see #releaseSession - */ - public static void initDeferredClose(Datastore datastore) { - Assert.notNull(datastore, "No Datastore specified"); - logger.debug("Initializing deferred close of Datastore Sessions"); - Map> holderMap = deferredCloseHolder.get(); - if (holderMap == null) { - holderMap = new HashMap>(); - deferredCloseHolder.set(holderMap); - } - holderMap.put(datastore, new LinkedHashSet(4)); - } - - /** - * Close the given Session or register it for deferred close. - * @param session the Datastore Session to close - * @param datastore Datastore that the Session was created with - * (may be null) - * @see #initDeferredClose - * @see #processDeferredClose - */ - public static void closeSessionOrRegisterDeferredClose(Session session, Datastore datastore) { - Map> holderMap = deferredCloseHolder.get(); - if (holderMap != null && datastore != null && holderMap.containsKey(datastore)) { - logger.debug("Registering Datastore Session for deferred close"); - holderMap.get(datastore).add(session); - } - else { - closeSession(session); - } - } - - /** - * Execute the closure in the current session if it exists, or create a new one and close it otherwise. - * @param datastore the datastore - * @param c the closure to execute - * @return the return value from the closure - */ - public static Object doWithSession(final Datastore datastore, final Closure c) { - boolean existing = datastore.hasCurrentSession(); - Session session = existing ? datastore.getCurrentSession() : bindSession(datastore.connect()); - try { - return c.call(session); - } - finally { - if (!existing) { - TransactionSynchronizationManager.unbindResource(session.getDatastore()); - closeSessionOrRegisterDeferredClose(session, datastore); - } - } - } - - /** - * Execute the callback in the current session if it exists, or create a new one and close it otherwise. - * @param the return type - * @param datastore the datastore - * @param callback the callback to execute - * @return the return value from the callback - */ - public static T execute(final Datastore datastore, final SessionCallback callback) { - boolean existing = datastore.hasCurrentSession(); - Session session = existing ? datastore.getCurrentSession() : bindSession(datastore.connect()); - try { - return callback.doInSession(session); - } - finally { - if (!existing) { - TransactionSynchronizationManager.unbindResource(session.getDatastore()); - closeSessionOrRegisterDeferredClose(session, datastore); - } - } - } - - /** - * Execute the callback in the current session if it exists, or create a new one and close it otherwise. - * @param datastore the datastore - * @param callback the callback to execute - */ - public static void execute(final Datastore datastore, final VoidSessionCallback callback) { - boolean existing = datastore.hasCurrentSession(); - Session session = existing ? datastore.getCurrentSession() : bindSession(datastore.connect()); - try { - callback.doInSession(session); - } - finally { - if (!existing) { - TransactionSynchronizationManager.unbindResource(datastore); - closeSessionOrRegisterDeferredClose(session, datastore); - } - } - } - - /** - * Bind the session to the thread with a SessionHolder keyed by its Datastore. - * @param session the session - * @return the session (for method chaining) - */ - public static Session bindSession(final Session session) { - TransactionSynchronizationManager.bindResource(session.getDatastore(), new SessionHolder(session)); - return session; - } - - /** - * Adds the session to the current SessionHolder's list of sessions, making it the current session. - * If there's no current session, calls bindSession. - * @param session the session - * @return the session - */ - public static Session bindNewSession(final Session session) { - SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.getResource(session.getDatastore()); - if (sessionHolder == null) { - return bindSession(session); - } - - sessionHolder.addSession(session); - return session; - } - - /** - * Unbinds and closes a session. If it's the only session in the SessionHolder, unbinds - * the SessionHolder, otherwise just removes the session from the holder's list. - * @param session the session - */ - public static void unbindSession(final Session session) { - SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.getResource(session.getDatastore()); - if (sessionHolder == null) { - logger.warn("Cannot unbind session, there's no SessionHolder registered"); - return; - } - - if (!sessionHolder.containsSession(session)) { - logger.warn("Cannot unbind session, it's not registered in a SessionHolder"); - return; - } - - if (sessionHolder.size() > 1) { - sessionHolder.removeSession(session); - } - else { - TransactionSynchronizationManager.unbindResource(session.getDatastore()); - } - - closeSessionOrRegisterDeferredClose(session, session.getDatastore()); - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/EntityCreationException.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/EntityCreationException.java deleted file mode 100644 index 665db05da..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/EntityCreationException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core; - -/** - * Thrown when there was an error creating an entity. - * - * @author Graeme Rocher - * @since 1.0 - */ -public class EntityCreationException extends RuntimeException { - - private static final long serialVersionUID = 1; - - public EntityCreationException(String msg) { - super(msg); - } - - public EntityCreationException(String msg, Throwable throwable) { - super(msg, throwable); - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/IdentityGenerationException.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/IdentityGenerationException.java deleted file mode 100644 index b9bccca5c..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/IdentityGenerationException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core; - -/** - * Thrown when an identity cannot be generated. - * - * @author Graeme Rocher - * @since 1.0 - */ -public class IdentityGenerationException extends RuntimeException { - - private static final long serialVersionUID = 1; - - public IdentityGenerationException(String msg) { - super(msg); - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/OptimisticLockingException.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/OptimisticLockingException.java deleted file mode 100644 index 83c26842b..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/OptimisticLockingException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2011 SpringSource - * - * 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.grails.datastore.mapping.core; - -import org.springframework.dao.OptimisticLockingFailureException; -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * Indicates an optimistic locking violation during an update. - * - * @author Burt Beckwith - * @since 1.0 - */ -public class OptimisticLockingException extends OptimisticLockingFailureException { - - private static final long serialVersionUID = 1; - - private final Object key; - private final PersistentEntity persistentEntity; - - public OptimisticLockingException(final PersistentEntity persistentEntity, final Object key) { - super("The instance was updated by another user while you were editing"); - this.key = key; - this.persistentEntity = persistentEntity; - } - - public PersistentEntity getPersistentEntity() { - return persistentEntity; - } - - public Object getKey() { - return key; - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Session.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Session.java deleted file mode 100644 index 344794e45..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Session.java +++ /dev/null @@ -1,309 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core; - -import java.io.Serializable; -import java.util.List; -import java.util.Map; - -import javax.persistence.FlushModeType; - -import org.grails.datastore.mapping.engine.Persister; -import org.grails.datastore.mapping.model.MappingContext; -import org.grails.datastore.mapping.query.Query; -import org.grails.datastore.mapping.query.api.QueryableCriteria; -import org.grails.datastore.mapping.transactions.Transaction; - -/** - * The Session represents the active interaction with a datastore. - * - * @author Graeme Rocher - * @author Guillaume Laforge - * - * @since 1.0 - */ -@SuppressWarnings("rawtypes") -public interface Session { - - /** - * Associates an attribute with the given persistent entity. Attributes will - * be cleared out when the Session is closed or cleared. - * - * @param entity The persistent instance (must be associated with this Session) - * @param attributeName The attribute name - * @param value The value - */ - void setAttribute(Object entity, String attributeName, Object value); - - /** - * Obtains an attribute for the given entity - * - * @param entity The entity - * @param attributeName The attribute - * @return The attribute value - */ - Object getAttribute(Object entity, String attributeName); - - /** - * Set a property on this session. Note that properties are not cleared out when a session is cleared. - * @param property The property name. - * @param value The property value. - * @return The previous property value, if there was one (or null). - */ - Object setSessionProperty(String property, Object value); - - /** - * Get the value of a property of the session. - * @param property The name of the property. - * @return The value. - */ - Object getSessionProperty(String property); - - /** - * Clear a property in a session. - * @param property The property name. - * @return The property value, if there was one (or null). - */ - Object clearSessionProperty(String property); - - /** - * @return true if connected to the datastore - */ - boolean isConnected(); - - /** - * Disconnects from the datastore. - */ - void disconnect(); - - /** - * Starts a transaction - * @return The transaction - */ - Transaction beginTransaction(); - - /** - * Obtains the MappingContext instance - * - * @return The MappingContext - */ - MappingContext getMappingContext(); - - /** - * Stores and object and returns its key - * - * @param o The object - * @return The the generated key - */ - Serializable persist(Object o); - - /** - * Forces an insert - * - * @param o The object - * @return The id - */ - Serializable insert(Object o); - - /** - * Refreshes the given objects state - * @param o The object to refresh - */ - void refresh(Object o); - - /** - * Attaches an object the current session - * @param o The object to attach - */ - void attach(Object o); - - /** - * Flushes any pending changes to the datastore - */ - void flush(); - - /** - * Clears any pending changes to the datastore - */ - void clear(); - - /** - * Clear a specific object - * @param o The object to clear - */ - void clear(Object o); - - /** - * Whether the object is contained within the first level cache - * @param o The object to check - * @return true if it is - */ - boolean contains(Object o); - - /** - * The flush mode, defaults to FlushModeType.AUTO - * - * @param flushMode The FlushModeType - */ - void setFlushMode(FlushModeType flushMode); - - /** - * Obtains the current FlushModeType - * @return The FlushModeType instance - */ - FlushModeType getFlushMode(); - - /** - * Obtains a write lock on the given object - * - * @param o The object to lock - */ - void lock(Object o); - - /** - * Releases a lock, if not called all locked objects should be released by {@link #disconnect()} - * - * @param o The object to unlock - */ - void unlock(Object o); - - /** - * Persists several objects returning their identifiers in the order specified by the Iterable - * - * @param objects The Objects - * @return The identifiers - */ - List persist(Iterable objects); - - /** - * Retrieves an individual object - * - * @param type The type - * @param key The key - * @return The object - */ - T retrieve(Class type, Serializable key); - - /** - * Retrieves a proxy for the given key - * - * @param type The type - * @param key The key - * @return The object - */ - T proxy(Class type, Serializable key); - - /** - * Retrieves an individual object, using a write lock to prevent loss of updates - * - * @param type The type - * @param key The key - * @return The object - */ - T lock(Class type, Serializable key); - - /** - * Deletes one or many objects - * - * @param objects The objects to delete - */ - void delete(Iterable objects); - - /** - * Deletes a single object - * @param obj The object to delete - */ - void delete(Object obj); - - /** - * Deletes all objects matching the given criteria - * - * @param criteria The criteria - * @return The total number of records deleted - */ - int deleteAll(QueryableCriteria criteria); - - /** - * Updates all objects matching the given criteria and property values - * @param criteria The criteria - * @param properties The properties - * @return The total number of records updated - */ - int updateAll(QueryableCriteria criteria, Map properties); - - /** - * Retrieves several objects for the specified keys - * @param type The type - * @param keys The keys - * @return A list of objects - */ - List retrieveAll(Class type, Iterable keys); - - /** - * Retrieves several objects for the specified keys - * @param type The type - * @param keys The keys - * @return A list of objects - */ - List retrieveAll(Class type, Serializable...keys); - - /** - * Creates a query instance for the give type - * - * @param type The type - * @return The query - */ - Query createQuery(Class type); - - /** - * @return The native interface to the datastore - */ - Object getNativeInterface(); - - /** - * The persister for the given object - * @param o The object - * @return The persister - */ - Persister getPersister(Object o); - - /** - * Obtains the current transaction instance - * @return The Transaction instance - */ - Transaction getTransaction(); - - /** - * The Datastore that created this Session - * @return The Datastore instance - */ - Datastore getDatastore(); - - /** - * Check if the instance has been modified since loading. - * @param instance the instance - * @return true if one or more fields have changed - */ - boolean isDirty(Object instance); - - /** - * Obtains the identifier for the instance - * @param instance The instance - * @return The identifier or null if it cannot be established - */ - Serializable getObjectIdentifier(Object instance); - - -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionCallback.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionCallback.java deleted file mode 100644 index 0e683b218..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionCallback.java +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core; - -import org.grails.datastore.mapping.core.Session; - -/** - * @author Burt Beckwith - * @param - */ -public interface SessionCallback { - T doInSession(Session session); -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionCreationEvent.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionCreationEvent.java deleted file mode 100644 index e8b4ef69d..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionCreationEvent.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.grails.datastore.mapping.core; - -import org.springframework.context.ApplicationEvent; - -/** - * Event fired when a session is created. This can be used to customize the session. - */ -public class SessionCreationEvent extends ApplicationEvent { - - private final Session session; - - public SessionCreationEvent(Session session) { - super(session.getDatastore()); - this.session = session; - } - - /** - * @return The session that has just been created. - */ - public Session getSession() { - return session; - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionImplementor.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionImplementor.java deleted file mode 100644 index 46aca683c..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SessionImplementor.java +++ /dev/null @@ -1,145 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Map; - -import org.grails.datastore.mapping.core.impl.PendingInsert; -import org.grails.datastore.mapping.core.impl.PendingUpdate; -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * Methods for the implementation of the {@link Session} interface to implement. - * - * @author Graeme Rocher - * @since 1.0 - */ -@SuppressWarnings("rawtypes") -public interface SessionImplementor { - - /** - * @return Whether the session is stateless - */ - boolean isStateless(); - - /** - * @return Whether the session is stateless - */ - boolean isStateless(PersistentEntity entity); - - /** - * Adds a pending insert operation - * - * @param insert The pending insert operation - */ - void addPendingInsert(PendingInsert insert); - - /** - * Adds a pending update operation - * @param update The pending update operation - */ - void addPendingUpdate(PendingUpdate update); - - /** - * @return The pending insert operations - */ - Map> getPendingInserts(); - - /** - * @return The pending updates - */ - Map> getPendingUpdates(); - - /** - * @return The pending deletes - */ - Collection getPendingDeletes(); - - /** - * Caches a native entry - * @param entity The entity - * @param key The key - * @param entry The native entry - */ - void cacheEntry(PersistentEntity entity, Serializable key, T entry); - - /** - * Obtains a cached entry - * @param entity The entity - * @param key The key - * @return The cached entry - */ - T getCachedEntry(PersistentEntity entity, Serializable key); - /** - * Obtains a cached entry - * @param entity The entity - * @param key The key - * @param forDirtyCheck Whether to obtain for purposes for dirty checking - * @return The cached entry - */ - T getCachedEntry(PersistentEntity entity, Serializable key, boolean forDirtyCheck); - - /** - * Caches an instance - * @param type The type - * @param key The key - * @param instance The instance - */ - void cacheInstance(Class type, Serializable key, Object instance); - - /** - * Get the cached instance if it exists. - * @param type the object type - * @param key the object key - * @return the instance or null - */ - Object getCachedInstance(Class type, Serializable key); - - /** - * Whether an object with the specified key is contained within the first level cache. - * @param type the object type - * @param key The key to check - * @return true if it is - */ - boolean isCached(Class type, Serializable key); - - /** - * Obtains a cached collection - * - * @param entity The entity - * @param key The key - * @param name The name - * @return The cached collection or null - */ - Collection getCachedCollection(PersistentEntity entity, Serializable key, String name); - - /** - * Caches a collection - * - * @param entity The entity - * @param key The key - * @param collection The collection - * @param name The name of the collection - */ - void cacheCollection(PersistentEntity entity, Serializable key, Collection collection, String name); - - /** - * Adds an operation to be executed after a flush - * @param runnable The runnable - */ - void addPostFlushOperation(Runnable runnable); -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SoftThreadLocalMap.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SoftThreadLocalMap.java deleted file mode 100644 index 9b0c31707..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/SoftThreadLocalMap.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.grails.datastore.mapping.core; - -import org.springframework.util.ConcurrentReferenceHashMap; - -/** - * Creates a InheritableThreadLocal with an intial value of a Map. - * - * @author Graeme Rocher - */ -public class SoftThreadLocalMap extends InheritableThreadLocal { - - /** - * Creates an initial value of a Map. - */ - @Override - protected ConcurrentReferenceHashMap initialValue() { - return new ConcurrentReferenceHashMap(); - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/StatelessDatastore.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/StatelessDatastore.java deleted file mode 100644 index 74cc62be3..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/StatelessDatastore.java +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2013 original authors - * - * 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.grails.datastore.mapping.core; - -/** - * For Datastores that support stateless connectivity - * - * @author Graeme Rocher - * @since 2.3 - */ -public interface StatelessDatastore extends Datastore{ - - /** - * Connect and return a stateless session - * @return The session - */ - Session connectStateless(); -} - diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/VoidSessionCallback.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/VoidSessionCallback.java deleted file mode 100644 index 2c1a00c63..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/VoidSessionCallback.java +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core; - -import org.grails.datastore.mapping.core.Session; - -/** - * @author Burt Beckwith - */ -public interface VoidSessionCallback { - void doInSession(Session session); -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingInsert.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingInsert.java deleted file mode 100644 index 9bcf27634..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingInsert.java +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core.impl; - -import org.grails.datastore.mapping.engine.EntityAccess; - -/** - * An insert that is pending execution in a flush() operation - * - * @param The native entry to persist - * - * @author Graeme Rocher - * @since 1.0 - */ -public interface PendingInsert extends Runnable, PendingOperation{ - /** - * @return The EntityAccess object for the entity to be inserted - */ - EntityAccess getEntityAccess(); -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingInsertAdapter.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingInsertAdapter.java deleted file mode 100644 index 8aa013548..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingInsertAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core.impl; - -import org.grails.datastore.mapping.engine.EntityAccess; -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * Provides default implementation for most of the methods in the {@link PendingInsert} interafce - * - * @param The native entry to persist - * - * @author Graeme Rocher - * @since 1.0 - */ -public abstract class PendingInsertAdapter extends PendingOperationAdapter implements PendingInsert{ - - private EntityAccess entityAccess; - - private boolean vetoed; - - public PendingInsertAdapter(PersistentEntity entity, K nativeKey, E nativeEntry, EntityAccess ea) { - super(entity, nativeKey, nativeEntry); - this.entityAccess = ea; - } - - public boolean isVetoed() { - return vetoed; - } - - public void setVetoed(boolean vetoed) { - this.vetoed = vetoed; - } - - public EntityAccess getEntityAccess() { - return entityAccess; - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperation.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperation.java deleted file mode 100644 index 4a324fa25..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperation.java +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core.impl; - -import java.util.List; - -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * An operation that is pending execution. - * - * @author Graeme Rocher - * - * @param The native entity type (examples could be Row, Document etc.) - * @param The native key - */ -public interface PendingOperation extends Runnable { - - /** - * @return Whether the operation has been vetoed - */ - boolean isVetoed(); - - /** - * @return The {@link PersistentEntity} being inserted - */ - PersistentEntity getEntity(); - - /** - * @return The native key to insert - */ - K getNativeKey(); - - /** - * @return The native entry to persist - */ - E getNativeEntry(); - - /** - * Operations to be executed directly prior to this operation - * @return The operations to execute prior - */ - List> getPreOperations(); - - /** - * Adds an operation to executed prior to other operations - * @param preOperation The prior operation - */ - void addPreOperation(PendingOperation preOperation); - - /** - * Operations to be executed directly following this operation - * @return The operations to cascade to - */ - List> getCascadeOperations(); - - /** - * Adds an operation that should be executed after this operation - * - * @param pendingOperation The pending operation - */ - void addCascadeOperation(PendingOperation pendingOperation); -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperationAdapter.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperationAdapter.java deleted file mode 100644 index 6e5d46797..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperationAdapter.java +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core.impl; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * Base implementation of the {@link PendingOperation} interface. - * - * @author Graeme Rocher - * - * @param The native entity type (examples could be Row, Document etc.) - * @param The native key - */ -public abstract class PendingOperationAdapter implements PendingOperation { - - protected PersistentEntity entity; - protected K nativeKey; - protected E nativeEntry; - private List> pendingOperations = new LinkedList>(); - private List> preOperations = new LinkedList>(); - private boolean vetoed; - - public PendingOperationAdapter(PersistentEntity entity, K nativeKey, E nativeEntry) { - this.entity = entity; - this.nativeKey = nativeKey; - this.nativeEntry = nativeEntry; - } - - public boolean isVetoed() { - return vetoed; - } - - public void setVetoed(boolean vetoed) { - this.vetoed = vetoed; - } - - public List> getPreOperations() { - return Collections.unmodifiableList(preOperations); - } - - public void addPreOperation(PendingOperation preOperation) { - preOperations.add(preOperation); - } - - public List> getCascadeOperations() { - return Collections.unmodifiableList(pendingOperations); - } - - public void addCascadeOperation(PendingOperation pendingOperation) { - pendingOperations.add(pendingOperation); - } - - public K getNativeKey() { - return nativeKey; - } - - public PersistentEntity getEntity() { - return entity; - } - - public E getNativeEntry() { - return nativeEntry; - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperationExecution.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperationExecution.java deleted file mode 100644 index d0ca9e868..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingOperationExecution.java +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core.impl; - -import java.util.List; - -/** - * Provides a default implementation to execute a pending operation. - * - * @author Graeme Rocher - */ -@SuppressWarnings({"rawtypes", "unchecked"}) -public class PendingOperationExecution { - - public static void executePendingOperation(PendingOperation pendingOperation) { - List preOperations = pendingOperation.getPreOperations(); - for (PendingOperation preOperation : preOperations) { - preOperation.run(); - } - pendingOperation.run(); - if(!pendingOperation.isVetoed()) { - List cascadeOperations = pendingOperation.getCascadeOperations(); - for (PendingOperation cascadeOperation : cascadeOperations) { - cascadeOperation.run(); - } - } - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingUpdate.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingUpdate.java deleted file mode 100644 index 5862b3af7..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingUpdate.java +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core.impl; - -import org.grails.datastore.mapping.engine.EntityAccess; - -/** - * An update that is pending execution in a flush() operation - * - * @param The native entry to persist - * @param The native key - * - * @author Graeme Rocher - * @since 1.0 - */ -public interface PendingUpdate extends Runnable, PendingOperation{ - /** - * @return The EntityAccess object for the entity to be inserted - */ - EntityAccess getEntityAccess(); -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingUpdateAdapter.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingUpdateAdapter.java deleted file mode 100644 index a998b4563..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/impl/PendingUpdateAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.core.impl; - -import org.grails.datastore.mapping.engine.EntityAccess; -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * Provides a default implementation for the {@link PendingUpdate} interface - * - * @param The native entry to persist - * - * @author Graeme Rocher - * @since 1.0 - */ -public abstract class PendingUpdateAdapter extends PendingOperationAdapter implements PendingUpdate{ - - private EntityAccess entityAccess; - - private boolean vetoed; - - public PendingUpdateAdapter(PersistentEntity entity, K nativeKey, E nativeEntry, EntityAccess ea) { - super(entity, nativeKey, nativeEntry); - this.entityAccess = ea; - } - - public boolean isVetoed() { - return vetoed; - } - - public void setVetoed(boolean vetoed) { - this.vetoed = vetoed; - } - - public EntityAccess getEntityAccess() { - return entityAccess; - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckable.groovy b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckable.groovy deleted file mode 100644 index 3cd0c165f..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckable.groovy +++ /dev/null @@ -1,52 +0,0 @@ -package org.grails.datastore.mapping.dirty.checking - -/** - * Interface to classes that are able to track changes to their internal state. - * - * - * @author Graeme Rocher - * @since 2.0 - */ -public interface DirtyCheckable { - - /** - * Indicates that the instance should start tacking changes. Note that if the instance is dirty this will clear any previously tracked - * changes - */ - void trackChanges() - - /** - * @return True if the instance has any changes - */ - boolean hasChanged() - - /** - * @param propertyName The name of the property - * @return True if the given property has any changes - */ - boolean hasChanged(String propertyName) - - /** - * Marks this instance as dirty - */ - void markDirty() - - /** - * Marks the given property name as dirty - * @param propertyName The property name - */ - void markDirty(String propertyName) - - /** - * @return A list of the dirty property names - */ - List listDirtyPropertyNames() - - /** - * Returns the original value of the property prior to when {@link #trackChanges()} was called - * - * @param propertyName The property name - * @return The original value - */ - Object getOriginalValue(String propertyName) -} \ No newline at end of file diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckingSupport.groovy b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckingSupport.groovy deleted file mode 100644 index 029d8cda2..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckingSupport.groovy +++ /dev/null @@ -1,77 +0,0 @@ -/* Copyright (C) 2013 original authors - * - * 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.grails.datastore.mapping.dirty.checking - -import groovy.transform.CompileStatic -import org.grails.datastore.mapping.collection.PersistentCollection -import org.grails.datastore.mapping.core.Session -import org.grails.datastore.mapping.model.PersistentEntity -import org.grails.datastore.mapping.model.types.Association -import org.grails.datastore.mapping.model.types.ToOne -import org.grails.datastore.mapping.reflect.ClassPropertyFetcher - -/** - * Support methods for dirty checking - * - * @author Graeme Rocher - * @since 2.0 - */ -@CompileStatic -class DirtyCheckingSupport { - - /** - * Checks whether associations are dirty - * - * @param session The session - * @param entity The entity - * @param instance The instance - * @return True if they are - */ - static boolean areAssociationsDirty(Session session, PersistentEntity entity, Object instance) { - if(!instance) return false - - final proxyFactory = session.mappingContext.proxyFactory - final cpf = ClassPropertyFetcher.forClass(instance.getClass()) - - final associations = entity.associations - for(Association a in associations) { - final isOwner = a.isOwningSide() || (a.bidirectional && !a.inverseSide?.owningSide) - if(isOwner) { - if(a instanceof ToOne) { - final value = cpf.getPropertyValue(instance, a.name) - if(proxyFactory.isInitialized(value)) { - if(value instanceof DirtyCheckingSupport) { - DirtyCheckable dirtyCheckable = (DirtyCheckable) value - if(dirtyCheckable.hasChanged()) { - return true - } - } - } - } - else { - final value = cpf.getPropertyValue(instance, a.name) - if(value instanceof PersistentCollection) { - PersistentCollection coll = (PersistentCollection)value - if(coll.isInitialized()) { - if(coll.isDirty()) return true - } - } - } - - } - } - return false - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/DocumentDatastore.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/DocumentDatastore.java deleted file mode 100644 index 401c5d0e0..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/DocumentDatastore.java +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.document; - -import org.grails.datastore.mapping.core.Datastore; - -/** - * @author Guillaume Laforge - */ -public interface DocumentDatastore extends Datastore {} \ No newline at end of file diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/Attribute.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/Attribute.java deleted file mode 100644 index 8bb036942..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/Attribute.java +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.document.config; - -import org.grails.datastore.mapping.config.Property; - -/** - * Configures how a Java property maps to a Document attribute - * - * @author Graeme Rocher - */ -public class Attribute extends Property { - - public void setAttr(String name) { - setTargetName(name); - } - - public void setAttribute(String name) { - setTargetName(name); - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/Collection.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/Collection.java deleted file mode 100644 index 9a3a6ba2a..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/Collection.java +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.document.config; - -import org.grails.datastore.mapping.config.Entity; - -/** - * Configures how an entity is mapped onto a Document collection - * - * @author Graeme Rocher - */ -public class Collection extends Entity{ - - private String name; - - /** - * The name of the collection - * @return The name of the collection - */ - public String getCollection() { - return name; - } - - /** - * Sets the name of the collection - * @param name The name of the collection - */ - public void setCollection(String name) { - this.name = name; - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/DocumentMappingContext.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/DocumentMappingContext.java deleted file mode 100644 index 8f388fb94..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/DocumentMappingContext.java +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.document.config; - -import groovy.lang.Closure; -import org.grails.datastore.mapping.model.AbstractMappingContext; -import org.grails.datastore.mapping.model.MappingConfigurationStrategy; -import org.grails.datastore.mapping.model.MappingFactory; -import org.grails.datastore.mapping.model.PersistentEntity; -import org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy; -import org.springframework.util.Assert; - -/** - * Models a {@link org.grails.datastore.mapping.model.MappingContext} for a Document store. - * - * @author Graeme Rocher - */ -@SuppressWarnings({"rawtypes", "unchecked"}) -public class DocumentMappingContext extends AbstractMappingContext { - String defaultDatabaseName; - MappingFactory mappingFactory; - - private MappingConfigurationStrategy syntaxStrategy; - private Closure defaultMapping; - - public DocumentMappingContext(String defaultDatabaseName) { - Assert.notNull(defaultDatabaseName, "Argument [defaultDatabaseName] cannot be null"); - this.defaultDatabaseName = defaultDatabaseName; - mappingFactory = createDocumentMappingFactory(null); - syntaxStrategy = new GormMappingConfigurationStrategy(mappingFactory); - } - public DocumentMappingContext(String defaultDatabaseName, Closure defaultMapping) { - Assert.notNull(defaultDatabaseName, "Argument [defaultDatabaseName] cannot be null"); - this.defaultDatabaseName = defaultDatabaseName; - mappingFactory = createDocumentMappingFactory(defaultMapping); - this.defaultMapping = defaultMapping; - syntaxStrategy = new GormMappingConfigurationStrategy(mappingFactory); - } - - public Closure getDefaultMapping() { - return defaultMapping; - } - - protected MappingFactory createDocumentMappingFactory(Closure defaultMapping) { - GormDocumentMappingFactory gormDocumentMappingFactory = new GormDocumentMappingFactory(); - gormDocumentMappingFactory.setDefaultMapping(defaultMapping); - return gormDocumentMappingFactory; - } - - public String getDefaultDatabaseName() { - return defaultDatabaseName; - } - - public MappingConfigurationStrategy getMappingSyntaxStrategy() { - return syntaxStrategy; - } - - @Override - public MappingFactory getMappingFactory() { - return mappingFactory; - } - - @Override - protected PersistentEntity createPersistentEntity(Class javaClass) { - return new DocumentPersistentEntity(javaClass, this); - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/DocumentPersistentEntity.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/DocumentPersistentEntity.java deleted file mode 100644 index 01dafdc70..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/DocumentPersistentEntity.java +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.document.config; - -import org.grails.datastore.mapping.model.AbstractClassMapping; -import org.grails.datastore.mapping.model.AbstractPersistentEntity; -import org.grails.datastore.mapping.model.ClassMapping; -import org.grails.datastore.mapping.model.IdentityMapping; -import org.grails.datastore.mapping.model.MappingContext; -import org.grails.datastore.mapping.model.PersistentEntity; - -public class DocumentPersistentEntity extends AbstractPersistentEntity { - - private DocumentCollectionMapping classMapping; - - public DocumentPersistentEntity(@SuppressWarnings("rawtypes") Class javaClass, MappingContext context) { - super(javaClass, context); - this.classMapping = new DocumentCollectionMapping(this, context); - } - - @SuppressWarnings("unchecked") - @Override - public ClassMapping getMapping() { - return classMapping; - } - - public class DocumentCollectionMapping extends AbstractClassMapping { - private Collection mappedForm; - - private IdentityMapping identityMapping; - public DocumentCollectionMapping(PersistentEntity entity, MappingContext context) { - super(entity, context); - this.mappedForm = (Collection) context.getMappingFactory().createMappedForm(DocumentPersistentEntity.this); - } - @Override - public Collection getMappedForm() { - return mappedForm ; - } - - @Override - public IdentityMapping getIdentifier() { - if (identityMapping == null) { - identityMapping = context.getMappingFactory().createIdentityMapping(this); - } - return identityMapping; - } - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/GormDocumentMappingFactory.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/GormDocumentMappingFactory.java deleted file mode 100644 index d97fe3b23..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/document/config/GormDocumentMappingFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.document.config; - -import org.grails.datastore.mapping.config.AbstractGormMappingFactory; - -public class GormDocumentMappingFactory extends AbstractGormMappingFactory { - - @Override - protected Class getPropertyMappedFormType() { - return Attribute.class; - } - - @Override - protected Class getEntityMappedFormType() { - return Collection.class; - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/AssociationIndexer.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/AssociationIndexer.java deleted file mode 100644 index ac5107647..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/AssociationIndexer.java +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.engine; - -import java.util.List; - -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * Responsible for creating indices for associations used in queries. - * - * An instance may be specific to a particular association of a particular native instance of an entity (the parent - * of the association). - * - * @author Graeme Rocher - * @since 1.0 - */ -public interface AssociationIndexer { - - /** - * Creates an index queryable via the primary key. This is called *before* the entity that this association - * indexer is part of is persisted, but after the native entry has been updated ready to be persisted. - * This allows the index to be placed in the native instance itself, e.g. in a document database. - * - * Usually, for a particular association type, only this OR {@link #index(Object, java.util.List)} will be - * implemented. - * @param primaryKey The primary key - * @param foreignKeys The foreign keys - */ - void preIndex(K primaryKey, List foreignKeys); - - /** - * Creates an index queryable via the primary key. This is called *after* the entity this association indexer - * is part of has been persisted. - * - * Usually, for a particular association type, only this OR {@link #preIndex(Object, java.util.List)} will be - * implemented. - * @param primaryKey The primary key - * @param foreignKeys The foreign keys - */ - void index(K primaryKey, List foreignKeys); - - /** - * Queries the given primary key and returns the foreign keys - * - * @param primaryKey The primary key - * @return The foreign keys - */ - List query(K primaryKey); - - PersistentEntity getIndexedEntity(); - - /** - * Index a single foreign key - * @param primaryKey The primaryKey - * @param foreignKey The foreignKey - */ - void index(T primaryKey, K foreignKey); -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/EntityAccess.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/EntityAccess.java deleted file mode 100644 index dd34d35de..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/EntityAccess.java +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.engine; - -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import org.springframework.beans.BeanWrapper; -import org.springframework.beans.PropertyAccessorFactory; -import org.springframework.core.convert.ConversionService; -import org.grails.datastore.mapping.model.ClassMapping; -import org.grails.datastore.mapping.model.IdentityMapping; -import org.grails.datastore.mapping.model.PersistentEntity; -import org.springframework.util.ReflectionUtils; - -/** - * Class used to access properties of an entity. Also responsible for - * any conversion from source to target types. - * - * @author Graeme Rocher - * @since 1.0 - */ -@SuppressWarnings({"rawtypes", "unchecked"}) -public class EntityAccess { - - private static final Set EXCLUDED_PROPERTIES = new HashSet(Arrays.asList("class", "metaClass")); - - protected Object entity; - protected BeanWrapper beanWrapper; - protected PersistentEntity persistentEntity; - - public EntityAccess(PersistentEntity persistentEntity, Object entity) { - this.entity = entity; - this.persistentEntity = persistentEntity; - beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity); - } - - public Object getEntity() { - return entity; - } - - public void setConversionService(ConversionService conversionService) { - beanWrapper.setConversionService(conversionService); - } - - public Object getProperty(String name) { - return beanWrapper.getPropertyValue(name); - } - - public Class getPropertyType(String name) { - return beanWrapper.getPropertyType(name); - } - - public void setProperty(String name, Object value) { - if(value == null) { - Class type = getPropertyType(name); - if(!type.isPrimitive()) { - beanWrapper.setPropertyValue(name, value); - } - } - else { - beanWrapper.setPropertyValue(name, value); - } - - } - - public Object getIdentifier() { - String idName = getIdentifierName(persistentEntity.getMapping()); - if (idName != null) { - return getProperty(idName); - } - return getProperty(persistentEntity.getIdentity().getName()); - } - - public void setIdentifier(Object id) { - String idName = getIdentifierName(persistentEntity.getMapping()); - setProperty(idName, id); - } - - protected String getIdentifierName(ClassMapping cm) { - final IdentityMapping identifier = cm.getIdentifier(); - if (identifier != null && identifier.getIdentifierName() != null) { - return identifier.getIdentifierName()[0]; - } - return null; - } - - public String getIdentifierName() { - return getIdentifierName(persistentEntity.getMapping()); - } - - public PersistentEntity getPersistentEntity() { - return persistentEntity; - } - - public void setPropertyNoConversion(String name, Object value) { - final PropertyDescriptor pd = beanWrapper.getPropertyDescriptor(name); - if (pd == null) { - return; - } - final Method writeMethod = pd.getWriteMethod(); - if (writeMethod != null) { - ReflectionUtils.invokeMethod(writeMethod, beanWrapper.getWrappedInstance(), value); - } - } - - /** - * Refreshes the object from entity state. - */ - public void refresh() { - final PropertyDescriptor[] descriptors = beanWrapper.getPropertyDescriptors(); - for (PropertyDescriptor descriptor : descriptors) { - final String name = descriptor.getName(); - if (EXCLUDED_PROPERTIES.contains(name)) { - continue; - } - - if (!beanWrapper.isReadableProperty(name) || !beanWrapper.isWritableProperty(name)) { - continue; - } - - Object newValue = getProperty(name); - setProperty(name, newValue); - } - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/EntityPersister.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/EntityPersister.java deleted file mode 100644 index 5a0934144..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/EntityPersister.java +++ /dev/null @@ -1,357 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.engine; - -import java.io.Serializable; -import java.sql.Timestamp; -import java.util.Date; -import java.util.List; - -import org.grails.datastore.mapping.core.Session; -import org.grails.datastore.mapping.engine.event.PostDeleteEvent; -import org.grails.datastore.mapping.engine.event.PostInsertEvent; -import org.grails.datastore.mapping.engine.event.PostLoadEvent; -import org.grails.datastore.mapping.engine.event.PostUpdateEvent; -import org.grails.datastore.mapping.engine.event.PreDeleteEvent; -import org.grails.datastore.mapping.engine.event.PreInsertEvent; -import org.grails.datastore.mapping.engine.event.PreLoadEvent; -import org.grails.datastore.mapping.engine.event.PreUpdateEvent; -import org.grails.datastore.mapping.model.MappingContext; -import org.grails.datastore.mapping.model.PersistentEntity; -import org.grails.datastore.mapping.proxy.ProxyFactory; -import org.springframework.context.ApplicationEventPublisher; - -/** - * A {@link org.grails.datastore.mapping.engine.Persister} specifically for persisting PersistentEntity instances. - * - * @author Graeme Rocher - * @since 1.0 - */ -public abstract class EntityPersister implements Persister { - private PersistentEntity persistentEntity; - private MappingContext mappingContext; - protected Session session; - protected org.grails.datastore.mapping.proxy.ProxyFactory proxyFactory; - protected ApplicationEventPublisher publisher; - - public EntityPersister(MappingContext mappingContext, PersistentEntity entity, - Session session, ApplicationEventPublisher publisher) { - this.persistentEntity = entity; - this.mappingContext = mappingContext; - this.session = session; - this.publisher = publisher; - } - - public Session getSession() { - return session; - } - - @SuppressWarnings("unchecked") - public Object proxy(Serializable key) { - return getProxyFactory().createProxy(session, getPersistentEntity().getJavaClass(), key); - } - - public ProxyFactory getProxyFactory() { - if (proxyFactory == null) { - proxyFactory = mappingContext.getProxyFactory(); - } - return proxyFactory; - } - - /** - * @return The MappingContext instance - */ - public MappingContext getMappingContext() { - return mappingContext; - } - - /** - * @return The PersistentEntity instance - */ - public PersistentEntity getPersistentEntity() { - return persistentEntity; - } - - @SuppressWarnings("rawtypes") - public Class getType() { - return persistentEntity.getJavaClass(); - } - - /** - * Obtains an objects identifer - * @param obj The object - * @return The identifier or null if it doesn't have one - */ - public Serializable getObjectIdentifier(Object obj) { - if (obj == null) return null; - final ProxyFactory pf = getProxyFactory(); - if (pf.isProxy(obj)) { - return pf.getIdentifier(obj); - } - return (Serializable) new EntityAccess(getPersistentEntity(), obj).getIdentifier(); - } - - @Override - public Serializable insert(Object obj) { - if (!persistentEntity.isInstance(obj)) { - final Persister persister = getSession().getPersister(obj); - if (persister == null) { - throw new IllegalArgumentException("Object [" + obj + - "] is not an instance supported by the persister for class [" + - getType().getName() + "]"); - } - - return persister.persist(obj); - } - - return persistEntity(getPersistentEntity(), obj, true); - } - - /** - * Subclasses should override to support explicit inserts - * @param entity The entity - * @param obj The object - * @param isInsert Whether it is an insert - * @return The id - */ - protected Serializable persistEntity(PersistentEntity entity, Object obj, boolean isInsert) { - return persistEntity(entity, obj); - } - - /** - * Obtains an objects identifer - * @param obj The object - */ - public void setObjectIdentifier(Object obj, Serializable id) { - new EntityAccess(getPersistentEntity(), obj).setIdentifier(id); - } - - /** - * Persists an object returning the identifier - * - * @param obj The object to persist - * @return The identifer - */ - public final Serializable persist(Object obj) { - if (!persistentEntity.isInstance(obj)) { - final Persister persister = getSession().getPersister(obj); - if (persister == null) { - throw new IllegalArgumentException("Object [" + obj + - "] is not an instance supported by the persister for class [" + - getType().getName() + "]"); - } - - return persister.persist(obj); - } - - return persistEntity(getPersistentEntity(), obj); - } - - public List persist(@SuppressWarnings("rawtypes") Iterable objs) { - return persistEntities(getPersistentEntity(), objs); - } - - public List retrieveAll(Iterable keys) { - return retrieveAllEntities(getPersistentEntity(), keys); - } - - public List retrieveAll(Serializable[] keys) { - return retrieveAllEntities(getPersistentEntity(), keys); - } - - protected abstract List retrieveAllEntities(PersistentEntity pe, Serializable[] keys); - - protected abstract List retrieveAllEntities(PersistentEntity pe, Iterable keys); - - protected abstract List persistEntities(PersistentEntity pe, @SuppressWarnings("rawtypes") Iterable objs); - - public final Object retrieve(Serializable key) { - if (key == null) { - return null; - } - - PersistentEntity entity = getPersistentEntity(); - - Object o = retrieveEntity(entity, key); - if (o == null) { - return null; - } - - return o; - } - - /** - * Retrieve a PersistentEntity for the given mappingContext and key - * - * @param pe The entity - * @param key The key - * @return The object or null if it doesn't exist - */ - protected abstract Object retrieveEntity(PersistentEntity pe, Serializable key); - - /** - * Persist the given persistent entity - * - * @param pe The PersistentEntity - * @param obj - * @return The generated key - */ - protected abstract Serializable persistEntity(PersistentEntity pe, Object obj); - - public final void delete(@SuppressWarnings("rawtypes") Iterable objects) { - if (objects == null) { - return; - } - - deleteEntities(getPersistentEntity(), objects); - } - - public void delete(Object obj) { - if (obj == null) { - return; - } - - deleteEntity(getPersistentEntity(), obj); - } - - protected abstract void deleteEntity(PersistentEntity pe, Object obj); - - protected abstract void deleteEntities(PersistentEntity pe, @SuppressWarnings("rawtypes") Iterable objects); - - protected EntityAccess createEntityAccess(PersistentEntity pe, Object obj) { - return new EntityAccess(persistentEntity, obj); - } - - protected Object newEntityInstance(PersistentEntity persistentEntity) { - Object o = persistentEntity.newInstance(); - publisher.publishEvent(new PreLoadEvent(session.getDatastore(), getPersistentEntity(), - new EntityAccess(persistentEntity, o))); - return o; - } - - /** - * Fire the beforeInsert even on an entityAccess object and return true if the operation should be cancelled - * @param persistentEntity The entity - * @param entityAccess The entity access - * @return true if the operation should be cancelled - */ - public boolean cancelInsert(final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - PreInsertEvent event = new PreInsertEvent(session.getDatastore(), persistentEntity, entityAccess); - publisher.publishEvent(event); - return event.isCancelled(); - } - - public void firePostInsertEvent(final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - publisher.publishEvent(new PostInsertEvent( - session.getDatastore(), persistentEntity, entityAccess)); - } - - /** - * Fire the beforeUpdate event on an entityAccess object and return true if the operation should be cancelled - * @param persistentEntity The entity - * @param entityAccess The entity access - * @return true if the operation should be cancelled - */ - public boolean cancelUpdate(final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - PreUpdateEvent event = new PreUpdateEvent(session.getDatastore(), persistentEntity, entityAccess); - publisher.publishEvent(event); - return event.isCancelled(); - } - - /** - * Fire the beforeDelete event on an entityAccess object and return true if the operation should be cancelled - * @param persistentEntity The entity - * @param entityAccess The entity access - * @return true if the operation should be cancelled - */ - public boolean cancelDelete( final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - PreDeleteEvent event = new PreDeleteEvent(session.getDatastore(), persistentEntity, entityAccess); - publisher.publishEvent(event); - return event.isCancelled(); - } - - /** - * Fire the beforeDelete event on an entityAccess object and return true if the operation should be cancelled - * @param persistentEntity The entity - * @param entityAccess The entity access - * @return true if the operation should be cancelled - */ - public boolean cancelLoad( final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - PreDeleteEvent event = new PreDeleteEvent(session.getDatastore(), persistentEntity, entityAccess); - publisher.publishEvent(event); - return event.isCancelled(); - } - - public void firePostUpdateEvent(final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - publisher.publishEvent(new PostUpdateEvent( - session.getDatastore(), persistentEntity, entityAccess)); - } - - public void firePostDeleteEvent(final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - publisher.publishEvent(new PostDeleteEvent( - session.getDatastore(), persistentEntity, entityAccess)); - } - - public void firePreLoadEvent(final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - publisher.publishEvent(new PreLoadEvent( - session.getDatastore(), persistentEntity, entityAccess)); - } - - public void firePostLoadEvent(final PersistentEntity persistentEntity, final EntityAccess entityAccess) { - publisher.publishEvent(new PostLoadEvent( - session.getDatastore(), persistentEntity, entityAccess)); - } - - protected boolean isVersioned(final EntityAccess ea) { - - if (!ea.getPersistentEntity().isVersioned()) { - return false; - } - - Class> type = ea.getPropertyType("version"); - return Number.class.isAssignableFrom(type) || Date.class.isAssignableFrom(type); - } - - protected void incrementVersion(final EntityAccess ea) { - if (Number.class.isAssignableFrom(ea.getPropertyType("version"))) { - Number currentVersion = (Number) ea.getProperty("version"); - if (currentVersion == null) { - currentVersion = 0L; - } - ea.setProperty("version", currentVersion.longValue() + 1); - } - else { - setDateVersion(ea); - } - } - - protected void setVersion(final EntityAccess ea) { - if (Number.class.isAssignableFrom(ea.getPropertyType("version"))) { - ea.setProperty("version", 0); - } - else { - setDateVersion(ea); - } - } - - protected void setDateVersion(final EntityAccess ea) { - if (Timestamp.class.isAssignableFrom(ea.getPropertyType("version"))) { - ea.setProperty("version", new Timestamp(System.currentTimeMillis())); - } - else { - ea.setProperty("version", new Date()); - } - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/LockableEntityPersister.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/LockableEntityPersister.java deleted file mode 100644 index bbf5bc95a..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/LockableEntityPersister.java +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.engine; - -import java.io.Serializable; - -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.dao.CannotAcquireLockException; -import org.grails.datastore.mapping.core.Session; -import org.grails.datastore.mapping.model.MappingContext; -import org.grails.datastore.mapping.model.PersistentEntity; - -/** - * Abstract base class for entity persisters that support locking. - * - * @author Graeme Rocher - * @since 1.0 - */ -public abstract class LockableEntityPersister extends EntityPersister { - - public static int DEFAULT_TIMEOUT = 30; - - public LockableEntityPersister(MappingContext mappingContext, PersistentEntity entity, - Session session, ApplicationEventPublisher publisher) { - super(mappingContext, entity, session, publisher); - } - - /** - * Locks an object for the given identifier returning the locked instance - * - * @param id The identifier - * @return The locked object - * @throws CannotAcquireLockException Thrown if a lock couldn't be acquired before the default timeout elapsed - */ - public abstract Object lock(Serializable id) throws CannotAcquireLockException; - - /** - * Acquire a lock using the given identifier and timeout delay - * @param id the identifier - * @param timeout the amount of time to wait before giving up in seconds - * @return The locked object - * @throws CannotAcquireLockException - */ - public abstract Object lock(Serializable id, int timeout) throws CannotAcquireLockException; - - /** - * Return whether an object is locked or not - * @param o The object - * @return True if it is locked - */ - public abstract boolean isLocked(Object o); - - /** - * Unlocks a locked object - * @param o The object to unlock - */ - public abstract void unlock(Object o); - - @Override - @SuppressWarnings("unchecked") - public Object proxy(Serializable key) { - return getProxyFactory().createProxy(session, getPersistentEntity().getJavaClass(), key); - } -} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/NativeEntryEntityPersister.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/NativeEntryEntityPersister.java deleted file mode 100755 index cadc6ccbb..000000000 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/NativeEntryEntityPersister.java +++ /dev/null @@ -1,1812 +0,0 @@ -/* Copyright (C) 2010 SpringSource - * - * 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.grails.datastore.mapping.engine; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; - -import javax.persistence.CascadeType; -import javax.persistence.FetchType; -import javax.persistence.FlushModeType; - -import org.grails.datastore.mapping.cache.TPCacheAdapter; -import org.grails.datastore.mapping.cache.TPCacheAdapterRepository; -import org.grails.datastore.mapping.collection.AbstractPersistentCollection; -import org.grails.datastore.mapping.collection.PersistentCollection; -import org.grails.datastore.mapping.collection.PersistentList; -import org.grails.datastore.mapping.collection.PersistentSet; -import org.grails.datastore.mapping.collection.PersistentSortedSet; -import org.grails.datastore.mapping.config.Property; -import org.grails.datastore.mapping.core.Session; -import org.grails.datastore.mapping.core.SessionImplementor; -import org.grails.datastore.mapping.core.impl.PendingInsert; -import org.grails.datastore.mapping.core.impl.PendingInsertAdapter; -import org.grails.datastore.mapping.core.impl.PendingOperation; -import org.grails.datastore.mapping.core.impl.PendingOperationAdapter; -import org.grails.datastore.mapping.core.impl.PendingOperationExecution; -import org.grails.datastore.mapping.core.impl.PendingUpdate; -import org.grails.datastore.mapping.core.impl.PendingUpdateAdapter; -import org.grails.datastore.mapping.dirty.checking.DirtyCheckable; -import org.grails.datastore.mapping.engine.event.PreDeleteEvent; -import org.grails.datastore.mapping.engine.internal.MappingUtils; -import org.grails.datastore.mapping.engine.types.CustomTypeMarshaller; -import org.grails.datastore.mapping.model.ClassMapping; -import org.grails.datastore.mapping.model.EmbeddedPersistentEntity; -import org.grails.datastore.mapping.model.MappingContext; -import org.grails.datastore.mapping.model.PersistentEntity; -import org.grails.datastore.mapping.model.PersistentProperty; -import org.grails.datastore.mapping.model.PropertyMapping; -import org.grails.datastore.mapping.model.types.Association; -import org.grails.datastore.mapping.model.types.Basic; -import org.grails.datastore.mapping.model.types.Custom; -import org.grails.datastore.mapping.model.types.Embedded; -import org.grails.datastore.mapping.model.types.EmbeddedCollection; -import org.grails.datastore.mapping.model.types.ManyToMany; -import org.grails.datastore.mapping.model.types.OneToMany; -import org.grails.datastore.mapping.model.types.Simple; -import org.grails.datastore.mapping.model.types.ToOne; -import org.grails.datastore.mapping.proxy.ProxyFactory; -import org.grails.datastore.mapping.query.Query; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.core.convert.ConversionService; -import org.springframework.dao.CannotAcquireLockException; - -/** - * Provides an implementation of the {@link org.grails.datastore.mapping.engine.EntityPersister} class that - * reads and writes against a native datastore type specified by the generic type parameter T - * - * @author Graeme Rocher - * @since 1.0 - */ -@SuppressWarnings({"unused", "rawtypes", "unchecked"}) -public abstract class NativeEntryEntityPersister extends LockableEntityPersister { - protected ClassMapping classMapping; - protected TPCacheAdapterRepository cacheAdapterRepository; - - public NativeEntryEntityPersister(MappingContext mappingContext, PersistentEntity entity, - Session session, ApplicationEventPublisher publisher) { - super(mappingContext, entity, session, publisher); - classMapping = entity.getMapping(); - } - - public NativeEntryEntityPersister(MappingContext mappingContext, PersistentEntity entity, - Session session, ApplicationEventPublisher publisher, TPCacheAdapterRepository cacheAdapterRepository) { - super(mappingContext, entity, session, publisher); - classMapping = entity.getMapping(); - this.cacheAdapterRepository = cacheAdapterRepository; - } - - public abstract String getEntityFamily(); - - public ClassMapping getClassMapping() { - return classMapping; - } - - /** - * Subclasses should override to optimize away manual property indexing if it is not required - * - * @return True if property indexing is required (the default) - */ - protected boolean doesRequirePropertyIndexing() { return true; } - - @Override - protected void deleteEntity(PersistentEntity persistentEntity, Object obj) { - if (obj == null) { - return; - } - - EntityAccess entityAccess = createEntityAccess(persistentEntity, obj); - PreDeleteEvent event = new PreDeleteEvent(session.getDatastore(), persistentEntity, entityAccess); - publisher.publishEvent(event); - if (event.isCancelled()) { - return; - } - - final K key = readIdentifierFromObject(obj); - if (key == null) { - return; - } - - FlushModeType flushMode = session.getFlushMode(); - try { - session.setFlushMode(FlushModeType.COMMIT); - cascadeBeforeDelete(persistentEntity, entityAccess, key, obj); - deleteEntry(getEntityFamily(), key, obj); - cascadeAfterDelete(persistentEntity, entityAccess, key, obj); - } - finally { - session.setFlushMode(flushMode); - } - - firePostDeleteEvent(persistentEntity, entityAccess); - } - - protected void cascadeDeleteCollection(EntityAccess entityAccess, Association association) { - Object propValue = entityAccess.getProperty(association.getName()); - if (!(propValue instanceof Collection)) { - return; - } - Collection collection = ((Collection) propValue); - for (Iterator iter = collection.iterator(); iter.hasNext(); ) { - Object child = iter.next(); - deleteEntity(getMappingContext().getPersistentEntity(child.getClass().getName()), child); - iter.remove(); - } - } - - @Override - protected EntityAccess createEntityAccess(PersistentEntity persistentEntity, Object obj) { - EntityAccess entityAccess = new EntityAccess(persistentEntity, obj); - entityAccess.setConversionService(getMappingContext().getConversionService()); - return entityAccess; - } - - protected EntityAccess createEntityAccess(PersistentEntity persistentEntity, Object obj, final T nativeEntry) { - final NativeEntryModifyingEntityAccess ea = new NativeEntryModifyingEntityAccess(persistentEntity, obj); - ea.setConversionService(getMappingContext().getConversionService()); - ea.setNativeEntry(nativeEntry); - return ea; - } - - /** - * Deletes a single entry - * - * @param family The family - * @param key The key - * @param entry the entry - */ - protected abstract void deleteEntry(String family, K key, Object entry); - - /** - * Delete collections before owner delete. - */ - protected void cascadeBeforeDelete(PersistentEntity persistentEntity, EntityAccess entityAccess, - K key, Object instance) { - - List props = persistentEntity.getPersistentProperties(); - for (PersistentProperty prop : props) { - String propertyKey = getPropertyKey(prop); - - if (prop instanceof OneToMany) { - OneToMany oneToMany = (OneToMany)prop; - if (oneToMany.isOwningSide() && oneToMany.doesCascade(CascadeType.REMOVE)) { - if (Collection.class.isAssignableFrom(oneToMany.getType())) { - cascadeDeleteCollection(entityAccess, oneToMany); - } - } - } - else if (prop instanceof ManyToMany) { - ManyToMany manyToMany = (ManyToMany)prop; - if (manyToMany.isOwningSide() && manyToMany.doesCascade(CascadeType.REMOVE)) { - Object propValue = entityAccess.getProperty(manyToMany.getName()); - if (Collection.class.isAssignableFrom(manyToMany.getType())) { - cascadeDeleteCollection(entityAccess, manyToMany); - } - } - } - } - } - - /** - * Delete many-to-ones after owner delete. - */ - protected void cascadeAfterDelete(PersistentEntity persistentEntity, EntityAccess entityAccess, - K key, Object instance) { - - List props = persistentEntity.getPersistentProperties(); - for (PersistentProperty prop : props) { - String propertyKey = getPropertyKey(prop); - if (prop instanceof Basic) { - Object propValue = entityAccess.getProperty(prop.getName()); - } - else if (prop instanceof OneToMany) { - OneToMany oneToMany = (OneToMany)prop; - if (oneToMany.isOwningSide() && oneToMany.doesCascade(CascadeType.REMOVE)) { - if (Collection.class.isAssignableFrom(oneToMany.getType())) { - cascadeDeleteCollection(entityAccess, oneToMany); - } - } - } - else if (prop instanceof ToOne) { - ToOne association = (ToOne) prop; - if (!(prop instanceof Embedded) && !(prop instanceof EmbeddedCollection) && - association.doesCascade(CascadeType.REMOVE)) { - if (association.isOwningSide()) { - Object value = entityAccess.getProperty(association.getName()); - if (value != null) { - Persister persister = session.getPersister(value); - if (persister != null) { - persister.delete(value); - } - } - } - } - } - } - } - - @Override - protected final void deleteEntities(PersistentEntity persistentEntity, Iterable objects) { - if (objects != null) { - final Set
getSession
releaseSession
false
null