Tuesday, September 5, 2017

WAS - Websphere Application Server - Something something..

Profiles - To create different types of WebSphere Application Server runtime environments, you must install the WebSphere Application Server 6 WebSphere Application Server V8.5 Administration and Configuration Guide for the Full Profile core product files and then create a set of configuration files called profiles.
Application server - The application server is the platform on which Java language-based applications run.
Node - A node is an administrative grouping of application servers for configuration and operational management within one operating system instance.
Deployment manager - The deployment manager is the central administration point of a cell that consists of multiple nodes and node groups in a distributed server
configuration.
Node agent - In distributed server configurations, each node has a node agent that works with the deployment manager to manage administration processes.
Cell - A cell is a group of nodes in a single administrative domain.
Administrative agent - An administrative agent is a component that provides enhanced management capabilities for multiple stand-alone application servers.
Job Manager - The job manager is a component that provides management capabilities for multiple stand-alone application servers, administrative agents, and deployment manager.

How to start websphere server

1: Start DeploymentManager
E:\IBM\WebSphere\AppServer\profiles\Dmgr02\bin>startManager.bat

2: Start Node
E:\IBM\WebSphere\AppServer\profiles\Node02Profile\bin\startNode.bat

3: Start BPM Server.[Optional - Only if required]
E:\IBM\WebSphere\AppServer\profiles\Node02Profile\bin>startServer.bat server1

(use admin/admin for any prompt)

4: Start AppServer.
E:\IBM\WebSphere\AppServer\profiles\AppSrv02\bin>startServer.bat server1

5: To Start queues [If queues need are available]
E:\IBM\WebSphere MQ\bin\strmqm
To End queue
E:\IBM\WebSphere MQ\bin>endmqm
To Open MQ Explorer
E:\IBM\WebSphere MQ\bin>strmqcfg

Wednesday, August 30, 2017

Debug mode in WAS


1) Go to http://localhost:9060/ibm/console
2) Servers --> Server Types --> Web Application Servers --> server1
3) Click on server1. Click on the 'Configuration' tab. Under Additional Services --> Click on  Debugging Service.
4) Ensure 'Enable service at server startup' ic clicked. The remote debug port would be port number as in 'JVM debug port'.

Saturday, August 26, 2017

DB2 Nitty Gritty Stuff

To change a column name of a table:

ALTER TABLE SCHEMANAME.TABLENAME RENAME COLUMN OLDCOLUMNNAME TO NEWCOLUMNNAME;

To take a DB backup:

db2stop force
db2start
db2 CONNECT TO DATABASENAME USER username USING password
db2 QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS
db2 CONNECT RESET
db2 BACKUP DATABASE DATABASENAME COMPRESS


Tip: SQL1035N  The operation failed because the specified database cannot be
connected to in the mode requested.  SQLSTATE=57019
If during database backup, if the above error comes up, check if any application server is accessing database or shut down any application server that can use database.


To restore a database backup:

db2> restore database DBNAME FROM D:\db_dump ON D:\ into DBNAME without prompting
D:\db_dump\DBNAME.0.DB2.DBPART000.20160610133049.001

DBNAME in bold is used in the above query

If the above command doesn't work.


1. Open Command as Administrator
2. Run the command runas /profile /user:machinename\dbadminuserid cmd
3. Enter the database password: dbadminpassword
4. Change to DB2 install location: [C:\Program Files\IBM\SQLLIB\BIN]
5. Run db2cwadmin.bat
6. Change directory to db_dump

7. Execute the above restore command.

Note: dbadminuserid must have been added in Windows user accounts [Control panel --> User Accounts]

To find database version:

db2> db2level

To verify if DB2 license is expired or not:

db2> db2licm.exe –l

To renew DB2 license, 
Open command prompt and change directory to the file location, where db2 license is stored. [db2ese_u.lic is the license file]

db2> db2licm -a db2ese_u.lic

To drop a database

db2> drop database DATABASENAME  

To list all the databases

 db2>list database directory

To drop a column from the table

db2> ALTER TABLE TABLENAME DROP COLUMNNAME

If after an alter script, the following error comes up
DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016, SQLERRMC=7;xxx.xxx, DRIVER=3.69.24 [SQL State=57016, DB Errorcode=-668]
This error means access to the database is restricted.
Execute the following query to resolve the error:

db2> REORG TABLE TABLENAME

To create a new database

db2> create database NEWDATABASENAME

To disconnect from the current database

db2> disconnect DATABASENAME
To find the current database connected to the database.
db2> SELECT CURRENT SERVER FROM SYSIBM.SYSDUMMY1

Tuesday, July 11, 2017

When Eclipse doesn't startup...

On clicking on Eclipse.exe, if it doesn't startup, then delete the file "workbench.xmi" under \.metadata\.plugins\org.eclipse.e4.workbench.
Then, try to restart, Eclipse usually starts up.

Monday, April 4, 2016

Date Formats and excetera

Using SimpleDateFormat to convert a date in string into a desired format

SimpleDateFormat sdfYYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");  // The input date string will be in yyyy-MM-dd format
SimpleDateFormat sdfDDMMMYYYY = new SimpleDateFormat("dd-MMM-yyyy"); //The output date string will be in dd-MMM-yyyy format
Date date;
try {
    date = sdfYYYYMMDD.parse("2012-12-09"); // Parse the input string into a date object. parse method throws a ParseException
    System.out.println(date); // Prints as Sun Dec 09 00:00:00 IST 2012
    String formattedDate = sdfDDMMMYYYY.format(date); // Format the date object to a string in the dd-MMM-yyyy (desired format).
    System.out.println(formattedDate); // Prints as 09-Dez-2012
} catch (ParseException e) {
    e.printStackTrace();
}
   

If we need to use sorting on dates, say for using Collections.sort(list), we implement Comparable interface and override the compareTo() method.

       @Override
        public int compareTo(EmpTable o) {
            String dateinstr1 = this.getDate();
            String dateinstr2 = o.getDate();
            try{
                SimpleDateFormat sdfyyyymmdd = new SimpleDateFormat("dd-MMM-yyyy");
                Date date1 = sdfyyyymmdd.parse(dateinstr1);
                Date date2 = sdfyyyymmdd.parse(dateinstr2);
                return date1.compareTo(date2);
            }catch(ParseException e){
                e.printStackTrace();
            }
            return 0;          
        }   

If dates are as Date objects, the above piece of code can be used for displaying dates in ascending format.
If they need to be in descending format, the highlighted text above needs to be written as
return - date1.compareTo(date2);
i.e., prefix with a minus sign. 

Thursday, March 24, 2016

Design Pattern - 7 Adapter and Facade Pattern

Giving a slip to Design pattern 6, the command pattern


Adapter pattern - Converts the interface of a class into another interface clients expect. Lets classes work together that couldn't otherwise because of incompatible interfaces.


Facade pattern - Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher level interface that makes the subsystem easier to use.


Adapter pattern - Typical example is using a adapter class to adapt a Enumeration class of Java to that of Iterator class.


Adapter pattern  has three interfaces -
- The Target interface
- The Adapter interface
- The Adaptee interface


Example: Lets have a Duck interface
interface Duck{
 void quack();
 void fly();
}


interface Turkey {
  void gobble();
  void shortFly();
}


class DuckAdapter implements Duck{
 Turkey turkey;
  DuckAdapter(Turkey turkey){
      this.turkey = turkey;
  }
  
  void quack(){
      turkey.gobble();
  }
 
  void fly(){
      turkey.shortFly();
 }
}


In the above example, the DuckAdapter adapts to the Turkey(Adaptee). The client is not aware that the turkey's methods are getting executed.


Adapter Patterns are of two forms - Class Adapters and Object Adapter. Class Adapter require multiple inheritance.


Facade Pattern - Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. A facade decouples a client from a complex subsystem.


For example, taking the example of home theatre system. It comprises of many subsystems such as a projector system, sound system, etcetra. If we were to do a simple job of watching a movie using the dvd player, and we take the subsystems into account, we end up creating multiple classes in a single class. Implementing Facade requires we compose the facade with its subsystem and use delegation to perform the work of the facade.


Use an Adapter, when you need to use an existing class and its interface is not the one you need.


Use a facade, when you need to simplify and unify a large interface or complex set of interfaces.


 








Tuesday, March 22, 2016

How to create a JPA project in RAD

The tutorials at the below link had excellent tutorial to create a JPA project in RAD. Useful to create in Eclipse as well.


http://www.ibm.com/support/knowledgecenter/SSRTLW_8.0.4/com.ibm.rad.samptut.doc/tutorials/javaee/topics/jpa_create_abst.html