I am working on a requirement. Currently there is a search page which has List Box with Values (Example Data) 1) Employee and 2) Sport Person.
Object Hierarchy (Hibernate Bean)
Person is the actual Object which has two different class
1) Employee and
2) Sports Person based
Discriminator Column
Person_Type (Discriminator Column).
On a search page , if user selects any of the list box, will result the data from that sub class.
Now requirement is to show both sub class result together and it is done by adding one more value in the list box as "Employee + Sports Person".
Problem's
1) Both sub class have different structure
2) There are other criteria which are compared with different attributes.
How can I union the two sub classes.
Please help me to resolve.
Please Note : I am trying not use Query Based Union. I am think in terms of OOPS
Loading both types of persons should not be a problem. If your query can access common attributes you can do FROM Person p WHERE <whatever_person_criteria_you_have>.
If your query need to use specific attributes of Employee and SportsPerson then you could execute 2 queries and put the result into a single List<Person>.
Sorting/displaying that list depends on what data needs to be displayed or compared. In case you have to compare different data, you could always use a Comparator<Person> which checks the actual class of the objects and maybe a wrapper which does the same to access the correct properties for display.
Related
I am looking to see whats out there in collections in any java framework like apache or guava that will let me handle the below. I am also open to consider any custom implementations if required
Basically I have
Inventory object , the inventory number field will help identify a
unique inventory object
Order object the order number field will
help identify a unique order
OrderItem Object, the order number and
item number fields will help identify a unique order (the key here
is composite)
I can have more objects come in later on with different attributes and having composite key types. Also I dont want to put the orderItem inside the order object
Basically I am looking to see if there is a elegant way to build a generic structure where in I can define the keys that will help identify a object and retrieve the object dynamically using the key? I should be able to specify composite key types as well.
structure.put(invKey, inventory);
structure.put(orderKey, order);
structure.put(orderItemKey, orderItem) (the key here is composite of two attributes)
I have to implement search based on almost 12 different fields.
For validation and processing, I am facing a lot of challenges. Following are those with which I am seeking inputs/help.
Classes:
SearchCriteria
(has) UserCriteria and AddressCriteria
PS. A few fields are related to user e.g. First Name, Date of Birth etc. which goes in UserCriteria and a Few fields are related to address e.g. Street Name, Building Number etc. which will go into AddressCriteria
Based on these criteria I have to search users.
Validate that at least one parameter is not null/not empty. I do not
want to keep checking each and every field for null and emptiness.
Before search validate based on which criteria you need to initiate
search. e.g. User or Address?
Implement validations such a way that you need not to worry about
specific field validation before adding it in query criteria
EDIT:
NOTE : I need to prepare a message with all the valid fields which will be passed to the module which helps me finding all records, I am not dealing with DB directly.
What if both of your objects (UserCriteria and AddressCriteria) has a method like,
public ArrayList<String> getSearchableFields() {
//return a ArrayList of searchable fields
}
Then you'll be able to call getSearchableFields() on each method and see what fields are available to use for your search.
I have a problem regarding my current CodeBook.
CodeBook is an entity that consists of two attributes, the Code and Description.
It is an abstract class. I extended that class with the Class Domain.
Domain class is also an abstract class and contains enum DomainType, which has values:
e.g. NATIONALITY, NATIVE_LANGUAGE, DISEAS.. etc
Now I have to make "document" entities which will later be filled with data.
So for example, the client has to pick the nationality. It will select one from the list of the values that has been entered in the codebook DomainNationality (Extends Domain) for the domainType.NATIONALITY, BUT what if I don't have his nationality in my CodeBook? I will put an option OTHER, that he can select,but I also need to put the field where he will type his OTHER nationality.
How do I keep a record of that other nationality?
Right now,my document entities has associative links to DomainNationality.DomainSex, DomainNativeLanguage etc.. Is the String field next to every domain in my document the best and easiest solution? I don't want to let clients enter new stuff in to the CodeBook.
Thank you!
This is mainly your design-decision. You can do it which-ever way you design your object-responsibilities. But here are my thoughts: Since you say it is possible that the client's nationality is not among those which you offer and want to offer him/her a field to enter a custom nationality you should just store the nationality as a string in the object (no enum). You can always check afterwards if the nationality of a client is among the pre-defined ones.
My use case is an index which holds titles of online media. The provider of the data associates a list of categories with each title. I am using SolrJ to populate the index via an annotated POJO class
e.g.
#Field("title")
private String title;
#Field("categories")
private List<Category> categoryList;
The associated POJO is
public class Category {
private Long id;
private String name;
...
}
My question has two parts:
a) is this possible via SolrJ - the docs only contain an example of #Field using a List of String, so I assume the serialization/marshalling only supports simple types ?
b) how would I set up the schema to hold this. I have a naive assumption I just need to set
multiValued=true on the required field & it will all work by magic.
I'm just starting to implement this so any response would be highly appreciated.
The answer is as you thought:
a) You have only simple types available. So you will have a List of the same type e.g. String. The point is you cant represent complex types inside the lucene document so you wont deserialize them as well.
b) The problem is what you are trying is to represent relational thinking in a "document store". That will probably work only to a certain point. If you want to represent categories inside a lucene document just use the string it is not necessary to store a id as well.
The only point to store an id as well is: if you want to do aside the search a lookup on a RDBMS. If you want to do this you need to make sure that the id and the category name is softlinked. This is not working for every 1:n relation. (Every 1:n relation where the n related table consists only of required fields is possible. If you have an optional field you need to put something like a filling emptyconstant in the field if possible).
However if these 1:n relations are not sparse its possible actually if you maintain the order in which you add fields to the document. So the case with the category relation can be probably represented if you dont sort the lists.
You may implement a method which returns this Category if you instantiate it with the values at position 0...n. So the solution would be if you want to have the first category it will be at position 0 of every list related to this category.
I was wondering how you use your ddd model within a web application. Within Eric Evan Cargo application there's the Cargo class which contains the value object Itinerary. Within Itinerary is a collection of Legs, again a value object. All value objects hide the surrogate id to the outside world.
So when using this domain model, how would I create a web app, where you can click on a cargo itinerary, list all legs and then show the details of a leg by redirecting to a new "leg detail" page. Usually I would pass the LegId within the query fields and read it out again on the detail page. But since it has no id, how would you do that?
Using the index of a leg which might change when the collection gets sorted?
Passing all values within the query fields since this is the value object identity?
Sounds like a step backwards to me :)
If the leg has no id, the only way you have to refer to it is through the Cargo, which has an identity, and therefore can be associated with a URI/URL. To refer to a specific leg, you have only the index, which can be a number, or a dictionary key. If you have sorting issues, you can define two lists: one with the canonical ordering for reference purposes, and another with the ordering, mapping order position and canonical index.
As for the reason why the value objects in Evans' example have ids, I think it's for serialization purposes.
Of course, you can also opt for a Itinerary/Leg with identity.