Appengine Entity Design Advice [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a dilemma on how to implement this requierement:
Let's say I have the following Contact classes
Student,
Tutor,
AdminStaff.
I am not sure what is the best way to structure it in DataStore:
shall I have one Contact entity which will contain shared fields and also corresponding extra fields for given type
or shall I have three separate entities
first approach allows me to search through all my contacts, and the second is to avoid extra filtering when I just need contacts of certain kind.
However I have one more requirement which I am not sure how to accommodate with any of these approaches. What if I have contact with multiple personalities e.g. Tutor and AdminStaff. This suggests I have a separate Contact entity and link to its various personalities. So for the above example I would have data about that person kept in three entities Contact,Tutor,AdminStaff.
I would appreciate for any suggestions

Regarding your concern about searching over all your contacts - even if you have 3 different entity types, I think you could still create an index that would allow you to search over all contacts.
I don't know how many attributes there are that are unique to the different contact roles, but I'd be worried about creating a single mega-class/entity that encompassed them all - it could be a very big and messy class.
And, as you have indicated, your final requirement does make things more complicated. It suggests that perhaps you should have a single contact class/entity for all roles, and then create class(es) for the 3 roles that can be #embed'ed into to the contact entity.

Related

Storing Data within a Restaurant Item [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
So I have a custom list of restaurants. When the restaurant is clicked I want a set of data coming up (Name, phone number, rating, category) and I want the user to be able to modify that data and for that data to remain the same when left from that screen. Is there any way to store the data for each restaurant? Thanks
If you want user changes to only be preserved in his device only then using a database is the best option. I highly recommend going with Room Library
First of all, you should define your restaurant model as an entity for room;
define a Dao object to create, list and edit your entities;
define an abstract class as the database. Room will provide the implementation at compile time itself;
access and manipulate database items using dao object in database implementation.
For details on the steps mentioned this guide is the best place to start.

Mapping a java Entity to a GraphQL object [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have difficulty in implementing GraphQL in a java project as a part of updating it. I'm trying to connect an entity (which uses the Hibernate ORM to map to different databases) to a GraphQLObjectType . Any suggestions how can I accomplish this? Can I omit the GraphQL database configurations if so?
There're multiple options here.
It's probably best to not even map an entity directly . Entities are direct representations of the DB and, as such, should probably not be directly exposed, but wrapped into DTOs (maybe allowing pagination, flattening relations, or whatever is appropriate) instead.
If you just need to map the class (entity or not) to a GraphQLObjectType, graphql-java-annotations is the simplest (and most limited) route (check the status of this project first, it was on a hiatus for a while)
If you want to expose the entire entity graph through GraphQL, graphql-jpa might be your best bet (as Sriram suggests), as it's intended to do exactly that, while also adding pagination, aggregation and sorting
If you want to automatically expose not only an entity/DTO class, but also the operations upon it (e.g. an arbitrary service class), look at graphql-spqr (I'm the author of that project)
If you already defined your entities using JPA/Hibernate, try this:
https://github.com/jcrygier/graphql-jpa

Using SQLite or a File [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am new to Android development and I am trying to make a Trivia application.
I need to store the data relating to questions somewhere and I am not entirely sure where to store it.
I plan to have multiple people playing so I need each person to have the same questions.
Basically I planned to have a list of categories and within each category I had question objects.
The question objects contained information regarding the question such as the answers and question itself.
However, if I use a database, I believe none of this would be needed due the questions being stored in tables which would represent categories.
In terms of speed what would be better:
to store it in a database
or to read from a file every time the application is loaded and store the data within a data structure?
You almost certainly want a database. Databases are made for fast search and easy insertion/deletion. There's really no advantage to having a file and doing in memory parsing each time.
Aside from performance benefits, here's a simple list of advantages of using SQLite rather than flat file:
You can query items as you wish -- don't need to load all of them and
select which ones you need.
Record deletion is a much less painful process. No rewriting of whole
files into wherever.
Updating a record is as easy as removing or creating one.
Have you ever tried doing cross-referencing lookups on a flat file?
Just.Not.Worth.It.
To summarize, it's every advantage a Database has over a text file.
Answer by josephus

The best way to store URL constants [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am trying to build an Android application. I've about 31 URLs. Currently I am storing the URL Strings as Constants in a class named UrlRes so that I can call UrlRes.SIGN_UP_URL or UrlRes.PRODUCT_ADD_URL. Is this a right approach? Should I store each URL on specific models ? example PRODUCT_ADD_URL in Product model. I think it'll be more meaningful when I call Product.PRODUCT_ADD_URL.
In android's implementation each ContentProvider provides some contract classes with the uris and fields of each entity. Each contract contains static inner classes or interfaces for the different parts of the ContentProvider it belongs to.
For instance the UserDictionary contains Words and the Contacts contract contains Settings, Groups and some helper methods.
I would prefer using the Product.PRODUCT_ADD_URL strategy because if more links will be added in the future it's much clearer for you or other developers working on your app to understand this approach.
String resources are used primarily for layouts and views so storing URLs in strings.xml is not considered best practice. You may instead want to store it in a class and making URL as public final static.

Best data structure to store peculiarly structured data [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
So, I'll be looping through a data base and there will be a bunch of campaigns. Each campaign will have some demos and some sites where certain conditions are satisfied. I want to plot some graphs for the data corresponding to all the campaigns, sites and demos. I was thinking of using java, first getting the campaign, site and demo combinations where the conditions are satisfied and then looping through all of them, running individual queries based on their values and plotting the graphs using maybe, GNU plot. My questions are -
Is there a better way to achieve this (with minimal queries).
If I do do it this way, I first have to store the information.
I was thinking of storing the campaign ids in an ArrayList of Integers, the demos for each campaign in
ArrayList<ArrayList<Integer>>
and the sites for each campaign in
ArrayList<ArrayList<Integer>>
Is there a more efficient way of storing this information?
I'd recommend creating a new class to hold your campaign data and storing references to each object within an ArrayList if you need to keep a handle to them in memory (may not be necessary).
From a purist point of view, the class should be backed by a Data Access Object (DAO) and Plain Old Java Object (POJO) to manage database access and storage in memory but if this is a simple prototype then I wouldn't worry too much. I'd also recommend a utility class to convert/write your chart data - all accessible from your Campaign class.
The Campaign class should also be able to work out whether your conditions are satisfied - and if it's worth generating those charts.

Categories