use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.
the class PartTreeUnitTest method validateEmptyOperatorParameters.
@Test
public void validateEmptyOperatorParameters() throws Exception {
List<FinderParameter> parameters = new ArrayList<FinderParameter>();
parameters.add(new FinderParameter(JavaType.INT_OBJECT, new JavaSymbolName("number")));
assertEqualsParameters(parameters, new PartTree("findByNumber", memberDetails).getParameters());
parameters.add(new FinderParameter(JavaType.INT_OBJECT, new JavaSymbolName("number2")));
assertEqualsParameters(parameters, new PartTree("findByNumberAndNumberOrderByNumber", memberDetails).getParameters());
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.
the class PartTreeUnitTest method identifiesFindFirstKUsersExplicit.
@Test
public void identifiesFindFirstKUsersExplicit() {
PartTree partTree = new PartTree("findFirst10NumberByText", memberDetails);
assertTrue(partTree.isValid() && partTree.getMaxResults() == 10);
partTree = new PartTree("findTop10NumberByText", memberDetails);
assertTrue(partTree.isValid() && partTree.getMaxResults() == 10);
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.
the class PartTreeUnitTest method disablesFindFirstKImplicitIfNotPresent.
@Test
public void disablesFindFirstKImplicitIfNotPresent() {
PartTree partTree = new PartTree("findByText", memberDetails);
assertTrue(partTree.isValid() && partTree.getMaxResults() == null);
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.
the class PartTreeUnitTest method identifiesFindFirst1Explicit.
@Test
public void identifiesFindFirst1Explicit() {
PartTree partTree = new PartTree("findFirst1ByText", memberDetails);
assertTrue(partTree.isValid() && partTree.getMaxResults() == 1);
partTree = new PartTree("findTop1ByText", memberDetails);
assertTrue(partTree.isValid() && partTree.getMaxResults() == 1);
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree in project spring-roo by spring-projects.
the class FinderCommands method installFinders.
@CliCommand(value = "finder add", help = "Installs a finder in the given target (must be an entity). This command needs an existing " + "repository for the target entity, you can create it with `repository jpa` command. The " + "finder will be added to targeted entity associated repository and associated service if " + "exists or when it will be created.")
public void installFinders(@CliOption(key = "entity", mandatory = true, unspecifiedDefaultValue = "*", optionContext = PROJECT, help = "The entity for which the finders are generated. When working on a mono module project, " + "simply specify the name of the entity. If you consider it necessary, you can also " + "specify the package. Ex.: `--class ~.domain.MyEntity` (where `~` is the base package). " + "When working with multiple modules, you should specify the name of the class and the " + "module where it is. Ex.: `--class model:~.domain.MyEntity`. If the module is not " + "specified, it is assumed that the entity is in the module which has the focus.") final JavaType entity, @CliOption(key = "name", mandatory = true, help = "The finder string defined as a Spring Data query. Use Spring Data JPA nomenclature. " + "Possible values are: any finder name following Spring Data nomenclature. " + "This option will not be available until `--entity` is specified.") final JavaSymbolName finderName, @CliOption(key = "formBean", mandatory = true, help = "The finder's search parameter. Should be a DTO and it must have at least same fields " + "(name and type) as those included in the finder `--name`, which can be target entity" + " fields or related entity fields. " + "Possible values are: any of the DTO's in the project. " + "This option is mandatory if `--returnType` is specified and its a projection. " + "This option is not available if `--entity` parameter has not been specified before or " + "if it does not exist any DTO in generated project. " + "Default if option not present: the entity specified in `--entity` option.") final JavaType formBean, @CliOption(key = "returnType", mandatory = false, optionContext = PROJECT, help = "The finder's results return type. " + "Possible values are: Projection classes annotated with `@RooEntityProjection` and " + "related to the entity specified in `--entity` option (use `entity projection` command), " + "or the same entity. " + "This option is not available if `--entity` parameter has not been specified before or " + "if it does not exist any Projection class associated to the targeted entity. " + "Default if not present: the default return type of the repository related to the entity, " + "which can be specified with `--defaultReturnType` parameter in `repository jpa` command.") JavaType returnType) {
// Check if specified finderName follows Spring Data nomenclature
PartTree partTree = new PartTree(finderName.getSymbolName(), getEntityDetails(entity), this);
// If generated partTree is not valid, shows an exception
Validate.isTrue(partTree.isValid(), "--name parameter must follow Spring Data nomenclature. Please, write a valid value using autocomplete feature (TAB or CTRL + Space)");
// related repository
if (returnType == null) {
// Obtain the related repository metadata
RepositoryJpaMetadata repositoryMetadata = getRepositoryJpaLocator().getFirstRepositoryMetadata(entity);
Validate.notNull(repositoryMetadata, "ERROR: You must create a repository related with this entity before to generate a finder");
// Use the repository metadata to obtain the default return type
returnType = repositoryMetadata.getDefaultReturnType();
}
Validate.notNull(returnType, "ERROR: The new finder must define a returnType");
// Check if the returnType is an entity. If is is not an entity validate
// that the formBean is not null
ClassOrInterfaceTypeDetails type = getTypeLocationService().getTypeDetails(returnType);
if (type.getAnnotation(RooJavaType.ROO_JPA_ENTITY) == null) {
Validate.notNull(formBean, "--formBean is requied when --returnType parameter is a projection.");
}
finderOperations.installFinder(entity, finderName, formBean, returnType);
}
Aggregations