MySQL News

Dec. 18th, 2008 12:56 am
armtuk: Cheetah (Default)
So in MySQL it's possible to have a table:

create table fish (
created_date datetime not null
);

and do

insert into fish values ('0000-00-00');

This is valid.

wow. Wow. WOW.

Let's face it - it's just not a serious product.

Java will of course fail to convert '0000-00-00' into a valid java.sql.Timestamp

I am going to have to write code that runs on initialization of the context that fixes the data in the database because MySQL is such a pile of rubbish.
armtuk: Cheetah (Default)
Today - I wrestled a database driven form out in just 50 minutes. That included coding the HTML for the form, coding the Data Object in Hibernate Annotations, creating the DAO, creating the processing ActionBean with validation, creating the display back HTML to display the data back out again, updating the Spring Context with the new DAO, adding the Database object to the hibernate configuration. Running the update scripts to change the database and testing the form to reveal that I hadn't done a couple of the steps above initialy.

50 minutes. We used to budget this kind of page at 4 hours. Stripes is awesome. Hibernate could generate more on the fly I still feel, but it's not bad considering I'm driving the DDL statements from the Java class. You have to write that code one place, either in HBM XML files, Annotated Java code, or SQL statements. I still think you could build the form HTML based on the database schema too which would save time. Maybe I'll make a helper application to do that.
armtuk: Cheetah (Default)
super computer science geekness here )
armtuk: Cheetah (Default)
So for today's hard knocks hibernate lesson we learn that putting annotations on Member variables instead of Member Functions is a really bad idea. It breaks when you use inheritance. If you inherit from a MappedSuperclass and that superclass has members that are complex objects, then when you inherit them, all the annotations are ignored in the subclass, so you end up with database fields being of type bytea (at least in PostgreSQL) instead of being correctly mapped as foreign keys.

So in summary: Don't put annotations on member variables, always put them on member functions.

*SIGH* time to refactor 32 database classes.

At least I found the problem quickly.
armtuk: Cheetah (Default)
So I am building this web app. For the first time, I'm trying to do it by the book. I have a spring context, DAOs and ORM through hibernate. Everything seems copacetic. Then I realize that the logic for stopping a workflow item has to be in two places. So I do the seemingly sensible thing and I pull it out into a method.

A few days pass, and the thought dawns on me that this is what they mean by 'business logic'. An operation that can be called independently of the website to perform a function against the data. The light goes on in my head. The ActionBean should be looking up an instance of this business object in the spring context and setting member variables and calling a method on the business object.

All my functionality like that should be moved into business objects.

D'Oh, Yay! I finally 'get it'. Nobody ever explained how this stuff is supposed to work to me.

This is a subtlety that most MVC guides fail to point out. There is really another level of abstraction there, MVCB, Model, View, Controller and Business Logic. If we were in a SOA this would be the stuff that would be at the other end of the service.

Let me tell you how awesome this is going to make Dot Artistry when I get it going.
armtuk: Cheetah (Default)
I am struggling through Hibernate funness. I bought the O'Reilly book, but it's a bit thin, and after reading a few peoples' reviews, I also got the Persistence with Hibernate book from Manning which is AWESOME.

the merge method is evil. It looks like a good replacement for persist() but it isn't. merge() doesn't actually tie the object to the database state, so if you call merge() repeatedly on an object with no Id, it will save it repeatedly. persist() however does the right thing. The only thing merge gives you is the ability to save an object across sessions, but it would probably be better to attempt to re-attach the object instead of merging it.

IntelliJ

Oct. 18th, 2008 10:22 am
armtuk: Cheetah (Default)
Can I just say that IntelliJ rocks. It detected that the graphic in my background-image inline style in an HTML tag in my JSP did not exist, and highlighted it as a problem. How awesome is that?

Plus, I have killer head-ache of doom :( so I'm a bit cranky.

MVC

Oct. 16th, 2008 09:28 pm
armtuk: Cheetah (Default)
MVC means Model, View Controller. Not Controller who makes a Model and passes it to the View. This is the normal usage of this system in many implementations, but that's not really what MVC is is it? The Model is an independent piece that isn't tied to the Controller directly any more than it's tied to the view. The Controller is responsible for updating the Model, and the view is responsible for rendering the Model.

In a normal Web based application, the Model is in the Database which is often an RDBMS. It doesn't break MVC to have the view talk to the database, because the database is the Model. The big mistake of many ORMs is trying to represent the Model in two places, in the database and in the application server. This of course creates all the same problems as multiple master replication causes for a database product. Every transaction has to be replicated across both systems incurring a huge overhead and making transactions way longer than on a single master system leading to huge performance problems. It's pretty common sense that the best form of distributing load is to have a share nothing cluster where you put different parts of the data set on different nodes. This is in opposition to multiple master replication which puts all the same data in two places. This is good for redundancy, but bad for performance, unless your interconnect is as fast as your local storage, which is rarely the case (don't just think throughput, think latency too). Of course you can do the best of both worlds and replicate and distribute like RAID 10, but this means having homogeneous copies, not heterogeneous copies like relational data and objects.

If we think of MVC as a three legged stool as in the first, we have true MVC, but if we corrupt it, then we get Bad MVC like the second which is like trying to have a two legged stool. It doesn't work too well:



Presenting the Model is the view's job. Preparing the data for presentation is not the controller's job. The controller's job is to process user input and update the model. The model is not a transient object that's instantiated and reads data from a store to a Model object, that's a proxy. The real model is the datastore. Most RDBMSes I know have pretty good methods to update the data within them. Most Models need to do internal checking to ensure that they are sane too and aren't corrupt. This behaviour does not belong in the controller. It's part of the Model. That means database constraints and triggers.

Any framework that forces you to build the Model in the Controller and pass it to the view is a corruption of MVC and is asking for serious concurrency and performance problems. This doesn't mean however that your View cannot be started by a servlet or similar that reads data from the database into a hash and then forwards the display to a JSP or something similar. Just that to do MVC right, your controller doesn't return a Model and a View like in SpringMVC, it might decide which view to send the user to, which will then in turn access the model.

This means that we need different functionality in the view than most frameworks give I think. Some of this can be done in JSTL, but it's kind of clunky.

I'm going to read the rest of the Wicket book in the hope they get this, but I'm doubtful.
armtuk: Cheetah (Default)
So a bunch of books arrived on various Java frameworks. I had a conversation on the #java channel on freenode and most people pan struts. They say that struts 1.0 was awful, and struts 2.0 is just about usable, but pretty bad. I asked what they thought of JSF (Java Server Faces) and they said that it's kind like asp.net in java, not really a ringing endorsement. The guy didn't like Spring MVC at all, described it as a train wreck. They liked wicket though, and didn't have much comment on stripes. The user in question had already validated himself by describing the very subtle difference between passing by reference, and passing a reference by value, which is a very subtle but important detail in Java, amongst other pearls of wisdom, so he wasn't a complete n00b. The drunk guy spouting aspersions about java.io.File suggested Groovy, but I haven't really looked at that yet, as you know, this was the drunk guy who was trying to re-invent Spring, and couldn't deal with cross platform file access. One of the Groovy guys is on the Java podcast I listen to (Java Posse), so I suppose that speaks well of it.

A guy who I worked with on another project had suggested stripes, and this is a person I have a lot of respect for, so I bought the stripes book, which is in beta, so I got a PDF, and they'll send me a book when it's ready. The upside was that I had a PDF to work with straight away, so I've spent the last couple of days reading on Stripes. It's pretty cool so far. It does a lot of sensible things very sensibly :). I like the general principle of convention over configuration, which is something Stripes in hot on.

I am guessing the wicket book will probably arrive Tuesday or Wednesday, and I'll have a look at that. I have a couple of projects that I need to do in the short term time frame so I need to make a decision pretty soon.

Spring MVC

Oct. 6th, 2008 09:11 pm
armtuk: Cheetah (Default)
Took a good look through the new Spring book over the weekend. I was hoping that Spring MVC would be the answer to all my prayers about a web based framework. It wasn't to be. I wish there was something that was between single controller, and portlets. The portlet spec sucks, and the documentation for it is lousy. There's like two books, one is on JSR-268, and the other is on JSR-168, and they both suck. Spring only supports JSR-168 at the moment anyway, and it seems kinda stupid to work with a technology that's already been obsolete for like three years. There seem to be zero docs on themeing, which is like the first thing you want to do with your portlets.

Anyway - I've ordered the newest good struts book I could see in the vague hope that struts has improved since I last looked at it. It seemed like a whole bunch of XML nightmare last time I worked with it that could be achieved with a well written web.xml and dispatcher forwarding (which is what I used in consultant-helper).

Somebody else I talked to recommended stripes, so I'm hoping to get the book on that when I get paid.

I also had got the book on JSF too that I was hoping wouldn't suck, but it doesn't look too hopeful.

It all seems that MVC is just fundamentally wrong. You don't have _a_ model, and _a_ view and _a_ controller. You have input data sets that need processing and then output data sets that all need initializing to render an output that are totally independent of each other. What's in the output fundamentally affects which data you want. One view of the output, say an XHTML page will want all the associated bits and pieces, headers, nav, other things you might like, latest news for this product/item etc. And the XML view just needs the basic data. Somewhere, something needs to know all this and initialize the Models appropriately based on what needs to be in the view. That's right folks, the view needs to drive the model, not the other way around. How else do you explain that pagination is fundamentally a view centric operation, but anybody in their right mind will implement it at the Model level, not the view level, because passing 2000 records through to the view from the database is stupid.

Also - why do we need a separate dispatcher from the web server? URLs are great for telling the system which page you want. Why not keep using them instead of re-inventing the wheel?
armtuk: Cheetah (Default)
In other news, my Spring 2.5 book came, which is exciting. So far I have really enjoyed Spring as a platform, and I'm looking forward to expanding my understanding of it. Now I have a bit more time it looks like, I should be able to find the time to study the book and get up to speed on some of the other useful features of Spring other than just Dependency Injection.

IDEs

Mar. 4th, 2008 10:57 am
armtuk: Cheetah (Default)
I have long spurned the use of IDEs preferring rather to rely on trusty tools that work on the command line that have been so well debugged that they just work. Vim, ant, sed, awk were my best friends in coding land. Then I had to develop a desktop application that had to run on Windows. In Windows Vista, cygwin and java do not get along, and cygwin doesn't work very well at all in Vista particularly. I turned my attention therefore to the leading IDE available for java: Eclipse (I poked NetBeans, but it sucked compared to Eclipse, in particular it couldn't import my ant build scripts successfully, and doesn't deal with other formats well). I started to work with it, and found that it's fairly easy to work with, and things are well set up and easy to find for the most part. Then I discovered it could handle my python files in the project (The project has a bin directory that has various python scripts that do trivial database operations that are too big to want to do in a stored procedure that gets smooshed into one transaction). Then I discovered AspectJ. I cannot imagine trying to work with AspectJ outside of an IDE that can figure out where your pointcuts are applied dynamically. It would be a total nightmare, and I'm getting very fond of AspectJ features, to the point that I purchased the AspectJ book. Then there is web.xml editing. Frequently when I edit this important file by hand, I make simple typing errors which causes a restart of tomcat over and over again till I get the format corrected. This does not happen in the IDE as it's presented as name value pairs where the name of the tag is pulled from the DTD and presented in a drop down menu when you want to add a new tag. This is getting particularly important as I am starting to shun the use of JSTL in JSP for submit pages, and move back to using pure servlets for this functionality after a big blow up with a database upgrade. All these things have dramatically reduced the time I spend fixing trivial typos in my project and allowed me to be more productive. I wrote a PDF library that will be used on multiple projects in about 4 days straight including tests with some Aspect Oriented features. I don't think that would have been possible on the command line.

My one and only complaint is that there is poor git integration. There is an egit project that is a pure Java client for git, but it doesn't work very well, and so I have to go back to the command line to work with git. This is a general weakness of git though. They have the wonderful gitk program, but when it comes to visual interfaces, particularly on Windows, it is severely lacking. Given some of the advanced features of git that I have had occasion to use like git filter-branch, I can't imagine switching to another VCS unless it had those features, which I'm pretty sure no other VCS does (though I'm looking into bazaaar).

Another nice feature is Eclipse's ability to capture stdout and stderr from various sub-processes like tomcat, and JUnit testing which allows me to see right in my IDE what's going on with the server or with my test cases.

In short, it appears that I am eclipse's newest convert, though to be honest, to make the best use of Eclipse you need a monster monitor for all the views, but I have that mostly taken care of with (New Egg 22" Acer wide-screen for just $229!).

There are many other features of eclipse that I am going to have to explore. It has some very nice looking plug-ins for creating UML documentation, and documentation is something we are lacking a bit. I tend to do a good job of keeping things in my head, and as there isn't another developer, I am a bit guilty of not documenting what I have built very well (though the code is commented, but I hate trolling through source code personally). Generally most of what I build is too simple to warrant complex UML diagrams anyway, they are mostly just websites that process basic information to a database in simple submit processing type forms, and basic search functionality on top of that data.
armtuk: Cheetah (Default)
I am writing some PDF functionality as you may well know if you've been reading this feed lately.  And I have come to the part where I write out a PDF object and it's children to a file.  Silly me, I figure I can use object inheritance to solve my problem:

simplified:
<pre>
public class PDFWriter {
    public void write(PDF p) {
       PDFObject a;
       for a in p {
          write(a);
       }
    }

    public void write(PDFName a) {
    }

    public void write(PDFDictionary a) {
    }
}
</pre>

of course what I am trying to do here <i>isn't</i> a feature of object inheritance, but rather a piece of functionality referred to as double dispatch.  And tonight I found out that Java doesn't <u>do</u> double dispatch.   Bummer said Dougal, time to figure out something else.  And for the first time introducing a design pattern that isn't obvious, the Visitor pattern.  Ok - so the essence of the pattern is that we use polymorphism/inheritance to act like double dispatch by calling a method on <pre>a</pre> instead of calling a method on the Writer passing a generic object.  The method on a is of course called on the inherited type rather than the base type, and it calls visit(this) on the visitor, which is the PDFWriter object.  All that remains to do is rename the methods called 'write' to 'visit'.  Pretty nifty.

That's my lesson in OO for tonight.
armtuk: Cheetah (Default)
Over the last couple of days, in an effort to simplify the development of the PDF Library I am working on, I have been fiddling a bit with aspect oriented programming. I have been hearing increasing amounts about aspect oriented programming for some time, so I finally decided to look into it a bit more. I found a PowerPoint presentation that was given by the Xerox Parc people about AspectJ, the Aspect Oriented wrapper for Java, and read the first 2/3 of it, and started experimenting. This is where I found that the PP was way old, and was in-fact using an archaic syntax that was no longer supported. I downloaded the plug-in for Eclipse that supported AspectJ and that came with some examples that cleared things up. Yesterday we went to Borders Books in King of Prussia, and they had the AspectJ in Action book, so I picked that up and have started perusing the contents thereof, although with an eye to the functional as I am working on stuff that really really needs to get done in a hurry. I have used a couple of aspects now to really help debugging the work I am doing, and it's very cool. Really cuts down on the insertion of System.out.println() calls in the code, and keeps the code nice and clean. So far I really like it.
armtuk: Cheetah (Default)
I am working on a new application for Pennmark publishing. This is a neat little application that sources images from a client and uploads them to a server for processing. I have decided that in this wonderful internet age, the application should be able to report any errors back to the server, so I am building an infrastructure to do remote error reporting. I really think this will be a big help to us when we are trying to debug what is going wrong with a clients instance of the system. I think I am also going to build an auto-updater too that will pull down the latest jar file of the software when it starts up. I have forgotten how much I love application programming. This is the stuff I really enjoy best of all. It reminds me of my days at Octagon building a PDF viewer in pure Java. That was an awesome project too. I might have to re-use some of that knowledge in this project to be able to do some PDF shinanegins on the server processing side. That should be a blast too. Today for the first time in awhile, I really do feel like I am riding the world.
armtuk: Cheetah (Default)
So - I'm working on getting a demo application ready for a client. It's a java application, so I figure the easiest way to work would be on a linux desktop, then jar it up and scp to my windows box for testing.

I have installed Ubuntu 7.10 on my spare machine here. Well. Where to begin. This system is definitely not for java developers. It ships with the stupid gij/gcj system which doesn't actually work apparently when running a simple Java 1.2 application that opens a window with one menu 'File' with one item 'Open'. Stunning. Stupidity 1, Linux 0.

First I try and get it connected to the network, but by default it comes in 'roaming mode' which means it doesn't find a network connection. How stupid is that? Stupidity 2, Linux 0. I have to manually change it to DHCP, which then doesn't work immediately, I have to start dhclient manually (I only know about this because we were messing with it on Marn's laptop the other day). Stupidity 3, Linux 0.

Then I try and get VNC working so that I can VNC in from my windows box and use the linux box 'remotely'. This is important as the tools I use for image maniuplation aren't on linux, namely photoshop and illustrator (You can talk about GIMP all you want, but it won't open a PDF and let me extract images from it). Well - I installed the vncserver package, and basically it doesn't work. After trolling the web a bit, I get some suggestions, but they don't work either. Stupidity 4, Linux 0. I go on IRC, the infamous support network for linux, both on #ubuntu, and on #gnome-hackers as I was hoping to use this setup for working on Metacity. No help there. Stupidity 5, Linux 0.

Then after working in firefox a bit, firefox crashes. Not only that, but it apparently takes X with it as no application will now start, with a connection refused message. Stupidity 6, Linux 0.

Ok - so I download the JDK for linux from Sun and ant from Apache, get them installed, and my JAVA_HOME set correctly, and I manage to compile and run my simple test application, hooray. Stupidity 7, Linux 1.

Ok - now I need to get my images off the windows box. Let me think how to do that - oh yes, SCP. Well - this is Ubuntu Desktop, so sshd is at least not running. which is reasonable. After trolling through the menu for some kind of services application, trying a couple of things - I find nothing. Wow - even the Mac has this shit guys, for pete's sake, do some basic research, OS X has been out for years. Stupidity 8, Linux 1. Ok - well maybe something that can tell me if it's installed, some kind of package manager, well there is something labeled synaptic package manager. Not really clear what this does from the name if you don't know that Ubuntu (and most other distros) is organized into packages. Well give one for each side on this: Stupidity 9, Linux 2.
Hooray - my search finds openssh-server, and I get it installed, and it starts! Woot! Stupidity 9, Linux 3.

So after nearly two days of wrangling, I am actualy starting to get some work done. Not what I had really pictured as my ideal outcome.

Oh - and the compiz window manager. Well - the effects on the Mac and Windows Vista are somehow pretty and unobtrusive. Not so with compiz. Too much bling going on, it's very distracting. Now I just have to figure out how to switch back to metacity. Plus I work on metacity a bit, so I have to use metacity out of principal and hate compiz :).

Is linux any better on the desktop than the last time I used it seriously 4 years ago? Nope. Still has major holes even if you just want to connect to a network for pete's sake and browse the web. And let's not even get started about how UGLY firefox rendering is in linux. It's not a patch on IE 7. At least I hear they are working on a new rendering engine in FF 3.

Update: I downloaded the Firefox 3 beta, and after some wrangling got it working. Could they make it more difficult to test it? The rendering engine was crap like in Firefox 2. IE 1, Firefox 0.

Profile

armtuk: Cheetah (Default)
armtuk

April 2017

S M T W T F S
      1
2345678
9101112131415
16171819 202122
23242526272829
30      

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 23rd, 2017 09:21 am
Powered by Dreamwidth Studios