Thursday, September 27, 2007
Composite Entity Pattern
With a Composite Entity, a client can obtain all required information with just one remote method call.
Wednesday, September 26, 2007
Getting row with latest timestamp
http://www.sql-server-performance.com/articles/per/history_status_table_performance_p2.aspx
What if, since they should be inserted in order of time, we just did a MAX(id)?
Tuesday, September 25, 2007
javascript undefined and strict comparators
There is a difference between a variable being undefined and null. Use if(someObject) since it should evaluate both undefined and null to false.
from http://weblogs.asp.net/bleroy/archive/2005/02/15/Three-common-mistakes-in-JavaScript-_2F00_-EcmaScript.aspx
You can't overload a function.
Developers who are used to languages like Java and C# overload methods all the time. Well, in JavaScript, there are no overloads, and if you try to define one, you won't even get an error. The interpreter will just pick the latest-defined version of the function and call it. The earlier versions will just be ignored.
Undeclared variables are global.
Always, always declare your variables using the var keyword. If you don't, your variable is global. So anyone who makes the same mistake as you (or more likely, if you do the same mistake in two different places) will create nice conflicts which give rise to very difficult-to-track bugs. Even loop counters should be properly declared.
There is actually a good way to do some basic sanity checks on your script files (like multiple declarations, forgotten declarations, unassigned variables, etc.): in Firefox, go to the about:config url and look for the javascript.options.strict entry.
from http://joeyjavascript.com/2007/04/25/javascript-difference-between-null-and-undefined/
n JavaScript, undefined means a variable has been declared but has not yet been assigned a value, such as:
var TestVar;
alert(TestVar); //shows undefined
alert(typeof TestVar); //shows undefined
null is an assignment value. It can be assigned to a variable as a representation of no value:
var TestVar = null;
alert(TestVar); //shows null
alert(typeof TestVar); //shows object
From the preceding examples, it is clear that undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
Unassigned variables are initialized by JavaScript with a default value of undefined.
JavaScript never sets a value to null. That must be done programmatically. As such, null can be a useful debugging tool. If a variable is null, it was set in the program, not by JavaScript.
null values are evaluated as follows when used in these contexts:
Boolean: false
Numeric: 0
String: “null”
undefined values are evaluated as follows when used in these contexts:
Boolean: false
Numeric: NaN
String: “undefined”
strange advanced javascript
Json is for defining a class. Not much diff btw a class and a dynamic hash.
http://www.sergiopereira.com/articles/advjs.html
Sunday, September 16, 2007
em.clear()
Saturday, September 8, 2007
Method naming conventions, ? for queries, ! for 'dangerous' methods eg. those that modify the receiver.
Specify defaults to method parameters: def cool_dude(arg1="Miles", arg2="Coltrane", arg3="Roach")
Variable length argument lists: def varargs(arg1, *rest)
Store block passed in in parameter: def initialize(name, &block)
private methods cannot be called with a "receiver"
You can return multiple things and ruby will put them into an array. You can assign these with the multi-assign thingy:
return num, square if square > 1000
num, square = meth_three
You can "explode" arrays when passing them to a method. It maps elements of the array to the parameters.
Ruby imitates keyword arguments with hashes as last parameter.
You can run OS commands by specifying them in backquotes. eg. `date`. It captures stdout.
Assignment returns back the assigned value so you can do things like File.open(name = gets.chomp)
Parallel assignment a, b = b, a
Parallel assignments and expanding arrays,
a = [1, 2, 3, 4]
b, c = a ! b == 1, c == 2
b, *c = a ! b == 1, c == [2, 3, 4]
There is also nested parallel assignment, which is a bit psycho.
words[key] ||= [] -> words[key] = words[key] || []
Case statement - you can have multiple matchers
kind = case year
when 1850..1889 then "Blues"
when 1940..1950 then "Bebop"
else "Jazz"
end
You can use while and until as "statement modifiers"
a *= 2 while a < 100
a -=10 until a < 100
Sunday, September 2, 2007
Transaction Isolation Levels
The levels are things like read commited, repeatable-read and serializable. The EJB spec doesn't define how these are set, so it's specific to the app server. Apparently you can set it if you get access to the JDBC connection, but then I assume you would have to make your whole bean BMP. There is pretty much no info on JBoss and isolation levels, except that it can be set in the datasource configuration. So perhaps you would have to create more than one datasource if you wanted more than one transaction isolation level available. Then I don't know how you would mix and match the use of these datasources with your session beans. Could you specify different entity managers and would these point to different persistence contexts and therefore not be in sync with eachother?
One article mentioned that with some appservers you can specify different isolations levels for different methods, which is ideal. Something like a transaction attribute I imagine.