Sharing model classes between pure java and Android - java

I am writing simple application that has Android client and java backend.
I want to create common library for those two applications that includes model classes used for communicatin between those.
However, both apps store those information i own database and thats where is the problem. I cant use JNDI with normal ORM framework in java, because i cant use that in Android. I also cannot use Realm or Room for persistence in Android, because i cant use those in normal java.
So, what should I do? Do I just ditch the idea of common library, copy-paste those classes and just change annotations to work with different framework, or is there something usable with both platforms? (actually i hoped that Realm would work for normal java, but that is not the case...).

You may use JDX for Java and JDXA for Android ORM products and share the object model definitions without any changes. JDX and JDXA have a similar way of defining the mapping specification declaratively in a text file. No need of annotations. Both products have similar APIs.
So you can have a virtually portable data access layer of your application for both the Java and the Android platforms. Disclaimer: I am the architect of JDX and JDXA ORMs.

Related

ORM entity class generator for two languages from common model definition

I have one database and want to access it directly using two different languages (Java, Python). I want to define the object relational mappings once and somehow generate the entity classes for Python and Java. Is there any way to do it? Any software that can do it? Maybe there is some common format that I should define the mappings that can be used by tools to generate Java and Python classes.
Any help appreciated
I'm just starting on solving this problem myself. My plan is to use ActiveObjects (https://bitbucket.org/activeobjects/ao) to define schemas in Java. This package has support for automatically creating database tables, constraints, etc.
On the Python side I'm going to use Orator (https://orator-orm.com/). This works out nicely because since Python is a dynamic language, there's no duplication between Python and Java. You simply point Orator to the tables that you created using ActiveObjects and it builds objects automatically using the metadata.
Note that all of this is somewhat theoretical, I haven't actually implemented. I'll update this answer if there are any pitfalls.

Embedding database operations in our framework

We started writing a Java Framework for our company. But we don't have enough experience about Java. We decided to use JPA framework for database CRUD operations.
What do you suggest about that:
about defining persistence.xml. We search creating dynamic
EntityManager and found some documents but we don't know that is
it best way.
Is it a good way that create a layer over JPA base db operations?
(for example CRUD methods.)
How can we do calling JPA CRUD methods from my CRUD methods in
framework?
We will use this framework for desktop and web applications. Is
deployment a problem for us.
Do we have to use EJB?
Is there alternative to JPA which you suggest? (example: ADF,JDBC)
Thanks
It highly depends on your requirements and what you want to do with your "framework". I do not know enough of your project to give you a real advise, but here are some thoughts:
What do you mean with "framework"? Are you developing a library which other people should use? What should be the purpose of your framework? Is it a data access layer for some of your company data? If so: JPA is a kind of a standard and might be a good fit since it is widely used. If other people should use your "framework" it is good to use something which is standard and used in many other applications and tools.
Do you really need a data access layer on the desktop? Do you have a rich client? It is no problem to just "deploy" the application to the desktop, but a data access layer must always be configured and (maybe) updated. And that's where the pain begins when you use a rich client. Users must configure a database, the database must be installed or accessible remote and the version of the client must match the version of the database. Sooner or later this will hit you.
What else have you considered already? What about a ORM? Hibernate might by a good and popular fit. Also eBeans which is used in Play! is very cool. If you make a CRUD applications, frameworks like eBeans are doing most of the work out-of-the-box for you. You create a model (just POJOs + annotations) and the frameworks provides the complete data access layer (including the database setup).

Using JPA in java from an EntityFramework in .Net perspective

I am very familiar with the .net framework. but new to java technologies. I am working on data-driven web application (using Netbeans, MySql, Glassfish) for my course work.
I have spent weeks trying to figure out how to use JPA technology for my JSF interface based web application. My assumption is that it is similar to entity framework in .net. I have searched and searched but it seems the videos/tutorials/explanations are for java people only.
If there is anyone who has transitioned from .net to java succesfully or who understands both platforms to help me.
I have created the entity classes so far, so I want to know what to do to be able to -
-Get and manage instance of entities from database,
-Manipulate and navigate through the entities
-Then save changes back to the database.
(just like in .net using the context.entityname.add(new entityInstance) and context.SubmitChanges() method to save changes back to the database.)
so how can I set the entity manager up and get it to work assuming I want to use it in a Managed Bean class backing my JSF pages.**
If I try to follow the documentation or tutorials from a java only based developer. I find it very difficult to understand.
A link to an article from a .net perspective can also be helpful.
Thanx alot.

How should I design a plugin system in a layered Java EE Application?

I have a Java EE based REST api application. It has a layered architecture like the following:
Resources (Jax-rs resources)
Object Validation
Object Mapper
Service Layer
Repository Layer
JPA Entities
Everything is wired using Spring dependency injection.
I need to design this core application in such a way that it allows other external developers to write extensions/plugins and override or extends any minor or major functionality in the core. Think of it like Wordpress CMS in Java EE if that helps. How would you design a plugin system around the current architecture?
One obvious way that I can think of is override or add new functionality to the proper resource (with validation, objectmapper), service, repository and entity and create a jar + xml out of it. But I want to make sure that the plugin developer has to write the absolutely minimum amount of code to get the new functionality working, while reusing mush of the core code.
Assume, you want to create a wordpress blog post extension that lets you create blog posts with few extra fields that don't exist in core yet. What would be the simplest and cleanest way to go about designing the current Java EE app, so its easy for the plugin/extension developers? Any patterns that could be useful like strategy or template method pattern?
Are there any open source Java CMS that follow the model using Spring/JPA and standard technologies?
I think you mean to extend the functionality, rather than override the core. Typical architecture examples define concerns which can be overridden (separate from core) and make provisions. Eclipse framework achieves this using a combination of plugin-extensions & extension-points mechanism. This is taken further using OSGI bundling.
Another alternative is to breakdown the application into smaller independent modules/services. All you need to do is host these modules over an ESB/Application Integrator (like Mule/Spring Integration) and allow users to configure their version of routing/transformation. Extension would mean creation of new transformers which get added to the message flow.

What are recommendable data modeling tools and techniques for a Flex / Java web app?

I'm looking for a comprehensive setup that you've successfully used already. I've already loads of hints as to what building bricks I might use, but I'm not sure how to put it all together. Tools that need to be bought are OK, too.
Details:
I'm developing a Flex front end client for a Java server application and I have a set of model classes that represent objects in my business logic and should have the same properties and exhibit the same behaviour throughout all layers. These objects
have form validation logic for user input
are displayed in various forms (lists, detail views ...) throughout the UI
are retrieved from and sent to the server using XML or AMF
are validated again on the server
are stored in a RDBM with tables and fields corresponding to the classes and fields
This is a very common application structure, I guess. I'm already using:
ORM for the Java backend (Eclipse persistency package)
automatic mapping from XML to Action Script, using XML schema and the classes in mx.rpc.xml, as described here.
Now, what I'd really like to do is define the objects once (I already have them in XSD) and have tools set up class stubs for the whole chain. What can I use?
I've already heard of (but not evaluated):
XMLBeans to generate Java classes from XML Schema
Granite DS to generate AS classes from Java classes
I don't think your Flex UI should know or care about Java objects.
Take a "contract first", XML schema-drive approach and come up with the messages that you need to exchange between the Flex client and your service tier. Once you have that in place, the two are completely decoupled. That's a good start.
I'd also recommend not buying into a generation scheme. You'll only have to pay that price once during development.
I'm a Spring user, so I'd recommend Spring's "contract first" web services, using the Spring OXM interfaces. That will keep your UI and service tiers nicely decoupled. Use the org.springframework.oxm interfaces to do your mappings.
You can use Spring/BlazeDS to integrate your Flex UI with the Spring back end.
You have the full power of Spring IoC and AOP to create the back end.
I think you'll find it's a good approach for this problem.

Categories