Search in sources :

Example 1 with TableDefinition

use of com.orm.androrm.TableDefinition in project androrm by androrm.

the class TableDefinitionTest method testTableName.

public void testTableName() {
    TableDefinition def = new TableDefinition("foo");
    assertEquals("foo", def.getTableName());
    assertEquals("CREATE TABLE IF NOT EXISTS `foo` ();", def.toString());
}
Also used : TableDefinition(com.orm.androrm.TableDefinition)

Example 2 with TableDefinition

use of com.orm.androrm.TableDefinition in project androrm by androrm.

the class TableDefinitionTest method testRelationalClasses.

public void testRelationalClasses() {
    TableDefinition def = new TableDefinition("foo");
    def.addRelationalClass(Product.class);
    List<Class<? extends Model>> relations = def.getRelationalClasses();
    assertEquals(1, relations.size());
    assertTrue(relations.contains(Product.class));
}
Also used : Model(com.orm.androrm.Model) TableDefinition(com.orm.androrm.TableDefinition) Product(com.orm.androrm.impl.Product)

Example 3 with TableDefinition

use of com.orm.androrm.TableDefinition in project androrm by androrm.

the class TableDefinitionTest method testAddSimpleField.

public void testAddSimpleField() {
    TableDefinition def = new TableDefinition("foo");
    IntegerField i = new IntegerField();
    def.addField("pk", i);
    assertEquals("CREATE TABLE IF NOT EXISTS `foo` (`pk` integer);", def.toString());
}
Also used : TableDefinition(com.orm.androrm.TableDefinition) IntegerField(com.orm.androrm.field.IntegerField)

Example 4 with TableDefinition

use of com.orm.androrm.TableDefinition in project androrm by androrm.

the class TableDefinitionTest method testForeignKeyNotCascading.

public void testForeignKeyNotCascading() {
    TableDefinition def = new TableDefinition("foo");
    ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
    fk.doNotCascade();
    def.addField("product", fk);
    assertEquals("CREATE TABLE IF NOT EXISTS `foo` (" + "`product` integer," + "FOREIGN KEY (`product`) " + "REFERENCES `product` (`mId`) " + "ON DELETE SET NULL);", def.toString());
}
Also used : ForeignKeyField(com.orm.androrm.field.ForeignKeyField) TableDefinition(com.orm.androrm.TableDefinition) Product(com.orm.androrm.impl.Product)

Example 5 with TableDefinition

use of com.orm.androrm.TableDefinition in project androrm by androrm.

the class TableDefinitionTest method testForeignKeyField.

public void testForeignKeyField() {
    TableDefinition def = new TableDefinition("foo");
    ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
    def.addField("product", fk);
    assertEquals("CREATE TABLE IF NOT EXISTS `foo` (" + "`product` integer," + "FOREIGN KEY (`product`) " + "REFERENCES `product` (`mId`) " + "ON DELETE CASCADE);", def.toString());
}
Also used : ForeignKeyField(com.orm.androrm.field.ForeignKeyField) TableDefinition(com.orm.androrm.TableDefinition) Product(com.orm.androrm.impl.Product)

Aggregations

TableDefinition (com.orm.androrm.TableDefinition)5 Product (com.orm.androrm.impl.Product)3 ForeignKeyField (com.orm.androrm.field.ForeignKeyField)2 Model (com.orm.androrm.Model)1 IntegerField (com.orm.androrm.field.IntegerField)1