AbstractGateway

83 views
Skip to first unread message

Gavin Baumanis

unread,
May 12, 2012, 7:54:06 AM5/12/12
to coldspri...@googlegroups.com
Hi there everyone,

I just came across an error when using the orm.hibernate.AbstractGateway class.

Element ID is undefined in LOCAL.

 
The error occurred in C:/DataPoint/com/coldspring/orm/hibernate/AbstractGateway.cfc: line 151
Called from C:/DataPoint/com/coldspring/orm/hibernate/AbstractGateway.cfc: line 80
Called from <generated>: line 1
Called from C:/inetpub/wwwroot/projectDir/trunk/com/projectDir/AbstractService.cfc: line 53
Called from C:/inetpub/wwwroot/projectDir/trunk/index.cfm: line 47
Called from C:/inetpub/wwwroot/projectDir/trunk/Application.cfc: line 266
149 : 			local.id = arguments.missingMethodArguments[1];
150 : 
151 : 			if(not len(local.id) OR local.id lte 0)
152 : 			{
153 : 				return getSessionWrapper().new(local.class)

There's nothing soecfically difficult to work out here - I used a getXXX() method and didn't provide an ID argument.

Adding an ID corrected the issue in my code - all was good in the world.

I thought I would add some code to the AbstractGateway class - and specifically check that the missingMethodArguments was defined.
but couldn't work what I should be returning.
I checked the sessionWrapper that it seemed to be using for everything else - to see if there was some sort of "throwError" method - but couldn't find one.

So I thought I would shoot off a message and see if it was a worthwhile suggestion (creating a custom error message function AND using the new function if something happens internally with the AbstractGateway).
And if it was - is there a specific place that makes the most sense to implement such a method?

Lastly,
While checking through the AbstractGateway I also noted on line 161 is the following line;
return getSessionWrapper().new(local.class);;

I assume the extra semi-colon is redundant?


Gavin.
 

Mark Mandel

unread,
May 17, 2012, 10:32:19 AM5/17/12
to coldspri...@googlegroups.com
Better error handling is always good :)

Have a look at the base exception.Exception object for how Coldspring manages exceptions.

Mark



Gavin.
 

--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/coldspring-users/-/9qgZZnDPQ0AJ.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.



--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast

Gavin Baumanis

unread,
Jun 20, 2012, 8:54:27 AM6/20/12
to coldspri...@googlegroups.com
Hi Mark,
Here is a diff that will provide a specific error message for a missing ID argument.
Of course - feel free to butcher it as required to suit you style / design standard.

Index: AbstractGateway.cfc

===================================================================

--- AbstractGateway.cfc (revision 12911)

+++ AbstractGateway.cfc (working copy)

@@ -146,19 +146,27 @@

  }
  else
  {
- local.id = arguments.missingMethodArguments[1];
+ if (isDefined(arguments.missingMethodArguments[1]))
+ {
+ local.id = arguments.missingMethodArguments[1];
 
- if(not len(local.id) OR local.id lte 0)
+ if(not len(local.id) OR local.id lte 0)
+ {
+ return getSessionWrapper().new(local.class);
+ }
+
+ local.return = getSessionWrapper().get(local.class, local.id);
+ }
+ else
  {
- return getSessionWrapper().new(local.class);
+ //throw an exception if the ID argument was not passed in
+ new coldspring.exception.Exception('MIssing ID argument', 'The ID argument was required, but not provided');
  }
-
- local.return = getSessionWrapper().get(local.class, local.id);
  }
 
  if(isNull(local.return))
  {
- return getSessionWrapper().new(local.class);;
+ return getSessionWrapper().new(local.class);
  }
 
  return local.return;
Mark

To post to this group, send email to coldspring-users@googlegroups.com.
To unsubscribe from this group, send email to coldspring-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.

Gavin Baumanis

unread,
Jun 20, 2012, 9:27:45 PM6/20/12
to coldspri...@googlegroups.com
Hi Mark,

Ignore my patch, please.
It is faulty.

I'll redo it - with some greater test coverage and repost when I have it corrected.

Mark Mandel

unread,
Jun 20, 2012, 9:32:00 PM6/20/12
to coldspri...@googlegroups.com
No worries.

Was also going to note that you haven't used the Exception mechanisms provided by ColdSpring.

Mark

To view this discussion on the web visit https://groups.google.com/d/msg/coldspring-users/-/rFcO4xQQiUkJ.

To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.

Mark Mandel

unread,
Jun 20, 2012, 9:36:17 PM6/20/12
to coldspri...@googlegroups.com
As an aside - curious why you didn't just fork CS in GitHub and send a pull request? Would have thought that would have been easier than a patch?

Mark

Gavin Baumanis

unread,
Jun 20, 2012, 10:08:03 PM6/20/12
to coldspri...@googlegroups.com

I don’t know how to use GIT.

Never have – possibly never will…

SVN all the way!

Mark

Mark

 

Mark

--

You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.

Brian Kotek

unread,
Jun 20, 2012, 11:13:45 PM6/20/12
to coldspri...@googlegroups.com
Just an aside: at this point all developers really should get familiar with the bare minimum of using Git. Even if it's not your preference, it is extremely widely used now. And one of the reasons that it's great is that this exact situation (contributing to an open source project) is handled so elegantly.

Brian

Gavin Baumanis

unread,
Jun 20, 2012, 11:49:43 PM6/20/12
to coldspri...@googlegroups.com

Hi Brian,

 

I realise it gets lost in the email…

But since I am the patch manager for Subversion – I was being facetious about Git.

Brian Kotek

unread,
Jun 21, 2012, 1:16:53 AM6/21/12
to coldspri...@googlegroups.com
I didn't know that, so yeah, that's a worthy reason hehe

Mark Mandel

unread,
Jun 21, 2012, 1:49:11 AM6/21/12
to coldspri...@googlegroups.com
Still no decent excuse ;o)

Mark

Dennis Clark

unread,
Jun 21, 2012, 4:37:01 AM6/21/12
to coldspri...@googlegroups.com
It is quite possible to use Git without "buying into it". There's a big gap between knowing enough Git to create and submit patches without driving yourself or the project owner insane, and inhaling the GitHub kool-aid.

With only a little Git knowledge you can create and submit patches that Mark can merge into his GitHub repository, without having to follow workflows such as "git-flow" or "GitHub pull requests" that Git fanbois keep rabbiting on about. I've thrown together a few commands to show you how to do this, which I am calling


*** A GIT HATER'S CRASH COURSE FOR FIXING BUGS IN COLDSPRING ***


Pros:
 - No need to have an account on GitHub or any other Git hosting service
 - It doesn't involve requesting anyone to "pull" you ;)
 - You still show up as the author of the bugfixes in the repository's history

Cons:
 - Still need to install git locally and use a few git commands (tho I've tried to keep it to the bare essentials)
 - Doesn't handle conflicts between your bugfixes and newer changes in upstream (but hey, at least you tried!)


Let's begin!

# Install Git and do one-time setup as described in http://gitimmersion.com/lab_01.html


# Create a local clone of the ColdSpring repository


# Time to start fixing some bugs!
cd coldspring
# Switch to the develop branch (where the all the new ColdSpring hotness lives)
git checkout develop
# Create a bugfix branch and switch immediately to it
git checkout -b fix_foobaz

# Edit some files
edit file1
edit file2
# Ask git on the status of the working tree
git status
# Schedule the changes made to the edited files for the next commit
git add file1 file2
# Commit the changes locally
git commit -m 'Foo did not baa correctly'

# We don't really need the docs, do we?
rm -rf docs
git status
# Oops; we screwed up the working tree! Undo _ALL_ uncommitted changes (scheduled or not) with a hard reset
# USE THIS COMMAND WITH CAUTION! THE EFFECTS CANNOT BE UNDONE!
# Note that a hard reset does not recover files that were not being tracked by Git
git reset --hard

# Edit another file
edit file3
git add file3
git status
# Oops; we needed to edit that file, but we don't want the change in the next commit. Unschedule the change with a reset
git reset HEAD -- file3

# Edit one more file
edit file4
git add file4
# Continue editing the same file
edit file4
git status
# We must add the file again if we want the second set of changes to be committed
git add file4
git status
# Everything looks good now; commit!
git commit -m 'Baz now works with foo'


# Create a special git multi-patch file of all the commits we made in our bugfix branch
git format-patch --stdout develop > fix_foobaz.am.txt
# Email fix_foobaz.am.txt to upstream


# Upstream accepted the patches, yay! Switch back to develop, pull the new history, and start all over again...
git checkout develop
git pull origin develop


*** END OF CRASH COURSE ***

This is all from a combination of memory and some of the online docs. I got the info on creating and applying patches from <http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/>. I'm not a Git expert, so corrections and other feedback is welcome.


-- Dennis
Reply all
Reply to author
Forward
0 new messages