понедельник, 27 июля 2015 г.

четверг, 23 июля 2015 г.

Singleton pattern in java

Currently I'm interested in software patterns. I'm reading the classic book: "Design patterns. Elements of reusable object-oriented software".

One of the patterns described is singleton. This is a popular pattern in java. So, how could you develop it java?

class Singleton{
private static Singleton singleton;
private Singleton{}
public static synchronized Singleton getInstance() {
if (instance == null) instance = new Singleton();
 return instance; 
 }
}

But, how about this?

public enum Singleton{
INSTANCE;
public void yourBusinessMethod(){}
}

A single-element enum type is the best way to implement a singleton. This is stated in "Effective Java".

What are the pros of this solution?
  1. no serialization problems
  2. guarantee against multiple instantiation
  3. easy to read (less) code
If you are afraid of using enum one can implement the interface for the enum. This means you can use the enum and object in method which expects the interface.

пятница, 19 июня 2015 г.

Productivity works

Do you like to work on multiple tasks simultaneously? If you are a computer, than you can. But if you are a human, that is hardly possible without sacrificing the quality of your job.

Can you do more working on multiple tasks simultaneously?
How much time do you spend on context switching between tasks?

Do you like when phone call, colleague or IM interrupts you during you work activity?

As for me I like to work on jobs in serial one by one. This means I can dedicate all my attention to the job. If you do multiple things at a time, than you can't complete them all.
Whenever possible, avoid interruptions and avoid working on more than one task at the same time. More on this one can read in the post by Kathy Sierra Your brain on multitasking.

четверг, 18 июня 2015 г.

WebSphere Portal 7 webdav theme resources

First, to upload theme static resources to portal use webdav url:
http://<host>:10039/wps/mycontenthandler/dav/themelist.

Second, to make modifications in uploaded theme static resources use the following url:
http://<host>:10039/wps/mycontenthandler/dav/fs-type1.

Maybe, this will save up some time.

понедельник, 1 июня 2015 г.

DB2 export data tables from remote database

If you have IBM DB2 client and you have to move data from remote source database to local target database then you can use db2 move utility.

First, catalog the node:
1) db2 catalog tcpip node <node_name> remote <server_name> server <port_number>
2) db2 terminate

Second, catalog the database:
3) db2 catalog db <remote_db_name> as <local_alias_db_name> at node <node_name>
4) db2 terminate

Export data:
db2move <db_name> export -sn <schema_name> -aw -u <login> -p <password>

You can move schemas or given tables. See help for db2move.

Before importing tables data in existent tables you should turn off identity constraint else import process fail:
db2 alter table <table_name> alter column <column_name_with_identity> drop identity

Import data:
db2move <db_name> import -u <login> -p <password>

After import restore identity constraint:
db2 ALTER TABLE <table_name> ALTER COLUMN <column_name_with_identity> SET GENERATED AS IDENTITY ( START WITH <count_the_number_yourself> INCREMENT BY 1)

To uncatalog database and node:
   db2 uncatalog database <alias-name>
   db2 uncatalog node <node_name>

понедельник, 25 мая 2015 г.

вторник, 5 мая 2015 г.

Db2 LUW 10.5 JDBC driver properties

Db2 JDBC driver for LUW has a lot of properties. Description  one can find on http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_r0052607.html.

One useful property I was needed is "currentSchema" . It specifies the default schema name that is used to qualify unqualified database objects in dynamically prepared SQL statements. The value of this property sets the value in the CURRENT SCHEMA special register on the database server. The schema name is case-sensitive, and must be specified in uppercase characters.

In WebSphere Application Server this properties  can be found in "Custom properties" section of the datasource.