/**
   * Tests that single- and multi-column user type mappings work correctly. Also Checks that the
   * "sqlType" property is honoured.
   */
  public void testUserTypeMappings() {
    DefaultGrailsDomainConfiguration config = getDomainConfig(MULTI_COLUMN_USER_TYPE_DEFINITION);
    PersistentClass persistentClass = config.getClassMapping("Item");

    // First check the "name" property and its associated column.
    Property nameProperty = persistentClass.getProperty("name");
    assertEquals(1, nameProperty.getColumnSpan());
    assertEquals("name", nameProperty.getName());

    Column column = (Column) nameProperty.getColumnIterator().next();
    assertEquals("s_name", column.getName());
    assertEquals("text", column.getSqlType());

    // Next the "other" property.
    Property otherProperty = persistentClass.getProperty("other");
    assertEquals(1, otherProperty.getColumnSpan());
    assertEquals("other", otherProperty.getName());

    column = (Column) otherProperty.getColumnIterator().next();
    assertEquals("other", column.getName());
    assertEquals("wrapper-characters", column.getSqlType());
    assertEquals(MyUserType.class.getName(), column.getValue().getType().getName());
    assertTrue(column.getValue() instanceof SimpleValue);
    SimpleValue v = (SimpleValue) column.getValue();
    assertEquals("myParam1", v.getTypeParameters().get("param1"));
    assertEquals("myParam2", v.getTypeParameters().get("param2"));

    // And now for the "price" property, which should have two
    // columns.
    Property priceProperty = persistentClass.getProperty("price");
    assertEquals(2, priceProperty.getColumnSpan());
    assertEquals("price", priceProperty.getName());

    Iterator<?> colIter = priceProperty.getColumnIterator();
    column = (Column) colIter.next();
    assertEquals("value", column.getName());
    assertNull("SQL type should have been 'null' for 'value' column.", column.getSqlType());

    column = (Column) colIter.next();
    assertEquals("currency_code", column.getName());
    assertEquals("text", column.getSqlType());
  }
 public static Table getTable(Column column) {
   if (column.getValue() != null) {
     return column.getValue().getTable();
   }
   return null;
 }
示例#3
0
 private void checkColumn(Column column) {
   if (column.getValue() != null) {
     // throw new JDBCBinderException("Binding column twice should not happen. " + column);
   }
 }