Persisting technology agnostic Java Model: JAXB vs. eCore [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
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.

Related

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

Selenium Webdriver (Java): What are the benefits (if any) of using an objectmap.properties file instead of Page Objects classes? [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 9 years ago.
Improve this question
I'm implementing Selenium Webdriver 2 automated testing for our website, and am unable to find a clear assessment of what the benefits are of using an objectmap.properties file to store all the element locators, versus storing them in page objects java classes?
Also, it seems that using java classes for Page Objects allows exposing and abstracting page operations in those page objects classes too, whereas I'm not clear how this would be done if using an objectmap.properties file instead?
Or have I missed the point and the 2 are best used in conjunction?
Thanks in advance!
This is purely subjective. Some people prefer the simplicity of my_object=something then just fetching it using objectmap.get('my_object') while others, prefer using objects in Java. e.g. using LoginPage.TXT_USERNAME
Depending on your personal preference, and philosophies, you should determine which way is easier to you.
Personally, I think using java page objects are much more efficient because of the auto-complete that eclipse provides. I could do
LoginPage.TXT_USERNAME
LoginPage.TXT_PASSWORD
instead of having the possibilty of misspelling your object if you use a properties file like this:
objectmap.getProperty('TXT_USRNAME') # oops! forgot the E, and i wouldn't've known it until runtime.

Java versus XML&Lua for storing voxel/block types [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 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.

Database Design with UML or Java [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 9 years ago.
Improve this question
What is the starting point in designing a database? UML or Java?
Eg: If u are using both java and UML for designing a database, how do you beging?
First with UML design and then Java script? Or the other way?
You need to start with Entity-Relationship diagram.
An ER model is an abstract way of describing a database. In the case
of a relational database, which stores data in tables, some of the
data in these tables point to data in other tables.For instance, your entry in the database could point to several entries for each of the phone numbers that are yours. The ER model would say that you are an entity, and each phone number is an entity, and the relationship between you and the phone numbers is 'has a phone number'. Diagrams created to design these entities and relationships are called entity–relationship diagrams or ER diagrams.
Microsoft Visio is one of the commonly used tool to do that.
The starting point is the Diagram you will make to describe the relationships between the tables.
In your project you will have to have two different diagrams, one for the Java classes and another one for the database tables.
EDIT
I would recommend you to take a look at this link Object-relational impedance mismatch, to make sure you will not confuse both schemes.
Definitely not the otherway... First design then validate the design then comes JAVA.
So use the Data Modeling (using ER diagrams) and then (if applicable) Object Modeling. As mentioned above Visio is a good tool, also you can use a pen-paper designs.
And when you talk about Data Design, ORM is very important to keep in mind.

What is the rationale behind Apache Jena's *everything is an interface if possible* design philosophy? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
If you are familiar with the Java RDF and OWL engine Jena, then you have run across their philosophy that everything should be specified as an interface when possible. This means that a Resource, Statement, RDFNode, Property, and even the RDF Model, etc., are, contrary to what you might first think, Interfaces instead of concrete classes.
This leads to the use of Factories quite often. Since you can't instantiate a Property or Model, you must have something else do it for you -- the Factory design pattern.
My question, then, is, what is the reasoning behind using this pattern as opposed to a traditional class hierarchy system given the nature of the content the library aims to serve? It is often perfectly viable to use either one. For example, if I want a memory backed Model instead of a database-backed Model I could just instantiate those classes, I don't need to ask a Factory to give me one.
As an aside, I'm in the process of writing a library for manipulating Pearltrees data, which is exported from their website in the form of an RDF/XML document. As I write this library, I have many options for defining the relationships present in the Peartrees data. What is nice about the Pearltrees data is that it has a very logical class system: A tree is made up of pearls, which can be either Page, Reference, Alias, or Root pearls.
My question comes from trying to figure out if I should adopt the Jena philosophy in my library which uses Jena, or if I should disregard it, pick my own design philosophy, and stick with it.

Categories