Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FORGE-2076: Added command to generate DAOs from JPA Entities #517

Merged
merged 1 commit into from
Oct 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ void newManyToManyRelationship(
Iterable<CascadeType> cascadeTypes) throws FileNotFoundException;

void newEmbeddedRelationship(
Project project,
JavaResource resource,
String fieldName,
Project project,
JavaResource resource,
String fieldName,
String fieldType)
throws FileNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ public interface PersistenceOperations
public static final String DEFAULT_UNIT_DESC = "Forge Persistence Unit";

/**
* Setups JPA in the project for the given attributes. If persistence unit with the name already exists, the unit will be overwritten.
* Setups JPA in the project for the given attributes. If persistence unit with the name already exists, the unit
* will be overwritten.
*
* @param unitName Name of the created Persistence Unit
* @param project Project for which the JPA is being set up
* @param dataSource JPA data-source configuration
* @param configureMetadata configure the metadata
*/
public FileResource<?> setup(String unitName, Project project, JPADataSource dataSource, boolean configureMetadata);

/**
* Get the object representing the persistence unit, null is returned when no persistence unit was found.
*
Expand Down Expand Up @@ -104,10 +105,9 @@ public JavaResource newEntity(Project project, String entityName, String entityP
public JavaResource newEntity(DirectoryResource target, String entityName, String entityPackage,
GenerationType idStrategy);


/**
* Creates a new {@link JavaResource} for an embeddable entity in the specified project. If a project is available, use
* {@link PersistenceOperations#newEmbeddableEntity(Project, String, String)}
* Creates a new {@link JavaResource} for an embeddable entity in the specified project. If a project is available,
* use {@link PersistenceOperations#newEmbeddableEntity(Project, String, String)}
*
* @param target the target directory resource to create this class
* @param entityName the name of the entity
Expand All @@ -116,18 +116,18 @@ public JavaResource newEntity(DirectoryResource target, String entityName, Strin
* @throws FileNotFoundException if something wrong happens while saving the {@link JavaClass}
*/
public JavaResource newEmbeddableEntity(DirectoryResource target, String entityName, String entityPackage);



/**
* Creates a new {@link JavaResource} for an embeddable entity in the specified target. If no project is available, use
* {@link PersistenceOperations#newEmbeddableEntity(DirectoryResource, String, String)}
* Creates a new {@link JavaResource} for an embeddable entity in the specified target. If no project is available,
* use {@link PersistenceOperations#newEmbeddableEntity(DirectoryResource, String, String)}
*
* @param project the current project to create the entity. Must not be null
* @param entityName the name of the entity
* @param entityPackage the package of the entity to be created
* @return the created java resource
* @throws FileNotFoundException if something wrong happens while saving the {@link JavaClass}
*/
public JavaResource newEmbeddableEntity(Project project, String entityName, String entityPackage) throws FileNotFoundException;
public JavaResource newEmbeddableEntity(Project project, String entityName, String entityPackage)
throws FileNotFoundException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.jboss.forge.addon.javaee.jpa.dao;

import org.jboss.forge.addon.projects.Project;
import org.jboss.forge.roaster.model.source.JavaClassSource;

/**
* Parameters for DAO resource generation.
*
* @author <a href="salem.elrahal@gmail.com">Salem Elrahal</a>
*
*/
public class DaoGenerationContext
{
private Project project;
private JavaClassSource entity;
private String targetPackageName;
private String persistenceUnitName;

public JavaClassSource getEntity()
{
return entity;
}

public void setEntity(JavaClassSource entity)
{
this.entity = entity;
}

public String getTargetPackageName()
{
return targetPackageName;
}

public void setTargetPackageName(String targetPackageName)
{
this.targetPackageName = targetPackageName;
}

public String getPersistenceUnitName()
{
return persistenceUnitName;
}

public void setPersistenceUnitName(String persistenceUnitName)
{
this.persistenceUnitName = persistenceUnitName;
}

public Project getProject()
{
return project;
}

public void setProject(Project project)
{
this.project = project;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.jboss.forge.addon.javaee.jpa.dao;

import java.util.List;

import org.jboss.forge.roaster.model.source.JavaClassSource;

/**
* Generates a DAO resource based on a JPA entity.
*
* @author <a href="salem.elrahal@gmail.com">Salem Elrahal</a>
*
*/
public interface DaoResourceGenerator
{
/**
* A readable description for this strategy
*/
String getName();

/**
* A human-readable description for this strategy
*/
String getDescription();

/**
* Generate a Dao based on a context
*/
List<JavaClassSource> generateFrom(DaoGenerationContext context) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface RestFacet extends JavaEEFacet

/**
* Returns the application path configured for this project
*
* @return
*/
public String getApplicationPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
@FacetConstraints({
@FacetConstraint(JavaSourceFacet.class),
@FacetConstraint(ServletFacet_3_0.class)
@FacetConstraint(JavaSourceFacet.class),
@FacetConstraint(ServletFacet_3_0.class)
})
public interface RestFacet_1_1 extends RestFacet
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
@FacetConstraints({
@FacetConstraint(JavaSourceFacet.class),
@FacetConstraint(ServletFacet_3_0.class)
@FacetConstraint(JavaSourceFacet.class),
@FacetConstraint(ServletFacet_3_0.class)
})
public interface RestFacet_2_0 extends RestFacet
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void addToEndpoints(JavaResource endpoint)
{
this.endpoints.add(endpoint);
}

public void addToEndpoints(Collection<JavaResource> endpoints)
{
this.endpoints.addAll(endpoints);
Expand All @@ -70,7 +70,7 @@ public void addToEntities(JavaResource entity)
{
this.entities.add(entity);
}

public void addToEntities(Collection<JavaResource> entities)
{
this.entities.addAll(entities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public interface ValidationNewAnnotationCommand extends UICommand
{}
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class BeansCommand
@Inject
private ProjectFactory projectFactory;

@Command(value = "CDI: List Interceptors", enabled = RequiresCDIFacetPredicate.class, categories = { "Java EE", "CDI" })
@Command(value = "CDI: List Interceptors", enabled = RequiresCDIFacetPredicate.class, categories = { "Java EE",
"CDI" })
public void listInterceptors(final UIContext context, final UIOutput output)
{
CDIFacet<?> cdi = getProject(context).getFacet(CDIFacet.class);
Expand All @@ -55,7 +56,8 @@ public void listInterceptors(final UIContext context, final UIOutput output)
}
}

@Command(value = "CDI: List Alternatives", enabled = RequiresCDIFacetPredicate.class, categories = { "Java EE", "CDI" })
@Command(value = "CDI: List Alternatives", enabled = RequiresCDIFacetPredicate.class, categories = { "Java EE",
"CDI" })
public void listAlternatives(final UIContext context, final UIOutput output)
{
CDIFacet<?> cdi = getProject(context).getFacet(CDIFacet.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ protected void createDefaultConfig(FileResource<?> descriptor)
{
WebFacesConfigDescriptor descriptorContents = Descriptors.create(WebFacesConfigDescriptor.class)
.version("2.1");
descriptor.setContents(descriptorContents.exportAsString());
descriptor.setContents(descriptorContents.exportAsString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ public NavigationResult getPrerequisiteCommands(UIContext context)
builder.add(FacesSetupWizardImpl.class);
}
}
return builder.build();
}
return builder.build();
}
}