Wednesday, August 26, 2015

Java: Run a non jar execution entrance class in a jar file

If you would like to run a class containing a main method other than the default execution entrance of the jar file, you may use the following command. Use forward slash in Linux/Unix system and use backward slash in Windows system.

java -cp <path to your jar>/<jar file name>.jar  <package path of the class>.<class name>

Otherwise, if you just want ot execute the jar through its default execution entrance, the command would be the following.

java -jar <path to your jar>/<jar file name>.jar



                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Thursday, August 20, 2015

Socket getPort vs getLocalPort

The getLocalPort() method returns the port to which the socket binds to. Whereas the getPort() method returns the remote port to which the socket connects to.

For example

ServerSocket serverSocket = new ServerSocket(6045, 50, <InetAddress>);

You create a Socket using the serverSocket's InetAddress and port number to connect to it. You may use this socket to read and write or you can also use the socket returned by serverSocket.accept() to read and write. However, they have different local and remote ports.

A. Using the created socket

Socket socket = new Socket(<InetAddress>, 6045);
socket.getPort() will return the port number used in the above line which is 6045. socket.getLocalPort will return something else, lets say 53222.

To this socket, the server is remote.

B. Using the accepted socket

Socket socket2 = serverSocket.accept();
socket2.getPort() will return 53222 and socket2.getLocalPort() will return 6045.

To this socket2, the server is local.

------------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.


Wednesday, August 19, 2015

SQL: Find and remove / delete all the locks / deadlocks / blockers in an Oracle or PostgreSQL database

If your executing program which updates records in the database hangs, a good chance is that the record it is trying to update is locked by another program.

To prevent concurrent modification of a record, Oracle locks a record when it is being modified. However, if a program, after it has locked some records for modification, hangs due to some reason, it will cause failure or hang of other programs that need to access the records. To find out the locked records in the database, you can get the sid, serial#, status, username, osuser, machine, terminal from the session view, and the owner, object_name and object_type from the dba_objects table, and use them in conjunction with the locked_object view.

Here is the SQL:

A. Oracle


SELECT a.sid, a.serial#, a.username, a.status, a.osuser, a.machine, a.terminal,
          b.owner, b.object_id, b.object_name, b.object_type,
          c. os_user_name
From v$session a, dba_objects b, v$locked_object c
WHERE a.sid = c.session_id and b.object_id = c.object_id;

Or use the one below to get what is holding a lock on an object for which another process is waiting.

SELECT sid, serial# From v$session where sid in (select HOLDING_SESSION from DBA_BLOCKERS);

Or find only the locks that have blocked another session for at least 30 seconds

select v1.sid, v1.serial# from v$session v1 where v1.sid in (select blocking_session from v$session v2 where v2.WAIT_TIME = 0 and v2.seconds_in_wait >= 30);

To remove a lock:
ALTER SYSTEM KILL SESSION 'SID, SERIAL#';

(If not enough privilege, login as sysdba and execute the command below.

               SQL> grant alter system to userid;

                        Grant succeeded.
)

B. PostgreSQL


SELECT t.relname, l.locktype, page, virtualtransaction, pid, mode, granted
FROM pg_locks l, pg_stat_all_tables t
WHERE l.relation=t.relid order by relation asc;

SELECT p.pid, p.usename, p.datname, l.relation::regclass,
l.granted, p.query, p.query_start
FROM pg_stat_activity AS p
JOIN pg_locks AS l ON l.pid = p.pid
WHERE l.relation IN (SELECT relation FROM pg_locks WHERE granted IS FALSE)
ORDER BY l.relation;

SELECT pid, (now() - query_start) AS duration, query, state
FROM pg_stat_activity
WHERE (now() - query_start) > interval '30 seconds';

To remove the lock:
select pg_terminate_backend(<blocking_pid>);


----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Monday, August 3, 2015

Pentaho report: displaying pentaho 0, pentaho 1, pentaho 2 ......

If a pop up appears when you open a report saying, "Missing column <column name>, do you want to remove the column from the report?"  If you choose "No", the report will display two rows with columns displaying values pentaho 0, pentaho 1, pentaho 2 .........

The way to fix it is to remove the column from the report, which does not exist in your meta data, or add such a field to your meta data.

-------------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Pentaho: Locations of pentaho log files

By default the pentaho log files are located at the following locations on your computer.

Pentaho/server/biserver-ee/logs/pentaho.log

Pentaho/server/biserver-ee/tomcat/logs/catalina.<date>.log

-------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.


Pentaho: org.pentaho.pms.core.exception.PentahoMetadataException: QueryXmlHelper.ERROR_0009 - Domain Instance returned null

The following exceptions are caused by that the meta data domain used in the Meta Data Editor and the meta data domain used in the Pentaho User Console are different.

Caused by: org.pentaho.reporting.engine.classic.core.ReportProcessingException: InteractiveAdhocReportUtils.ERROR_0002 - Unable to load report query.
at com.pentaho.iadhoc.service.b.b.a(SourceFile:113)
at com.pentaho.iadhoc.service.b.b.a(SourceFile:80)
at com.pentaho.iadhoc.service.b.k.a(SourceFile:501)
at com.pentaho.iadhoc.service.b.k.a(SourceFile:117)
at com.pentaho.iadhoc.service.InteractiveAdhocService.getThinSpec(SourceFile:157)
at com.pentaho.iadhoc.service.InteractiveAdhocService.getReportSpecificationJson(SourceFile:99)
... 88 more
Caused by: org.pentaho.pms.core.exception.PentahoMetadataException: QueryXmlHelper.ERROR_0009 - Domain Instance <Domain Name> returned null
at org.pentaho.metadata.query.model.util.QueryXmlHelper.fromXML(QueryXmlHelper.java:349)
at org.pentaho.metadata.query.model.util.QueryXmlHelper.fromXML(QueryXmlHelper.java:339)
at com.pentaho.iadhoc.service.h.a(SourceFile:64)
at com.pentaho.iadhoc.service.b.b.a(SourceFile:110)

To fix this problem: 

1. From your Pentaho Metadata Editor, click File in the top menu bar and choose Publish to Server.

2. In the pop up window, make sure that the Domain Name matches the domain name in the exception. Click OK.

Or do the following.

1. From your Pentaho Metadata Editor, click File in the top menu bar and choose Publish to Server.

2. Look for the Domain Name in the pop up window,.

3. Go to Pentaho User Console, click the Create New button, and choose Data Source

4. In the pop up window, make sure to use  the Domain Name you saw in step 2 as the Data Source Name. Continue and finish creating the data source.

5. Create your reports using the new data source.

------------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.