You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2010/11/10 23:35:07 UTC

svn commit: r1033767 - in /cayenne/sandbox/cayenne-mixin/trunk: ./ src/main/java/org/apache/cayenne/mixin/audit/

Author: aadamchik
Date: Wed Nov 10 22:35:07 2010
New Revision: 1033767

URL: http://svn.apache.org/viewvc?rev=1033767&view=rev
Log:
generic abstract auditable mixin

Added:
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AbstractAuditableMixinHandler.java
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/Auditable.java
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AuditableOperation.java
Modified:
    cayenne/sandbox/cayenne-mixin/trunk/.classpath
    cayenne/sandbox/cayenne-mixin/trunk/pom.xml

Modified: cayenne/sandbox/cayenne-mixin/trunk/.classpath
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/.classpath?rev=1033767&r1=1033766&r2=1033767&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/.classpath (original)
+++ cayenne/sandbox/cayenne-mixin/trunk/.classpath Wed Nov 10 22:35:07 2010
@@ -2,7 +2,7 @@
 <classpath>
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

Modified: cayenne/sandbox/cayenne-mixin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/pom.xml?rev=1033767&r1=1033766&r2=1033767&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/pom.xml (original)
+++ cayenne/sandbox/cayenne-mixin/trunk/pom.xml Wed Nov 10 22:35:07 2010
@@ -8,7 +8,7 @@
 		<version>3.1-SNAPSHOT</version>
 	</parent>
 	<artifactId>cayenne-mixin</artifactId>
-	<version>3.1.0.2</version>
+	<version>3.1.0.3</version>
 	<name>Library: cayenne-mixin</name>
 	<packaging>jar</packaging>
 	<properties>

Added: cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AbstractAuditableMixinHandler.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AbstractAuditableMixinHandler.java?rev=1033767&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AbstractAuditableMixinHandler.java (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AbstractAuditableMixinHandler.java Wed Nov 10 22:35:07 2010
@@ -0,0 +1,75 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.cayenne.mixin.audit;
+
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.LifecycleEvent;
+import org.apache.cayenne.mixin.MixinHandler;
+import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
+
+/**
+ * A superclass of application specific handlers of the {@link Auditable} mixin
+ * that provides basic needed callbacks.
+ */
+public abstract class AbstractAuditableMixinHandler implements
+		MixinHandler<Auditable> {
+
+	protected EntityResolver entityResolver;
+
+	public AbstractAuditableMixinHandler(EntityResolver entityResolver) {
+		this.entityResolver = entityResolver;
+	}
+
+	@Override
+	public Class<Auditable> getMixinType() {
+		return Auditable.class;
+	}
+
+	@Override
+	public void addMixin(Class<? extends DataObject> type) {
+
+		LifecycleCallbackRegistry registry = entityResolver
+				.getCallbackRegistry();
+		registry.addListener(LifecycleEvent.POST_PERSIST, type, this,
+				"insertAudit");
+		registry.addListener(LifecycleEvent.POST_REMOVE, type, this,
+				"deleteAudit");
+		registry.addListener(LifecycleEvent.POST_UPDATE, type, this,
+				"updateAudit");
+	}
+
+	/**
+	 * A worker method that creates audit records, as appropriate in a given
+	 * application. Subclasses may insert audit records, log a message, etc.
+	 */
+	protected abstract void audit(Object object, AuditableOperation operation);
+
+	void insertAudit(Object object) {
+		audit(object, AuditableOperation.INSERT);
+	}
+
+	void deleteAudit(Object object) {
+		audit(object, AuditableOperation.DELETE);
+	}
+
+	void updateAudit(Object object) {
+		audit(object, AuditableOperation.UPDATE);
+	}
+}

Added: cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/Auditable.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/Auditable.java?rev=1033767&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/Auditable.java (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/Auditable.java Wed Nov 10 22:35:07 2010
@@ -0,0 +1,41 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.cayenne.mixin.audit;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.cayenne.mixin.ref.Referenceable;
+
+/**
+ * A built-in mixin annotation that adds auditable behavior to DataObjects. All
+ * Auditable objects must be also tagged with {@link Referenceable} annotation,
+ * as audit records are based on UUIDs.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+public @interface Auditable {
+
+}

Added: cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AuditableOperation.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AuditableOperation.java?rev=1033767&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AuditableOperation.java (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/audit/AuditableOperation.java Wed Nov 10 22:35:07 2010
@@ -0,0 +1,9 @@
+package org.apache.cayenne.mixin.audit;
+
+/**
+ * An enum of auditable operations.
+ */
+public enum AuditableOperation {
+
+	INSERT, UPDATE, DELETE;
+}