Commit d08dbee8 by Antti Tönkyrä

Merge branch 'feature/meta-rest-and-db' into 'master'

Feature/meta rest and db

The META REST API:

Setting:
curl -XPOST -H 'Content-Type: application/json' --data-ascii '{"setting-a":1}' http://localhost:8080/MoyaWeb/rest/meta/printedcard/2247/module1-settings
curl -XPOST -H 'Content-Type: application/json' --data-ascii '{"type":"ladyfit", "size":"S"}' http://localhost:8080/MoyaWeb/rest/meta/printedcard/2247/shirt-preference

Getting:
curl http://localhost:8080/MoyaWeb/rest/meta/printedcard/2247/ => {"shirt-preference":{"type":...,"size":...}}
curl http://localhost:8080/MoyaWeb/rest/meta/printedcard/2247/shirt-preference => {"type":...,"size":...}
curl http://localhost:8080/MoyaWeb/rest/meta/printedcard/2247/foo/bar

ALSO:
- Fixed Changed Fields Optimistic Locking policy to NOT to try compare JSON fields on UPDATE (cannot compare json objects in PostgreSQL, tries to do UPDATE table SET meta='{"foo":1}' WHERE id = 23 AND meta = '{"foo":2}'; or so and explodes)
- Fixed Returning Policy to do INSERT ... RETURNING id;
- BROKER DDL GENERATION: does not currently do "id SERIAL" but "id INTEGER" because eclipselink assumes too much.
2 parents d5b147cf ba9d9ad6
Showing with 710 additions and 413 deletions
eclipse.preferences.version=1 eclipse.preferences.version=1
entitygen.DEFAULT_PACKAGE=model
org.eclipse.jpt.core.discoverAnnotatedClasses=true org.eclipse.jpt.core.discoverAnnotatedClasses=true
org.eclipse.jpt.core.platform=eclipselink2_5 org.eclipse.jpt.core.platform=eclipselink2_5
org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true
......
...@@ -60,7 +60,18 @@ ...@@ -60,7 +60,18 @@
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version> <version>9.3-1101-jdbc41</version>
</dependency>
<dependency>
<groupId>org.ancoron.postgresql</groupId>
<artifactId>org.postgresql.net</artifactId>
<version>9.1.901.jdbc4.1-rc9</version>
<exclusions>
<exclusion>
<artifactId>org.postgresql</artifactId>
<groupId>org.ancoron.postgresql</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -12,14 +12,13 @@ ...@@ -12,14 +12,13 @@
<property name="eclipselink.logging.logger" value="ServerLogger" /> <property name="eclipselink.logging.logger" value="ServerLogger" />
<property name="eclipselink.jdbc.uppercase-columns" value="false" /> <property name="eclipselink.jdbc.uppercase-columns" value="false" />
<property name="eclipselink.target-database" <property name="eclipselink.target-database"
value="fi.codecrew.moya.database.MoyaPostgreSQLPlatform" /> value="fi.codecrew.moya.database.eclipselink.MoyaPostgreSQLPlatform" />
<property name="eclipselink.session-event-listener" <property name="eclipselink.create-ddl-jdbc-file-name" value="moyaCreateDDL.sql" />
value="org.ancoron.postgresql.jpa.eclipselink.ConverterInitializer" /> <property name="eclipselink.drop-ddl-jdbc-file-name" value="moyaDropDDL.sql" />
<property name="eclipselink.descriptor.customizer" <property name="eclipselink.target-server" value="Glassfish" />
value="fi.codecrew.moya.database.MoyaDescriptorCustomizer" /> <property name="eclipselink.session.customizer"
<property name="eclipselink.create-ddl-jdbc-file-name" value="moyaCreateDDL.sql"/> value="fi.codecrew.moya.database.eclipselink.MoyaSessionCustomizer" />
<property name="eclipselink.drop-ddl-jdbc-file-name" value="moyaDropDDL.sql"/>
</properties> </properties>
</persistence-unit> </persistence-unit>
</persistence> </persistence>
package fi.codecrew.moya.database.eclipselink;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.persistence.descriptors.ChangedFieldsLockingPolicy;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.internal.helper.DatabaseTable;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Filters out JSON fields from Optimistic Locking policy that checks changed
* fields. JSON fields in PostgreSQL cannot be compared.
*
* @author jkj
*
*/
public class MoyaChangedFieldsOptimisticLockingPolicy extends ChangedFieldsLockingPolicy {
private static final long serialVersionUID = -1951931955910848024L;
private static final Logger log = LoggerFactory.getLogger(MoyaChangedFieldsOptimisticLockingPolicy.class);
/**
* Skip PGobject from ChangedFieldsLockingPolicy. PostgreSQL does not now
* how to compare JSON column, and this was the easiest way to work around
* it.
*/
@Override
protected List<DatabaseField> getFieldsToCompare(DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow) {
// log.info("getFieldsToCompare({}, {}, {})", table, transRow,
// modifyRow);
List<DatabaseField> changedFields = super.getFieldsToCompare(table, transRow, modifyRow);
ArrayList<DatabaseField> fieldsToCompare = new ArrayList<DatabaseField>(changedFields.size());
// Filter out JSON fields because they cannot be compared
for (DatabaseField f : changedFields) {
// log.info("Field with typeName={}: {}", f.toString(),
// f.getTypeName());
if (!f.getTypeName().equals("org.postgresql.util.PGobject")) {
log.debug("Ignoring a PGobject field from changed fields optimistic locking policy: {}", f);
fieldsToCompare.add(f);
}
}
return fieldsToCompare;
}
}
package fi.codecrew.moya.database; package fi.codecrew.moya.database.eclipselink;
import java.util.List; import java.util.List;
import org.eclipse.persistence.config.DescriptorCustomizer; import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ChangedFieldsLockingPolicy;
import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.ReturningPolicy; import org.eclipse.persistence.descriptors.ReturningPolicy;
import org.eclipse.persistence.internal.helper.DatabaseField; import org.eclipse.persistence.internal.helper.DatabaseField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MoyaDescriptorCustomizer implements DescriptorCustomizer { public class MoyaDescriptorCustomizer implements DescriptorCustomizer {
private static final Logger log = LoggerFactory.getLogger(MoyaDescriptorCustomizer.class);
@Override
public void customize(ClassDescriptor descriptor) throws Exception { @Override
public void customize(ClassDescriptor descriptor) throws Exception {
// Optimistic locking policy log.info("Customizing Descriptor: {}", descriptor);
ChangedFieldsLockingPolicy changedFieldsLockingPolicy = new ChangedFieldsLockingPolicy();
descriptor.setOptimisticLockingPolicy(changedFieldsLockingPolicy); // Optimistic locking policy
MoyaChangedFieldsOptimisticLockingPolicy changedFieldsLockingPolicy = new MoyaChangedFieldsOptimisticLockingPolicy();
// Returningpolicy // log.debug("Setting Optimistic Locking Policy: {}",
ReturningPolicy returningPolicy = new ReturningPolicy(); // changedFieldsLockingPolicy);
descriptor.setOptimisticLockingPolicy(changedFieldsLockingPolicy);
List<DatabaseField> pkFields = descriptor.getPrimaryKeyFields();
for (final DatabaseField field : pkFields) { // ReturningPolicy
returningPolicy.addFieldForInsertReturnOnly(field); ReturningPolicy returningPolicy = new ReturningPolicy();
field.setUpdatable(false); descriptor.setReturningPolicy(returningPolicy);
field.setInsertable(false);
} /*
* // generation strategy IDENTITY has sequence number field
for (final DatabaseField field : descriptor.getFields()) { * DatabaseField seqNumberField = descriptor.getSequenceNumberField();
* if (seqNumberField != null) {
if (pkFields.contains(field)) * returningPolicy.addFieldForInsertReturnOnly(seqNumberField); }
continue; */
returningPolicy.addFieldForInsert(field); List<DatabaseField> pkFields = descriptor.getPrimaryKeyFields();
returningPolicy.addFieldForUpdate(field); for (final DatabaseField field : pkFields) {
} returningPolicy.addFieldForInsertReturnOnly(field);
field.setUpdatable(false);
descriptor.setReturningPolicy(returningPolicy); field.setInsertable(false);
} }
/*
* for (final DatabaseField field : descriptor.getFields()) {
*
* if (pkFields.contains(field)) continue;
*
* returningPolicy.addFieldForInsert(field);
* returningPolicy.addFieldForUpdate(field); }
*/
// log.info("Set descriptor's RETURNING policy to: {}",
// returningPolicy);
}
} }
package fi.codecrew.moya.database; package fi.codecrew.moya.database.eclipselink;
import java.util.Hashtable; import java.util.Hashtable;
import org.ancoron.postgresql.jpa.eclipselink.ExtendedPostgreSQLPlatform;
import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition; import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
import org.eclipse.persistence.platform.database.PostgreSQLPlatform; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MoyaPostgreSQLPlatform extends PostgreSQLPlatform { /**
private static final long serialVersionUID = 6351395815598077327L; * Smarter defaults. Use TEXT for string columns and understand JSON fields.
* Also inherit ExtendedPostgreSQLPlatform which understand the Inet types.
*
* @author jkj
*
*/
public class MoyaPostgreSQLPlatform extends ExtendedPostgreSQLPlatform {
private static final long serialVersionUID = 6351395815598077327L;
private static final Logger log = LoggerFactory.getLogger(MoyaPostgreSQLPlatform.class);
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
protected Hashtable buildFieldTypes() { protected Hashtable buildFieldTypes() {
Hashtable map = super.buildFieldTypes(); log.info("Customizing SQL Platform field types for Moya");
Hashtable map = super.buildFieldTypes();
map.put(String.class, new FieldTypeDefinition("TEXT", false)); map.put(String.class, new FieldTypeDefinition("TEXT", false));
map.put(java.sql.Timestamp.class, new FieldTypeDefinition("TIMESTAMPTZ", false)); map.put(java.sql.Timestamp.class, new FieldTypeDefinition("TIMESTAMPTZ", false));
map.put(javax.json.JsonObject.class, new FieldTypeDefinition("JSON", false)); map.put(javax.json.JsonObject.class, new FieldTypeDefinition("JSON", false));
return map; return map;
} }
} }
package fi.codecrew.moya.database.eclipselink;
import org.eclipse.persistence.config.SessionCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.sessions.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MoyaSessionCustomizer implements SessionCustomizer {
private static final Logger log = LoggerFactory.getLogger(MoyaSessionCustomizer.class);
@Override
public void customize(Session session) throws Exception {
log.info("Customizing session: {}", session);
MoyaDescriptorCustomizer customizer = new MoyaDescriptorCustomizer();
for (ClassDescriptor descriptor : session.getDescriptors().values()) {
// log.info("Looking into descriptor: {}", descriptor);
customizer.customize(descriptor);
}
}
}
...@@ -17,9 +17,6 @@ import javax.persistence.Table; ...@@ -17,9 +17,6 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Account event contains the money / credit traffic for the user. Each row * Account event contains the money / credit traffic for the user. Each row
* references a Product entity. * references a Product entity.
...@@ -27,7 +24,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -27,7 +24,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "account_events") @Table(name = "account_events")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class AccountEvent extends GenericEntity { public class AccountEvent extends GenericEntity {
private static final long serialVersionUID = 2588419823225148100L; private static final long serialVersionUID = 2588419823225148100L;
......
...@@ -18,15 +18,12 @@ import javax.persistence.Table; ...@@ -18,15 +18,12 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
import fi.codecrew.moya.enums.ActionLogMessageState; import fi.codecrew.moya.enums.ActionLogMessageState;
@Entity @Entity
@Table(name = "actionlog_messages") @Table(name = "actionlog_messages")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ActionLogMessage extends GenericEntity { public class ActionLogMessage extends GenericEntity {
private static final long serialVersionUID = -2902547412412000488L; private static final long serialVersionUID = -2902547412412000488L;
......
...@@ -12,14 +12,10 @@ import javax.persistence.Table; ...@@ -12,14 +12,10 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.ActionLogMessageState; import fi.codecrew.moya.enums.ActionLogMessageState;
@Entity @Entity
@Table(name = "actionlog_message_responses") @Table(name = "actionlog_message_responses")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ActionLogMessageResponse extends GenericEntity { public class ActionLogMessageResponse extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -5,13 +5,10 @@ import javax.persistence.Entity; ...@@ -5,13 +5,10 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
@Entity @Entity
@Table(name = "actionlog_message_tags") @Table(name = "actionlog_message_tags")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ActionLogMessageTag extends GenericEntity { public class ActionLogMessageTag extends GenericEntity {
private static final long serialVersionUID = -2902547412412000488L; private static final long serialVersionUID = -2902547412412000488L;
......
...@@ -16,12 +16,8 @@ import javax.persistence.Table; ...@@ -16,12 +16,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "api_applications") @Table(name = "api_applications")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ApiApplication extends GenericEntity { public class ApiApplication extends GenericEntity {
public static enum AuthType { public static enum AuthType {
......
...@@ -8,15 +8,11 @@ import javax.persistence.Table; ...@@ -8,15 +8,11 @@ import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.BortalApplication; import fi.codecrew.moya.enums.BortalApplication;
import fi.codecrew.moya.enums.apps.IAppPermission; import fi.codecrew.moya.enums.apps.IAppPermission;
@Entity @Entity
@Table(name = "application_permissions", uniqueConstraints = { @UniqueConstraint(columnNames = { ApplicationPermission.ROLE_ID_COLUMN, ApplicationPermission.APPLICATION_COLUMN, ApplicationPermission.PERMISSION_COLUMN }) }) @Table(name = "application_permissions", uniqueConstraints = { @UniqueConstraint(columnNames = { ApplicationPermission.ROLE_ID_COLUMN, ApplicationPermission.APPLICATION_COLUMN, ApplicationPermission.PERMISSION_COLUMN }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ApplicationPermission extends GenericEntity { public class ApplicationPermission extends GenericEntity {
protected static final String APPLICATION_PERMISSION_CONVERTER = "application_permission_perm_typeconverter"; protected static final String APPLICATION_PERMISSION_CONVERTER = "application_permission_perm_typeconverter";
......
...@@ -20,8 +20,6 @@ import javax.persistence.Temporal; ...@@ -20,8 +20,6 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -34,7 +32,6 @@ import fi.codecrew.moya.utilities.BillUtils; ...@@ -34,7 +32,6 @@ import fi.codecrew.moya.utilities.BillUtils;
*/ */
@Entity @Entity
@Table(name = "bills", uniqueConstraints = { @UniqueConstraint(columnNames = { Bill.EVENT_ID_COLUMN, "bill_number" }) }) @Table(name = "bills", uniqueConstraints = { @UniqueConstraint(columnNames = { Bill.EVENT_ID_COLUMN, "bill_number" }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Bill extends GenericEntity { public class Bill extends GenericEntity {
/** /**
......
...@@ -16,15 +16,11 @@ import javax.persistence.ManyToOne; ...@@ -16,15 +16,11 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "bill_lines") @Table(name = "bill_lines")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class BillLine extends GenericEntity { public class BillLine extends GenericEntity {
private static final long serialVersionUID = 2L; private static final long serialVersionUID = 2L;
......
...@@ -5,12 +5,8 @@ import javax.persistence.JoinColumn; ...@@ -5,12 +5,8 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "card_code") @Table(name = "card_code")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class CardCode extends GenericEntity { public class CardCode extends GenericEntity {
private static final long serialVersionUID = 307145499023412008L; private static final long serialVersionUID = 307145499023412008L;
......
...@@ -15,15 +15,11 @@ import javax.persistence.ManyToOne; ...@@ -15,15 +15,11 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* ID-card templates for the event. * ID-card templates for the event.
*/ */
@Entity @Entity
@Table(name = "card_templates") @Table(name = "card_templates")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class CardTemplate extends GenericEntity { public class CardTemplate extends GenericEntity {
private static final long serialVersionUID = -5754760238181167610L; private static final long serialVersionUID = -5754760238181167610L;
......
...@@ -20,15 +20,11 @@ import javax.persistence.Table; ...@@ -20,15 +20,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Competition to be held at the event. * Competition to be held at the event.
*/ */
@Entity @Entity
@Table(name = "compos") @Table(name = "compos")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Compo extends GenericEntity { public class Compo extends GenericEntity {
private static final long serialVersionUID = 2L; private static final long serialVersionUID = 2L;
......
...@@ -20,15 +20,11 @@ import javax.persistence.Table; ...@@ -20,15 +20,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "compo_entries") @Table(name = "compo_entries")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class CompoEntry extends GenericEntity { public class CompoEntry extends GenericEntity {
private static final long serialVersionUID = 2L; private static final long serialVersionUID = 2L;
......
...@@ -21,8 +21,6 @@ import javax.persistence.Temporal; ...@@ -21,8 +21,6 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -31,7 +29,6 @@ import org.slf4j.LoggerFactory; ...@@ -31,7 +29,6 @@ import org.slf4j.LoggerFactory;
*/ */
@Entity @Entity
@Table(name = "compo_entry_files") @Table(name = "compo_entry_files")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class CompoEntryFile extends GenericEntity { public class CompoEntryFile extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Column(name = "mime_type") @Column(name = "mime_type")
......
...@@ -10,15 +10,11 @@ import javax.persistence.Table; ...@@ -10,15 +10,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "compo_entry_participations") @Table(name = "compo_entry_participations")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class CompoEntryParticipant extends GenericEntity { public class CompoEntryParticipant extends GenericEntity {
private static final long serialVersionUID = 2L; private static final long serialVersionUID = 2L;
......
...@@ -22,39 +22,38 @@ public class DBModel implements ModelInterface { ...@@ -22,39 +22,38 @@ public class DBModel implements ModelInterface {
@Id @Id
@Column(name = ID_COLUMN, nullable = false) @Column(name = ID_COLUMN, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id;
private Integer id;
@Column(name = "revision", nullable = false) @Column(name = "revision", nullable = false)
private Integer revision; private Integer revision;
@Column(name = "applied_at") @Column(name = "applied_at")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date appliedAt = new Date(); private Date appliedAt = new Date();
@Override @Override
public final Integer getId() { public final Integer getId() {
return id; return id;
} }
@Override @Override
public final void setId(Integer id) { public final void setId(Integer id) {
this.id = id; this.id = id;
} }
public Date getAppliedAt() { public Date getAppliedAt() {
return appliedAt; return appliedAt;
} }
public void setAppliedAt(Date appliedAt) { public void setAppliedAt(Date appliedAt) {
this.appliedAt = appliedAt; this.appliedAt = appliedAt;
} }
public Integer getRevision() { public Integer getRevision() {
return revision; return revision;
} }
public void setRevision(Integer revision) { public void setRevision(Integer revision) {
this.revision = revision; this.revision = revision;
} }
} }
...@@ -5,15 +5,11 @@ import javax.persistence.JoinColumn; ...@@ -5,15 +5,11 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "discount_instances") @Table(name = "discount_instances")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class DiscountInstance extends GenericEntity { public class DiscountInstance extends GenericEntity {
private static final long serialVersionUID = 2192672129232748522L; private static final long serialVersionUID = 2192672129232748522L;
......
...@@ -12,8 +12,6 @@ import javax.persistence.OneToMany; ...@@ -12,8 +12,6 @@ import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
/** /**
...@@ -21,7 +19,6 @@ import org.eclipse.persistence.annotations.PrivateOwned; ...@@ -21,7 +19,6 @@ import org.eclipse.persistence.annotations.PrivateOwned;
*/ */
@Entity @Entity
@Table(name = "maps") @Table(name = "maps")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class EventMap extends GenericEntity { public class EventMap extends GenericEntity {
private static final long serialVersionUID = 3411450245513673619L; private static final long serialVersionUID = 3411450245513673619L;
......
...@@ -9,15 +9,11 @@ import javax.persistence.OneToMany; ...@@ -9,15 +9,11 @@ import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "event_organiser") @Table(name = "event_organiser")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class EventOrganiser extends GenericEntity { public class EventOrganiser extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -26,14 +26,10 @@ import javax.persistence.Temporal; ...@@ -26,14 +26,10 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.Gender; import fi.codecrew.moya.enums.Gender;
@Entity @Entity
@Table(name = "event_users", uniqueConstraints = @UniqueConstraint(columnNames = { EventUser.USER_ID_COLUMN, EventUser.EVENT_ID_COLUMN })) @Table(name = "event_users", uniqueConstraints = @UniqueConstraint(columnNames = { EventUser.USER_ID_COLUMN, EventUser.EVENT_ID_COLUMN }))
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class EventUser extends GenericEntity { public class EventUser extends GenericEntity {
protected static final String USER_ID_COLUMN = "user_id"; protected static final String USER_ID_COLUMN = "user_id";
......
...@@ -19,15 +19,11 @@ import javax.persistence.Table; ...@@ -19,15 +19,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "food_waves") @Table(name = "food_waves")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class FoodWave extends GenericEntity { public class FoodWave extends GenericEntity {
private static final long serialVersionUID = 9221716203467295049L; private static final long serialVersionUID = 9221716203467295049L;
......
...@@ -18,15 +18,11 @@ import javax.persistence.OneToMany; ...@@ -18,15 +18,11 @@ import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "food_wave_templates") @Table(name = "food_wave_templates")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class FoodWaveTemplate extends GenericEntity { public class FoodWaveTemplate extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -6,8 +6,6 @@ import java.io.Serializable; ...@@ -6,8 +6,6 @@ import java.io.Serializable;
import javax.persistence.*; import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: GameID * Entity implementation class for Entity: GameID
...@@ -15,7 +13,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -15,7 +13,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
*/ */
@Entity @Entity
@Table(name="game_ids") @Table(name="game_ids")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class GameID extends GenericEntity implements Serializable { public class GameID extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -13,34 +13,34 @@ import fi.codecrew.moya.utilities.jpa.ModelInterface; ...@@ -13,34 +13,34 @@ import fi.codecrew.moya.utilities.jpa.ModelInterface;
@MappedSuperclass @MappedSuperclass
public class GenericEntity extends EntityEquals implements ModelInterface, EntityMeta { public class GenericEntity extends EntityEquals implements ModelInterface, EntityMeta {
private static final long serialVersionUID = -9041737052951021560L; private static final long serialVersionUID = -9041737052951021560L;
public static final String ID_COLUMN = "id"; public static final String ID_COLUMN = "id";
@Id @Id
@Column(name = ID_COLUMN, nullable = false) @Column(name = ID_COLUMN, nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id;
private Integer id;
@Column(name = "meta", columnDefinition = "json")
private JsonObject meta; private JsonObject meta;
@Override @Override
public final Integer getId() { public final Integer getId() {
return id; return id;
} }
@Override @Override
public final void setId(Integer id) { public final void setId(Integer id) {
this.id = id; this.id = id;
} }
@Override @Override
public JsonObject getMeta() { public JsonObject getMeta() {
return meta; return meta;
} }
@Override @Override
public void setMeta(JsonObject meta) { public void setMeta(JsonObject meta) {
this.meta = meta; this.meta = meta;
} }
} }
...@@ -16,9 +16,6 @@ import javax.persistence.Table; ...@@ -16,9 +16,6 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
...@@ -26,7 +23,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -26,7 +23,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
@Table(name = "group_memberships") @Table(name = "group_memberships")
// , uniqueConstraints = { @UniqueConstraint(columnNames = { // , uniqueConstraints = { @UniqueConstraint(columnNames = {
// GroupMembership.EVENTUSER_ID, GroupMembership.GROUP_ID }) }) // GroupMembership.EVENTUSER_ID, GroupMembership.GROUP_ID }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class GroupMembership extends GenericEntity { public class GroupMembership extends GenericEntity {
/** /**
......
...@@ -10,12 +10,8 @@ import javax.persistence.Table; ...@@ -10,12 +10,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "inventory_events") @Table(name = "inventory_events")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class InventoryEvent extends GenericEntity { public class InventoryEvent extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -17,8 +17,6 @@ import javax.persistence.Table; ...@@ -17,8 +17,6 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
import fi.codecrew.moya.enums.EventStatus; import fi.codecrew.moya.enums.EventStatus;
...@@ -29,7 +27,6 @@ import fi.codecrew.moya.model.salespoint.Salespoint; ...@@ -29,7 +27,6 @@ import fi.codecrew.moya.model.salespoint.Salespoint;
*/ */
@Entity @Entity
@Table(name = "events") @Table(name = "events")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LanEvent extends GenericEntity { public class LanEvent extends GenericEntity {
private static final long serialVersionUID = 179811358211927126L; private static final long serialVersionUID = 179811358211927126L;
......
...@@ -7,12 +7,8 @@ import javax.persistence.Lob; ...@@ -7,12 +7,8 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "event_domains") @Table(name = "event_domains")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LanEventDomain extends GenericEntity { public class LanEventDomain extends GenericEntity {
public LanEventDomain() { public LanEventDomain() {
......
...@@ -14,15 +14,11 @@ import javax.persistence.Table; ...@@ -14,15 +14,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "licensecodes") @Table(name = "licensecodes")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LicenseCode extends GenericEntity { public class LicenseCode extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -15,15 +15,11 @@ import javax.persistence.OneToMany; ...@@ -15,15 +15,11 @@ import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "licensetargets") @Table(name = "licensetargets")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LicenseTarget extends GenericEntity { public class LicenseTarget extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -13,9 +13,6 @@ import javax.persistence.ManyToOne; ...@@ -13,9 +13,6 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
...@@ -26,7 +23,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -26,7 +23,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
// //
// @NamedQuery(name = "Location.findByLocationName", query = // @NamedQuery(name = "Location.findByLocationName", query =
// "SELECT l FROM Location l WHERE l.name = :name") }) // "SELECT l FROM Location l WHERE l.name = :name") })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Location extends GenericEntity { public class Location extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -16,15 +16,11 @@ import javax.persistence.ManyToOne; ...@@ -16,15 +16,11 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "event_log") @Table(name = "event_log")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LogEntry extends GenericEntity { public class LogEntry extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -15,9 +15,6 @@ import javax.persistence.NamedQuery; ...@@ -15,9 +15,6 @@ import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
...@@ -29,7 +26,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -29,7 +26,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
@NamedQuery(name = "LogEntryType.findAll", query = "SELECT l FROM LogEntryType l"), @NamedQuery(name = "LogEntryType.findAll", query = "SELECT l FROM LogEntryType l"),
@NamedQuery(name = "LogEntryType.findByName", query = "SELECT l FROM LogEntryType l WHERE l.name = :name"), @NamedQuery(name = "LogEntryType.findByName", query = "SELECT l FROM LogEntryType l WHERE l.name = :name"),
@NamedQuery(name = "LogEntryType.findByDescription", query = "SELECT l FROM LogEntryType l WHERE l.description = :description") }) @NamedQuery(name = "LogEntryType.findByDescription", query = "SELECT l FROM LogEntryType l WHERE l.description = :description") })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LogEntryType extends GenericEntity { public class LogEntryType extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -17,8 +17,6 @@ import javax.persistence.Table; ...@@ -17,8 +17,6 @@ import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
import fi.codecrew.moya.enums.BortalApplication; import fi.codecrew.moya.enums.BortalApplication;
...@@ -30,7 +28,6 @@ import fi.codecrew.moya.enums.apps.IAppPermission; ...@@ -30,7 +28,6 @@ import fi.codecrew.moya.enums.apps.IAppPermission;
MenuNavigation.ITEM_COLUMN, MenuNavigation.ITEM_COLUMN,
MenuNavigation.EVENT_COLUMN }) MenuNavigation.EVENT_COLUMN })
}) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class MenuNavigation extends GenericEntity implements Comparable<MenuNavigation> { public class MenuNavigation extends GenericEntity implements Comparable<MenuNavigation> {
private static final long serialVersionUID = 1404769998091479699L; private static final long serialVersionUID = 1404769998091479699L;
......
...@@ -9,13 +9,10 @@ import javax.persistence.Lob; ...@@ -9,13 +9,10 @@ import javax.persistence.Lob;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
@Entity @Entity
@Table(name = "menuitem") @Table(name = "menuitem")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Menuitem extends GenericEntity { public class Menuitem extends GenericEntity {
private static final long serialVersionUID = -3544095800802935237L; private static final long serialVersionUID = -3544095800802935237L;
......
...@@ -11,14 +11,10 @@ import javax.persistence.Table; ...@@ -11,14 +11,10 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.NetworkAssociationStatus; import fi.codecrew.moya.enums.NetworkAssociationStatus;
@Entity @Entity
@Table(name = "network_associations") @Table(name = "network_associations")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class NetworkAssociation extends GenericEntity { public class NetworkAssociation extends GenericEntity {
private static final long serialVersionUID = -7621152614442737756L; private static final long serialVersionUID = -7621152614442737756L;
......
...@@ -11,16 +11,12 @@ import javax.persistence.Table; ...@@ -11,16 +11,12 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
* @author jkj * @author jkj
*/ */
@Entity @Entity
@Table(name = "news") @Table(name = "news")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class News extends GenericEntity { public class News extends GenericEntity {
private static final long serialVersionUID = 498925968565236275L; private static final long serialVersionUID = 498925968565236275L;
......
...@@ -18,8 +18,6 @@ import javax.persistence.OrderBy; ...@@ -18,8 +18,6 @@ import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
/** /**
...@@ -28,7 +26,6 @@ import org.eclipse.persistence.annotations.PrivateOwned; ...@@ -28,7 +26,6 @@ import org.eclipse.persistence.annotations.PrivateOwned;
*/ */
@Entity @Entity
@Table(name = "news_groups", uniqueConstraints = @UniqueConstraint(columnNames = { NewsGroup.EVENT_ID_COLUMN, NewsGroup.GROUP_NAME })) @Table(name = "news_groups", uniqueConstraints = @UniqueConstraint(columnNames = { NewsGroup.EVENT_ID_COLUMN, NewsGroup.GROUP_NAME }))
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class NewsGroup extends GenericEntity { public class NewsGroup extends GenericEntity {
protected static final String GROUP_NAME = "group_name"; protected static final String GROUP_NAME = "group_name";
......
...@@ -12,16 +12,12 @@ import javax.persistence.ManyToOne; ...@@ -12,16 +12,12 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: OrganizationalRole * Entity implementation class for Entity: OrganizationalRole
* *
*/ */
@Entity @Entity
@Table(name = "org_roles", uniqueConstraints = { @UniqueConstraint(columnNames = { OrgRole.EVENTORG_ID_COLUMN, OrgRole.NAME_COLUMN }) }) @Table(name = "org_roles", uniqueConstraints = { @UniqueConstraint(columnNames = { OrgRole.EVENTORG_ID_COLUMN, OrgRole.NAME_COLUMN }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class OrgRole extends GenericEntity { public class OrgRole extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -12,12 +12,8 @@ import javax.persistence.Table; ...@@ -12,12 +12,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "site_page_content") @Table(name = "site_page_content")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class PageContent extends GenericEntity { public class PageContent extends GenericEntity {
private static final long serialVersionUID = 8359021214886290522L; private static final long serialVersionUID = 8359021214886290522L;
......
...@@ -13,15 +13,11 @@ import javax.persistence.Table; ...@@ -13,15 +13,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "places") @Table(name = "places")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Place extends GenericEntity { public class Place extends GenericEntity {
/** /**
......
...@@ -20,15 +20,11 @@ import javax.persistence.Table; ...@@ -20,15 +20,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "groups") @Table(name = "groups")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class PlaceGroup extends GenericEntity { public class PlaceGroup extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -18,16 +18,12 @@ import javax.persistence.OrderBy; ...@@ -18,16 +18,12 @@ import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: Poll * Entity implementation class for Entity: Poll
* *
*/ */
@Entity @Entity
@Table(name = "poll") @Table(name = "poll")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Poll extends GenericEntity { public class Poll extends GenericEntity {
/** /**
......
...@@ -9,12 +9,8 @@ import javax.persistence.Lob; ...@@ -9,12 +9,8 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "poll_answer") @Table(name = "poll_answer")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class PollAnswer extends GenericEntity implements Serializable { public class PollAnswer extends GenericEntity implements Serializable {
/** /**
......
...@@ -13,12 +13,8 @@ import javax.persistence.OneToMany; ...@@ -13,12 +13,8 @@ import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "poll_question") @Table(name = "poll_question")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class PollQuestion extends GenericEntity { public class PollQuestion extends GenericEntity {
public PollQuestion() { public PollQuestion() {
......
...@@ -11,12 +11,8 @@ import javax.persistence.ManyToOne; ...@@ -11,12 +11,8 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "possible_answer") @Table(name = "possible_answer")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class PossibleAnswer extends GenericEntity { public class PossibleAnswer extends GenericEntity {
public PossibleAnswer() { public PossibleAnswer() {
......
...@@ -25,9 +25,6 @@ import javax.persistence.TemporalType; ...@@ -25,9 +25,6 @@ import javax.persistence.TemporalType;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.CardState; import fi.codecrew.moya.enums.CardState;
/** /**
...@@ -37,7 +34,6 @@ import fi.codecrew.moya.enums.CardState; ...@@ -37,7 +34,6 @@ import fi.codecrew.moya.enums.CardState;
@Table(name = "printed_cards", uniqueConstraints = { @Table(name = "printed_cards", uniqueConstraints = {
@UniqueConstraint(columnNames = { "event_id", "rfid_uid", }), @UniqueConstraint(columnNames = { "event_id", "rfid_uid", }),
@UniqueConstraint(columnNames = { "event_id", "barcode" }) }) @UniqueConstraint(columnNames = { "event_id", "barcode" }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class PrintedCard extends GenericEntity { public class PrintedCard extends GenericEntity {
private static final long serialVersionUID = 8603481931116401027L; private static final long serialVersionUID = 8603481931116401027L;
......
...@@ -27,8 +27,6 @@ import javax.persistence.OneToMany; ...@@ -27,8 +27,6 @@ import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
/** /**
...@@ -36,7 +34,6 @@ import org.eclipse.persistence.annotations.PrivateOwned; ...@@ -36,7 +34,6 @@ import org.eclipse.persistence.annotations.PrivateOwned;
*/ */
@Entity @Entity
@Table(name = "products") @Table(name = "products")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Product extends GenericEntity { public class Product extends GenericEntity {
private static final String PRODUCTFLAG_TABLE_PRODUCTID = "product_id"; private static final String PRODUCTFLAG_TABLE_PRODUCTID = "product_id";
......
...@@ -11,12 +11,8 @@ import javax.persistence.Lob; ...@@ -11,12 +11,8 @@ import javax.persistence.Lob;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@Entity @Entity
@Table(name = "product_limitations") @Table(name = "product_limitations")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ProductLimitation extends GenericEntity { public class ProductLimitation extends GenericEntity {
/** /**
......
...@@ -25,9 +25,6 @@ import javax.persistence.OneToOne; ...@@ -25,9 +25,6 @@ import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.model.salespoint.SalesEntity; import fi.codecrew.moya.model.salespoint.SalesEntity;
/** /**
...@@ -35,7 +32,6 @@ import fi.codecrew.moya.model.salespoint.SalesEntity; ...@@ -35,7 +32,6 @@ import fi.codecrew.moya.model.salespoint.SalesEntity;
*/ */
@Entity @Entity
@Table(name = "readers", uniqueConstraints = { @UniqueConstraint(columnNames = { "reader_ident", "event_id" }) }) @Table(name = "readers", uniqueConstraints = { @UniqueConstraint(columnNames = { "reader_ident", "event_id" }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Reader extends GenericEntity { public class Reader extends GenericEntity {
public Reader(LanEvent ev, String ident) { public Reader(LanEvent ev, String ident) {
......
...@@ -14,15 +14,11 @@ import javax.persistence.Table; ...@@ -14,15 +14,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "reader_events") @Table(name = "reader_events")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class ReaderEvent extends GenericEntity { public class ReaderEvent extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -14,8 +14,6 @@ import javax.persistence.OneToMany; ...@@ -14,8 +14,6 @@ import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
/** /**
...@@ -23,7 +21,6 @@ import org.eclipse.persistence.annotations.PrivateOwned; ...@@ -23,7 +21,6 @@ import org.eclipse.persistence.annotations.PrivateOwned;
*/ */
@Entity @Entity
@Table(name = "roles", uniqueConstraints = { @UniqueConstraint(columnNames = { Role.EVENT_ID_COLUMN, Role.NAME_COLUMN }) }) @Table(name = "roles", uniqueConstraints = { @UniqueConstraint(columnNames = { Role.EVENT_ID_COLUMN, Role.NAME_COLUMN }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Role extends GenericEntity { public class Role extends GenericEntity {
private static final long serialVersionUID = -4602863502464505404L; private static final long serialVersionUID = -4602863502464505404L;
......
...@@ -12,13 +12,10 @@ import javax.persistence.OneToMany; ...@@ -12,13 +12,10 @@ import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
@Entity @Entity
@Table(name = "site_pages", uniqueConstraints = @UniqueConstraint(columnNames = { SitePage.EVENT_ID_COLUMN, "name" })) @Table(name = "site_pages", uniqueConstraints = @UniqueConstraint(columnNames = { SitePage.EVENT_ID_COLUMN, "name" }))
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class SitePage extends GenericEntity { public class SitePage extends GenericEntity {
private static final long serialVersionUID = -4333555423866132524L; private static final long serialVersionUID = -4333555423866132524L;
......
...@@ -9,8 +9,6 @@ import java.util.List; ...@@ -9,8 +9,6 @@ import java.util.List;
import javax.persistence.*; import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: Tournament * Entity implementation class for Entity: Tournament
...@@ -18,7 +16,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -18,7 +16,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
*/ */
@Entity @Entity
@Table(name="tournaments") @Table(name="tournaments")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Tournament extends GenericEntity implements Serializable { public class Tournament extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -9,8 +9,6 @@ import java.util.List; ...@@ -9,8 +9,6 @@ import java.util.List;
import javax.persistence.*; import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: Tournament * Entity implementation class for Entity: Tournament
...@@ -18,7 +16,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -18,7 +16,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
*/ */
@Entity @Entity
@Table(name="tournament_games") @Table(name="tournament_games")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentGame extends GenericEntity implements Serializable { public class TournamentGame extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -8,8 +8,6 @@ import java.util.List; ...@@ -8,8 +8,6 @@ import java.util.List;
import javax.persistence.*; import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: Match * Entity implementation class for Entity: Match
...@@ -17,7 +15,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -17,7 +15,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
*/ */
@Entity @Entity
@Table(name="matches") @Table(name="matches")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentMatch extends GenericEntity implements Serializable { public class TournamentMatch extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -3,8 +3,6 @@ package fi.codecrew.moya.model; ...@@ -3,8 +3,6 @@ package fi.codecrew.moya.model;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.*; import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: MatchResult * Entity implementation class for Entity: MatchResult
...@@ -12,7 +10,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -12,7 +10,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
*/ */
@Entity @Entity
@Table(name="match_results") @Table(name="match_results")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentMatchResult extends GenericEntity implements Serializable { public class TournamentMatchResult extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -6,8 +6,6 @@ import java.util.List; ...@@ -6,8 +6,6 @@ import java.util.List;
import javax.persistence.*; import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: TournamentParticipant * Entity implementation class for Entity: TournamentParticipant
...@@ -15,7 +13,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -15,7 +13,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
*/ */
@Entity @Entity
@Table(name="tournament_participants") @Table(name="tournament_participants")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentParticipant extends GenericEntity implements Serializable { public class TournamentParticipant extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -9,8 +9,6 @@ import java.util.List; ...@@ -9,8 +9,6 @@ import java.util.List;
import javax.persistence.*; import javax.persistence.*;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Entity implementation class for Entity: Tournament * Entity implementation class for Entity: Tournament
...@@ -18,7 +16,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -18,7 +16,6 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
*/ */
@Entity @Entity
@Table(name="tournament_rules") @Table(name="tournament_rules")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentRule extends GenericEntity implements Serializable { public class TournamentRule extends GenericEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -10,14 +10,10 @@ import javax.persistence.JoinColumn; ...@@ -10,14 +10,10 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import fi.codecrew.moya.enums.TournamentTeamMemberRole; import fi.codecrew.moya.enums.TournamentTeamMemberRole;
@Entity @Entity
@Table(name="tournament_team_members") @Table(name="tournament_team_members")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class TournamentTeamMember extends GenericEntity implements Serializable { public class TournamentTeamMember extends GenericEntity implements Serializable {
private static final long serialVersionUID = 8511689754953929329L; private static final long serialVersionUID = 8511689754953929329L;
......
...@@ -22,8 +22,6 @@ import javax.persistence.TemporalType; ...@@ -22,8 +22,6 @@ import javax.persistence.TemporalType;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned; import org.eclipse.persistence.annotations.PrivateOwned;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -36,7 +34,6 @@ import fi.codecrew.moya.utilities.PasswordFunctions; ...@@ -36,7 +34,6 @@ import fi.codecrew.moya.utilities.PasswordFunctions;
*/ */
@Entity @Entity
@Table(name = "users") @Table(name = "users")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class User extends GenericEntity implements IUser { public class User extends GenericEntity implements IUser {
// private static final Logger logger = LoggerFactory.getLogger(User.class); // private static final Logger logger = LoggerFactory.getLogger(User.class);
......
...@@ -19,15 +19,11 @@ import javax.persistence.Table; ...@@ -19,15 +19,11 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* *
*/ */
@Entity @Entity
@Table(name = "user_images") @Table(name = "user_images")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class UserImage extends GenericEntity { public class UserImage extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -16,15 +16,11 @@ import javax.persistence.Temporal; ...@@ -16,15 +16,11 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* A vote for a compo entry * A vote for a compo entry
*/ */
@Entity @Entity
@Table(name = "compo_votes", uniqueConstraints = { @UniqueConstraint(columnNames = { Vote.ENTRY_ID, Vote.VOTER_USER_ID }) }) @Table(name = "compo_votes", uniqueConstraints = { @UniqueConstraint(columnNames = { Vote.ENTRY_ID, Vote.VOTER_USER_ID }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Vote extends GenericEntity { public class Vote extends GenericEntity {
protected static final String VOTER_USER_ID = "voter_userevent_id"; protected static final String VOTER_USER_ID = "voter_userevent_id";
......
...@@ -10,47 +10,62 @@ import javax.persistence.AttributeConverter; ...@@ -10,47 +10,62 @@ import javax.persistence.AttributeConverter;
import javax.persistence.Converter; import javax.persistence.Converter;
import org.postgresql.util.PGobject; import org.postgresql.util.PGobject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Converter(autoApply = true) @Converter(autoApply = true)
public class JsonAttributeConverter implements AttributeConverter<JsonObject, PGobject> { public class JsonAttributeConverter implements AttributeConverter<JsonObject, PGobject> {
private static final Logger log = LoggerFactory.getLogger(JsonAttributeConverter.class);
public PGobject convertToDatabaseColumn(JsonObject attribute) { /**
final PGobject dataValue = new PGobject(); * JsonObject -> PGobject
dataValue.setType("json"); */
try { public PGobject convertToDatabaseColumn(JsonObject jsonObject) {
if (attribute == null) log.info("Converting JsonObject to PGobject. Original JsonObject: {}", jsonObject);
dataValue.setValue("null");
else
dataValue.setValue(attribute.toString());
} catch (SQLException e) {
// This will never run because PGobject.setValue() cannot really
// throw an SQLException. There is nothing but setting a property.
throw new RuntimeException("THIS SHOULD NEVER HAPPEN", e);
}
return dataValue;
}
public JsonObject convertToEntityAttribute(PGobject dbData) {
// Has any?
if (dbData == null) {
return null;
}
// Correct type of object?
if (dbData.getType().equals("json") == false) {
throw new RuntimeException("Expected JSON object from database");
}
if(!dbData.getValue().equals("null")) {
// Read as JSON object
final StringReader stringReader = new StringReader(dbData.getValue());
final JsonReader jsonReader = Json.createReader(stringReader);
return jsonReader.readObject();
} else {
return null;
}
}
PGobject pgObject = new PGobject();
pgObject.setType("json");
try {
if (jsonObject != null) {
pgObject.setValue(jsonObject.toString());
} else {
pgObject.setValue(null);
}
} catch (SQLException e) {
log.warn("PGobject.setValue() threw an exception. Should not happen. Something is wrong.", e);
}
log.info("Converted JsonObject to PGobject: {}", pgObject);
return pgObject;
}
/**
* PGobject -> JsonObject
*/
public JsonObject convertToEntityAttribute(PGobject pgObject) {
log.info("Converting PGobject to JsonObject. Original PGobject: {}", pgObject);
// Convert null values to empty object
if (pgObject == null) {
log.info("PGobject was null. Retruning an empty JsonObject.");
return Json.createObjectBuilder().build();
}
// Correct type of object?
if (pgObject.getType().equals("json") == false) {
log.error("Expected to be converting JSON column, but got PGobject whose type is not json but {}", pgObject.getType());
throw new RuntimeException("Expected JSON object from database");
}
// Read the value as JSON
String stringValue = pgObject.getValue();
if (stringValue != null) {
JsonReader jsonReader = Json.createReader(new StringReader(stringValue));
JsonObject jsonObject = jsonReader.readObject();
log.info("Converted PGobject to JsonObject: {}", jsonObject);
return jsonObject;
} else {
log.info("Null value. Returning empty JsonObject");
return Json.createObjectBuilder().build();
}
}
} }
...@@ -26,7 +26,10 @@ ...@@ -26,7 +26,10 @@
<dependent-module archiveName="org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/ancoron/postgresql/org.ancoron.postgresql.jpa/9.1.901.jdbc4.1-rc9/org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar"> <dependent-module archiveName="org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/ancoron/postgresql/org.ancoron.postgresql.jpa/9.1.901.jdbc4.1-rc9/org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="postgresql-9.3-1100-jdbc41.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/postgresql/postgresql/9.3-1100-jdbc41/postgresql-9.3-1100-jdbc41.jar"> <dependent-module archiveName="postgresql-9.3-1101-jdbc41.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/postgresql/postgresql/9.3-1101-jdbc41/postgresql-9.3-1101-jdbc41.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="org.postgresql.net-9.1.901.jdbc4.1-rc9.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/ancoron/postgresql/org.postgresql.net/9.1.901.jdbc4.1-rc9/org.postgresql.net-9.1.901.jdbc4.1-rc9.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="pdfjet-0.0.0-2013-08-19.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/fi/iudex/pdfjet/pdfjet/0.0.0-2013-08-19/pdfjet-0.0.0-2013-08-19.jar"> <dependent-module archiveName="pdfjet-0.0.0-2013-08-19.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/fi/iudex/pdfjet/pdfjet/0.0.0-2013-08-19/pdfjet-0.0.0-2013-08-19.jar">
......
package fi.codecrew.moya.utilities;
import java.util.List;
import java.util.Map;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
public class JsonUtils {
/**
* Gets a sub object from a JsonObject. Returns an empty object if not
* found.
*
* @param jsonObject
* @param path
* @return
*/
public static JsonObject getSubObject(JsonObject jsonObject,
List<String> path) {
JsonObject sub = jsonObject;
for (String s : path) {
sub = sub.getJsonObject(s);
if (sub == null)
break;
}
if (sub == null) {
sub = Json.createObjectBuilder().build();
}
return sub;
}
/**
* Adds or alters one key in JsonObject
*
* @param jsonObject
* @param key
* which key to add/alter
* @param value
* The value associate to the key
* @return JsonObject with the key:value pair added
*/
public static JsonObject assocJsonObject(JsonObject jsonObject, String key,
JsonValue value) {
JsonObjectBuilder builder = Json.createObjectBuilder();
// Copy all non conflicting json entries
for (Map.Entry<String, JsonValue> v : jsonObject.entrySet()) {
if (v.getKey() != key) {
builder = builder.add(v.getKey(), v.getValue());
}
}
// Add our new json entry
builder = builder.add(key, value);
return builder.build();
}
/**
* Goes into a json object and sets subobject assocInJsonObject("{}",
* ["foo", "bar"], "{\"a\":\"b\"}") => {\"foo\":{\"bar\":{\"a\":\"b\"}}}
*
* @param jsonObject
* @param keys
* path inside key hierarchy
* @param value
* @return JsonObject with the value added
*/
public static JsonObject assocInJsonObject(JsonObject jsonObject,
List<String> keys, JsonValue value) {
// Recurse?
if (keys.size() > 1) {
String firstKey = keys.get(0);
List<String> restKeys = keys.subList(0, keys.size());
JsonObject subObj = jsonObject.getJsonObject(firstKey);
return assocJsonObject(jsonObject, firstKey,
assocInJsonObject(subObj, restKeys, value));
}
// End?
String firstKey = keys.get(0);
return assocJsonObject(jsonObject, firstKey, value);
}
public static JsonObject alterSubObject(JsonObject jsonObject,
List<String> path, JsonObject subObject) {
return assocInJsonObject(jsonObject, path, subObject);
}
}
...@@ -6,49 +6,45 @@ import java.util.Random; ...@@ -6,49 +6,45 @@ import java.util.Random;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.persistence.Transient; import javax.persistence.Transient;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@MappedSuperclass @MappedSuperclass
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public abstract class EntityEquals { public abstract class EntityEquals {
@Override @Override
public final String toString() { public final String toString() {
return new StringBuilder(this.getClass().getCanonicalName()).append("[").append(getId()).append("]").toString(); return new StringBuilder(this.getClass().getCanonicalName()).append("[").append(getId()).append("]").toString();
} }
@Transient @Transient
private Integer rndid; private Integer rndid;
protected abstract Object getId(); protected abstract Object getId();
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
boolean ret = false; boolean ret = false;
if (this == o) { if (this == o) {
ret = true; ret = true;
} else if (o != null && o instanceof EntityEquals && this.getClass().getCanonicalName().equals(o.getClass().getCanonicalName())) { } else if (o != null && o instanceof EntityEquals && this.getClass().getCanonicalName().equals(o.getClass().getCanonicalName())) {
EntityEquals oobj = (EntityEquals) o; EntityEquals oobj = (EntityEquals) o;
if (getId() == null) { if (getId() == null) {
ret = (getRndid().equals(oobj.rndid)); ret = (getRndid().equals(oobj.rndid));
} else { } else {
ret = getId().equals(oobj.getId()); ret = getId().equals(oobj.getId());
} }
} }
return ret; return ret;
} }
private Integer getRndid() { private Integer getRndid() {
if (rndid == null) { if (rndid == null) {
Random rng = new Random(new Date().getTime()); Random rng = new Random(new Date().getTime());
rndid = Integer.valueOf(rng.nextInt()); rndid = Integer.valueOf(rng.nextInt());
} }
return rndid; return rndid;
} }
@Override @Override
public final int hashCode() { public final int hashCode() {
return ((rndid != null || getId() == null) ? getRndid() : getId().hashCode()); return ((rndid != null || getId() == null) ? getRndid() : getId().hashCode());
} }
} }
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/MoyaUtilities"/>
<classpathentry kind="con" path="oracle.eclipse.tools.glassfish.lib.system">
<attributes>
<attribute name="owner.project.facets" value="jst.utility"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MoyaUtilitiesTest</name>
<comment></comment>
<projects>
<project>MoyaUtilities</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
line.separator=\n
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="MoyaUtilitiesTest">
<wb-resource deploy-path="/" source-path="/src"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="GlassFish 4.0"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.utility" version="1.0"/>
</faceted-project>
disabled=06target
eclipse.preferences.version=1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-utils-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Manifest-Version: 1.0
Class-Path:
package fi.codecrew.moya.utilities;
import java.io.StringReader;
import java.util.ArrayList;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class JsonUtilsTest {
private JsonObject jsonObject(String jsonText) {
JsonReader jsonReader = Json.createReader(new StringReader(jsonText));
JsonObject jsonObject = jsonReader.readObject();
jsonReader.close();
return jsonObject;
}
@Before
public void setUp() throws Exception {
}
@Test
public final void testGetSubObject() {
JsonObject meta = jsonObject("{\"foo\":\"bar\",\"baz\":{\"quuz\":\"plop\"}}");
JsonObject expected = jsonObject("{\"quuz\":\"plop\"}");
ArrayList<String> path = new ArrayList<String>();
path.add("baz");
JsonObject actual = JsonUtils.getSubObject(meta, path);
Assert.assertEquals(expected.toString(), actual.toString());
}
@Test
public final void testAlterSubObject() {
JsonObject meta = jsonObject("{\"foo\":\"bar\"}");
JsonObject newData = jsonObject("{\"quux\":\"plop\"}");
ArrayList<String> path = new ArrayList<String>();
path.add("baz");
JsonObject actual = JsonUtils.alterSubObject(meta, path, newData);
JsonObject expected = jsonObject("{\"foo\":\"bar\",\"baz\":{\"quux\":\"plop\"}}");
Assert.assertEquals(expected.toString(), actual.toString());
}
}
package fi.codecrew.moya.rest.meta.v1;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;
import fi.codecrew.moya.beans.CardTemplateBeanLocal;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.utilities.JsonUtils;
@RequestScoped
@Path("/meta/v1/printedcard")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
public class PrintedCardRestViewV1 {
@EJB
CardTemplateBeanLocal cardTemplateBeanLocal;
/**
* Convert List<PathSegment> to List<String>
*
* @param path
* List<PathSegment>
* @return List<String>
*/
public List<String> pathToStrings(List<PathSegment> path) {
ArrayList<String> stringList = new ArrayList<String>(path.size());
for (PathSegment s : path) {
stringList.add(s.getPath());
}
return stringList;
}
/**
* Metadata for entity.
*
* @param id
* @param keys
* The path segments after card id
* @return
*/
@GET
@Path("/{id}/{keys:.*}")
@Produces(MediaType.APPLICATION_JSON)
public String getPrintedCardMeta(@PathParam("id") Integer id,
@PathParam("keys") List<PathSegment> keys) {
// Get the card's metadata
PrintedCard printedCard = cardTemplateBeanLocal.findCard(id);
JsonObject meta = printedCard.getMeta();
// Must be something
if (meta == null) {
meta = Json.createObjectBuilder().build();
}
// Remove lone empty string
if (keys.size() == 1 && keys.get(0).getPath().isEmpty()) {
keys = new ArrayList<PathSegment>();
}
// Get the subobject
JsonObject subObject = JsonUtils
.getSubObject(meta, pathToStrings(keys));
return subObject.toString() + "\n";
}
/**
* Alter metadata in one subproperty of the object.
*
* @param id
* @param keys
* @return
*/
@POST
@Path("/{id}/{keys:.*}")
@Consumes(MediaType.APPLICATION_JSON)
public String setPrintedCardMeta(@PathParam("id") Integer id,
@PathParam("keys") List<PathSegment> keys, String jsonData) {
// Get PrintedCard and it's metadata
PrintedCard printedCard = cardTemplateBeanLocal.findCard(id);
JsonObject meta = printedCard.getMeta();
// If no metadata yet, make empty metadata object
if (meta == null) {
meta = Json.createObjectBuilder().build();
}
// Parse the new json data to be inserted
JsonReader jsonReader = Json.createReader(new StringReader(jsonData));
JsonObject newData = jsonReader.readObject();
// Merge the new json data into existing metadata object
JsonObject alteredMeta = JsonUtils.alterSubObject(meta,
pathToStrings(keys), newData);
// Save the changed meta back to database
printedCard.setMeta(alteredMeta);
cardTemplateBeanLocal.saveCard(printedCard);
return null;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!