Wednesday, November 21, 2012

How to show all privileges from a user in oracle

You can try these below views.
SELECT * FROM USER_SYS_PRIVS; 
SELECT * FROM USER_TAB_PRIVS;
SELECT * FROM USER_ROLE_PRIVS;
 
http://stackoverflow.com/questions/9811670/how-to-show-all-privileges-from-a-user-in-oracle 

How can I list all user-owned functions?

You can list any user owned objects by querying the user_objects table.
To do this for functions:
select object_name from user_objects where object_type = 'FUNCTION';
This table can also show other objects, like procedures and packages.
The user_objects table is supplemented by the table all_objects, which contains all the objects the current user has access to (i.e. grants to tables in other schemas etc).
The object_types this can be queried for on both tables is as follows:
select distinct object_type from all_objects;

OBJECT_TYPE
-------------------
JOB CLASS
INDEXTYPE
PROCEDURE
JAVA CLASS
SCHEDULE
WINDOW
WINDOW GROUP
JAVA RESOURCE
TABLE
TYPE
VIEW
FUNCTION
PROGRAM
SYNONYM
CONSUMER GROUP
EVALUATION CONTEXT
OPERATOR
PACKAGE
SEQUENCE
XML SCHEMA
 
http://dba.stackexchange.com/questions/8190/how-can-i-list-all-user-owned-functions 

Tuesday, November 20, 2012

shortcut to manually Reload file from Disk

  1. Go to Settings>Shortcut mapper.
  2. Select the first tab (main menu)
  3. Find the "reload from disk" option.
  4. Put an unused shortcut.
http://superuser.com/questions/34563/shortcut-to-manually-reload-file-from-disk

Oracle select with subquery

Try this:
SELECT "NEWS"."NEWSID" as ID,
   "NEWS"."SLUG",
   "NEWS_TRANSLATION".*, 
   (SELECT * FROM (SELECT FILENAME FROM NEWS_MEDIA WHERE NEWSID = ID ORDER BY POSITION ASC) AND rownum = 1) as FILENAME
FROM "NEWS" 
INNER JOIN "NEWS_TRANSLATION" ON NEWS.NEWSID = NEWS_TRANSLATION.NEWSID 
WHERE (NEWS.PUBLISH = 1) AND (NEWS_TRANSLATION.LANG = :lang) 
ORDER BY "NEWS"."NEWSID" DESC;
When are you are using "order by" and "rownum" together, you need to first order them and look for the first record.

http://stackoverflow.com/questions/11794242/oracle-select-with-subquery

Saturday, November 17, 2012

Difference between using var and not using var in JavaScript

If you're in the global scope then there's no difference.
If you're in a function then "var" will create a local variable, "no var" will look up the scope chain until it finds the variable or hits the global scope (at which point it will create it):
// These are both globals
var foo = 1;
bar = 2;

function()
{
    var foo = 1; // Local
    bar = 2;     // Global

    // Execute an anonymous function
    (function()
    {
        var wibble = 1; // Local
        foo = 2; // Inherits from scope above (creating a closure)
        moo = 3; // Global
    }())
}
If you're not doing an assignment then you need to use var:
var x; // Declare x
 
http://stackoverflow.com/questions/1470488/difference-between-using-var-and-not-using-var-in-javascript 

Thursday, November 15, 2012

Actual Use Of validate and input in struts config file

These attributes are only used if you're using the Struts Validator Framework or if you override the validate(...) method of your ActionForm. The validate attribute indicates whether or not validation will be performed for this action, and the input attribute indicates where to forward if there is a validation error.

For more information on how to use the validator framework, see the Struts Validator Guide.
[ July 25, 2008: Message edited by: Merrill Higginson ]

http://www.coderanch.com/t/59130/Struts/Actual-validate-input-struts-config

Friday, November 9, 2012

Exception while compiling: wrong version 50.0, should be 49.0

The library you're using was compiled with Java 6
Your compiler is Java 5 that's why it doesn't understand that format.
To fix it you have to get a 1.5 version of the library or upgrade your compiler to 1.6 I suggest the later.

http://stackoverflow.com/questions/1766216/exception-while-compiling-wrong-version-50-0-should-be-49-0

Wednesday, November 7, 2012

Retrying Operations in Java

There are many cases in which you may wish to retry an operation a certain number of times. Examples are database failures, network communication failures or file IO problems.
Approach 1
This is the traditional approach and involves a counter and a loop.
final int numberOfRetries = 5 ;
final long timeToWait = 1000 ;
 
for (int i=0; i
 //perform the operation
 try {
  Naming.lookup("rmi://localhost:2106/MyApp");
  break;
 }
 catch (Exception e) {
  logger.error("Retrying...",e);
  try {
   Thread.sleep(timeToWait);
  }
  catch (InterruptedException i) {
  }
 }
}
Approach 2
In this approach, we hide the retry counter in a separate class called RetryStrategy and call it like this:
public class RetryStrategy
{
 public static final int DEFAULT_NUMBER_OF_RETRIES = 5;
 public static final long DEFAULT_WAIT_TIME = 1000;
 
 private int numberOfRetries; //total number of tries
 private int numberOfTriesLeft; //number left
 private long timeToWait; //wait interval
 
 public RetryStrategy()
 {
  this(DEFAULT_NUMBER_OF_RETRIES, DEFAULT_WAIT_TIME);
 }
 
 public RetryStrategy(int numberOfRetries, long timeToWait)
 {
  this.numberOfRetries = numberOfRetries;
  numberOfTriesLeft = numberOfRetries;
  this.timeToWait = timeToWait;
 }
 
 /**
  * @return true if there are tries left
  */
 public boolean shouldRetry()
 {
  return numberOfTriesLeft > 0;
 }
 
 /**
  * This method should be called if a try fails.
  *
  * @throws RetryException if there are no more tries left
  */
 public void errorOccured() throws RetryException
 {
  numberOfTriesLeft --;
  if (!shouldRetry())
  {
   throw new RetryException(numberOfRetries +
     " attempts to retry failed at " + getTimeToWait() +
     "ms interval");
  }
  waitUntilNextTry();
 }
 
 /**
  * @return time period between retries
  */
 public long getTimeToWait()
 {
  return timeToWait ;
 }
 
 /**
  * Sleeps for the duration of the defined interval
  */
 private void waitUntilNextTry()
 {
  try
  {
   Thread.sleep(getTimeToWait());
  }
  catch (InterruptedException ignored) {}
 }
 
 public static void main(String[] args) {
  RetryStrategy retry = new RetryStrategy();
  while (retry.shouldRetry()) {
   try {
    Naming.lookup("rmi://localhost:2106/MyApp");
    break;
   }
   catch (Exception e) {
    try {
     retry.errorOccured();
    }
    catch (RetryException e1) {
     e.printStackTrace();
    }
   }
  }
 }
}
Approach 3
Approach 2, although cleaner, hasn't really reduced the number of lines of code we have to write. In the next approach, we hide the retry loop and all logic in a separate class called RetriableTask. We make the operation that we are going to retry Callable and wrap it in a RetriableTask which then handles all the retrying for us, behind-the-scenes:
public class RetriableTask implements Callable {
 
 private Callable task;
 public static final int DEFAULT_NUMBER_OF_RETRIES = 5;
 public static final long DEFAULT_WAIT_TIME = 1000;
 
 private int numberOfRetries; // total number of tries
 private int numberOfTriesLeft; // number left
 private long timeToWait; // wait interval
 
 public RetriableTask(Callable task) {
  this(DEFAULT_NUMBER_OF_RETRIES, DEFAULT_WAIT_TIME, task);
 }
 
 public RetriableTask(int numberOfRetries, long timeToWait,
                      Callable task) {
  this.numberOfRetries = numberOfRetries;
  numberOfTriesLeft = numberOfRetries;
  this.timeToWait = timeToWait;
  this.task = task;
 }
 
 public T call() throws Exception {
  while (true) {
   try {
    return task.call();
   }
   catch (InterruptedException e) {
    throw e;
   }
   catch (CancellationException e) {
    throw e;
   }
   catch (Exception e) {
    numberOfTriesLeft--;
    if (numberOfTriesLeft == 0) {
     throw new RetryException(numberOfRetries +
     " attempts to retry failed at " + timeToWait +
     "ms interval", e);
    }
    Thread.sleep(timeToWait);
   }
  }
 }
 
 public static void main(String[] args) {
  Callable task = new Callable() {
   public Remote call() throws Exception {
    String url="rmi://localhost:2106/MyApp";
    return (Remote) Naming.lookup(url);
   }
  };
 
  RetriableTask r = new RetriableTask(task);
  try {
   r.call();
  }
  catch (Exception e) {
   e.printStackTrace();
  }
 }
}
References: http://fahdshariff.blogspot.com/2009/08/retrying-operations-in-java.html

Tuesday, November 6, 2012

Jboss server startup exception

Yeah! Fixed the issue, one of the port was in use.
<attribute name="ServerBindPort">4445</attribute> 
4445 was in use, so changed to 4446
File name : jboss-4.0.3SP1\server\default\conf\jboss-service.xml
netstat was useful to identify the port
netstat -an |find /i "4445"
TCP 0.0.0.0:4445 0.0.0.0:0 LISTENING

http://stackoverflow.com/questions/4475171/jboss-server-startup-exception

What are “%1” and “%2” in batch files?

It represents the first command line argument passed to the batch file.
If you run your batch file with:
myfile.bat firstArg secondArg
%1 becomes "firstArg" and %2 becomes "secondArg"
The related shift command shifts the position of arguments one to the left. Running shift once in a batch file will make "%1" value to be the second argument, "%2" becomes the third, and so on. It's useful for processing command line arguments in a loop in the batch file.

http://stackoverflow.com/questions/2309968/what-are-1-and-2-in-batch-files

How to run this java class in command line in windows?

You would run
java com.test01.test01
but having a class with the same name as a package is a really bad idea (as well as not following the Java naming conventions).
You'd need to run it with the relevant class on the classpath. For example, you could just compile it like this (from the "root" of your source tree):
javac -d . [path to source file]
java com.test01.test01
or if you've got your source organized appropriately already:
javac com\test01\test01.java
java com.test01.test01
 
http://stackoverflow.com/questions/6314648/how-to-run-this-java-class-in-command-line-in-windows

Changing current version of Java within Windows

In the command shell:
set JAVA_HOME=C:\jdk1.6.0u24
set PATH=%JAVA_HOME%\bin;%PATH%
That will temporarily set up the environment in the command shell. Maven, Ant, etc. will pick up on your new version of Java without having to go to the Control Panel repeatedly.
Tools like Eclipse should be able to select which JDK to use in their own configuration tools for use within their environments.

http://superuser.com/questions/262757/changing-current-version-of-java-within-windows

Thursday, November 1, 2012

What is the dual table in Oracle?

It's a sort of dummy table with a single record used for selecting when you're not actually interested in the data, but instead want the results of some system function in a select statement:
e.g. select sysdate from dual;
See http://www.adp-gmbh.ch/ora/misc/dual.html

http://stackoverflow.com/questions/73751/what-is-the-dual-table-in-oracle

ora-00979 not a GROUP BY expression

You must put all columns of the SELECT in the GROUP BY or use functions on them which compress the results to a single value (like MIN, MAX or SUM).

http://stackoverflow.com/questions/1520608/ora-00979-not-a-group-by-expression