Menu

[r678]: / javaontracks / src / net / jot / test / FSUser.java  Maximize  Restore  History

Download this file

102 lines (84 with data), 2.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
/*
------------------------------------
JavaOnTracks Thibaut Colar
tcolar-jot AT colar DOT net
Artistic Licence 2.0
http://www.javaontracks.net
------------------------------------
*/
package net.jot.test;
import net.jot.persistance.JOTDBUpgrader;
import net.jot.persistance.JOTModel;
import net.jot.persistance.JOTModelMapping;
/**
* Internal JOT class for self-test
* Test user for testing of JOTFS DB implementation
* @author thibautc
*
*/
public class FSUser extends JOTModel
{
// NOTE: must be protected or public
public String firstName;
public String lastName;
public int age;
//private String fieldToIgnore=null;
public String defineStorage()
{
return "testjot";
}
// Required (A model version MUST be defined)
protected int defineVersion()
{
return 3;
}
// Required, but can be empty
public void customize(JOTModelMapping mapping)
{
// All the following definitions are optional (example)
// The name of the table in the database, if different than classname.toLowerCase()
mapping.defineTableName("JOT_TMP_TEST_USER");
// Set the Primary key FB field name (if not 'dataId')
mapping.definePrimaryKey("dataid");
// If you have defined fields in this class that you want to ignore (Not saved in the database table)
// Note, you should call this very first, preferably.
String[] ignore={"fieldToIgnore"};
mapping.defineFieldsToIgnore(ignore);
// For variable-length fields(ie: varchar), you SHOULD define the length
mapping.defineFieldSize("firstName",57);
mapping.defineFieldSize("lastName",60);
//Optional definitions examples
// Field(column) name in DB, if different than fieldname.tolowercase()
mapping.defineFieldDBName("firstName","firstname");
// Define validation values
mapping.defineFieldMaxlength("firstName",20);
mapping.defineFieldMinlength("firstName",0);
mapping.defineFieldMinValue("age",0);
mapping.defineFieldMaxValue("age",130);
}
// Required (but can be empty)
public void upgradeTable(int fromVersion)
{
if(fromVersion<=1)
{
// alter something
}
if(fromVersion<=2)
{
// alter something else
}
}
// for testing purpose we want to reset the table before each run
public void resetTable() throws Exception
{
deleteTable();
createTableIfNecessary(getMapping());
}
public String toString()
{
return "Age: "+age+" ID:"+dataId+" first:"+firstName+" last:"+lastName;
}
protected void upgrade(int fromVersion, JOTDBUpgrader upgrader) throws Exception
{
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.