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
Related
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 5 years ago.
Improve this question
Today I had an interview for test automation in one of the MNC.
They asked me "why do we need to create an object?"
I explained about OOPs concepts with example of individual bank account holders. But he is not convinced. He just need a definition.
What could be a suitable answer for that question?
You require an object to represent state.
At the most simple definition, a class defines behaviour and an instance of a class (an object) represents state.
Of course there are other things like static contexts which can also maintain state, which you can mention also, but above is the clearest answer which I believe they were looking for.
It also always helps to give an example. You could talk about, for example, an Employee class. You would need an object to represent John and another to represent Jane.
I think that this question is kind of generic and does not give much value to an interview. But some generic question should have a generic answer, and here is mine:
We need to create objects in java so we can get instances that have a state inside our application. This allows us to have persistent encapsulated elements that contain any required information, and methods that operate with it.
Just plain basic OOP theory.
There are many reasons why we create a object apart from basic oops
1) To bring up persistent state data to transactional state to perform action (curd and other) and persist back to data storage.(EJB, POJO,etc )
2) Creating handler to serve service and send fluid data across wire like web-service.
3)Stuctural behavior in action.for example you designed a class for a workflow and to make in action state we create a object and serve the behavior example validation , authorization , etc class
All in all to make design time architecture to response based live system
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
Problem
Given a technology specific Java Model T, I want to have:
a technology agnostic model A to use in my code (i.e. the M in MVC).
a persistence mechanism P to store my model A.
Approach
Currently I have figured out some options:
Option 1:
Manually create the classes for A
Manually create the code to translate T to A
Manually create an XSD of a third JAXB-Model J
Generate JAXB-Model-Classes from J
Manually create the code to translate A to J
Use JAXB to automatically save J
When loading all translations have to be created into the other direction manually.
Advantage: can't see one. Thats my question :)
Disadvantage: most developing effort of all Options.
Option 2:
Manually create an XSD of a JAXB-Model of A
Generate JAXB-Model-Classes for A
Manually create the code to translate T to A
Use JAXB to automatically save A
When loading the translations has to be created into the other direction manually.
Advantage: Low developing effort. A can be persisted directly.
Disadvantage: I read, that it's a bad Idea, to use JAXB-classes as modell. But I don't understand why.
Option 3:
Manually create the Model of A as an eCore-Model
Generate the classes of A from the ecore-Model
Manually create the code to translate T to A
Use eCore-resources to automatically save A
When loading the translations has to be created into the other direction manually.
Advantage: Low developing effort. A can be persisted directly.
Disadvantage: None?
Looking at the advantages and disadvatages, I it seems like I should definitly use eCore instead of JAXB.
Question
Is it really that clear, to use eCore? Or are there advantages/disadvantages I should also think about?
Is here an easier way to translate from the technology specific model T to the technology agnostic modell A. Currenly I have to implement A and the translation A <-> T myself. Some easier way would be nice.
You could use JAXB to convert your Model A to XML. This leverages the Java first aspect of JAXB instead if the schema first in your question.
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 9 years ago.
Improve this question
So, I want it to be very easy to create all the entities of my game and for other people to come in and do the same. I was thinking I could just let the users/myself create an XML sheet the stores all the properties of each block (Like a Terraria or Minecraft voxel) and add Lua scripts that are referenced in the XML for additional functionality of any of the blocks.
I'm starting to think It would just be easier to let the user create a JAR file full of classes for each block. And then that JAR file could easily be used to get all the blocks. It'd just be interesting to reference all the blocks by a block id without storing all the classes by ID. Or I could give each class a static id. But that's not important.
Okay, so my short question is what are the pros and cons of storing all the the different types of blocks as classes versus in an XML sheet with Lua for additional functionality?
UPDATE: It looks like I'll be using pure Lua! Looks like an interesting and effective way to do it!
A limitation of the JAR approach is that your data would need to be compiled before it got used. With XML/Lua the data gets read/interpreted at runtime.
A third option that you did not mention is using straight Lua tables instead of XML. This lets you load the data with a simple "require", "dofile" or similar instead of needing to use a XML library as well.
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.
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 9 years ago.
Improve this question
At my work place, we use DAO pattern to hancle any sort of database operation. It hides bulky statements from programmer. Programmers need to write sql query and logic to handle output data. BaseDao handles all sort of operation and return output in required format.
I found that this class is not perfect. I added the code to control number of connections and to handle connection issues like slow connectivity, no connectivty, number of atttempts for connection etc.
But I would have to add more code to support advance feature of JDBC like providing/accessing binary data, Handling resultsets returned from SPs etc.
Is there any Java Framework or group of classes which can cover many of the database operations?
Please suggest.
I think that you are looking for Java Persistence API. It's a Java EE specification and Hibernate is the most popular implementation.
You could try Spring DAO instead. They have a nice template pattern for handling resultsets.
Or you can take another step step back away from JDBC and use Hibernate.
Spring Data JPA does even more abstraction than the other suggestions people have made. With that and Hibernate you don't even need to write queries unless it's a complex operation you need to perform.