You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Roshan Vishwakarma <ro...@celeritio.com> on 2018/02/01 07:40:27 UTC
Apache ISIS - Store multiple selected values into Single column in database
Hi,
I have an use case where I have to insert multiple values in a single
column.
For example:
1. Door.java
public class Door implements Comparable<Door>{
@javax.jdo.annotations.Column(name="name" ,allowsNull = "true")
@Property(editing = Editing.ENABLED)
@Getter @Setter
private String name;
@javax.inject.Inject
@javax.jdo.annotations.Column(name="doortype", allowsNull="true")
@Getter @Setter
DoorType[] doorType;
}
2. DoorMenu.java
@Action(domainEvent = CreateDomainEvent.class)
@ActionLayout(cssClassFa="fa-clock-o", named="Door")
@MemberOrder(sequence = "1")
public Door createDoor(
@Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Name") String name,
@Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Door Type") DoorType[] doorType){
return doorRepository.create(name, doorType);
}
3. DoorRepository.java
public Door createDoor(
final String name,
final DoorType[] doorType){
final Door door = new Door();
door.setName(name);
door.setDoorType(doorType);
serviceRegistry.injectServicesInto(door);
repositoryService.persist(door);
return door;
}
4. DoorType.java - This will contain name of the type of door
From the above example I have to insert multiple DoorType in single column.
But when code is executed it does not create column "doortype".
I don't see error in the log.
Is this correct way of defining "DoorType[]"?
How we can achieve multiple values in single column. Which dataType is
considered here?
Regards,
Roshan
Re: Apache ISIS - Store multiple selected values into Single column
in database
Posted by Andi Huber <ah...@apache.org>.
Hi Roshan,
whenever I have such a use-case as you described (multiple values in one
column), I do the following ...
Split the the property (in your case the 'doorTypes') into 2 parts:
1) visible part as rendered by Isis (make this transient: @NotPersistent)
@NotPersistent
List<DoorType> getDoorTypes(){
// parse field 'doorTypesStringified' ...
}
void setDoorTypes(List<DoorType> doorType){
// update field 'doorTypesStringified' ...
}
// add support methods here ...
2) hidden part as persisted by JDO (exemplified with 'String', but you
can choose whatever you like)
@PropertyLayout(hidden=Where.EVERYWHERE)
@Getter @Setter @Column(allowsNull="true")
String doorTypesStringified;
Regards, Andi
On 2018/02/01 07:40:27, Roshan Vishwakarma <r....@celeritio.com> wrote:
> Hi,>
>
> I have an use case where I have to insert multiple values in a single>
> column.>
>
> For example:>
>
> 1. Door.java>
> public class Door implements Comparable<Door>{>
>
> @javax.jdo.annotations.Column(name="name" ,allowsNull = "true")>
> @Property(editing = Editing.ENABLED)>
> @Getter @Setter>
> private String name;>
>
> @javax.inject.Inject>
> @javax.jdo.annotations.Column(name="doortype", allowsNull="true")>
> @Getter @Setter>
> DoorType[] doorType;>
> }>
>
> 2. DoorMenu.java>
> @Action(domainEvent = CreateDomainEvent.class)>
> @ActionLayout(cssClassFa="fa-clock-o", named="Door")>
> @MemberOrder(sequence = "1")>
> public Door createDoor(>
> @Parameter(optionality = Optionality.OPTIONAL)>
> @ParameterLayout(named="Name") String name,>
> @Parameter(optionality = Optionality.OPTIONAL)>
> @ParameterLayout(named="Door Type") DoorType[] doorType){>
> return doorRepository.create(name, doorType);>
> }>
>
> 3. DoorRepository.java>
> public Door createDoor(>
> final String name,>
> final DoorType[] doorType){>
>
> final Door door = new Door();>
>
> door.setName(name);>
> door.setDoorType(doorType);>
>
> serviceRegistry.injectServicesInto(door);>
> repositoryService.persist(door);>
>
> return door;>
> }>
>
> 4. DoorType.java - This will contain name of the type of door>
>
> From the above example I have to insert multiple DoorType in single
column.>
> But when code is executed it does not create column "doortype".>
> I don't see error in the log.>
> Is this correct way of defining "DoorType[]"?>
> How we can achieve multiple values in single column. Which dataType is>
> considered here?>
>
>
> Regards,>
> Roshan>
>