Author: simoneg
Date: Sun Jan 24 19:40:00 2010
New Revision: 902629
URL: http://svn.apache.org/viewvc?rev=902629&view=rev
Log:
Support setting the primary key
Modified:
labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/DatabaseIdentity.java
Modified:
labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/DatabaseIdentity.java
URL:
http://svn.apache.org/viewvc/labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/DatabaseIdentity.java?rev=902629&r1=902628&r2=902629&view=diff
==============================================================================
---
labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/DatabaseIdentity.java
(original)
+++
labs/magma/trunk/foundation-database/src/main/java/org/apache/magma/database/DatabaseIdentity.java
Sun Jan 24 19:40:00 2010
@@ -90,16 +90,39 @@
try {
idval = idgetter.invoke(value);
} catch (Exception e) {
- throw new MagmaException("Error accessing the
field {0}.{1}, which is key for the class {2}",
idfield.getDeclaringClass().getName(), idfield.getName(), myclass.getName());
+ throw new MagmaException("Error accessing the
method {0}.{1}, which is key for the class {2}", idgetter.getDeclaringClass(),
idgetter.getName(), myclass.getName());
}
} else if (idfield != null) {
try {
idval = idfield.get(value);
} catch (Exception e) {
- throw new MagmaException("Error accessing the
field {0}.{1}, which is key for the class {2}",
idfield.getDeclaringClass().getName(), idfield.getName(), myclass.getName());
+ throw new MagmaException("Error accessing the
field {0}.{1}, which is key for the class {2}", idfield.getDeclaringClass(),
idfield.getName(), myclass.getName());
}
}
return idval;
}
+ public void setPrimaryKey(DatabasePersisted bean, Object value) {
+ if (idfield != null) {
+ try {
+ idval = idfield.set(bean, value);
+ return;
+ } catch (Exception e) {
+ throw new MagmaException("Error setting the
field {0}.{1}, which is key for the class {2}",
idfield.getDeclaringClass().getName(), idfield.getName(), myclass.getName());
+ }
+ }
+ if (idgetter != null) {
+ String name = idgetter.getName();
+ if (name.startsWith("get")) name = name.substring(3);
+ name = "set" + name;
+ try {
+ Method method = this.myclass.getMethod(name,
value.getClass());
+ method.invoke(bean, value);
+ return;
+ } catch (Exception e) {
+ throw new MagmaException("Error callong method
{0}.{1}, which is key setter for the class {2}", idgetter.getDeclaringClass(),
name, myclass.getName());
+ }
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]