Friday, August 10, 2007

MySQL Admin

- MySQL
By default, the user cannot connect to mysql db remotely. To enable remote access to a mysql db, suppose the user connect from host IP 10.4.115.211


c:>mysql> mysql --user=root --password=mypassword
mysql> grant select,insert,update, delete on db_name.* to user_name@10.4.115.211 IDENTIFIED BY "user_password";

mysql>show schemas;
mysql>show tables;
mysql>show columns from tbl;

mysql>select * from tbl into outfile 'C:/myexport.txt';

mysql>select * from tbl\G; // the option \G format the output

Wednesday, August 8, 2007

WebWork value stack & Interceptor

The value stack is central to the dynamic context-driven nature of webwork. A stack of objects against which expressions can be evaluated to find property values dynamically, by searching for the first object (from the top of the stack down) that has a property of that name. WebWork builds up the value stack during execution by pushing action onto stack (so action property is available to expressions in view pages). Note that not property itself but the contained object in the stack.

It provides a convenient way to expose common values such as security permission to the front-end. Creating a custom interceptor SecurityGateInterceptor, which push a secInfo object into the value stack, then all the properties available through getxxx() in SecInfo object will be exposed to all the view pages.

Relate methods are: context.getValueStack.push(obj); context.getValueStack().findValue("propertyName");

Interceptors are conceptually the same as servlet filters and JDK's Proxy class. They provides a way to supply pre-processing and post-processing around the action. With it, we can do dependency injection using a combination of set injection and interface injection. With the assistance of interfaces such as PrincipalAware, SessionAware, etc.

Monday, July 30, 2007

Javascript validation using keyCode check

The user is not able to enter certain characters using this approach.


function isDigit(e) {
if (!e) var e = window.event;

var code;
if(e.keyCode) {
code = e.keyCode;
} else if(e.which) {
code = e.which;
}
// 8-backspace, 9-tab, 13-enter, 46-delete
if (code == 8 || code == 9 || code == 13 || code == 46) {
return true;
}
var character = String.fromCharCode (code);
return '0' <= character && character <= '9';
}


<input type="text" name="versionMajor" onkeypress="return isDigit(event);" ../>

onkeydown: Returns a unique integer keyCode representing the the physical key that is pressed. e.g., "1" key on top of keyboard produce "49" whereas in numeric keypad produces "97" since they are different keys. For details.
onkeypress: Returns an integer keyCode representing the Unicode value of the character associated with the key. "1" key produces "49"; Also, for those shift, alt, ctrl combination keys, the combined result is produced such as SHIFT+3 = '#'

The onkeypress (or onkeydown) event hander to respond to a keystroke and to capture the keyCode. If the function returns true and the keystroke produces the character in the textbox. Otherwise, the function returns false and the character is not produced.

The function String.fromCharCode(unicode) is used to convert unicode to ASCII character.

BTW, the comparison of onmousedown and onclick:
onmousedown will trigger when either the left or right (or middle) is pressed. Similarly, onMouseUp will trigger when any button is released. onmousedown will trigger even when the mouse is clicked on the object then moved off of it, while onMouseUp will trigger if you click and hold the button elsewhere, then release it above the object.

onclick will only trigger when the left mouse button is pressed and released on the same object. In case you care about order, if the same object has all 3 events set, it's onmousedown, onMouseUp, then onclick. Each even should only trigger once though.

Wednesday, July 11, 2007

JMS

- A distributed system logically divide into two pieces: actual business/functional code and infrastructure/pluming code (middleware). Definition of middleware: "The wide range of software layered between applications and an operating system that provide specialized services and interoperability between distributed applications" There are Remote Procedure Call (RPC) based middelware and Message-oriented Middleware (MOM).

- JMS is a specification that defines a set of interfaces and associated semantics, which allow applications written in Java to access the services of any JMS compliant Message MOM product.

- JMS supports two messaging styles: point-to-point and publish-and-subscribe. Point-to-point system typically either a one-to-one to many-(senders)-to-one (receivers); publish/subscribe is a many-to-many system. (Queue vs. Topic)

- Administrable objects - destination and connection factory, not standardized by JMS. JMS defines "marker" interface, but JMS providers create and customize the objects, used by client to gain access to messaging product.

- ConnectionFactory => Connection => Session (QueueSession, TopicSession) => MessageConsumer (QueueReceiver, TopicSubscriber), MessageProducer (QueueSender, TopicPublisher)