Conversation
…etting rid of hibernate annotations; cleaning up code and tests; added new test to test PK/ID generation
Since we move all UUID generation into the model, what about the reset https://github.com/aerogear/aerogear-unifiedpush-server/blob/UUID_Generation/src/main/java/org/jboss/aerogear/unifiedpush/rest/registry/applications/AbstractVariantEndpoint.java#L64 ? |
@@ -44,8 +44,6 @@ | |||
/** | |||
* Identifier used to register variants with this PushApplication | |||
*/ | |||
void setPushApplicationID(String pushApplicationID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep setters? They are handy/needed for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpiwko done
@sebastienblanc not sure; the set(Master)Secret() would be still there |
public PersistentObject() { | ||
id = UUID.randomUUID().toString(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could move initialisation to the field:
private String id = UUID.randomUUID().toString();
@GenericGenerator(name = "system-uuid", strategy = "uuid") | ||
@Column(name = "id", updatable = false, nullable = false) | ||
private String id = null; | ||
private String id = UUID.randomUUID().toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Premature optimization is evil - but could not resist here ;-)
UUID.randomUUID() is quite expensive operation, wouldn't it be possible to skip generation for entity creation when field is actually retrieved from DB? Same holds for other UUID generations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpiwko the id is generated when the class is loaded, putting it in the getter will delay the generation by milliseconds / maybe less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the point was to generate only if null - so generation would not happen if id is retrieved from database. Current impl wil generate UUID and then replace it with value stored in database. See https://issues.jboss.org/browse/AGPUSH-444
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your right that is waste of cpu power we could change it, but then we would have to tell jpa to use the getter instead of the field, like this:
private String id = null;
@Id
public String getId() {
if (id == null) {
id = UUID.randomUUID().toString();
}
return this.id;
}
but then I get an error in the test MappingException: Could not determine type for: java.util.Set, at table: AbstractVariant, for columns: [org.hibernate.mapping.Column(installations)]
So let's leave that as an issue for possible improvement
oops wrong button |
Was done for: