PK `&?ʾA~M M build.xml
PK `G?E}_ _ README.textileh1. Chronostamp module for Play!
Chronostamp adds magic timestamp fields to Models, like Ruby on Rails:
* created_at
* updated_at
h2. Features
* will add timestamp magic fields (created_at and updated_at) in an unobtrusive way.
* will automatically record creation and update timestamps of database objects.
* avoid inheritance coupling just for adding two attributes.
* avoid to write @MappedSuperclass for every single model.
h2. Note:
* SpringPlugin has a priority of 1000 and it clashes with this one if it has a priority <= 1000, that's why this plugin has a priority of 1001
h2. How to Use
Well it's kind of easy, just add this module to your dependecy.yml file
If you have a legacy DB with tables that doesn't have created_at and updated_at timestamp columns,
you can skip the creation of these magic timestamp fields by annotating the Model with
@NoChronostamp
If you control the creation of DB (Evolution, MyBatis Migrations, etc).
the timestamp columns must be of type TIMESTAMP
h4. Testing the timestamping
Start play in test mode and launch a browser to "http://localhost:9000/@test"
Done!
You may find a sample app bundled with the module
h2. Credits
This module is inspired on Ruby on Rails magic timestamp fields and Code snippet
"Keep track of JPA record creation/updates":http://www.playframework.org/community/snippets/5
Author: Omar O. Román
PK LK?NK$ $ manifestversion=0.1
frameworkVersions=1.2.3
PK Q|4?FT LICENSE
This software is licensed under the Apache 2.0 license, quoted below.
Copyright 2011 Omar O. Román
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.
PK l'?tB6 6 5 samples-and-tests/chronostamp-app/test/BasicTest.javaimport org.apache.commons.beanutils.PropertyUtils;
import org.junit.*;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import play.test.*;
import models.*;
public class BasicTest extends UnitTest {
@Before
public void setup() {
Fixtures.deleteAllModels();
Fixtures.loadModels("data.yml");
}
@Test
public void testMagicTimestampFields() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
Article article = (Article) Article.findAll().get(0);
assertNotNull(PropertyUtils.getProperty(article, "created_at"));
assertNotNull(PropertyUtils.getProperty(article, "updated_at"));
assertNotSame(new Date().getTime(), ((Date)PropertyUtils.getProperty(article, "created_at")).getTime());
assertNotSame(new Date().getTime(), ((Date)PropertyUtils.getProperty(article, "updated_at")).getTime());
assertEquals(((Date)PropertyUtils.getProperty(article, "created_at")).getTime(), ((Date)PropertyUtils.getProperty(article, "updated_at")).getTime());
article.name = "Logitech";
article.save();
assertNotSame(((Date)PropertyUtils.getProperty(article, "created_at")).getTime(), ((Date)PropertyUtils.getProperty(article, "updated_at")).getTime());
}
@After
public void doTestMagicTimestampFields() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
Article article = (Article) Article.findAll().get(0);
// Since created_at and updated_at fields are injected at run time
// they must be invoked by using reflection
Date created_at = (Date) PropertyUtils.getProperty(article, "created_at");
Date updated_at = (Date) PropertyUtils.getProperty(article, "updated_at");
}
}
PK