Design considerations: Java database applications (JPA) [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm about to write a JPA based web application in Java and since it's my first time seriously working with persistent classes and databases in general, I would like to learn if I have to make specific considertions f.i. while designing the overall class structures like building it as flat as possible to keep the count of persistent classes low and the database structure simple. I really don't expect long explanations but would like to get a short overview of general considerations which might not appear to be that obvious to one who is unexperienced with database applications.
Thanks in advance.

general considerations which might not appear to be that obvious to
one who is unexperienced with database applications
Using an ORM is superficially easy and transparent, but there are many small issues to consider:
Object identity. Understand the root mismatch that relational database work with rows and keys, while in the object world, each object has one identity. There various ways to handle identity correctly, or incorrectly.
Mapping Data. First understand how you map simple data types (string, number, URL, etc.). See and understand techniques to handle convertion problems (URL or string, byte or blob).
Mapping Relations. Understand how you map relations (uni- and bi-directional), how to maintain the invariants with proper encapsulation, the issue of "orphans" objects who lost their parent, and how to map several relations to the same class differently, how to load eagerly or lazily and the link with the "N+1" select issue.
Mapping Inheritance. Understand the mismatch between object, class, and tables. Understand how far you can support inheritance with ORM.
Working with Sessions. Understand working with sessions: when an object is attached or detached, what's the impact on lazy loading, how to deal with optimistic locking, the link between transaction and session.
There is an abundant literature on JPA and ORM in general. The list above is just what came to my mind.
Ideally, ORM should not impose constraints on your design. However, my advice would be keep it flat and simple.

You should go through this first
http://www.oracle.com/technetwork/articles/marx-jpa-087268.html

There is no need to make your database simpler because you're using JPA.
One of the main benefits of JPA is that it manages relationships for you.
It would be a pretty crappy API if you had to dumb down your database just to use it!
(espcially since it's typically used in a JavaEE environment)

Related

which database for java to store data in memory? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm looking for a database which would allow me to store most of the objects in the memory. Basically I want to store in the memory everything except some rarely used data (history of changes, etc).
I'm looking for:
simple API for java, preferably non-ORM
ACID is not required (well, D is)
some support for queries, but nothing fancy
The idea is to operate on a model in memory, store any "command" mutating the model in the database, periodically synchronize model to database (like prevayler does)
Which database matches my needs? (I'll use postgres or H2 if there isn't anything simpler).
You need one of object databases: http://en.wikipedia.org/wiki/Comparison_of_object_database_management_systems
You should use Terracotta. It is usually used for caching, but its exactly what you are asking for, except that it's "querying" abilities are sparse.
Update:
The previous link was to their "enterprise" edition, but they have the open source project Ehcache which fits your needs, and their enterprise product is based on.

Overlap in C++ and Java data structures: stack "top" vs "peek" [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I often use the Stack data structure in both Java and C++. This is a standard data structure, very common in implementing many algorithms.
My question is (and the thing that drives me crazy) why does C++ use "top" as a function-name that returns the top-most element value without removing it, and Java uses "peek" as it's method name?
I know there is no standard for data structures, but hasn't computer science come far enough along that there should be a standard? Or am I just too much of a novice to know about a standard...
Do those of you that are professional programmers write your own data-structure libraries that adhere to a common interface across languages? That seems like the best thing to do, in my mind. I write code in C++, Java, Python, C, Perl, and PHP. I just don't see any other way but to write a custom interface for all of these languages. I like "peek", but is there any standard I should be aiming for?
Writing a custom interface just to make method names the same would be a colossal waste of time. What exactly would be the point? You wouldn't be able to easily copy-and-paste most code between the languages you've mentioned even with such a feature.
Personally, I don't like the name of the STL vector method push_back(). I would prefer if it were just called add(), for one thing it'd be less typing. It never occurred to me that I might change it, however. Doing so would just make my code less portable and less readable for others. Now, I suppose this could be done fairly easily with a pre-processor macro, but even that would be a waste of time in my mind.
No there can't be, won't be, and never will be a standard. Anyway, both names are valid, and if you ask me, top makes more sense. Also, as #mimicocotopus says, it's not like having the same method names would let you copy paste code from one language to another. Also, languages like C++ and Java are very distinct, and support different features. If a standard had to use the lowest common denominator, it couldn't take advantage of all of the features of the language it was implemented in.
Anyway, remember what happened last time we standardized something? Cross browser compatibility and porting C code. It gives me shudders just to think of it.

Where can I find tasks for using patterns [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
There are a lot books/online resources about using patterns. But I didn't find any tasks for using it. But for good understanding of patterns it's need practice. Maybe someone faced with some resources where there are tasks for using patterns.
For example. Mediator pattern:1)write chat application where...
Thanks in advance.
UPDATE:
I found:
http://www.cs.sjsu.edu/~pearce/modules/labs/patterns/
How to study design patterns?
I'll give you five, with easy and/or moderate difficulty:
Singleton
easy: single database access class for the entire application.
Factory
easy: English-to-another-language translator. I need to be able to add and then access a new language translator with minimal code changes.
Observer
easy: Central data structure that has several copies within the application that need to be updated automatically when a change to the main DS occurs.
moderate: Make this work over a network with cooperating processes updating a central data structure.
Memento
easy: A simple game with the ability to save/load.
Decorator
easy: A simple persistence class with read/write ability. I want to be able to dynamically switch between XML or database persistence.
I know only of one such resource, and it is not formulated as you have specified, but maybe it'll help a bit: In the last chapters of the Head First Design Patterns book, the MVC pattern is explained as a compound pattern, involving several others : Composite, Strategy, Adapter etc.
It is explained with the help of a small application. You could look up the chapter and build the described to practice.
Ever use an iterator? Pattern. My guess is you use a lot of patterns without even really realizing you're using them. Created a buffered reader out of a file reader? Decorator; pattern. Don't set out trying to use patterns--let the problem discover them. They're everywhere, that's why they're patterns.
Things like facades, decorators, iterators, factories, etc. crop up in every single domain. Pick anything you're interested in writing, and discover the patterns already present. Refactor mercilessly--patterns.

Which algorithms are worth to learn or recall on preparation to Java developer interview? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
I know that is Collections.sort() method in Java but I think quicksort is worth to remember and try.
My work target is general Java: web, database access, integration, not game developer, scientific application or another one that depends on advanced algorithms.
Which algorithms should I learn to pass without stress Java developer interview?
Fizz Buzz
I usually don't care, if a developer knows the basic algorithms by heart. I do care, if he is capabale of understanding requirements and translating them in correct, testable and understandable pieces of code.
Ah, and I do care if he knows how to implement the most common design patterns. And he should know when and how to use collections, threads and - String#split - it's amazing how many "developers" don't know how to read and process a simple csv file.
Although I fully agree with Joachim comment, I would go for : collection selection. This is not an algorithm per se, but rather a good view of which collection is good for which purpose :
sorted content with constant lookup time ? TreeSet !
mapped data with memorization of insertion order ? LinkedHashMap !
using that, and some knowledge of design patterns behind collections, you will far too often reply to algorithms questions using the knuth answer (or the subtle variation : as long as Sun developpers implemented it correctly, I only have to choose wisely).

performance tuning for JSF [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Can any one list out the tips to tune JSF WebApp # its best.
JSF RichFace
Never put logic into your getters.
They are called multiple times and
should only return something already
populated by another method. For
example if you are chaining drop-downs
together use an a4j:support tag on the
first one with an action attribute
that loads the data which is then
retrieved when you reRender the second
one.
Use the ajaxSingle="true" unless
you actually want to send the whole
form back to the server.
Don't use a
rich component if you only need a
normal one. For example don't use
rich:dataTable unless you are making
use of some of the features that it
has over and above h:dataTable.
Consider using immediate=true
attributes on elements where you do
not need validation Avoid displaying
large tables to user.
Use pagination
Do not over complicate EL expressions,
code them in Java in backing bean
JSF BestPractices
Performance Tuning
Moving to Stateless JSF would offer a great performance boost. Now it's possible to use JSF entirely stateless. See this blog & this issue. A payoff is that you can't create views dynamically (e.g. by binding, JSTL tags, etc), nor manipulate it after creation.
A Stateless JSF operation mode
would be incredibly useful for high-load applications and
architectures:
http://industrieit.com/blog/2011/11/stateless-jsf-high-performance-zero-per-request-memory-overhead/#comment-4
This has previously been suggested by Jacob:
http://weblogs.java.net/blog/jhook/archive/2006/01/experiment_goin.html
This would help JSF ditch the stigma of "slow and memory hog," and
help keep up with current tech trends (stateless architectures.)

Categories

Resources