Category: Debugging

Getting Dumped While Using MXUnit

With all my real world experience getting dumped, I never thought it could ever be a good thing. But in programming, getting dumped, more specifically, dumping variables, is immensely useful when debugging. I use it all the time when writing code.

But having lately been playing more and more with unit testing, specifically using MXUnit in Eclipse, debugging errors through unit testing seemed a bit more problematic.  I could put dumps in my CFCs but that output would never make it to my test case results. How was I expected to debug that way.

Then I had an idea. Stop me if you heard this one.  Instead of using “writeDump”, I raised an error. I used the throw statement. For the error type I put the name of the variable. For the message I put the value of the variable:  For instance, I put:

throw(message=userID, type=”User ID”);

When I run my unit test in Eclipse in my results I see “User ID: 84756”. Voila!  One caveat  however, and it is a big one, it only works with scalar values.  Figuring out how to dump structures and arrays will be my next task.

Always learning….always growing.

OhRM! Why Aren’t You Updating?

One of the great (and probably terrible) things about having so much to learn in the development world is that I often find myself trying to learn several things at the same time.  For example, late last week I began playing with the jQGrid plug-in. But I had to build back-end support for it, so I did that in ColdBox (which I also have been playing with).

Things went great on pulling the data and pushing it to the plug-in.  But things got more complicated when I had to build the back-end methods for processing the updates from jQGrid.  Building the SQL statements was a challenge. In the back of my mind I heard a voice screaming “ORM” (Object Relational Mapping), but while I have flirted with ORM (by that I mean watched one or two online presentations about it), I hadn’t taken the plunge.  So did I really want to add a third variable to this R&D?  I resisted as long as I could…but going non-ORM with this was getting ridiculous, especially since I was building a back-end to handle just about any table we need it to.  No doubt about it. ORM was the way to go!

So I took the plunge.  First hurdle….how can I use ORM on existing tables without running the risk of it modifying those table structures. A quick Google search brought me the answer (on Ben Nadel’s Blog no less…..a lot of CF developers need to buy him drinks for the amount of time his posts save).  Simply adding:

this.ormSettings = { dbCreate = “none”}

to the application.cfc file solves that problem.  It prevents ORM from making structure changes.  Great!  Now I can move on!

Fetching data with ORM was a breeze!  It also allowed me to eliminate several private methods in my CFC.  Sweet!  And look.  Updating information is as easy as loading an entity, changing its properties, and saving it back out.  Perfect….except….the data in the DB table didn’t change.

What was I doing wrong? I scoured numerous blog posts on ORM, tried everything from saving, to not saving, to flushing….no joy! I spent a good 6 hours or more trying numerous things and cursing this wretched beast known as ORM!!!!

Then I found the problem.  Because I was building this back-end to handle any table we need it to, having to know the names of the setters and getters was troublesome.  In ORM, those are created for you and are named based on the property name. For instance, I have a title field. So the setter is setTitle() and the getter is getTitle(). Simple enough, but I won’t know what fields my entity has until run-time since it will depend on what entity is being requested.  As an aside, would it not make more sense to autogenerate a function called “setProperty” and pass it the property name and value, and a function called “getProperty” and pass it the property name and value, than to generate two functions for each and every property in the entity?  Would love to know why its done that way.

However, one way around this I saw was just to set the property directly on the entity. So if my entity’s name was oTest, I could set the title by saying “oTest.title = “This is a test”.   Basically what is happening is, ColdFusion implicitly calls the correct setter based on the property name…but only  if you put the statement

this.invokeImplicitAccessor = true;

into your application.cfc.  What a great solution!

But what confused me is I had done all of that and still it was not updating my DB.  Hours went by. Finally I tried a test using the setter directly. The database changed.  Looking at the dump of my entity showed it having all the properties I set and a property called “properties” that also had each one of the properties but with the values pulled from the DB. That should have been my clue.  The invokeImplictAccessor setting was failing. It was not giving me an error. It just wasn’t working.   The culprit….support for invokeImplicitAccessor started in CF10. I am developing on CF9.  Grrrr! Not giving up on ORM…just have to go find a workaround now. Suggestions welcomed.

How Many Installs Does Development Take?

About two weeks back, in the middle of a development crunch of course, the hard drive on my work laptop began gently letting me know it was not long for this world.  Without hesitation, I rushed my machine to our IT department for a hard drive transplant.  It proved to be more difficult than first anticipated, and so I was given a loaner laptop.

First day or so I did a lot of online education, not wanting to install anything since it should have only been for a day.  But the problem became increasingly difficult, and ultimately terminal.  The loaner was now going to be my laptop for the next few weeks.

Development couldn’t wait!  I had to get the laptop set up for dev work. No sweat. Code is all committed to source control. Just download my preferred IDE, check out the branch I am working on and away we go!

Hmmm….IDE has changed versions since I first installed it. This version is a little different. Ah…I’ll adjust. Oh yeah, source control was done through a plug-in to the IDE…but which one?  Ok…there are a few….must have been this one!  Nope…but…this might be better.  Ok…code checked out! Let’s develop!

Oh…didn’t set up local server.  I’ve got to do that.  Ok. That’s working.  But pages aren’t serving right. Oh yeah. Need to grab developer version of ColdFusion.  Installed…but don’t have the list of mappings I need.  Bug other team members for mappings. Still not quite right. Oh yeah…forgot custom tag mappings are in two places. All good….no…not quite yet.  A few other settings, and boom!  CF is now working!  Now to develop!

Drat! Homepage works but the other pages are failing.  Oh yeah!  URL rewrites. Need to install rewriter. Grab file of rewrites from repo. Voila. Ready to develop. On to first ticket!

Oops. Ticket involves needing to access the database. Need to reinstall SQL Developer tools.  What?  Can’t get to the install discs today? Oh man!  Ok…what was that freeware tool I used a few years back….frog or something….oh yeah. I remember.  It’s not free anymore?  Figures. I’ll try it out anyway, maybe its better.  Hmm, wonder why they needed my phone number. (five minutes later)  “Hello….yes I did just install the froggie DB thing….like JUST installed it. Your from where? You own the program?  Wait…I thought you made computers…not software?  What am I planning on doing with it? I just thought I would try it out.” (Leaving out that I did so because I was in a bind). “Sure…I’ll call you if I decide to purchase the product at the end of the trial”  (Have a nice life…doubt you will hear from me again).

Oh…a couple of other IDE plug-ins I forgot! I haven’t even reinstalled my VMs, or the framework I am playing with, or the cool open source browser ([ ]) I keep seeing plugged in my Twitter feed.  Oh…and my machine only has IE. So I have some browsers and their associated plug-ins to download. Really. “HOW MANY INSTALLS DOES IT TAKE TO DO SIMPLE DEVELOPMENT?”

Anyone remember when all it took was notepad and a copy of NCSA Mosaic?

© 2018 Script Van Winkle

Theme by Anders NorenUp ↑