Arron Ferguson

Greenhorn
+ Follow
since Feb 01, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Arron Ferguson

I found the answer to my own question so I figured I'd post it in case anyone else winds up with the same question. First, a great link from the Apache Software Foundation describes the differences between each of the classes and their purpose:

http://openejb.apache.org/3.0/jpa-concepts.html

So, I created a simple servlet that did the following within its doGet:



The above code utilized a static EntityManagerFactory declared within the servlet. The average time was about 0.15 ms and so the performance was quite good; I had seen a post somewhere from 2007 where someone claimed that TopLink's ORM was 140+ ms per operation - but don't know if that was correct or not.

Next I did the following:



The average, which I was only able to run twice, gave an average time of about 130 ms. Quite the difference! However, and this has more of an implication than the performance, but attempting to call this servlet (i.e. reload page) more than twice caused an exception stack trace with Hibernate declaring that MySQL couldn't honor the request due to "too many connections". I attempted to reconfigure Hibernate to allow more connections (and also MySQL) but the times did not change.

More explanation about why this performance difference exists comes from the Hibernate documentation for EntityManager:

http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html_single/

Which states

When Persistence.createEntityManagerFactory() is called, the persistence implementation will search your classpath for any META-INF/persistence.xml files using the ClassLoader.getResource("META-INF/persistence.xml") method. Actually the Persistence class will look at all the Persistence Providers available in the classpath and ask each of them if they are responsible for the creation of the entity manager factory manager1. Each provider, from this list of resources, it will try to find an entity manager that matches the name you specify in the command line with what is specified in the persistence.xml file (of course the provider element must match the current persistent provider). If no persistence.xml with the correct name are found or if the expected persistence provider is not found, a PersistenceException is raised.



And:

An entity manager factory is typically create at application initialization time and closed at application end. It's creation is an expensive process. For those who are familiar with Hibernate, an entity manager factory is very much like a session factory. Actually, an entity manager factory is a wrapper on top of a session factory. Calls to the EntityManagerFactory are thread safe.



So it's safe to set up an entity manager factory as a static variable because it is thread safe - but also because it is an expensive operation.

And lastly,

A EntityManagerFactory is an expensive-to-create, threadsafe object intended to be shared by all application threads. It is created once, usually on application startup.



So, at this point there should be no question whether or not EntityManagerFactory should be a static, even final, variable in a class.

Anyway, I figured I'd share this in case anyone else fairly new to application managed entity managers comes across this sort of an issue. I had been using JBoss Seam and so Seam had been managing the entity manager for me via DI and I therefore did not have to know the intrinsic behavior of entity managers and what's involved.

Btw: if anyone sees anything to add or correct (if I'm incorrect about any of this), please post.
My question is rather Matrix-esque in that I've already written the code and it works but I'm trying to understand it.

Anyways, I'm using Hibernate and I'm using JPA calls and JPA annotations for the class that is mapped to a table. Again everything works fine. I have a simple CRUD sample application where objects are added, edited, deleted, and listed. I have the following variable in the service class:



My addCustomer method is:

My question is:

1) Am I doing this in the most efficient manner? I seem to remember reading somewhere (can't remember where) that there was no penalty for continuing recreate a factory and the entity manager but my intuition is suggesting otherwise. Any feedback most welcome.
Okay this is the last post from me in this thread - I just figured I would share so as to help anyone else from making the same mistake. The PNG with transparency is correctly set to TYPE_INT_ARGB (i.e. with alpha). What I did wrong (and it was my fault), was that I made the following instance method call in the class GraphicsConfiguration:

gc.createCompatibleImage(w, h, Transparency.BITMASK);

This resulted in being considered a "TYPE_CUSTOM " BufferedImage. As soon as I said:

gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);

The BufferedImage.getType returned TYPE_INT_ARGB (== 2)

Sorry for all the posts.
10 years ago
Here's the funny thing ...

I tried this:


And it drew a black pixel ... which means that it is in fact TYPE_INT_ARGB not TYPE_CUSTOM. Funny those Sun engineers wouldn't call it what it is but treat it as it is.

10 years ago
Hey all,

I'm trying to load a PNG image in that has transparency in it using JDK 1.6 u10 and manipulate the image data (pixels). The problem is if I do this:



Or this:



Or this:



The type is always TYPE_CUSTOM and not TYPE_INT_ARGB - which seems odd because the PNG file that I am loading has transparency in it.

What I want is the BufferedImage (which has the PNG image data I'm interested in) so that I can play with the image data (e.g. perform a projective transformation) :




Any advice would be greatly appreciated!
10 years ago

Campbell Ritchie wrote:

Arron Ferguson wrote:But then I'm faced with the entire graphics context having the transforms/translations applied to it rather than local transforms/translations.

No, you only apply the transforms to the copy object.

You need a copy object regardless; you can transform and un-transform a Graphics object, but the floating-point arithmetic is never quite precise, so your Graphics will be slightly skewed afterwards. That seems to be more of a problem with rotation and shearing than scaling or translation.

And sorry for not replying earlier. And Craig Wood's code always works well, doesn't it



Ah yes, I saw that afterwards and realized that what you just said is correct. Whether I use the AffineTransform or the methods of the Graphics2D class you can always reset it. Talking about not precise, I have yet to see a differences in quality for rotation/shear/scale. For example:



Has absolutely no affect (or effect) on images that have been sheared, scaled, or rotated. I've tested this both on Linux (Ubuntu) as well as Vista - both using JRE 6 u10. Both computers show no change between using rendering hints either on the Graphics2D object nor on an AffineTransformOp. I've compared screen captures and zoomed in to see differences and there are none.

I came across a few bug reports on the Sun site suggesting that a couple of years back bicubic wasn't implemented and that for printing these values had undesirable artefacts but nothing particularly suggesting anything wrong with rendering hints not working. I'm less apt to file a bug report since the last few I've posted in the last few months don't get addressed - so I'll just use what works and move on.

For affine transforms in Java, I came across a fellow who made a utility class called AffineTransformUtil and it helped me to see what was being done.

Additionally for arbitrary transforms to images, I came across Jerry Huxtable's web page that has a library (under the Apache License) which contains a perspective filter - which was really what this whole adventure was all about: creating arbitrary (and stationary) sides to a cube based on images fed into the UI. Sometimes the search through Google takes one through some interesting paths.

And yes, Craig Wood's code works and is easy to follow.
10 years ago

Craig Wood wrote:not sure whether this method is suppose to take a matrix or if it's suppose to take a set of arbitrary points
AffineTransform contains the matrix and does the matrix math in the background. The transform method takes an arry of arbitrary points (in any space) and transforms them into the space defined by the AffineTransform.



Wow, Craig, thanks, this is exactly what I needed. Thank you very much for your time in answering my question.
10 years ago

Campbell Ritchie wrote:Suggest you try copying the Graphics object with its create() method. You might have to cast it to Graphics2D. Then use its scale, rotate, translate and shear methods. The API for AffineTransform tells you which matrix operations they use for the different transforms.



But then I'm faced with the entire graphics context having the transforms/translations applied to it rather than local transforms/translations.
10 years ago

Rob Camick wrote:Don't know if its any better than the API, but the Transforming Shapes, Text, and Images tutorial might help.



Thanks Rob for a quick reply. Yeah, I did look at this and it doesn't go beyond scratching the surface and so no coverage of the transform methods and what the values fed to it are for.
10 years ago
I have been scouring the web looking for examples and documentation concerning the java.awt.geom.AffineTransform class's overloaded transform method - specifically this one:



The Javadoc is sketchy at best on how to use this method (same with the Java 2D tutorial - no mention of how to use the method). I'm not sure whether this method is suppose to take a matrix or if it's suppose to take a set of arbitrary points which can then be used to transform (e.g. warp) an image (I'm hoping the latter).

What I'm trying to do is take an image, rotate it by 45 degrees, squish the image so that this diamond shape is now 2h = w. Basically the pseudo isometric tile (pseudo because true isometric has all 3 angles being equal and a rise over run of 1:2 is actually dimetric due to only 2 sides being the same). I've managed to do the shearing correctly:


And so on. I want to be able to do this with the standard Java 2 SE and not use advanced imaging or Java 3D.

Any help, tips, links, advice, or even code snippets most welcome.

10 years ago
Mike Simmons:

I think you're misinterpreting section 6.4.3 of the JLS. Re-quoting:

Members are either declared in the type, or inherited because they are accessible members of a superclass or superinterface which are neither private nor hidden nor overridden.



In order to be inherited, the following must be true:
  • super-class member has no private access modifier
  • super-class member is not hidden (IOW it's not static)
  • super-class member is not overridden


  • So a super class member that is static cannot be inherited.
    Rajshekhar:

    I guess my point is that the compiler shouldn't be giving misleading information like this. It's not something that I would think 10+ year old technology would so blatantly be doing.

    Anyways, thanks for your answer. I guess the idea is to ignore the message.
    Rajshekhar:

    Incorrect. Static methods are not inherited. The SCJP authors makes this clear, the Java specification makes this clear.

    Prateek:

    The compiler is most definitely not behaving as it should. It's implying that I've overridden the method but you cannot override static (class methods). This is contradiction from the Java compiler and a bug. I can't believe this is in there, seriously.
    First off, I do know that you cannot override final or static methods, . However, what I'm not clear about is why the compiler should complain about this:



    The compiler error is:



    Hmm. Funny message. The compiler is contradicting the rules of the Java specification which make it quite clear that I cannot override static methods. And yet here it is complaining about access modifiers. But the only way I can break access modifiers is if I'm overriding. Why is this error message even there?

    Comments?
    Look at my first explanation in this thread, it answers your question:

    Covariant problem