Skip to content

Commit

Permalink
Added result message when finishing DatabaseTableSelectionStep
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Apr 10, 2014
1 parent ee93332 commit 5251c05
Showing 1 changed file with 54 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public boolean isEnabled(UIContext context)
{
return true;
}

@Inject
private GenerateEntitiesCommandDescriptor descriptor;

@Inject
private HibernateToolsHelper helper;

private JDBCMetaDataConfiguration jmdc;

@SuppressWarnings("unchecked")
Expand All @@ -87,10 +87,12 @@ public void initializeUI(UIBuilder builder) throws Exception
helper.buildMappings(descriptor.urls, descriptor.driverClass, jmdc);
Iterator<Object> iterator = jmdc.getTableMappings();
ArrayList<String> tables = new ArrayList<String>();
while (iterator.hasNext()) {
while (iterator.hasNext())
{
Object mapping = iterator.next();
if (mapping instanceof Table) {
Table table = (Table)mapping;
if (mapping instanceof Table)
{
Table table = (Table) mapping;
tables.add(table.getName());
}
}
Expand All @@ -101,70 +103,86 @@ public void initializeUI(UIBuilder builder) throws Exception

@Override
public Result execute(UIExecutionContext context)
{
exportSelectedEntities();
return Results.success();
{
Collection<String> entities = exportSelectedEntities();
return Results.success(entities.size() + " entities were generated");
}

@Override
public void validate(UIValidationContext context)
{
}

private boolean isSelected(Collection<String> selection, POJOClass element) {

private boolean isSelected(Collection<String> selection, POJOClass element)
{
boolean result = false;
if (element.isComponent()) {
if (element instanceof ComponentPOJOClass) {
ComponentPOJOClass cpc = (ComponentPOJOClass)element;
if (element.isComponent())
{
if (element instanceof ComponentPOJOClass)
{
ComponentPOJOClass cpc = (ComponentPOJOClass) element;
Iterator<?> iterator = cpc.getAllPropertiesIterator();
result = true;
while (iterator.hasNext()) {
while (iterator.hasNext())
{
Object object = iterator.next();
if (object instanceof Property) {
Property property = (Property)object;
if (object instanceof Property)
{
Property property = (Property) object;
String tableName = property.getValue().getTable().getName();
if (!selection.contains(tableName)) {
if (!selection.contains(tableName))
{
result = false;
break;
}
}
}
}
} else {
if (element instanceof EntityPOJOClass) {
EntityPOJOClass epc = (EntityPOJOClass)element;
}
else
{
if (element instanceof EntityPOJOClass)
{
EntityPOJOClass epc = (EntityPOJOClass) element;
Object object = epc.getDecoratedObject();
if (object instanceof PersistentClass) {
PersistentClass pc = (PersistentClass)object;
if (object instanceof PersistentClass)
{
PersistentClass pc = (PersistentClass) object;
Table table = pc.getTable();
if (selection.contains(table.getName())) {
if (selection.contains(table.getName()))
{
result = true;
}
}
}
}
}
return result;
}

private Collection<String> getSelectedTableNames() {

private Collection<String> getSelectedTableNames()
{
ArrayList<String> result = new ArrayList<String>();
Iterator<String> iterator = databaseTables.getValue().iterator();
while (iterator.hasNext()) {
while (iterator.hasNext())
{
result.add(iterator.next());
}
return result;
}
private void exportSelectedEntities()
{
final Collection<String> selectedTableNames = getSelectedTableNames();

private Collection<String> exportSelectedEntities()
{
final Collection<String> selectedTableNames = getSelectedTableNames();
JavaSourceFacet java = descriptor.selectedProject.getFacet(JavaSourceFacet.class);
POJOExporter pj = new POJOExporter(jmdc, java.getSourceDirectory()
.getUnderlyingResourceObject()) {
.getUnderlyingResourceObject())
{
@Override
@SuppressWarnings("rawtypes")
protected void exportPOJO(Map additionalContext, POJOClass element) {
if (isSelected(selectedTableNames, element)) {
protected void exportPOJO(Map additionalContext, POJOClass element)
{
if (isSelected(selectedTableNames, element))
{
super.exportPOJO(additionalContext, element);
}
}
Expand All @@ -175,6 +193,7 @@ protected void exportPOJO(Map additionalContext, POJOClass element) {
pj.setProperties(pojoProperties);
pj.setArtifactCollector(new ArtifactCollector());
pj.start();
return selectedTableNames;
}

private ReverseEngineeringStrategy createReverseEngineeringStrategy()
Expand Down

0 comments on commit 5251c05

Please sign in to comment.