Skip to content

Commit

Permalink
FORGE-2101: Using not-nullable, not-insertable and not-updatable
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Nov 7, 2014
1 parent c8f38f2 commit bb5cf81
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ public class NewFieldWizard extends AbstractJavaEECommand implements UIWizard, P
private UIInput<String> named;

@Inject
@WithAttributes(label = "Nullable", defaultValue = "true")
private UIInput<Boolean> nullable;
@WithAttributes(name = "not-nullable", label = "Not Nullable")
private UIInput<Boolean> notNullable;

@Inject
@WithAttributes(label = "Updatable", defaultValue = "true")
private UIInput<Boolean> updatable;
@WithAttributes(name = "not-updatable", label = "Not Updatable")
private UIInput<Boolean> notUpdatable;

@Inject
@WithAttributes(label = "Insertable", defaultValue = "true")
private UIInput<Boolean> insertable;
@WithAttributes(name = "not-insertable", label = "Not Insertable")
private UIInput<Boolean> notInsertable;

@Inject
@WithAttributes(label = "Field Type", description = "The type intended to be used for this field", type = InputType.JAVA_CLASS_PICKER, required = true, defaultValue = "String")
Expand Down Expand Up @@ -278,23 +278,23 @@ public Boolean call() throws Exception
return !transientField.getValue();
}
});
nullable.setEnabled(new Callable<Boolean>()
notNullable.setEnabled(new Callable<Boolean>()
{
@Override
public Boolean call() throws Exception
{
return !transientField.getValue();
}
});
insertable.setEnabled(new Callable<Boolean>()
notInsertable.setEnabled(new Callable<Boolean>()
{
@Override
public Boolean call() throws Exception
{
return !transientField.getValue();
}
});
updatable.setEnabled(new Callable<Boolean>()
notUpdatable.setEnabled(new Callable<Boolean>()
{
@Override
public Boolean call() throws Exception
Expand Down Expand Up @@ -345,7 +345,7 @@ public Boolean call() throws Exception
});

builder.add(targetEntity).add(named).add(type).add(temporalType).add(columnName).add(length)
.add(nullable).add(insertable).add(updatable)
.add(notNullable).add(notInsertable).add(notUpdatable)
.add(relationshipType)
.add(lob).add(transientField)
.add(enumType);
Expand Down Expand Up @@ -493,17 +493,17 @@ else if (beanOperations.isFieldTypeEnum(project, targetEntity, type.getValue()))
field.addAnnotation(Column.class).setStringValue("name", columnName.getValue());
}

if (nullable.isEnabled() && nullable.hasValue())
if (notNullable.isEnabled() && notNullable.getValue())
{
setLiteralValueInColumn(field, "nullable", nullable.getValue().toString());
setLiteralValueInColumn(field, "nullable", "false");
}
if (insertable.isEnabled() && insertable.hasValue())
if (notInsertable.isEnabled() && notInsertable.getValue())
{
setLiteralValueInColumn(field, "insertable", insertable.getValue().toString());
setLiteralValueInColumn(field, "insertable", "false");
}
if (updatable.isEnabled() && updatable.hasValue())
if (notUpdatable.isEnabled() && notUpdatable.getValue())
{
setLiteralValueInColumn(field, "updatable", updatable.getValue().toString());
setLiteralValueInColumn(field, "updatable", "false");
}
}
else
Expand All @@ -514,23 +514,23 @@ else if (beanOperations.isFieldTypeEnum(project, targetEntity, type.getValue()))
}
if (length.isEnabled() && length.getValue() != null && length.getValue().intValue() != 255)
{
field.getAnnotation(Column.class).setLiteralValue("length", String.valueOf(length.getValue()));
setLiteralValueInColumn(field, "length", String.valueOf(length.getValue()));
}
if (columnName.isEnabled() && columnName.hasValue())
{
field.getAnnotation(Column.class).setStringValue("name", columnName.getValue());
}
if (nullable.isEnabled() && nullable.hasValue())
if (notNullable.isEnabled() && notNullable.getValue())
{
setLiteralValueInColumn(field, "nullable", nullable.getValue().toString());
setLiteralValueInColumn(field, "nullable", "false");
}
if (insertable.isEnabled() && insertable.hasValue())
if (notInsertable.isEnabled() && notInsertable.getValue())
{
setLiteralValueInColumn(field, "insertable", insertable.getValue().toString());
setLiteralValueInColumn(field, "insertable", "false");
}
if (updatable.isEnabled() && updatable.hasValue())
if (notUpdatable.isEnabled() && notUpdatable.getValue())
{
setLiteralValueInColumn(field, "updatable", updatable.getValue().toString());
setLiteralValueInColumn(field, "updatable", "false");
}
if (temporalType.isEnabled())
{
Expand All @@ -546,11 +546,13 @@ else if (beanOperations.isFieldTypeEnum(project, targetEntity, type.getValue()))
}
}

private void setLiteralValueInColumn(FieldSource<JavaClassSource> field, String literal, String value) {
if (field.getAnnotation(Column.class) != null) {
field.getAnnotation(Column.class).setLiteralValue(literal, value);
}
}
private void setLiteralValueInColumn(FieldSource<JavaClassSource> field, String literal, String value)
{
if (field.getAnnotation(Column.class) != null)
{
field.getAnnotation(Column.class).setLiteralValue(literal, value);
}
}

/**
* @param context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testNewField() throws Exception
}

@Test
public void testNewFieldWithNullableInsertableUpdatableTrue() throws Exception
public void testNewFieldWithNotNullableInsertableUpdatableTrue() throws Exception
{
JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
Expand All @@ -130,9 +130,9 @@ public void testNewFieldWithNullableInsertableUpdatableTrue() throws Exception
Assert.assertFalse(controller.canExecute());
controller.setValueFor("named", "firstName");
controller.setValueFor("columnName", "FIRST_NAME_COLUMN");
controller.setValueFor("nullable", "true");
controller.setValueFor("insertable", "true");
controller.setValueFor("updatable", "true");
controller.setValueFor("not-nullable", "true");
controller.setValueFor("not-insertable", "true");
controller.setValueFor("not-updatable", "true");
Assert.assertFalse(controller.canMoveToNextStep());
Assert.assertTrue(controller.canExecute());
Result result = controller.execute();
Expand All @@ -145,14 +145,14 @@ public void testNewFieldWithNullableInsertableUpdatableTrue() throws Exception
Assert.assertTrue(field.hasAnnotation(Column.class));
Assert.assertEquals("String", field.getType().getName());
Assert.assertEquals("FIRST_NAME_COLUMN", field.getAnnotation(Column.class).getStringValue("name"));
Assert.assertEquals("true", field.getAnnotation(Column.class).getLiteralValue("nullable"));
Assert.assertEquals("true", field.getAnnotation(Column.class).getLiteralValue("updatable"));
Assert.assertEquals("true", field.getAnnotation(Column.class).getLiteralValue("insertable"));
Assert.assertEquals("false", field.getAnnotation(Column.class).getLiteralValue("nullable"));
Assert.assertEquals("false", field.getAnnotation(Column.class).getLiteralValue("updatable"));
Assert.assertEquals("false", field.getAnnotation(Column.class).getLiteralValue("insertable"));
}


@Test
public void testNewFieldWithNullableInsertableUpdatableFalse() throws Exception
public void testNewFieldWithNotNullableInsertableUpdatableFalse() throws Exception
{
JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
try (WizardCommandController controller = uiTestHarness.createWizardController(NewFieldWizard.class,
Expand All @@ -164,9 +164,9 @@ public void testNewFieldWithNullableInsertableUpdatableFalse() throws Exception
Assert.assertFalse(controller.canExecute());
controller.setValueFor("named", "firstName");
controller.setValueFor("columnName", "FIRST_NAME_COLUMN");
controller.setValueFor("nullable", "false");
controller.setValueFor("insertable", "false");
controller.setValueFor("updatable", "false");
controller.setValueFor("not-nullable", "false");
controller.setValueFor("not-insertable", "false");
controller.setValueFor("not-updatable", "false");
Assert.assertFalse(controller.canMoveToNextStep());
Assert.assertTrue(controller.canExecute());
Result result = controller.execute();
Expand All @@ -179,9 +179,9 @@ public void testNewFieldWithNullableInsertableUpdatableFalse() throws Exception
Assert.assertTrue(field.hasAnnotation(Column.class));
Assert.assertEquals("String", field.getType().getName());
Assert.assertEquals("FIRST_NAME_COLUMN", field.getAnnotation(Column.class).getStringValue("name"));
Assert.assertEquals("false", field.getAnnotation(Column.class).getLiteralValue("nullable"));
Assert.assertEquals("false", field.getAnnotation(Column.class).getLiteralValue("updatable"));
Assert.assertEquals("false", field.getAnnotation(Column.class).getLiteralValue("insertable"));
Assert.assertNull(field.getAnnotation(Column.class).getLiteralValue("nullable"));
Assert.assertNull(field.getAnnotation(Column.class).getLiteralValue("updatable"));
Assert.assertNull(field.getAnnotation(Column.class).getLiteralValue("insertable"));
}

@Test
Expand Down

0 comments on commit bb5cf81

Please sign in to comment.