You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/09/16 15:13:05 UTC

svn commit: r815755 - in /labs/magma/trunk: database-jpa/src/main/java/org/apache/magma/database/openjpa/ foundation-database/src/main/java/org/apache/magma/database/

Author: simoneg
Date: Wed Sep 16 13:13:04 2009
New Revision: 815755

URL: http://svn.apache.org/viewvc?rev=815755&view=rev
Log:
LABS-409 : id is common to all databases, not just jpa

Added:
    labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/InstallIdByDefault.aj
    labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/NoId.java
Removed:
    labs/magma/trunk/database-jpa/src/main/java/org/apache/magma/database/openjpa/InstallIdByDefault.aj
    labs/magma/trunk/database-jpa/src/main/java/org/apache/magma/database/openjpa/NoId.java

Added: labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/InstallIdByDefault.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/InstallIdByDefault.aj?rev=815755&view=auto
==============================================================================
--- labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/InstallIdByDefault.aj (added)
+++ labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/InstallIdByDefault.aj Wed Sep 16 13:13:04 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.magma.database;
+
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.EmbeddedId;
+
+import org.apache.magma.beans.MagReadOnly;
+
+/**
+ * Adds by default an id to those entities that does not have it.
+ *
+ * @author Simone Gianni <si...@apache.org>
+ */
+public aspect InstallIdByDefault {
+
+	/**
+	 * Marker interface for beans receiving the default id.
+	 *
+	 * @author Simone Gianni <si...@apache.org>
+	 */
+	public static interface WithDefaultId {
+		
+	}
+	
+	// TODO commented to avoid AspectJ bug
+	//declare parents : ((@Entity *) && !(@NoId *) && !hasmethod(@(Id||EmbeddedId) public * get*()) && !hasfield(@(Id||EmbeddedId) * *)) implements WithDefaultId;
+	declare parents : ((@Entity *) && !(@NoId *)) implements WithDefaultId;
+	
+	/**
+	 * The default provided id field.
+	 */
+	private long WithDefaultId.id;
+	
+	/**
+	 * Getter for the default id.
+	 * @return The entity id.
+	 */
+	@Id
+	@GeneratedValue
+	public long WithDefaultId.getId() {
+		return id;
+	}
+	
+	/**
+	 * Setter for the default id.
+	 * @param newId The entity id.
+	 */
+	@MagReadOnly
+	public void WithDefaultId.setId(long newId) {
+		id = newId;
+	}
+	
+}

Added: labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/NoId.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/NoId.java?rev=815755&view=auto
==============================================================================
--- labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/NoId.java (added)
+++ labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/NoId.java Wed Sep 16 13:13:04 2009
@@ -0,0 +1,21 @@
+package org.apache.magma.database;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * Use this annotation on {@link Entity} beans that does not have an {@link Id} and should
+ * not receive the default one.
+ *
+ * @author Simone Gianni <si...@apache.org>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface NoId {
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org