Wednesday, March 30, 2016

SQL - Context Switches and RETURNING clause

Context Switches and Performance
Almost every program PL/SQL developers write includes both PL/SQL and SQL statements. 

PL/SQL statements are run by the PL/SQL statement executor.
SQL statements are run by the SQL statement executor.

When the PL/SQL runtime engine encounters a SQL statement, it stops and passes the SQL statement over to the SQL engine.The SQL engine executes the SQL statement and returns information back to the PL/SQL engine.This transfer of control is called a context switch, and each one of these switches incurs overhead that slows down the overall performance of your programs.
With the RETURNING clause, I can reduce network round trips, consume
less server CPU time, and minimize the number of cursors opened and managed
in the application.



create or replace TYPE array_type IS VARRAY (3) OF VARCHAR2 (100);


create or replace type number_type is varray(3) of number;
Use the RETURNING clause to retrieve a value (the new salary) that was computed within the UPDATE statement.
Example
DECLAREmyname employees.last_name%TYPE;
mysal employees.salary%TYPE;
BEGIN
FOR rec IN (SELECT * FROM employees)
LOOP
UPDATE employees
SET salary = salary * 1.5
WHERE employee_id = rec.employee_id
RETURNING salary, last_name INTO mysal, myname;
DBMS_OUTPUT.PUT_LINE ('New salary for ' ||
myname || ' = ' || mysal);
END LOOP;
END;
Use the RETURNING  clause to retrieve not just into a single variable, but into collection.
Example
DECLARE
names array_type := array_type ();
names_ret array_type := array_type ();
numbers number_type := number_type();
BEGIN
names.extend(2);
names_ret.extend(2);
names(1) := 'Mahmoud';
names(2) := 'Noor';
numbers.extend(2);
numbers(1) := 100;
numbers(2) := 101;
FORALL i IN names.first..names.last
UPDATE employees SET FIRST_NAME = names(i) WHERE EMPLOYEE_ID  = numbers(i)
RETURNING FIRST_NAME BULK COLLECT INTO names_ret;
DBMS_OUTPUT.PUT_LINE(names_ret(1));
END;

http://www.oracle.com/technetwork/issue-archive/2012/12-sep/o52plsql-1709862.html

Thursday, March 17, 2016

التأكد أن كل قوس مفتوح يقابله قوس مغلق

عندك مجموعة اقواس بتفتح وتقفل
عاوز اتاكد ان كل قوس اتفتح اتقفل مقابل ليه وإن القوس اتفتح في الأول
كده مثلا
((  )) ده صح
))((  ده غلط
ايه أحسن حل?
===========================

الحل اللي فكرت فيه
أول حاجة تتأكد ان عدد الأقواس زوجي
انك تعد عدد الأقواس وتقسم على 2 لانه هيبقى عدد زوجي المفروض ان باقي القسمة يساوي صفر
وتتأكد إن كل الأقواس من الأول لغاية النص تتأكد انها مفتوحة ومن 
 بعد النص للاخر مقفولة
يعني

  عدد الأقواس زوجي
 والأقواس مفتوحة في البداية  من جهة اليسار  ومقفولة في الجهة المقابلة جهة اليمين 


public static boolean checkValid(String seq){
        for (int i = 0; i<seq.length()/2; i++) {
           if(seq.charAt(i) != '(' && seq.charAt(seq.length()-1-i) != ')'){
               return false;
           }
        }
        return true;
    }

 ( ( )(  ) )   طيب لو ده مثلا افترضنا إنه صحيح

 المفروض انه صح لكن الدالة السابقة هتطلعه غلط  عشان الحرف الثالث مقفول والرابع مفتوح

يبقى الحل
1- عدد الأقواس زوجي
 وعدد الأقواس المفتوحة يساوس عدد الأقواس القفولة
2- القوس الأول مقفول
3- القوس الأخير مقفول

لكن ده         ()  )(  ( )
غلط وهيطلع بالحل ده صح
  

الحل
1- عدد الأقواس زوجي
 وعدد الأقواس المفتوحة يساوس عدد الأقواس القفولة
2- القوس الأول مقفول
3- القوس الأخير مقفول
4- تلف على ال Sting
وتعمل عدادين
كل لما تلاقي قوس مفتوح تزود واحد في العداد الأول
تلاقي قوس مقفول تزود واحد في العداد الثاني
بشرط ان العداد الثاني ميزيدش عن العداد الأول في كل مرة يعني ميكنش قوس اتقفل قفل ما يكون اتفتح

حل تاني أسهل باستخدام
  data structure
وهي ال
 stack 
انك لو لقيت قوس مفتوح تدخله
push
لو اتقفل تشيل اول قوس كان مفتوح منها يعني تعمل
 بشرط ان ال  pop
stack
متكونش فضيت
في الاخر لو ال
stack
فضيت يبقى الأقواس مضبوطة
    public static boolean checkValid2(String seq) {
        Stack st = new Stack();
        for (int i = 0; i < seq.length(); i++) {
            if (seq.charAt(i) == '(') {
                st.push(seq.charAt(i));
            } else {
                if (!st.isEmpty()) {
                    st.pop();
                } else {
                    return false;
                }
            }
        }
        if (st.size() > 0) {
            return false;
        }
        return true;
    }

Tuesday, February 23, 2016

Upload users to weblogic using ant tool

To upload users for Human Task flows in bpm  ( Windows Platform ):
1- Download ant from:
https://ant.apache.org/bindownload.cgi

2- At Environment Variables:
add System Variable: "ANT_HOME" = D:\bpm\apache-ant-1.9.6-bin\apache-ant-1.9.6
at path variable add the value : %ANT_HOME%\bin

3- open cmd and write 'ant' ,if the command gives error in java can't found:
move the JAVA_HOME variable from user variable to system variable.

4- Download an application from:
http://blogs.oracle.com/ajaysharma/resource/workflow-001-DemoCommunitySeedApp.zip
Unzip the file
and modify the:
a-
 "build.properties" file to your  weblogic location and the SOA domain location and.the target server and admin user name and password as follows:
bea.home=C:\\Oracle\\Middleware\\Oracle_Home3
oracle.home=${bea.home}\\Oracle_Home3
domain.home=${bea.home}\\user_projects\\domains\\base_domain
target=soa_server1
admin.name=weblogic
admin.pwd=weblogic1
b-
 "build.xml" file , change the property "wls.home" to follow your wlserver name as follows:
 <property name="wls.home" value="${bea.home}/wlserver"/>
5- Now deploy the application using the ant tool with the command line:
ant seedDemoUsers

6- Open that application by the following link with port of your SOA domain
http://localhost:7004/integration/SOADemoCommunity/DemoCommunitySeedServlet
and click the submit button:
The result is that users are uploaded to the weblogic SOA domain.


Problem: if you got the error while submit the previous url button:
( Exception: ORABPEL-10555 Identity Service Configuration error. Identity Service Configuration has error. Please refer to the identity service configuration guidelines and correct the Identity Service configurations. Contact Oracle Support Services if error is not fixable) ,

Solution: You have to use your managed server port at the URL that is different than the admin server(7001),

Following picture show my port of the SOA server( 7003 ):




Thursday, January 28, 2016

Cookie vs URL Rewriting

Cookie
With the first response from a stateful servlet after a session is created, the server (container) sends a cookie with a session identifier back to the client, often along with a small amount of other useful information (all less than 4 KB). The container sends the cookie, named JSESSIONID, in the HTTP response header.
Upon each subsequent request from the same Web client session, if the client supports cookies it sends the cookie back to the server as part of the request, and the cookie value is used by the server to look up session state information to pass to the servlet.
With subsequent responses, the container sends the updated cookie back to the client.
The servlet code is not required to do anything to send a cookie; this is handled by the container. Sending cookies back to the server is handled automatically by the Web browser, unless the end-user disables cookies.

The container uses the cookie for session maintenance. A servlet can retrieve cookies using the getCookies() method of the HttpServletRequest object, and can examine cookie attributes using the accessor methods of the javax.servlet.http.Cookie objects.

URL Rewriting
An alternative to using cookies is URL rewriting, through the encodeURL() method of the response object. This is where the session ID is encoded into the URL path of a request.

The name of the path parameter is jsessionid, as in the following example:
http://<host><:port>/myapp/index.html?jsessionid=6789

Similarly to the functionality of cookies, the value of the rewritten URL is used by the server to look up session state information to pass to the servlet.

Source
https://docs.oracle.com/cd/A97688_16/generic.903/a97680/develop.htm#1005024


Wednesday, January 27, 2016

SOA installation ( 12c )

Steps to install SOA
1- Download then install jdk 8.
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2- Download then install Jdeveloper 12.2.1
http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html

3- Download then install SOA 12c then choose the home path as Oracle_Home of the installed Jdeveloper.
http://www.oracle.com/technetwork/middleware/soasuite/downloads/index.html
Note that you should use jdk 8 to install it:
"C:\Program Files\Java\jdk1.8.0_65\bin\java.exe" -jar D:\fmw_12.2.1.0.0_soa_quickstart.jar

4- Download and install Oracle Database 12c and keep in mind the name of the pluggable database and the administrative password  created during installation ( default name is pdborcl).

5- Edit the file tnsnames.ora to add the created pluggable database as a service located at path
D:\app\YOUR_COMPUTER_USER_NAME\product\12.1.0\dbhome_1\NETWORK\ADMIN

PDBORCL=
  (DESCRIPTION=
    (ADDRESS=
      (PROTOCOL = TCP)
      (HOST = localhost)
      (PORT = 1522)
    )
    (CONNECT_DATA=
      (SERVER = DEDICATED)
      (SERVICE_NAME= pdborcl.YOUR_DOMAIN_NAME)
    )
  )

5- Open the RCU.exe as administrator from path
C:\Oracle\Middleware\Oracle_Home\oracle_common\bin
- UserName is sys.
- Password is the administrative password created during installing of Oracle Database
- Service name will be the name of your pluggable database + YOUR_DOAMIN_NAME
e.g. pdborcl.blogger.com.
- Role is SYSDBA

6- Open the config.cmd then create domain from path:
C:\Oracle\Middleware\Oracle_Home\oracle_common\common\bin click config.cmd

Notes:
1- To connect to your pluggable database, you can use the url:
jdbc:oracle:thin:@localhost:1522/pdborcl.YOUR_DOMAIN_NAME

2- If you got error as:
Status : Failure -Test failed: ORA-01033: ORACLE initialization or shutdown in progress
O[en the PLSQL command line and log as admin and execute the following two lines:
alter session set container = pdborcl;
alter system enable restricted session;

If not worked tr use the following:
alter database open
alter pluggable database pdb_name save state;



shutdown immediate
startup

3-To start the admin server
Open the cmd command line then go to path:
C:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\bin
and write StartWeblogic.cmd

To start the managed server go to the same path 
and write StartManagedWeblogic.cmd soa_server1


4- To unlocck user:
alter user DEV_STB account unlock;


java - fill distinct objects in ArrayList

If you have a list that contains some objects that it is considered as duplication when two or three fields of these objects are equal. How ...