PK 0L}?XU U README.markdownSiena support for Play! Framework v2.x
======================================
The siena module automatically enables [Siena](http://www.sienaproject.com) support for your application for GAE/MySQL/PostgreSQL/H2 databases.
Release notes
--------------------
* v2.0.6 provides support for :
+ GAE
+ MySQL
+ Postgresql
+ H2
+ GoogleCloudSQL
+ Amazon SDB
* v2.x brings support for IDs of type Long (auto-generated or manual) and String (manual or auto-generated as UUID).
* v2.x brings a new class called __EnhancedModel__ which is a normal __siena.Model__ enhanced at runtime by Play to provide __all()__ function (and other functions also but it will be detailed later). Please see below for more details.
* v2.x is a complete refactoring of siena module based on Siena v1.x. Yet, for those who used Siena before, it doesn't change anything as Siena v1.0.0 is 100% backward compatible (at least in theory).
* v2.x is compatible with Play version >1.2.1 and uses dependency management.
> **Note** v1.x only supported GAE but this is not the case anymore. Other NoSQL Databases will be added later.
PK 0L}?%
RELEASE-NOTESPlay CRUD Siena release notes:
v2.0.6
----------------------------------------------------------
== BUG FIXES ==
== ENHANCEMENTS ==
* Contribution by swallez to allow Siena and JPA to be used simultaneously
* Support for GoogleCloudSQL (needed to disable DBPLugin and c3pO when using it)
v2.0.5
----------------------------------------------------------
== BUG FIXES ==
== ENHANCEMENTS ==
* early integration of SDB (not fully implemented on siena side but already functional)
* tutorial to use Play+Siena+SDB on Heroku documentation/tutorials/heroku_sdb_tutorial.textile
v2.0.4
----------------------------------------------------------
== BUG FIXES ==
* corrects bug in YAML loading of models with @Id field not named “id”
* YAML loading of related entities
== ENHANCEMENTS ==
* brings siena-1.0.0-b6
* provides GAE Native Embedding
v2.0.3
----------------------------------------------------------
== BUG FIXES ==
* correcting bugs on EnhancedModel functions which were not enhanced at all (findById, getByKey & batch)
v2.0.2
----------------------------------------------------------
== BUG FIXES ==
== ENHANCEMENTS ==
* integrated + tested management of models with new GAE Native embedding feature
PK K1@Hn n build.xml
PK DL1@K) ) manifestversion=2.0.7
frameworkVersions=[1.2.3,)
PK e> : samples-and-tests/sienatest/app/models/ContainerModel.javapackage models;
import play.modules.siena.EnhancedModel;
import siena.Column;
import siena.Generator;
import siena.Id;
import siena.Table;
import siena.embed.Embedded;
import siena.embed.EmbeddedList;
@Table("container_models")
@EmbeddedList
public class ContainerModel extends EnhancedModel{
@Id(Generator.NONE)
public String id;
@Embedded
@Column("embed")
public EmbeddedModel embed;
public String toString() {
return id + " " + embed;
}
}
PK e>ܷ 9 samples-and-tests/sienatest/app/models/EmbeddedModel.javapackage models;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Model;
import siena.Table;
import siena.embed.EmbeddedMap;
@Table("embedded_models")
@EmbeddedMap
public class EmbeddedModel extends EnhancedModel{
@Id(Generator.NONE)
public String id;
public String alpha;
public short beta;
public String toString() {
return id + " " + alpha + " " + beta;
}
}
PK WE?5 8 samples-and-tests/sienatest/app/models/OtherIdModel.javapackage models;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Table;
@Table("otherid_models")
public class OtherIdModel extends EnhancedModel{
@Id(Generator.AUTO_INCREMENT)
public Long myId;
public String alpha;
public short beta;
public String toString() {
return myId + " " + alpha + " " + beta;
}
}
PK e> Gnw w 5 samples-and-tests/sienatest/app/models/UUIDModel.javapackage models;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Table;
@Table("uuid_models")
public class UUIDModel extends EnhancedModel{
@Id(Generator.UUID)
public String id;
public String alpha;
public short beta;
public String toString() {
return id + " " + alpha + " " + beta;
}
}
PK e>}l2 > samples-and-tests/sienatest/app/models/DiscoveryLifeCycle.javapackage models;
import siena.Generator;
import siena.Id;
import siena.Max;
import siena.Model;
import siena.Table;
import siena.core.lifecycle.PostDelete;
import siena.core.lifecycle.PostFetch;
import siena.core.lifecycle.PostInsert;
import siena.core.lifecycle.PostSave;
import siena.core.lifecycle.PostUpdate;
import siena.core.lifecycle.PreDelete;
import siena.core.lifecycle.PreFetch;
import siena.core.lifecycle.PreInsert;
import siena.core.lifecycle.PreSave;
import siena.core.lifecycle.PreUpdate;
@Table("discoveries_lifecycle")
public class DiscoveryLifeCycle extends Model {
@Id(Generator.AUTO_INCREMENT)
public Long id;
@Max(100)
public String name;
public DiscoveryLifeCycle(String name) {
this.name = name;
}
public DiscoveryLifeCycle() {
}
@PreFetch
private void preFetch() {
System.out.println("preFetch");
}
@PostFetch
private void postFetch() {
System.out.println("postFetch");
}
@PreInsert
private void preInsert() {
System.out.println("preInsert");
}
@PostInsert
private void postInsert() {
System.out.println("postInsert");
}
@PreDelete
private void preDelete() {
System.out.println("preDelete");
}
@PostDelete
private void postDelete() {
System.out.println("postDelete");
}
@PreUpdate
private void preUpdate() {
System.out.println("preUpdate");
}
@PostUpdate
private void postUpdate() {
System.out.println("postUpdate");
}
@PreSave
private void preSave() {
System.out.println("preSave");
}
@PostSave
private void postSave() {
System.out.println("postSave");
}
@Override
public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass())
return false;
DiscoveryLifeCycle other = (DiscoveryLifeCycle) obj;
if(other.name != null && other.name.equals(name))
return true;
return false;
}
public boolean isOnlyIdFilled() {
if(this.id != null
&& this.name == null
) return true;
return false;
}
public String toString() {
return "Discovery [ id:"+id+" - name:"+name+" ]";
}
}
PK e>IhQ G samples-and-tests/sienatest/app/models/TransactionAccountFromModel.java/*
* Copyright 2011 Pascal
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package models;
import siena.Generator;
import siena.Id;
import siena.Model;
import siena.Query;
import siena.Table;
import siena.core.batch.Batch;
@Table("transaction_from")
public class TransactionAccountFromModel extends Model{
@Id(Generator.AUTO_INCREMENT)
public Long id;
public Long amount;
public TransactionAccountFromModel() {
}
public TransactionAccountFromModel(Long amount) {
this.amount = amount;
}
public Query all() {
return Model.all(TransactionAccountFromModel.class);
}
public Batch batch() {
return Model.batch(TransactionAccountFromModel.class);
}
public String toString() {
return "id: "+id+", amount: "+amount;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((amount == null) ? 0 : amount.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TransactionAccountFromModel other = (TransactionAccountFromModel) obj;
if (amount == null) {
if (other.amount != null)
return false;
}
if(!amount.equals(other.amount))
return false;
return true;
}
public boolean isOnlyIdFilled() {
if(this.id != null
&& this.amount == null
) return true;
return false;
}
}
PK e>h = samples-and-tests/sienatest/app/models/ManualStringModel.javapackage models;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Model;
import siena.Table;
@Table("manual_string_models")
public class ManualStringModel extends EnhancedModel{
@Id(Generator.NONE)
public String id;
public String alpha;
public short beta;
public String toString() {
return id + " " + alpha + " " + beta;
}
}
PK e>|#
4 samples-and-tests/sienatest/app/models/Employee.javapackage models;
import java.util.Date;
import java.util.List;
import java.util.Map;
import play.data.validation.Password;
import siena.Column;
import siena.DateTime;
import siena.Entity;
import siena.Filter;
import siena.Generator;
import siena.Id;
import siena.Index;
import siena.Json;
import siena.Max;
import siena.Model;
import siena.NotNull;
import siena.Query;
import siena.Table;
import siena.core.batch.Batch;
import siena.embed.At;
import siena.embed.Embedded;
import siena.embed.EmbeddedList;
import siena.embed.EmbeddedMap;
@Table("employees")
public class Employee extends Model {
@Id(Generator.AUTO_INCREMENT)
public Long id;
@Column("first_name")
@Max(10) @NotNull
//@play.data.validation.MaxSize(10) @play.data.validation.Required
public String firstName;
@Column("last_name")
@Max(200) @NotNull
public String lastName;
@Password
@Column("pwd")
public String pwd;
@Column("contact_info")
public Json contactInfo;
@Column("hire_date")
public Date hireDate;
@Column("fire_date")
@DateTime
public Date fireDate;
@Column("boss") @Index("boss_index")
public Employee boss;
@Filter("boss")
public siena.Query employees;
@Embedded
public Image profileImage;
@Embedded
public List otherImages;
@Embedded
public Map stillImages;
@EmbeddedMap
public class Image {
public String filename;
public String title;
public int views;
public MyEnum itemEnum;
}
@Embedded
public List items;
@EmbeddedList
public class UserBlabla {
@At(0) public String item;
@At(1) public String item2;
@At(2) public MyEnum itemEnum;
}
public MyEnum enumField;
public static enum MyEnum{
VAL1,
VAL2,
VAL3
};
public String toString() {
return firstName + " " + lastName;
}
public static Query all() {
return Model.all(Employee.class);
}
public static Batch batch() {
return Model.batch(Employee.class);
}
public Employee(Employee emp){
this.firstName = emp.firstName;
this.lastName = emp.lastName;
this.pwd = emp.pwd;
this.contactInfo = new Json(emp.contactInfo);
this.hireDate = emp.hireDate;
this.fireDate = emp.fireDate;
this.boss = emp.boss;
this.enumField = emp.enumField;
// ...
}
}PK e>pFZja a <