Follow by Email

Tuesday, December 10, 2013

ORA-03115: unsupported network datatype or representation

In a code written by another developer I was trying to replace JDBC statement code with prepared statements

So I was trying to do something like
   
PreparedStatement preparedStatement=con.prepareStatement(sql);
preparedStatement.setString(1, START_DT);

preparedStatement.setString(2, END_DT);

    
ResultSet set = preparedStatement.executeQuery(sql);

but all the queries being executed by above code were giving me the below exception


"ORA-03115: unsupported network datatype or representation"

I found that mistakenly I was calling the executeQuery method and passing it the sql again (this happend because I changed the code to use PreparedStatements instead of Statement , and if you are using statement you need to pass sql to execute query) , which is wrong I needed to call the function like

ResultSet set = preparedStatement.executeQuery();

and this resolved the problem :).

Wednesday, November 20, 2013

javascript capture ctrl+key


Using below Javascript snippet you can trigger things in your web application based on key combinations
 

  /*http://stackoverflow.com/questions/2878983/capture-key-press-without-placing-an-input-element-on-the-page*/  

  document.onkeydown = function(evt) {

          evt = evt || window.event;

          //ctrl+caps

          if (evt.ctrlKey && evt.keyCode == 20 ) {

             

              //**Open a new tab and shift the focus to it

              window.open('url to your page','_blank');

              win.focus();

          }

      };

 

The below website can be used to look for the key codes

Thursday, October 31, 2013

How to get list of tables used in a stored procedure or package

Try to run below query and privide the first value as the owner of this procedure and second value as the procedure name

select
   owner,
   type,
   name,
   referenced_owner,
   referenced_type,
   referenced_name
from
   dba_dependencies
where
   ((owner like upper('&1')
   and
      name like upper('&2') )
   or
   (referenced_owner like upper('&1')
   and
   referenced_name like upper('&2') ))
   and
   referenced_owner != 'SYS'
   and
   referenced_type != 'NON-EXISTENT'
order by
   owner, type, name;

This will give you a list of all tables , synonym , other packages used in your stored procedure.

For more information please see the below link
http://www.dba-oracle.com/t_tables_referenced_inside_pl_sql_procedures.htm 

Tuesday, October 29, 2013

oracle execute privilege on package

 In order to see which roles have execute priviliges on a table/package/any other database object I use below sql query 

SELECT grantee
  FROM all_tab_privs
 WHERE table_name = '<Database object name>'
  AND privilege = 'EXECUTE'

For more details have a look at below stackoverflow thread. http://stackoverflow.com/questions/1255310/how-do-i-check-which-schemata-have-been-granted-execute-permission-on-an-oracle


Monday, October 28, 2013

ORA-08103: object no longer exists

I got this exception while I was trying to run a procedure (written by somebody else in our company) which takes very long time to execute , I found that because of the below sequence of events I was getting this exception

Steps Which Produced This Problem
  1. Procedure was opening a cursor (selecting records) , keeping it open for sometime during which it had to do other operations
  2. After finihing those operations it was trying to execute a loop on the cursor (It created before) and was getting this problem.
Reason
     I found that during this time some of those records my cursor was refering to were deleted , and when the cursor tried to fetch those records in the loop there I was getting "ORA-08103: object no longer exists".

Solution
    The only solution I have in mind is to open the cursor and start  utilizing it immidiatly , i.e. don't keep it open waiting for someother operations to finish.This way I will be able to minimoze the probability of this problem to occur in future.

I was trying to fetch the records in a generic oracle table (which I inserted) , another possible reason could be that you have insert rights but don't have select rights on that table. This was not the case in my situation as I had all the rights on the table but I am sharing it here to give you another possible reason of this problem.

Please also have a look at below Stackover threads for detailed discussions on this problem

http://stackoverflow.com/questions/18747649/exception-ora-08103-object-no-longer-exists-on-using-setfetchsize-of-hirabenate

http://stackoverflow.com/questions/2696519/global-temporary-table-on-commit-delete-rows-functionality-discrepancy

Wednesday, October 23, 2013

error occurred during initialization of vm could not reserve enough space for object heap

I was facing this error today where everytime I was trying to run my tomcat server in eclipse I was getting

"error occurred during initialization of vm could not reserve enough space for object heap"

It looked like a problem with the heap size VM arguments I  checked my eclipse.ini it had below correct heap size settings, Still I was getting the problem

-Xms256m
-Xmx768m
Soultion

I found that there is another place in eclipse where I had to set these VM aruguments and that was the option under

Windows-->Prefrences-->Java --> Installed JRE
I had to edit the configured JDK and add "-Xms256m -Xmx768m" to Default VM Argument.
 

Spring forward to another controller

I use the following approach in my spring applicaitons whenever I need to forward the request from one controller to another controller


@RequestMappping({"/MyURL"})

public String execute(Model model){
   if(){
       //Do Something
      return "forward:/URLNO1"
   } else {
      //Do Something
      return "forward:/URLNO2"
   }

}


As recomended in the below stackoverflow thread

http://stackoverflow.com/questions/7366170/spring-3-0-forwarding-request-to-different-controller/7366199#7366199
 

Sunday, October 13, 2013

java.lang.IllegalArgumentException: Can't convert argument: null



Problem

java.lang.IllegalArgumentException: Can't convert argument: null

I got this exception when I was trying to run a JEE web application in tomcat 6 using ECLIPSE IDE.

Problem Cause
I noticed that my web.xml file contained many "javaee:" tags although the namespace for javaee was already defined at < web-app >  level as xmlns="http://java.sun.com/xml/ns/javaee"

Solution

This is the first time I noticed these javaee tags in a web.xml so I got rid of those , and tried to run the application again on tomcat this time it is working fine.

The below stackoverflow thread has some good details about it

http://stackoverflow.com/questions/2293797/tomcat-startup-web-xml-issue


 

Tuesday, October 8, 2013

A Better Prototyping Approach


I would like to share one experience I had changing the way of prototyping and making it more fun for myself and the user also saving time.

 
Prototyping is very important in a project , a finished prototype having  the user agreement may mean you have already developed 70-80 percent of your database and you have clear understanding of what you will be needing in terms of data , now you are in a better position to find out the availability of that data and less risk of finding surprises later on.

Traditional Way Of Prototyping

                The common practice is to gather the user requirements and use HTML , FLEX,MS WORD or any other technology to build screenshots and show it to user get his feedback change the screens again and repeat the same process few number of times until you have an agreement with the user. This process takes time to finalize the prototype. Sometime we also go ahead and introduce some functionality into the system where a prototype is actually saving and getting the data from database , and this adds some more time to the whole effort.

Remember the goal of this effort is to get user’s agreement on what he needs in the application.

Prototyping approach recommended by David A.Patterson
I took a course at Coursera instructed by David A.Patterson where he shared his experience with the traditional prototyping and the approach he came up with (in fact he said the approach is widely being used these days ).

 Basically he recommended to forget about all the prototyping tools at this stage of your project and take a paper a pencil and sit with user let him draw whatever he has in his mind for what he really wants in the application , of course it will span on multiple screens and discuss all one by one repeat the process until you both agree on a single screen and then do it for other screens. He said this is the fastest and fun way of working on a prototype. Once you agree on a screen think about it in different prospective , like who should be able to see this screen , what should he see and what should be hidden based on role , here you are preparing your test/acceptance cases.

I tried this approach in one recent system I developed for my company and it really helped and saved some time and involve the user at very early stage of the project. Since he drew his requirements for me he had the right expectations from the first iteration of the project J.

Sunday, September 29, 2013

stacktrace to string in java , exception stacktrace

I wanted to get the exception stacktrace from any exception in my application and send it as an email to support staff so that we can do teh proactive support of our application , I came up with the following solution which requires using commons liabrary like below

org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(Throwable)

For more detail and exploring the other options please look at below link

http://stackoverflow.com/questions/1149703/stacktrace-to-string-in-java

Saturday, September 28, 2013

Oracle list of Active Directory errors and there meannings


Here is a list of Active Directory errors:
525 - user not found
52e - invalid credentials
530 - not permitted to logon at this time
532 - password expired
533 - account disabled
701 - account expired
773 - user must reset password



Common Active Directory LDAP bind errors:

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 525, v893
HEX: 0x525 - user not found
DEC: 1317 - ERROR_NO_SUCH_USER (The specified account does not exist.)
NOTE: Returns when username is invalid.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 52e, v893
HEX: 0x52e - invalid credentials
DEC: 1326 - ERROR_LOGON_FAILURE (Logon failure: unknown user name or bad password.)
NOTE: Returns when username is valid but password/credential is invalid. Will prevent most other errors from being displayed as noted.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 530, v893
HEX: 0x530 - not permitted to logon at this time
DEC: 1328 - ERROR_INVALID_LOGON_HOURS (Logon failure: account logon time restriction violation.)
NOTE: Returns only when presented with valid username and password/credential.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 531, v893
HEX: 0x531 - not permitted to logon from this workstation
DEC: 1329 - ERROR_INVALID_WORKSTATION (Logon failure: user not allowed to log on to this computer.)
LDAP[userWorkstations: <multivalued list of workstation names>]
NOTE: Returns only when presented with valid username and password/credential.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 532, v893
HEX: 0x532 - password expired
DEC: 1330 - ERROR_PASSWORD_EXPIRED (Logon failure: the specified account password has expired.)
LDAP[userAccountControl: <bitmask=0x00800000>] - PASSWORDEXPIRED
NOTE: Returns only when presented with valid username and password/credential.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 533, v893
HEX: 0x533 - account disabled
DEC: 1331 - ERROR_ACCOUNT_DISABLED (Logon failure: account currently disabled.)
LDAP[userAccountControl: <bitmask=0x00000002>] - ACCOUNTDISABLE
NOTE: Returns only when presented with valid username and password/credential.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 701, v893
HEX: 0x701 - account expired
DEC: 1793 - ERROR_ACCOUNT_EXPIRED (The user's account has expired.)
LDAP[accountExpires: <value of -1, 0, or extemely large value indicates account will not expire>] - ACCOUNTEXPIRED
NOTE: Returns only when presented with valid username and password/credential.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 773, v893
HEX: 0x773 - user must reset password
DEC: 1907 - ERROR_PASSWORD_MUST_CHANGE (The user's password must be changed before logging on the first time.)
LDAP[pwdLastSet: <value of 0 indicates admin-required password change>] - MUST_CHANGE_PASSWD
NOTE: Returns only when presented with valid username and password/credential.

80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 775, v893
HEX: 0x775 - account locked out
DEC: 1909 - ERROR_ACCOUNT_LOCKED_OUT (The referenced account is currently locked out and may not be logged on to.)
LDAP[userAccountControl: <bitmask=0x00000010>] - LOCKOUT
NOTE: Returns even if invalid password is presented.

For more details please see below thread

https://forums.oracle.com/thread/1157585?start=0&tstart=0

Sunday, September 15, 2013

ERROR ~ IO Exception attempting to acquire interprocess lock

Problem Statement
I was getting below exception in my Documentum code (DFC) yesterday

ERROR ~ IO Exception attempting to acquire interprocess lock
java.io.FileNotFoundException: /bea/documentumCache/cache/6.7.1000.0027/bof/myDocBase/content.lck (No such file or directory)

I was able to login successfully on Documentum but the above problem comes when I was trying to fetch a folder’s content like below

IDfFolder folder = session.getFolderByPath(folderPath);

Reason :
Luckily found out the reason after discussing it with server team , we found out that a the
folder "/bea/documentumCache/cache/6.7.1000.0027/bof/myDocBase" was recently being deleted by the server team. And somehow it was not created again by documentum/weblogic.

Solution :
Like Always once we knew the reason the solution was very easy , we restarted the weblogic server and I believe weblogic/documentum created all those needed folders again. Now I am able to fetch the contents of my folder and do other operations like workflow e.t.c. without any problem.

Note :
Exceptions like this may waste a significant amount of our time to find out the solution while others may have already faced the same problem and their knowledge can be used and solution can be applied in no time.

Thursday, September 5, 2013

ORA-03115: unsupported network datatype or representation

This exception happend to me when i was mistakenly assigning another query to my prepared statement.
I was setting all the parametes to my string query and the trying to run the execute method on my prepared statement passing it the sql string again ,what was happening behind the scene that I was unpreparing my statement and losing all the parameters and passing a qury with "?" in it :) so below is teh solution

Instead of:
rs = ps.executeQuery(Query);
you should execute:
rs = ps.executeQuery();
 

oracle rename existing table


First make sure you have the needed privilages to alter the table and then use below command to rename your table.

ALTER TABLE old_table_name RENAME TO new_table_name;

Tuesday, September 3, 2013

SQL to get the list of child tables for a given table from oracle

Below is the oracle query to get the list of child tables for a given table "Employee"
 
 
SELECT a.table_name,

       a.column_name,

       a.constraint_name,

       c.owner,

       -- referenced pk

       c.r_owner,

       c_pk.table_name      r_table_name,

       c_pk.constraint_name r_pk

  FROM all_cons_columns a

  JOIN all_constraints c

    ON a.owner = c.owner

   AND a.constraint_name = c.constraint_name

  JOIN all_constraints c_pk

    ON c.r_owner = c_pk.owner

   AND c.r_constraint_name = c_pk.constraint_name

WHERE c.constraint_type = 'R'

   AND c_pk.table_name like '%Employee%'

Wednesday, July 3, 2013

Spring roo table column title

I wanted to add a tooltip to the columns in my table and I am using table.tagx by Spring Roo.
Because of the limitations in this tag you can't do it without changeing the tag library itself , I was able to do it and below are the steps to do that
  •  In the the table tag file where we are trying to add a new column to this table , under the td tag I defined the parameter title as  title ="${colTxt}".
  • But the colTxt is defined inside the td tag , so in order to allow the above to run we will have to define the colTxt filter before td like below

<c:set var="colTxt">
<spring:eval expression="item[column]" htmlEscape="false" />
</c:set>

Now the table will show tooltip/title for the columns in it.

Just in case if you need the whole tag file below is a copy paste of table.tagx file


 <jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" xmlns:spring="http://www.springframework.org/tags" xmlns:form="http://www.springframework.org/tags/form" xmlns:fmt="http://java.sun.com/jsp/jstl/fmt" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
  <jsp:directive.tag import="java.util.ArrayList" />
  <jsp:output omit-xml-declaration="yes" />
  <jsp:directive.attribute name="id" type="java.lang.String" required="true" rtexprvalue="true" description="The identifier for this tag (do not change!)" />
  <jsp:directive.attribute name="data" type="java.util.Collection" required="true" rtexprvalue="true" description="The collection to be displayed in the table" />
  <jsp:directive.attribute name="path" type="java.lang.String" required="true" rtexprvalue="true" description="Specify the URL path" />
  <jsp:directive.attribute name="typeIdFieldName" type="java.lang.String" required="false" rtexprvalue="true" description="The identifier field name for the type (defaults to 'id')" />
  <jsp:directive.attribute name="create" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Include 'create' link into table (default true)" />
  <jsp:directive.attribute name="update" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Include 'update' link into table (default true)" />
  <jsp:directive.attribute name="delete" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Include 'delete' link into table (default true)" />
  <jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
  <jsp:directive.attribute name="z" type="java.lang.String" required="false" description="Used for checking if element has been modified (to recalculate simply provide empty string value)" />
  <c:if test="${empty render or render}">
    <c:set var="columnProperties" scope="request" />
    <c:set var="columnLabels" scope="request" />
    <c:set var="columnMaxLengths" scope="request" />
    <c:set var="columnTypes" scope="request" />
    <c:set var="columnDatePatterns" scope="request" />
    <jsp:doBody />
    <c:if test="${empty typeIdFieldName}">
      <c:set var="typeIdFieldName" value="id" />
    </c:if>
    <c:if test="${empty update}">
     <c:set var="update" value="true" />
     
    </c:if>
    <c:if test="${empty delete}">
    <!-- Added by Sajjad , if this is an admin user then he should be able to delete a best practice otherwise no      -->
<!--
       <c:choose>
   <c:when test="${user.admin}">
    <c:set var="delete" value="true" />
   </c:when>
   <c:otherwise>
    <c:set var="delete" value="true" />
   </c:otherwise>
    </c:choose>
 -->
        <c:set var="delete" value="true" />
     
<!--         <c:set var="delete" value="true" />  -->
    </c:if>
    <spring:message var="typeName" code="menu_item_${fn:toLowerCase(fn:split(id,'_')[fn:length(fn:split(id,'_')) - 1])}_new_label" htmlEscape="false" />
    <c:set var="lengths" value="${fn:split(columnMaxLengths, '&#9999;')}" scope="request" />
    <c:set var="types" value="${fn:split(columnTypes, '&#9999;')}" scope="request" />
    <c:set var="patterns" value="${fn:split(columnDatePatterns, '&#9999;')}" scope="request" />
    <spring:eval var="colCounter" expression="1" />
    <table>
      <thead>
        <tr>
          <c:forTokens items="${columnLabels}" delims="${'&#9999;'}" var="columnHeading">
            <th>
              <c:out value="${columnHeading}" />
              <spring:eval var="colCounter" expression="colCounter  + 1" />
            </th>
          </c:forTokens>
          <th></th>
          <c:if test="${update}">
            <th></th>
            <spring:eval var="colCounter" expression="colCounter  + 1" />
          </c:if>
          <c:if test="${delete}">
            <th></th>
            <spring:eval var="colCounter" expression="colCounter  + 1" />
          </c:if>
        </tr>
      </thead>
      <c:forEach items="${data}" var="item">
        <tr>
          <c:forTokens items="${columnProperties}" delims="${'&#9999;'}" var="column" varStatus="num">
            <c:set var="columnMaxLength" value="${lengths[num.count-1]}" />
            <c:set var="columnType" value="${types[num.count-1]}" />
            <c:set var="columnDatePattern" value="${patterns[num.count-1]}" />
            <c:set var="colTxt">
              <spring:eval expression="item[column]" htmlEscape="false" />
            </c:set>
          
            <td title="${colTxt}">
              <c:choose>
                <c:when test="${columnType eq 'date'}">
                  <spring:escapeBody>
                    <fmt:formatDate value="${item[column]}" pattern="${fn:escapeXml(columnDatePattern)}" var="colTxt" />
                  </spring:escapeBody>
                </c:when>
                <c:when test="${columnType eq 'calendar'}">
                  <spring:escapeBody>
                    <fmt:formatDate value="${item[column].time}" pattern="${fn:escapeXml(columnDatePattern)}" var="colTxt"/>
                  </spring:escapeBody>
                </c:when>
                <c:otherwise>
<!--                   <c:set var="colTxt">
                     <spring:eval expression="item[column]" htmlEscape="false" />
                   </c:set> -->
                </c:otherwise>
              </c:choose>
              <c:if test="${columnMaxLength ge 0}">
                <c:set value="${fn:substring(colTxt, 0, columnMaxLength)}" var="colTxt" />
              </c:if>
              <c:out value="${colTxt}" />
            </td>
          </c:forTokens>
          <c:set var="itemId"><spring:eval expression="item[typeIdFieldName]"/></c:set>
          <td class="utilbox">
            <spring:url value="${path}/${itemId}" var="show_form_url" />
            <spring:url value="/resources/images/show.png" var="show_image_url" />
            <spring:message arguments="${typeName}" code="entity_show" var="show_label" htmlEscape="false" />
            <a href="${show_form_url}" alt="${fn:escapeXml(show_label)}" title="${fn:escapeXml(show_label)}">
              <img alt="${fn:escapeXml(show_label)}" class="image" src="${show_image_url}" title="${fn:escapeXml(show_label)}" />
            </a>
          </td>
          <c:if test="${update}">
            <td class="utilbox">
            <!-- Added by sajjad if the user is not the creator of this record then don't show update link  -->
             <c:if test="${item.networkId == user.networkId}">
           
               <spring:url value="${path}/${itemId}" var="update_form_url">
                 <spring:param name="form" />
               </spring:url>
               <spring:url value="/resources/images/update.png" var="update_image_url" />
               <spring:message arguments="${typeName}" code="entity_update" var="update_label" htmlEscape="false" />
               <a href="${update_form_url}" alt="${fn:escapeXml(update_label)}" title="${fn:escapeXml(update_label)}">
                 <img alt="${fn:escapeXml(update_label)}" class="image" src="${update_image_url}" title="${fn:escapeXml(update_label)}" />
               </a>
           </c:if>   
            </td>
          </c:if>
          <c:if test="${delete}">
            <td class="utilbox">
              <!-- Added by sajjad if the user is not the creator of this record then don't show delete link  -->
              <c:if test="${item.networkId == user.networkId}">
               <spring:url value="${path}/${itemId}" var="delete_form_url" />
               <spring:url value="/resources/images/delete.png" var="delete_image_url" />
               <form:form action="${delete_form_url}" method="DELETE">
                 <spring:message arguments="${typeName}" code="entity_delete" var="delete_label" htmlEscape="false" />
                 <c:set var="delete_confirm_msg">
                   <spring:escapeBody javaScriptEscape="true">
                     <spring:message code="entity_delete_confirm" />
                   </spring:escapeBody>
                 </c:set>
                 <input alt="${fn:escapeXml(delete_label)}" class="image" src="${delete_image_url}" title="${fn:escapeXml(delete_label)}" type="image" value="${fn:escapeXml(delete_label)}" onclick="return confirm('${delete_confirm_msg}');" />
                 <c:if test="${not empty param.page}">
                   <input name="page" type="hidden" value="1" />
                 </c:if>
                 <c:if test="${not empty param.size}">
                   <input name="size" type="hidden" value="${fn:escapeXml(param.size)}" />
                 </c:if>
               </form:form>
            </c:if>  
            </td>
          </c:if>
        </tr>
      </c:forEach>
      <tr class="footer">
        <td colspan="${colCounter}">
          <c:if test="${empty create or create}">
            <span class="new">
              <spring:url value="${path}" var="create_url">
                <spring:param name="form" />
              </spring:url>
              <a href="${create_url}">
                <spring:url value="/resources/images/add.png" var="create_img_url" />
                <spring:message arguments="${typeName}" code="global_menu_new" var="add_message" htmlEscape="false" />
                <img alt="${fn:escapeXml(add_message)}" src="${create_img_url}" title="${fn:escapeXml(add_message)}" />
              </a>
            </span>
            <c:out value=" " />
          </c:if>
          <c:if test="${not empty maxPages}">
            <util:pagination maxPages="${maxPages}" page="${param.page}" size="${param.size}" />
          </c:if>
        </td>
      </tr>
    </table>
  </c:if>
</jsp:root>


Sunday, June 9, 2013

Printing web page with CCS applied

I was trying to print a web page which has only a normal HTML table in it and was getting crazy by the fact that whenever I print it using browser's ctrl+p button it was always ignoring all the CSS applied to the page.

I only found out in the below discussion that while including style sheet to your web page if you don't define any value for "media" attribute or if you define it as "media=screen" the CSS will not be applied when you try to take the print out of this page

http://stackoverflow.com/questions/6921573/is-there-no-difference-between-no-media-and-media-all-in-css-link/6921600#6921600

So for me the solution was to include my stylesheet as

<link rel="stylesheet" media="all" type="text/css" href="MyStyleSheet.css" />

Tuesday, May 28, 2013

Refresh a web page after given time


If you want your web page to refresh itself or redirect to someother page after a given time below is the way to do that without going into the pain of writing java script or anyother script

Below code will refresh/call the given page after 1200 seconds = 20 Mins.

  • Replace "URlToYourPage" to any page you want
  • The time is given as seconds as a first parameter in content attribute you can change it to whatever time you want

<meta http-equiv="refresh" content="1200;url=URlToYourPage">

Thursday, May 23, 2013

Multithreading - Scheduling tasks in Java

Java provides us a very good mechanism to schedule any tasks to be executed after a specified time for once or for each specified time period. Take a look at following example which will print a single line after given specified time. We can use this approach to write scheduled  routines who will refresh /recycle heavy resources in our applications (both server and client) .


public class TestTimerAndSechaduledTask {
      Timer timer = new Timer();
      //**interval after which the task will be executed
      int intervel=100;
      int period=100;
    
      private TestTimerAndSechaduledTask(){
            ScheduledClass scheduledClass = new ScheduledClass();
            //**will execute task after given intervel(when programe is executed)
            //**and then after after each time period specified
            timer.schedule(scheduledClass, intervel,period);
      }
    
      /**
       * Class which will be used by timer to eecute any task
       * @author sajjad.paracha
       *
       */
      public class ScheduledClass extends TimerTask{

            public void run() {
                  System.out.println("======>timer task executed    ");
            }
      }
      public static void main (String args[]){
            TestTimerAndSechaduledTask testTimerAndSechaduledTask =new TestTimerAndSechaduledTask();
      }
}


Example : I have defined such scheduled routine in a chating server which after specified time can get rid of extra useless resources on server such as logged out client sessions ,InputStreams,OupputStreams and client socket refrences.
 

Friday, April 5, 2013

org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos ): Indexing into type


Cause Of Exception

I faced this problem and found out that a getter method for a field in  my JPA Entity class was not following the proper java bean naming convention , when I was trying to fetch that column in my list page using below Spring MVC code

Code Causing Problem

< table:column label="My Property Label" property="myProperty" id="myclass_myProperty" z="user-managed" / >

Solution

The getter method was defined as getmyProperty() , notice "m" I changed it to getMyProperty() and was able to get rid of this exception.

There could be other causes but for me once I understood the problem the solution was very simple.

Sunday, March 10, 2013

cannot run eclipse on windows 7



I faced a problem today where my eclipse suddenly stopped working.
I was trying to run eclipse on my machine but I saw below alert  

"The Publisher could not be varified are you sure you want to run this software?
Publisher : Unknown Publisher"
 
I press ok and just nothing happens , eclipse didn’t start 
First of all try to run eclipsec.exe file in your eclipse installation folder if you see an error message like below

“Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object”

You won’t be able to run eclipse using the eclipse.exe file

Solution

Make sure that you have Jdk1.6 installed on your machine  , open the eclipse.ini file and add “-vm” argument to it like below

-vm

D:\software\jdk1.6.0_20\bin\javaw.exe

Please make sure you replace the path to your javaw.exe file according to the JDK installation at your machine. Now try to run eclipse and you should be able to run it now.

Note :
If you still see the above alert message when you try to start eclipse , try to copy your jdk folder from program files to your  D (or C) drive and update the “-vm” argument in eclipse.ini accordingly.

I was able to run eclipse after doing the above  steps. 

 

 

Friday, January 25, 2013

Benefits Of Going Towards SOA And Avoiding Software Silos


Many Organizations believe in shift of approach from creating individual applications to creating software baskets having many modules inside them integrated with each other.

This is good but I believe we have to take care of some good design principles here which if we don’t we will end up having big silos instead of small ones like we have now.
I believe SOA (Service Oriented Architecture) is the natural choice here, which simply says stop integrating and begin service enabling.
So what does Service enabling your software mean? It means your software should be publishing services which can then be used by any other application in your organization.
Service enabling basically means both , integration and flexibility or reusability.

To understand the concept let’s look into the traditional approach, whenever an application needs data from another application we do one of below things
1.       Directly communicate with the database and get the data from it.
Advantages:
·         It’s quick
·         No need to go through painful process of approvals
·         No need to wait for someone else to provide you the data or to develop something in his application you can use.
Disadvantages
·         Since you are not the owner of this data , and nobody knows that you are using it.The owner may change the data or it’s nature at any time without informing you and you will start getting all sort of errors in your application.
·         Let’s say you applied some business rules on the data which you discussed with the owner of that application you applied the rules in your application. Now in future if the rules change you will have to keep track of where else you are using the same rules and it would become night mare in some cases.
·         The ownership of business rules should be with a proper person/group , but in this case it’s not.
2.       Force the user to open the other application, login again and view the needed information.
a.       What if your user needs more information then shown in that page?
b.      What if they want to see less information? Or wants to add more stuff to the same page?
c.       In many cases you can’t just wait for the project lead of that application to create the page you want.

A much Better Approach:
While designing new Applications
We keep in our mind the service enabling principles , we can easily judge that this functionality of our application can be opened as a service or a web service. And then keep on creating those web services.
Of course we will need to maintain an inventory for those web services in future , but we can even continue  developing web services and then organize those in an inventory in future.
Having Service Inventory will help in easily finding an already written service , organize services in proper categories , finding and approaching the owner of the service. Making sure we don’t redo anything.

What If an application was already developed and now you need to integrate it with other applications
We need to be very careful in these cases , many times reinvention of the wheel (developing whole application from scratch) is not needed , instead you can decide to keep using whatever there is since user is already utilizing the software with almost no problems and do all the new enhancements in a way that where ever you see an integration between two system you don’t integrate you service enable it.
Which simply means instead of writing tightly coupled code between the two applications , write the integration as service open for other systems in future if needed.
See this is the difference , if we decide to go by creating bigger systems integrated all the related modules inside one basket and ignore the service enabling principle we will end up having bigger problems J.
However sometimes based on the requirement it can be decided to rewrite the whole application , and this brings us to another point if the same application was being developed in a way that it had reusable services , re writing the same application will be less painful because you can still reuse a lot of service made for old application.

The below pictures will help us understand Silos and what can happen in future J