SyntaxHighlighter JS

2013-11-24

WebLogic Server 12.1.2 and IntelliJ IDEA 11 not working

I performed a new install of WebLogic 12.1.2 on my Mac OSX. I could not get IntelliJ IDEA 11 to add it as a valid Application Server. The error I got was "Warning: Directory is not BEA home".

The new WebLogic 12.1.2 no longer creates registry.xml in the WebLogic home directory. This file had been created by WebLogic since at least version 8. Even WebLogic 12.1.1 created registry.xml.

To fix the WebLogic 12.1.2 and IDEA 11 incompatibility, I add the file registry.xml to the WebLogic home directory. (The WebLogic home directory is the one that contains the directory wlsserver)

The contents of registry.xml

<?xml version="1.0" encoding="UTF-8"?>
<bea-product-information>
  <host home="/Users/juttayaya/javadev/weblogic/wls12120" name="${env.HOST}">
    <product format="1.0" name="WebLogic Platform">
      <release level="12.1"
        ServicePackLevel="2" PatchLevel="0"
        Status="installed" BeaProgramGroup="BEA WebLogic Platform 12.1"
        StartMenu="" InstallTime="@INSTALL_TIME@"
        InstallDir="/Users/juttayaya/javadev/weblogic/wls12120/wlserver"
        JavaHome="/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home"
        JavaVersion="1.7.0" JavaVendor="@JAVA_VENDOR@">
        <component name="WebLogic Server" version="12.1.2.0">
          <component name="Server"/>
        </component>
     </release>
    </product>
    <java-installation Name="jdk170_45" JavaHome="@SUN_JAVA_HOME@" 
        JavaVersion="1.7.0" JavaVendor="Sun">
        <dependent-product Name="WebLogic Platform" Version="12.1.2.0"/>
    </java-installation>

 </host>
</bea-product-information>

2013-11-21

Java on Mac OSX

Notes to myself about Java on Mac OS X since I always forget and have to Google it every time.

  • How do you find all the Java installed on your Mac?
    /usr/libexec/java_home -V

  • How do you set JAVA_HOME to a specific version?
    export JAVA_HOME=`/usr/libexec/java_home -v 1.6`

  • How do you execute a specific version of Java to run?
    /usr/libexec/java_home -v 1.6 --exec javac -version

  • What is the difference between the Java in /System/Library and /Library?
    The Java in /System/Library is the version of Java from Apple. Apple uses it for its system runtime so do not touch or modify it.  The Java in /Library is what you installed from Sun.

  • Where do you put Java Extensions?
    In directory /Library/Java/Extensions

2013-11-20

Auditing Unix input/output

When accessing a customer's Unix server, it is helpful to allow the customer to audit the commands you execute on the server.

To log all your command line inputs and output to a file, use the command

script filename

This will log all your inputs and output into a log file named filename. (Of course replace filename with whatever you want the file name to be).

To finish with logging your commands, type

exit

To share a Unix screen terminal, so the customer can see your inputs and output in real-time, use the screen command.

  1. You and the customer log in as the same Unix user in ssh
  2. You type in the command

    screen -d -m -S myscreenname
    screen -x myscreenname

    (Of course replace myscreenname with whatever you want the screen name to be).
  3. The customer types the command

    screen -x myscreenname
  4. To finish with sharing your Unix terminals, type in the command

    exit
The great feature of screen is that the customer can type in commands from his Unix terminal and you can see the output on your screen. It is an excellent way to do pair-administration.

If you want to use both script and screen at the same time, run the screen command first. The script command will not record the screen inputs/outputs if it is executed first.

How to get rid of color in ls

 Many Unix administrators will force the command  "ls" to automatically output with colors by adding the following alias to the ~/.bashrc

alias ls='ls --color'

To make "ls" not display colors for your session, type in the follow command at the command prompt

unalias ls

2013-11-17

Oracle PL/SQL best practice: Select statements

Question:
What is the best way to do SQL select statements in Oracle PL/SQL?

Answer:
For best performance of select statements returning many rows, use the PL/SQL fetch bulk collect with limit.

DECLARE
    CURSOR hr_employees_cur IS
        SELECT first_name, last_name, hire_date, salary
        FROM hr.employees;
        
    TYPE hr_employees_rec IS record(
        first_name hr.employees.first_name%TYPE,
        last_name hr.employees.last_name%TYPE,
        hire_date hr.employees.hire_date%TYPE,
        salary hr.employees.salary%TYPE
    );
    
    batchSize CONSTANT PLS_INTEGER := 100;    
    TYPE hr_employees_vat IS VARRAY(100) OF hr_employees_rec;    
    hr_employees hr_employees_vat;
    
BEGIN
    OPEN hr_employees_cur;
    LOOP
        FETCH hr_employees_cur BULK COLLECT INTO hr_employees LIMIT batchSize;
        FOR i IN 1 .. hr_employees.COUNT()
        LOOP
            IF ( hr_employees(i).salary > 10000 AND
                 hr_employees(i).hire_date > TO_DATE('15-04-1999', 'DD-MM-YYYY') )
            THEN
                sys.dbms_output.put_line(
                  'New employee over salary limit: ' || 
                   hr_employees(i).first_name || 
                   ' ' || 
                   hr_employees(i).last_name);
            ELSIF ( hr_employees(i).salary < 2400 AND
                    hr_employees(i).hire_date > TO_DATE('15-04-1999', 'DD-MM-YYYY') )
            THEN
                sys.dbms_output.put_line(
                  'New employee under salary limit: ' || 
                   hr_employees(i).first_name || 
                   ' ' || 
                   hr_employees(i).last_name);                     
            END IF;
        END LOOP;
        
        EXIT WHEN hr_employees.COUNT() < batchSize;
    END LOOP;
    
    CLOSE hr_employees_cur;

END;

Notes:
  1. Fetch bulk collect performs the best because it reduces context switching between the PL/SQL and SQL engine. When PL/SQL executes a SQL statement, like in a select SQL fetch, the PL/SQL engine has to pass the processing to the separate SQL engine.  The passing of processing between the PL/SQL and SQL engine is called context switching and it is CPU expensive. Executing a 10,000 row select fetch in a loop results in 10,000 context switches.  Bulk collect fetch batches multi-row select fetches into 1 context switch.
  2. Limit is needed so the bulk collect fetch does not consume excessive per-session memory for select queries that returns a large number of rows.
  3. A batch size of 100 is a good balance between memory and performance. Increasing the batch size above 100 usually leads to diminishing returns in performance.
  4. Unfortunately, Oracle VARRAY does not accept a variable as its initial size.
  5. Oracle recommends exiting the loop via the VARRAY.COUNT instead of CURSOR%NOTFOUND.
  6. Oracle 10g by default (plsql_optimize_level=2) optimizes cursor for-loops to speeds comparable to fetch bulk collect with limit of 100 and with less code.  If you do not need to tune the bulk collect limit size, the cursor for-loop is a good compromise between fast code creation/maintainability and runtime performance.

    The above example using cursor for-loops
DECLARE
    CURSOR hr_employees_cur IS
        SELECT first_name, last_name, hire_date, salary
        FROM hr.employees;
BEGIN
    FOR hr_employees_rec IN hr_employees_cur
    LOOP
            IF ( hr_employees_rec.salary > 10000 AND
                 hr_employees_rec.hire_date > TO_DATE('15-04-1999', 'DD-MM-YYYY') )
            THEN
                sys.dbms_output.put_line(
                  'New employee over salary limit: ' || 
                   hr_employees_rec.first_name || 
                   ' ' || 
                   hr_employees_rec.last_name);
            ELSIF ( hr_employees_rec.salary < 2400 AND
                    hr_employees_rec.hire_date > TO_DATE('15-04-1999', 'DD-MM-YYYY') )
            THEN
                sys.dbms_output.put_line(
                  'New employee under salary limit: ' || 
                   hr_employees_rec.first_name || 
                   ' ' || 
                   hr_employees_rec.last_name);                     
            END IF;    
    END LOOP;
END;

Sources: