Friday, April 27, 2007
log4j good logging tool
Reference web page:
http://my.so-net.net.tw/idealist/Java/Log4j.html (chinese)
http://wiki.apache.org/logging-log4j/Log4jXmlFormat
Thursday, April 26, 2007
Quartz Basic structure: (referenece book: Quartz Job Schedule Framework)
Classes:
1. Job - interface class- provide method execute(JobExecutionContext c)
- JobExecutionContext - getJobDetail() to get the JobDetail instance.
- JobDetail contain the job name and JobDataMap instance from getJobDataMap.
- JobDataMap can help pass the data inside the Job.
Sample:
Create JobDetail, JobDataMap and Trigger.JobDetail jobDetail = new JobDetail("ScanDirectory", Scheduler.DEFAULT_GROUP, ScanDirectoryJob.class);
// Configure the directory to scan
jobDetail.getJobDataMap().put("SCAN_DIR", "c:\quartz-book\input");
// Create a trigger that fires every 10 seconds, forever
Trigger trigger = TriggerUtils.makeSecondlyTrigger(10); trigger.setName("scanTrigger");
// Start the trigger firing from now
trigger.setStartTime(new Date());
// Associate the trigger with the job in the scheduler scheduler.scheduleJob(jobDetail, trigger);
For CronTrigger
It could be help to develop a more complex trigger than SimpleTrigger.
| Name | Required | Allowed Values | Special Characters |
|---|---|---|---|
| Seconds | Yes | 059 | , - * / |
| Minutes | Yes | 059 | , - * / |
| Hours | Yes | 23 | , - * / |
| Day of Month | Yes | 131 | , - * ? / L W C |
| Month | Yes | 112 or JAN-DEC | , - * / |
| Day of Week | Yes | 17 or SUN-SAT | , - * ? / L C # |
| Year | No | Blank or 19702099 | , - * / |
| The names of months and days of the week are not case sensitive. FRI is the same as fri. | |||
Understanding the Special Characters
As with UNIX cron, Quartz cron expressions support special characters that can be used to create more complicated execution schedules. However, Quartz supports many more than the standard UNIX cron expression.
The * Character
Using the asterisk (*) in a field indicates that you want to include all legal values for that field. For example, using this character in the month field means to fire the trigger for every month.
Example expression:
0 * 17 * * ?
Meaning: Fire the trigger every minute, every day starting at 5 PM until 5:59 PM. It stops at 5:59 PM because the value 17 is in the hour field, and at 6 PM, the hour becomes 18 and doesn't agree with this trigger until the next day at 5 PM.
Use the * character when you want the trigger to fire for every valid value of the field.
The ? Character
The question mark (?) character can be used only in the dayofmonth and dayofweek fields, but not at the same time. You can think of the ? character as "I don't care what value is in this field." This is different from the asterisk, which indicates every value for the field. The ? character says that no value was specified for this field.
The reasons a value can't be specified for both fields are tough to explain and even tougher to understand. Basically, if a value was specified for each, the meaning would become ambiguous: Consider if an expression had the value 11 in a field for the day of the month and a value of WED in the field for the day of the week. Should that trigger fire only on the 11th of the month if it falls on a Wednesday? Or should it fire on both the 11th and every Wednesday? The ambiguity is removed by not allowing a value in both fields at the same time.
Just remember that if you specify a value in one of the two fields, you must put a ? in the other.
Example expression:
0 10,44 14 ? 3 WED
Meaning: Fire at 2:10 PM and 2:44 PM every Wednesday in the month of March.
The , Character
The comma (,) character is used to specify a list of additional values within a given field. For example, using the value 0,15,30,45 in the second field means to fire the trigger every 15 seconds.
Example expression:
0 0,15,30,45 * * * ?
Meaning: Fire the trigger on every quarter-hour.
The / Character
The slash (/) character is used to schedule increments. We just used the comma to increment every 15 minutes, but we could have also written it like 0/15.
Example expression:
0/15 0/30 * * * ?
Meaning: Fire the trigger every 15 seconds on the hour and half-hour.
You can't increment beyond the fields range. For example, you can't specify 30/20 in the second field and expect the scheduler to fire correctly.
The Character
The hyphen (-) character is used to specify a range. For example, 3-8 in the hour field means "the hours 3, 4, 5, 6, 7, and 8." The fields will not wrap, so values such as 50-10 are not allowed.
Example expression:
0 45 3-8 ? * *
Meaning: Fire the trigger on 45 past the hours 3 AM through 8 AM.
The L Character
The L character represents the last allowed value for the field. It is supported by the dayofmonth and dayofweek fields only. When used in the dayofmonth field, it represents the last day of the month for the value specified in the month field. For example, when the month field has JAN specified, using L in the dayofmonth field would cause the trigger to fire on January 31. If SEP was specified as the month, then L would mean to fire on September 30. In order words, it means to fire the trigger on the last day of whatever month is specified.
The expression 0 0 8 L * ? means to fire the trigger at 8:00 AM the last day of every month. The * character in the month field gives us the "every month" part.
When the L character is used in the dayofweek field, it indicates the last day of the week, which is Saturday (or, numerically, 7). So if you needed to fire the trigger on the last Saturday of every month at 11:59 PM, you could use the expression 0 59 23 ? * L.
When used in the dayofweek field, you can use a numerical value in conjunction with the L character to represent the last X day of the month. For example, the expression 0 0 12 ? * 2L says to fire the trigger on the last Monday of every month.
The W Character
The W character stands for weekday (MonFri) and can be used only in the dayofmonth field. It is used to specify the weekday that is nearest to the given day. Most business processes are based on the work week, so the W character can be very important. For example, a value of 15W in the dayofmonth field means "the nearest weekday to the 15th of the month." If the 15th was on a Saturday, the trigger would fire on Friday the 14th because it's closer to the 15th than Monday, which would be the 17th in this example. The W character can be specified only when the day of the month is a single day, not a range or list of days.
The # Character
The # character can be used only in the dayofweek field. It's used to specify the nth XXX day of the month. For example, if you specified the value 6#3 in the dayofweek field, it would mean the third Friday of the month (6 = Friday and #3 means the third one in the month). Another example of 2#1 means the first Monday of the month (2 = Monday and #1 means the first one of the month). Note that if you specify #5 and there is no 5 of the given day of the week in the month, no firing will occur that month.
Monday, April 23, 2007
Howtoforge
http://www.howtoforge.com/
A very good article for install Internet Explorer on Ubuntau
http://www.howtoforge.com/ubuntu_internet_explorer
Thursday, April 19, 2007
JBoss rules
DRL file is represent one package.
Under DRL file it contains many rule with a identify name with package.
JBoss IDE for JBoss rules (necessary install in Eclipse 3.2.x) . It just add some views and DRL and DSL Editor. (so i think it just good for help you to check the syntax).
the programming steps:
1. PackageBuilder -> Package
2. RunBaseFactory -> RunBase -> add -> Package
3. RunBase -> new -> WorkingMemory
4. WorkingMemory -> assertObject for fireAllRules().
It will use all assertObjects in WorkingMemory to run for all rules except you have add filter for call method of fireAllRules();
DRL sytax:
rule :
rule "name"
while "condition"
then "process"
end
e.g.
rule "Your First Rule"
salience 10
when
$m : Man(age <> 25)
then
System.out.println("first : " + $m.getName());
mans.add($m);
end
rule "Your Second Rule"
salience 5
when
$m : Man(age > 25, $name : name)
then
System.out.println("second : " + $name);
end
note: if miss salience .. then all rule by default salience = 0.
If fireAllRules() "Your Second Rule" execute first and then "Your First Rule"
query:
query "name"
"condition"
end
e.g. DRL
query "test"
$man Man(age > 25);
end
e.g. Java
QueryResults qrs = WorkingMemory.getQueryResults("test");
qrs.size();
It could return all valid the query objects.
Personal comment:
From example most rule only check about the assertObject and update the state of object ... but never return anything ..... such as only true/false.
If you have other thing out of set state, you need to define global object to return.
Wednesday, April 18, 2007
oracle reverse enginee and select sql query with case
http://www.eveandersson.com/writing/data-model-reverse-engineering#columns
use Select sql query with case:
syntax
case when
when
...
else
end
sample:
select sal, case when sal < style="font-family: monospace;">'category 1'else 'category 4'
end
from emp;
Thursday, April 12, 2007
Open source free Java docking framework and discovery new DB Engine
http://mydoggy.sourceforge.net/
I tried the tutorial. It is a very simple docking framework. It cannot place more than panel on the same dock.
H2 Database Engine. it seems better than hypersonic SQL database
http://www.h2database.com/html/frame.html
Wednesday, April 11, 2007
oracle 10g FlashBack function
http://dbaoracle.itpub.net/post/901/271132
Issue one of the following statements:
ALTER SESSION SET recyclebin = ON/OFF;
SELECT object_name, original_name FROM dba_recyclebinThe recycle bin table name is "dba_recyclebin"
How to purge the recycle bin:
PURGE TABLE BIN$jsleilx392mk2=293$0;
or
PURGE RECYCLEBIN;
Maybe you also can append PURGE after drop table statement.
DROP TABLE ABC PURGE;
then the table will direct delete not add to recycle bin.
Tuesday, November 14, 2006
Spring JDBC connection
- configure the xml
- DriverManagerDataSource class help you to configuration and get the connection from database
- DataSourceTransactionManager class that help to create the transaction when you want to insert or update the database.
- Create your own Dao Class, it just like a class represent a table but i do not help you to maintain the Has-a relationship.
In my sample project (you can import to Eclipse)
App.java - contain main method to execute (but i am connecting SQL Server... you can teach the concert)
OrderDao - interface class to represent what method contain in OrderDaoImpl
OrderDaoImpl - contain code to process
Order - Order represent the table Orders in Database
OrderRowMap - It help you to mapping value from resultset to create the object instance
It contain the method call "public Object mapRow(ResultSet rs, int index)" from the name you know it for mapping.
Tuesday, October 24, 2006
Use single value to store multiple settings
static final int problem1 = 0x1;
static final int problem2 = 0x10;
static final int problem3 = 0x100;
- when user selected problem1 and problem2
we can store the value like that
int userSelVal;
userSelVal = userSelVal | problem1;
userSelVal = userSelVal | problem2;
-then you will ask how to know the user is selected problem1 and problem2
if((userSelVal & problem1) == problem1){
//represent user select problem1
System.out.println("User is selected problem1");
}
if((userSelVal & problem2) == problem2){
//represent user select problem2
System.out.println("User is selected problem2");
}
if((userSelVal & problem3) == problem3){
//represent user select problem3
System.out.println("User is selected problem3");
}
- via to compare the binary position value, each position represent one setting then we can store int binary size setting in one int.
Sunday, October 22, 2006
Create a signed jar
description:
need to use keytool and jarsigner
C:\> keytool -genkey -validity
C:\> keytool -selfcert -validity
C:\> jarsigner test.jar mykey
http://www.ccw.com.cn/htm/center/prog/02_7_8_4.asp
http://www.owasp.org/index.php/Signing_jar_files_with_jarsigner#Create_a_new_DSA_Key_Pair_for_Bob
Not all the detail, it will be edit later but you can use the upper command to finish it.
signed jar for web start application.
Ant jar file ( Do you remember the script? )
*project name="XDoclet Generator" default="jar"*
*target name="jar" description="Create binary distribution after xxx"*
*!-- Create application JAR file --*
*mkdir dir="MyJarDir"*
*jar jarfile="MyJarDir/MyJarFile.jar" basedir="classes"*
*/jar*
*/mkdir*
Simple easy under stand but let me write down.... thx. I easy forget
Saturday, October 21, 2006
readExif php script
- description
It read the JPEG file's EXIF information, and use the DateTime value to separate the image file to different folder.
-execution
1. Set php installed folder in envirnment variable.
2. then you can directly type "php" to execute php script on local computer.
3. enable the in php.ini (it may locate on Windows / WINNT folder):
extension=php_mbstring.dll
extension=php_exif.dll
4. put readExif.php into the image folder.
5. type "php readExif.php"
6. It will process.
Thursday, October 19, 2006
convert number to English words
I find one java sample:
reference: site
my own copy and modify code: my modify source file
It is quite simple to convert, just use a little bit time to understand
I think it can help to ppl no need to convert number when write cheque.
Wednesday, October 18, 2006
one-to-one bidirectional (in hibernate example) xDoclet
1. assume each user only have one car
user class reference car
car class reference user
2. identify From & To direction
assume that user (from) - car (to)
then user primary key store to car table (foreign key)
3. xDoclet tag
== code ==
car class:
/**
* @hibernate.many-to-one
* class = "local.sample.oo.User"
* column = "userId"
*/
public User getUser()
{
return _user;
}
== code ==
car is to --> so that is many-to-one relationship (from logic it is one-to-one but if both side one to one cannot be identify to & from)
column -> represent the user primary key store column on car table
== code ==
user class:
/**
* @hibernate.one-to-one
* cascade = "save-update"
*/
public Car getCar()
{
return _car;
}
== code ==
user is from -> so that is one-to-one relationship
cascade -> when update user, it also request car to update (if car is modified)
Monday, October 16, 2006
Simple Sample to use Spring, xDoclet and Hibernate
In my experience, I suggest to use Eclipse 3.1.x & JBoss IDE plugins to develop the Hibernate and Spring application.
I will provide the simple project. It demo how to create one-to-one, one-to-many, many-to-many.
You need to pay attention on :
- persistent classes xDoclect's Hibernate tag.
- Spring configuration xml file ( hibernate.xml) - datasource, hbm config, bean of spring
- xDoclet configuration. Project > right click > property > XDoclect configuration
** Sample download**
Useful resource to futher study Hibernate.
- HibernateGossip
Any problem, please feel free to contact me:
mingkit@gmail.com
Mylar is eclipse plugin for project management
http://www-128.ibm.com/developerworks/java/library/j-mylar1/?ca=dgr-jw01Mylar-1
http://www.hibernate.org/43.html
MySQL add new user account
mysql -u root
1. create user account.
- CREATE USER mingkit IDENTIFIED BY 'password';
2. grant right for the accout.
- for localhost
GRANT ALL PRIVILEGES ON *.* TO 'mingkit'localhost'IDENTIFIED BY 'password' WITH GRANT OPTION;
- for worldwide or certain ip
GRANT ALL PRIVILEGES ON *.* TO 'mingkit'%'IDENTIFIED BY 'password' WITH GRANT OPTION;