diff --git a/database-tools/impl/src/main/java/org/jboss/forge/addon/database/tools/generate/DatabaseTableSelectionStep.java b/database-tools/impl/src/main/java/org/jboss/forge/addon/database/tools/generate/DatabaseTableSelectionStep.java index c630d53227..bd2a26677f 100644 --- a/database-tools/impl/src/main/java/org/jboss/forge/addon/database/tools/generate/DatabaseTableSelectionStep.java +++ b/database-tools/impl/src/main/java/org/jboss/forge/addon/database/tools/generate/DatabaseTableSelectionStep.java @@ -68,13 +68,13 @@ public boolean isEnabled(UIContext context) { return true; } - + @Inject private GenerateEntitiesCommandDescriptor descriptor; - + @Inject private HibernateToolsHelper helper; - + private JDBCMetaDataConfiguration jmdc; @SuppressWarnings("unchecked") @@ -87,10 +87,12 @@ public void initializeUI(UIBuilder builder) throws Exception helper.buildMappings(descriptor.urls, descriptor.driverClass, jmdc); Iterator iterator = jmdc.getTableMappings(); ArrayList tables = new ArrayList(); - 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()); } } @@ -101,70 +103,86 @@ public void initializeUI(UIBuilder builder) throws Exception @Override public Result execute(UIExecutionContext context) - { - exportSelectedEntities(); - return Results.success(); + { + Collection entities = exportSelectedEntities(); + return Results.success(entities.size() + " entities were generated"); } @Override public void validate(UIValidationContext context) { } - - private boolean isSelected(Collection selection, POJOClass element) { + + private boolean isSelected(Collection 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 getSelectedTableNames() { + + private Collection getSelectedTableNames() + { ArrayList result = new ArrayList(); Iterator iterator = databaseTables.getValue().iterator(); - while (iterator.hasNext()) { + while (iterator.hasNext()) + { result.add(iterator.next()); } return result; } - - private void exportSelectedEntities() - { - final Collection selectedTableNames = getSelectedTableNames(); + + private Collection exportSelectedEntities() + { + final Collection 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); } } @@ -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()