from a database row to an object

“a datatype with methods”. In a longer sentence, “a datatype with specific operations defined for it”

For example, a “student” datatype has fields representing the object’s state and and operations appropriate for a student such as enroll(courseID), payFees()….

This is a good example of the simplest type of class — a data class.

Another short answer — “a C struct with methods”

Advertisements

deterministic — DB stored program

sproc? usually non-deterministic
table functions in db2? usually non-deterministic
simple scalar functions? usually deterministic

For every input data, if every time you pass the the input into this blackbox you always get consistent output, then …. deterministic

If you find some input data that could lead to inconsistent output, then …. non-deterministic

tablespace in db2

When you hear people mention db2 “tablespace”, remember these 5 key points (knowledge pearls)

– each tablespace has its page size. page size affects many things including performance

– tablespaces are often named after the departments like Eq, FICC, Legal …

– a tablespace can hold many tables. I think a table can span tablespaces.

– the term “tablespace” means the same to db2 and oracle,
db2: tablespace
oracle: tablespace
sybase: segment

tool vs server in DB2

Certain features (like autocommit) are in “tools” and not the “server”. Make this fundamental distinction.

For DB2, Tools = Command-line-processor, Command-editor, Developer-work-bench, Aqua-Studio.

I call these “db2 clients”

Q: what db2 client do you use in a shell script?
A: CLP

java constructor^method: more differences than similarities

— diff:
* static constructor? illegal. i thought they are all static by default
* abstract constructor? illegal.
* final constructor? illegal. no overriding anyway
* return type? illegal
* throws? constructors can’t declare a “throws”, but both constructors and methods can throw.
* inheritance@@ NO, constructors aren’t inherited. A subclass can invoke super() in a very strict way. In other classes, if you have a pointer to “my” subclass, u can’t call “me”, the superclass constructor
* overriding? NO, because not inherited. subclass can access super(). No way to override super()

–similar:
* protected constructor? yes
* private constructor? yes.
* overloading? yes

what realworld entity a class represents

The Challenge: given a complex class, how do i quickly find out what kind of realworld thingy, if any, it models? I hope this post offers practical, quick solutions.

Conversely, a good OO-design can help show what kind of entity the class represents. Beside naming and comments, a designer can consider the list below.

Tip: Occassionally, you notice a field of a collection type. The entities inside the collection is the realworld thingy represented by this class. Common design pattern. Perhaps a simple pattern, but NOT obvious!

Tip: See if it has relatively few instance variables. In a good design, instance variables collectively represent object *state*.

Tip: See if the constructors are simple and meaningful. Some constructors receive key argument(s) that reveal the role of this class among the /domain-objects/.

Tip: See if the class advertises an obvious “service” method, perhaps supported by helper-methods

Tip: always see the base types.

Tip: getters and setters are an obvious clue.

IDE features that i badly need

Resolve IDE issues or go without IDE? Justify your IDE-maintenance tcost!

(No time for details)

— 5pr
1) [n] step-through, break on access to a var
2) [n] refactor tools
“call hier” ie list every caller-method calling this method

# eor
highlight a variable or class -> right click -> references -> project, to see “where and how is this object used during the object interactions?”
compile prj — like ant
click inside an exception stack to open selected source file
[n] type hierarchy
unhide all inherited members
[n] method signature as tooltip, revealing types of arguments
[n=no alt]

synthesized no-arg ctor — c++ ^ java

(Backgrounder — in both c++ and java, online tests and interviewers are crazy about nitty gritty of default ctor)

C++ standard — default constructor is a constructor that can be called with no arguments. –> Unlike java, this includes a constructor whose parameters all have default arguments [1]. By this definition, “default ctor” means something different from the synthesized no-arg (in multiple ways, but let’s not digress).

It’s best to avoid the ambiguous “default dtor” terminology in favor of “synthesized no-arg ctor”

In both java and c++, IF default ctor is needed in you program, you can create compilation errors by accidentally suppressing no-arg synthesization. As soon as you DECLARE/define any ctor in your class,
that synthesization is immediately suppressed.

* [1] Item 45 [[eff c++]] describes the default ctor as an no-arg.
* java also refers to it as the no-arg.

java static^non-static method: 3 fundamental diffs #need polishing

See other blog posts why the author is biased towards static methods.

The more you study how non-static CALLS (we didn’t say “method”) work, the more you appreciate the huge differences between static vs non-static methods.

Compared to instance methods, static methods are much, much simpler to use by callers. (See reasons below.) Perhaps the only major complication is access modifier. Static methods are like Thread.sleep() and Math.abs… They don’t have a receiver-object or host-object. Often[2] a caller-METHOD (we didn’t say “object”) calls a static method to retrieve [1] something in read-only mode. The “customer-object” [3] of such a call is … well, can’t be the host-object. Obvious, but sometimes u need to bear it in mind.

Handle-perspective + messaging-perspective — when a client needs to call a target method M(), usually you need to plan how the client first gets a handle on the msg-receiver object , before “sending the message”. But static methods are completely simple.

Service/resource-perspective — an instance method publishes a service to caller methods. This service is *provided* by the host-object to the caller. The provider object has resources represented by its state. Caller-method must get a handle on the host-0bject first. Example — resource/”state” is a pool of database connections and the “service” is access to database. No such service without that resource.

Operation-perspective — an instance method exposes an operation. The operation is *performed* by this very receiver-object on behalf of the caller-method.

[1] or compute, or extract
[2] exception to the rule: Thread.sleep() actually affects the caller-thread by putting it to sleep!
[3] see earlier blog post

see major.minor versions of a classfile

http://blogs.sun.com/sundararajan/entry/thou_shall_know_the_class

http://forum.java.sun.com/thread.jspa?threadID=5178593&messageID=9692487 says : Just open the class file with something that can display hexidecimal data and look at bytes 5 – 8 in the file. They contain the minor:major versions in hex.

I used textpad and saw 2E ie 48 for major version. javap reported 0 and 0.

conversion ctor ^ conversion method – pervasive

I feel the various type-converters are essential for code TRACING. Compiler implicitly uses conversion ctor (cvctor) and operator-overload-converter (OOC) whenever it needs to.

Note converter methods without “operator something” are explicitly invoked — much easier to spot. They often look like

   XXX asXXX(void)

As pointed out in other posts, cvctor and OOC can be invoked implicitly by static_cast into a nonref type.

Here are some converters —

Eg: scoped_lock myLock(myMutex);
Eg: string ( const char * s );
Eg: string.operator vector(), and string cvctor from vector. P197-198 [[STL tut]]
Eg: the conversions between auto_ptr, shared_ptr and raw ptr
Eg: conversion between vector iterators
Eg: back_inserter(myVector) returns a back_insert_iterator object

USP@ejb @@

— USP ] %% xp
#1 CMR/CMP to automatically load/store related database tablesssss just like hibernate/JDO. THE real value of ejb in the eyes of Union Bank of Switzerland.

[[ ejb ]] book obviously treat CMP as the heart of ejb technology

#2 biz-tier cluster, behind the web tier cluster
THE real reason for oceanlake

— USP ] theory
#1 XA. according to both [[ ejb ]] and Rod Johnson — XA ie (declarative?) dist tx. Other solutions support tx or remoting(J2SE RMI) but not both.

#2 distributed objects?
corba
dcom
dotnet remoting?

#x MDB is the finest breed of EJB (Rod Johnson?) [[ ejb ]] author also singled out MDB as a top 5 j4EJB. Unique? not sure

#x ejb security? declarative? ejb fits like a glove if your biz logic are well-represented by security roles
[[ ejb ]] frequently mentions “transactional and security features” in one breath

====Well, almost Unique. U can call them “valuable features@ejb”

perl-ebcdic resources online

http://perldoc.perl.org/perlebcdic.html — Considerations for running Perl on EBCDIC platforms, not about “converting between ebcdic and ascii”

http://search.cpan.org/~cxl/Convert-EBCDIC-0.06/lib/Convert/EBCDIC.pm — Convert::EBCDIC, ascii2ebcdic, ebcdic2ascii – Perl module for string conversion between EBCDIC and ASCII

http://www.foo.be/docs/tpj/issues/vol2_4/tpj0204-0005.html — 1997 article on perl and EBCDIC. Good historical background coverage of ascii^ebcdic

vi corrupting your file

I once had a strange feed file. If I use vi to delete any line, the feed can no longer be processed by the feeder system. I suspect once vi write the file back to disk, it’s corrupted.

Solution: In my case split -1 and head -1 can do a good enough job of deleting lines. Both keep the feed file in good condition.

Q: is vi designed to edit a binary file?

Q: can perl keep all unaffected lines unaffected?

Acid test: less can show the unprintable characters and shows that after deleting one line, every other line has something missing.

c++ : first thing in angle bracket

(Let’s exclude the obvious scenario of “template “. Instead, suppose we encounter an *instantiation* of an existing template.)

* First thing could be a simple, real type like int or Account
* First thing could be a dummy type like T or InputIterator. Note the type should be declared in an enclosing “template <class T…", so now we are inside a template definition, using the dummy type to instantiate *another* template. See [[essential c++]]
* first thing could be a typedef

Next, you realize you could also encounter a ptr/ref to the above. (This is why java generics are cleaner.)
* first thing could be a ptr to a typedef
* first thing could be a ptr to a dummy type?

Finally, a typedef can be a complex type involving dummy types and ptr/ref.

These make c++ template syntax/usage significantly messier and more complex than java generics.

anyObject.wait(maxDuration)^ static Thread.sleep(howLong)

It’s instructive to compare these 2. See P71 [[Java Threads]].

During sleep(), the sleeping thread doesn’t release lock. In fact, sleep() is a static method with no object mentioned.

I think *inside*[1] the myObj.wait() JVM takes the lock off the current thread. Immediately before/after wait(), current thread must possess the lock on myObj. thread blocks until this happens.

[1]right after we enter myObj.wait() and right before we exit myObj.wait().

stepping through class/object loading

Based on P28, 30 [[ Java Precisely ]], and P110 [[practical java]]. There are dozens of important details [1]. Here we cover a few interesting observations. Assuming class C extends B, extending A.

Step: static initializer blocks and field initializers run, in order of apperance. Once static fields are initialized, they are available for use by all including static methods.

Step: static methods loaded and available to be called from the call-stack

— By this /milestone/, the class is “loaded” with all static stuff ready —

Note: Before any C-specific initializations, B() always *completes its steps* and returns a complete B object, to be wrapped in the onion.

Let’s skip ahead and look at…
Step K1: A’s instance field initializers and instance initializer blocks run, in order of apperance. These always appear outside the constructor.

Step K2: A() statements.

Note: By this time, no B state-initialization[2]. However, A() statements could call a B method — see [[baseclass dependent on subclass]]

Repeat K12 for B, and then C

[1] see Example 60 [[ Java Precisely ]].
[2] i think this is obvious. loading B’s method definition doesn’t count.
[3] Obviously, Object() and A() must complete beforehand.

interrupt() — 2 real threads, 1 Thread object

myThread.interrupt() methods involves 2 real threads. As another post mentions, each real thread has a rather poor handle on it in the form of a Thread object. In this case, one such object is involved — the target thread object. So the real and fake thread thingies involved are

A) the real sender thread (thread23) — the call stack containing the method (sendInterruptMsg()) that sends the interrupt() message
C) the target thread object — myThread object.
B) the real target thread — the thread accessible by myThread object, potentially executing some blocking method.

void sendInterruptMsg(){ // runs in thread23
myThread.interrupt()
}

Note, in this case, the thread object is not a poor handle on the real thread, but a solid handle on the real thread. There are very few such useful instance methods in a thread object though, that’s why i say thread objects are a poor handle on the real threads.

Next thing to learn is the exception thrown as a result of the interrupt.

Q: Which real thread (stack) will generate and receive the exception?
A: (B), not C, since the thread object is NOT a call stack and can’t deal with exceptions.

Q: which method will throw it?
A: the interrupted method. Note all other exceptions are triggered by actions by the call stack itself — synchronous. But InterruptedException is triggered by a lightning strike — asynchronous.

Q: what methods can be interrupted this way?
A: blocking methods. Any method that can be interrupted must declare “throws InterruptedException”. Actually there are very few such methods, so they are important — static Thread.sleep, myObject.wait()…

baseclass dependent on subclass

A parent calls a method overridden by a subclass .. template method. A lot of plugin, callback, hollywood principal uses something like template method.

Say you have just one class. Within it, you call your own methods. Those private and final methods are fine but all other methods are virtual (ie overridable and “subject to overriding”). Problematic if this happens by accident not by design. Now I think baseclass depending on subclass is a very likely mistake.


The MIT course note (in an earlier blog) points out the danger when a super class method B.m1() calls m2(), which is defined in B, overriden in subclass C.

In this case, “dependent” means “when the subclass C.m2() changes, B may need change, since B’s behaviour is affected.”

Q: whose m2() runs?
A: the innermost onion’s m2(), in this case, C.m2()

Q: how do u specify B’s m2() to be used in m1()? B.m2 ?
A: B.m2 will probably fail. B.m2() requires m2 be static.
A: I think u need to provide a private final m2a(), and make m2() call m2a().

If your class B need to call your own method m2(), you need to decide whether to call the m2 defined in this class or a subclass (by dynamic binding) or a parent class. Not sure if it’s possible to implement your decision.

For a full example, see Example 60 [[ java precisely ]]

composite pattern (complicated!) — keywords

tree —

apache tiles — a good eg of the tree concept

subtree — a subtree and a leaf are treated the same, as 2 “components” — a lifeless abstract jargon.

operations — an operation can be an instance method (polymorphism) of the component, or can be a method accepting an arg of the component’s type.

Now the most important keyword is …

transparency — clients can treat subtree or leaf uniformly. Simply put, they share a supertype (interface or superclass). Transparency is big in OO layer design. Transparency means separation of concern.

Once you wrap your mind around it, you may finally sigh a sigh of relief and realize Composite is a simple and practical device (like factory, template method, State)

See [[head first design patterns]] for a simple eg.

financial jargon: trade-date ^ settlement-date

— based on http://www.investopedia.com/ask/answers/06/settlementtradedate.asp
When it comes to buying *shares*, there are two key dates involved in the transaction. The first date is the trade date, which is simply the date that the order is executed in the market. The second date is the settlement date, at which time the transfer of shares is made between the two parties. It is the settlement date, however, that marks an official transfer of ownership from the seller to the buyer. While there may be differing rules for the various jurisdictions around the world, the general view is that ownership is transferred when the funds are given in exchange for the security, which happens on the settlement date.

— based on http://www.investopedia.com/terms/t/tradedate.asp

Settlement-date?
* the date by which a buyer must pay for the securities delivered by the seller.
* Usually between one (T+1) and five (T+5) days after the trade date, depending on the transaction type.
* The settlement date for stocks and bonds is usually three (T+3) business days after the trade was executed. For government securities and options, the settlement date is usually the next (T+1) business day.

dependency, rigid, fragile — OO design concepts

— based on http://www.objectmentor.com/resources/articles/oodmetrc.pdf

rigidity (in-flexible, un-adaptable) is due to the fact that a single change to heavily interdependent software begins a cascade of changes in dependent modules. When the extent of that cascade of change cannot be predicted by the designers or maintainers the impact of the change cannot be estimated. This makes the cost of the change impossible to estimate. Managers, faced with such unpredictability, become reluctant to authorize changes.

Fragility (non-robust) is the tendency of a program to break in many places when a single change is made. Often the new problems are in areas that have no conceptual relationship with the area that was changed. Simple changes to one part of the application lead to failures in other parts that appear to be completely unrelated.

———————
I think this “change-impact” analysis would help answer the question “how to reduce subclass/superclass dependency”

rule compiler — learning notes

a rule-compiler compiles rule-source-code into executable-rules. You deploy excutable-rules just as any other java class, to JVM.

rule-compiler contains a rule-parser.

executable-rule files have an encoding format to hold the condition/action.

rule-compilation is an initialization overhead to minimize, perhaps by caching.

Q: How does this compilation affect the edit-cycle?

index Lesson#5: understand non-clustered before clustered index

As explained in the post on 3+1 data pages, each pointer on the index leaf page points to a table row (not table-page). That’s non-clustered index.

(Get a firm grip on regular index structure before you read further, or risk permanent head damage – PhD.)

A clustered index requires a twist. As in non-clustered, a pointer in the branch node points to a PAGE. Unlike non-clustered, this PAGE is a table page.

Similar to an index leaf page, our clustered table page stores records sorted. In contrast, A table page in a heap table (without clustered index) stores records in insertion order, presumably.

Each table page has a lower number of data rows — lower than the number of index objects on a index leaf page. Think about why …

.. because a table row is fatter than an index object.

index Lesson#3: B+ tree index — key-pointer pairs

Nodes: root page, leaf pages and branch(or intermediate) pages. It’s a -> t r e e < -. Physically, Each node is an index-PAGE on disk. There's another post on these PAGES.

Logically, a node contains key-pointer pairs. I call these “objects”. You can represent them better in xml. A leaf page probably contains thousands of pairs, which read like
name rowId
————-
Tom -> 12989
May -> 2390
May -> 907
May -> 2090 // non-unique index
This is, of course, an index on firstName.

Now you see that In a leaf node, an object consists of
1) a key ie a value in the index column. (consider single-column index for simplicity.)
2) a pointer to exactly 1 table ROW. pointer is a physical address, known as row-id in sybase, ROWID in oracle, RID in DB2

In a sybase non-clustered index, each object contains a ptr to 1 row, not 1 page.

In non-leaf nodes, an object consist of
1) a key
2) a pointer to a child PAGE (Consider a unique index for simplicity)

http://www.itworld2.com/frmdsBplus.aspx
http://db.ucsd.edu/CSE232W99/Indexing/sld031.htm
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20020_1251/html/databases/X59082.htm

index Lesson#6: clustered index combines leaf pages and table pages

clustered index — physical ordering. Important to know what physical ordering means and what it doesn’t mean. First, understand the index tree structure. Ignore B+tree jargon. Just get the tree idea. Next, really understand that

    The (usually thousands) entries on a single index page are sorted [1]. Pages’ disk addresses aren’t sorted by the key [2].

Page addresses are neither contiguous nor sorted. Imagine you insert a Magic row belonging to the exact midpoint, you may get page split, and new row gets a new disk page with a random disk address.

For any tree structure, node physical address is neither contiguous nor sorted.

The enormous power of indexing (CI or NCI) derives from the tree and feature [1], despite feature [2]. If I take any index (CI or NCI) and read table using it, data do come out sorted, thanks to the tree.

Unlike non-clustered, Clustered Index leaf pages contain table data — explained better in another post. That’s the so-called __physical_ordering__.

A clustered index combines { directed tree + sorted list }

See also http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20020_1251/html/databases/X59082.htm

index Lesson#1: 3+1 page types for an index

Before studying key-ptr pairs, it’s good to know the 3+1 types of disk pages relevant to an index.
* root page
* branch page
* index leaf page
—————– above are index pages, below isn’t [2] —
* table page — not in the index.

Above is actually a 4-level hierarchy, typical of a non-clustered index. Each pointer (among hundreds) on an index-leaf page points to a table ROW (not table-page). Therefore you can say the data rows are the real leaves of the tree.

Remember, an index tree is a directed graph, starting at the root node, ending on the table ROWs.

In any clustered or non-clustered index, there’s always
= 1 root page, no more no less
= 0 or more branch pages
= 0 or more leaf pages [1]
= 1 or more table pages

[2] Clustered index combine leaf pages and table pages. See other posts.
[1] leaf node is usually present

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20020_1251/html/databases/X59082.htm

picture button – HASA^ISA

Q: In real world, given a family of button objects/interfaces, perhaps in an inheritance hierarchy, and a family of picture objects/interfaces, how do you provide a button with a picture on it. Use ISA and then use HASA

Design 1: MyButton extends Button, and has-a pointer to an abstract picture type.

Design 2 — ISA: MyButton extends Button implements Picture => implements some of the Picture.java methods.
The existing environment may favor this design if Picture.java interface is the only thing there is, and everyone implements it and no one extends it.

Design 3: dependency injection. a container containing 2 pointers to a button and a picture. Most flexible. An end-user can choose the picture/button at run time and our class could setPic() and setButton() at run-time.

How about visitor pattern linking the 2 families?