Skip to content

Commit

Permalink
* renamed samples-and-test/sienatest to crudsienatest
Browse files Browse the repository at this point in the history
* added some models for tests
  • Loading branch information
pascal authored and pascal committed May 29, 2011
1 parent 74dd949 commit 2c7d12d
Show file tree
Hide file tree
Showing 38 changed files with 166 additions and 246 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -1 +1,7 @@
/.project
/lib
/.classpath
/commands.pyc
/dist
/.settings
/modules
163 changes: 47 additions & 116 deletions app/controllers/CRUD.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/views/CRUD/show.html
@@ -1,6 +1,6 @@
#{extends 'CRUD/layout.html' /}
%{
def keyVal = play.modules.crudsiena.SienaUtils.findKey(object)
def keyVal = play.modules.siena.SienaModelUtils.keyValue(object)
}%
<div id="crudShow" class="${type.name}">

Expand Down
2 changes: 1 addition & 1 deletion app/views/tags/crud/navigation.html
Expand Up @@ -4,7 +4,7 @@
<li>&gt; <a href="@{list()}">&{_caller.type.name}</a></li>
#{/if}
#{if _caller.object}
<li>&gt; <a href="@{show(play.modules.crudsiena.SienaUtils.findKey(_caller.object))}">${_caller.object?.toString()?.escape()?.raw()}</a></li>
<li>&gt; <a href="@{show(play.modules.siena.SienaModelUtils.keyValue(_caller.object))}">${_caller.object?.toString()?.escape()?.raw()}</a></li>
#{/if}
#{if request.actionMethod == 'blank'}
<li>&gt; <a href="@{blank()}">&{'crud.blank'}</a></li>
Expand Down
4 changes: 2 additions & 2 deletions app/views/tags/crud/table.html
Expand Up @@ -49,7 +49,7 @@
}%
%{ } else { }%
%{ if(i == 0) { }%
<a href="@{show(play.modules.crudsiena.SienaUtils.findKey(object))}">${object[field]?.toString()?.escape()?.raw() ?: '(no value)'}</a>
<a href="@{show(play.modules.siena.SienaModelUtils.keyValue(object))}">${object[field]?.toString()?.escape()?.raw() ?: '(no value)'}</a>
%{ } else { }%
%{ if(_caller.type.getField(field).type == 'file') { }%
%{ if(object[field]) { }%
Expand All @@ -73,7 +73,7 @@
#{doBody body:handler /}
%{ } else { }%
<td>
<a href="@{show(play.modules.crudsiena.SienaUtils.findKey(object))}">${object.toString()?.escape()?.raw() ?: '(no value)'}</a>
<a href="@{show(play.modules.siena.SienaModelUtils.keyValue(object))}">${object.toString()?.escape()?.raw() ?: '(no value)'}</a>
</td>
%{ } }%
%{ } }%
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -13,7 +13,7 @@
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${play.path}/modules/">
<fileset dir="${play.path}/modules/siena-2.0.0">
<include name="**/*siena*.jar"/>
</fileset>
</path>
Expand Down
4 changes: 2 additions & 2 deletions conf/dependencies.yml
@@ -1,8 +1,8 @@
# Application dependencies

self: play -> crudsiena 2.0
self: play -> crudsiena 2.0.0

require:
- play [1.2.1,)
- play -> siena [2.0,)
- play -> siena [2.0.0,)

Expand Up @@ -11,3 +11,4 @@
/.classpath
/test-result
/tmp
/modules
@@ -0,0 +1,8 @@
package controllers;

import models.ContainerModel;

@CRUD.For(ContainerModel.class)
public class ContainerModels extends controllers.CRUD {

}
@@ -0,0 +1,8 @@
package controllers;

import models.EmbeddedModel;

@CRUD.For(EmbeddedModel.class)
public class EmbeddedModels extends controllers.CRUD {

}
@@ -0,0 +1,8 @@
package controllers;

import models.UUIDModel;

@CRUD.For(UUIDModel.class)
public class UUIDModels extends controllers.CRUD {

}
@@ -1,6 +1,6 @@
package models;

import play.modules.siena.Model;
import play.modules.siena.EnhancedModel;
import siena.Column;
import siena.Generator;
import siena.Id;
Expand All @@ -10,14 +10,16 @@

@Table("container_models")
@EmbeddedList
public class ContainerModel extends Model{
public class ContainerModel extends EnhancedModel{
@Id(Generator.NONE)
public String id;

@Embedded
@Column("embed")
public EmbeddedModel embed;

public long test;

public String toString() {
return id + " " + embed;
}
Expand Down
@@ -1,14 +1,14 @@
package models;

import play.modules.siena.Model;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Table;
import siena.embed.EmbeddedMap;

@Table("embedded_models")
@EmbeddedMap
public class EmbeddedModel extends Model{
public class EmbeddedModel extends EnhancedModel{
@Id(Generator.NONE)
public String id;

Expand Down
Expand Up @@ -5,18 +5,16 @@
import java.util.Map;

import play.data.validation.Password;
import play.modules.siena.Model;
import play.modules.siena.EnhancedModel;
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.NotNull;
import siena.Query;
import siena.Table;
import siena.embed.At;
import siena.embed.Embedded;
Expand All @@ -25,7 +23,7 @@


@Table("employees")
public class Employee extends Model {
public class Employee extends EnhancedModel {

@Id(Generator.AUTO_INCREMENT)
public Long id;
Expand Down
@@ -1,13 +1,12 @@
package models;

import play.modules.siena.Model;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Table;
import siena.embed.EmbeddedMap;

@Table("manual_string_models")
public class ManualStringModel extends Model{
public class ManualStringModel extends EnhancedModel{
@Id(Generator.NONE)
public String id;

Expand Down
@@ -1,13 +1,12 @@
package models;

import play.modules.siena.Model;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Table;
import siena.embed.EmbeddedMap;

@Table("otherid_models")
public class OtherIdModel extends Model{
public class OtherIdModel extends EnhancedModel{
@Id(Generator.AUTO_INCREMENT)
public Long myId;

Expand Down
@@ -1,13 +1,12 @@
package models;

import play.modules.siena.Model;
import play.modules.siena.EnhancedModel;
import siena.Generator;
import siena.Id;
import siena.Table;
import siena.embed.EmbeddedMap;

@Table("uuid_models")
public class UUIDModel extends Model{
public class UUIDModel extends EnhancedModel{
@Id(Generator.UUID)
public String id;

Expand Down
@@ -1,12 +1,12 @@
# This is the main configuration file for the application.
# ~~~~~
application.name=sienatest
application.name=crudsienatest

# Application mode
# ~~~~~
# Set to dev to enable instant reloading and other development help.
# Otherwise set to prod.
application.mode=prod
application.mode=dev
%prod.application.mode=prod

# Secret key
Expand Down Expand Up @@ -77,7 +77,7 @@ application.log=DEBUG
# To quickly set up a development database, use either:
# - mem : for a transient in memory database (H2 in memory)
# - fs : for a simple file written database (H2 file stored)
#db=fs
db=mem
#
# To connect to a local MySQL5 database, use:
#db=mysql:sienatest:sienatest@sienatest
Expand Down
7 changes: 7 additions & 0 deletions samples-and-tests/crudsienatest/conf/dependencies.yml
@@ -0,0 +1,7 @@
# Application dependencies

require:
- play -> play [1.2.1,)
- play -> crudsiena 2.0.0
#- play -> gae 1.4
#- postgresql -> postgresql 8.4-702.jdbc4
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions samples-and-tests/sienatest/conf/dependencies.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/play.plugins
@@ -1 +1 @@
0:play.modules.crudsiena.CrudSienaPlugin
500:play.modules.crudsiena.CrudSienaPlugin
40 changes: 37 additions & 3 deletions src/play/modules/crudsiena/CrudSienaEnhancer.java
Expand Up @@ -16,18 +16,52 @@
import play.Logger;
import play.classloading.ApplicationClasses.ApplicationClass;
import play.classloading.enhancers.Enhancer;
import siena.ClassInfo;
import siena.Max;

public class CrudSienaEnhancer extends Enhancer {

@Override
public void enhanceThisClass(ApplicationClass applicationClass)
throws Exception {
final CtClass ctClass = makeClass(applicationClass);

if (!ctClass.subtypeOf(classPool.get("play.modules.siena.Model"))) {
Logger.debug("CrudSiena: trying to enhance class:" + applicationClass.name);
final CtClass ctClass = makeClass(applicationClass);
if(ctClass == null) return;
String pack = ctClass.getPackageName();
if(pack==null || pack.startsWith("java.")){
return;
}
if (ctClass.subtypeOf(classPool.get(siena.Json.class.getName()))) {
return;
}
boolean isModel = false;

if(ctClass.subclassOf(classPool.get(siena.Model.class.getName()))){
isModel = true;
}
else {
CtField[] fields = ctClass.getDeclaredFields();
CtClass cl = ctClass;
while(cl != null){
for (CtField field : fields) {
Object[] annotations = field.getAnnotations();
for(Object ann: annotations){
if(ann.getClass() == siena.Id.class){
isModel = true;
break;
}
}
if(isModel){
break;
}
}

cl = cl.getSuperclass();
}
}
if(!isModel){
return;
}

Logger.debug("CrudSiena: start to enhance class:" + applicationClass.name);
// this method will be called after configuration finished
Expand Down
5 changes: 4 additions & 1 deletion src/play/modules/crudsiena/CrudSienaPlugin.java
Expand Up @@ -4,12 +4,15 @@
import play.classloading.ApplicationClasses.ApplicationClass;

public class CrudSienaPlugin extends PlayPlugin {

private CrudSienaEnhancer enhancer = new CrudSienaEnhancer();

/**
* Enhance this class
* @param applicationClass
* @throws java.lang.Exception
*/
public void enhance(ApplicationClass applicationClass) throws Exception {
CrudSienaEnhancer.class.newInstance().enhanceThisClass(applicationClass);
enhancer.enhanceThisClass(applicationClass);
}
}

0 comments on commit 2c7d12d

Please sign in to comment.