Monday, February 24, 2014

Sample ADF CRUD web application

In this post i will show you how to use ADF to create a simple CRUD application in just few minutes.

To know more about ADF "Application development framework" please go to this link.

1. Create an ADF web application.


2. Set application name "Sample Crud" and click finish.


3. Choose "Connect to a Database" and press "Create a Database Connection".


4. Put connection details, and connect to the Oracle Sample HR database, and make sure to test the connection.

Note: Make sure that the hr user is not locked, and if its locked you may need to unlock it.


5. Mark the "Connect to a database" step as Done.


6. Expand the "Build Business Services" step and click "Go to Substeps".


7. Expand "Create Entity Objects and Associations", Press "Create Entity Objects and Associations".



8. Choose the model project.


9. Choose the database connection created in step 3.


10. Press the Query button, and move the Jobs table to the right column.


11. For the updatable views, chose JobsView and move it to the right column, then press finish.


12. Mark the "Build Business Services" step as Done.


13. Open the "adf-config" unbounded task flow.


14. From the "Component Palette" panel drag the view icon to the task flow.


15. Rename it to "jobsView" and double click on it, and then click Ok.


16. Drag a button from "Component Palette" panel into the page, and rename it from the property panel.



17. Do the same for the Edit, Delete, View buttons.



18. From the "Data Control" panel, drag the JobsView1 into the page, and insert it as a read only table.


19. Choose "Single Row" for selection, and click Ok.


20. Back to the "adf-config" unbounded task flow, and drag a new view for the job form.


21. Double click the new page, and drag the JobsView1 into it from the "Data Control" panel as a form.



22. Check the "Include submit button" checkbox, and click Ok.



23. Back to the "adf-config" unbounded task flow, and drag a new view for the job details.


24. Double click the new view, and add the JobsView1 into it as a read only form, and click Ok.


25. Back to the "adf-config" unbounded task flow, In the "Data Control" panel, expand the JobsView1 -> Operations and drag the "CreateInsert" operation into the task flow.



26. Do the same for "Delete" operation.

27. From "Data Control" -> Operations, drag "Commit" and "Rollback" operations into the task flow page.


28. From the "Component Palette" panel click the "Control Flow Case" icon and drag from "jobsView" page to the "viewJobDetails" page, and name it "view".


29. Do the following to complete navigation flow for our business case:

A. "create" flow from "jobsView" to "createInsert" operation.
B. "edit" flow from "jobsView" to "jobForm" page.
C. "delete" flow from "jobsView" to "delete" operation.
D. "CreateInsert" flow from "CreateInsert" operation to "jobForm" page.
E. "Delete" flow from "Delete" operation to "Commit" operation.
F. "save" flow from "jobForm" page to "Commit" operation.
G. "cancel" flow from "jobForm" page to "Rollback" operation.
H. "Commit" flow from "Commit" operation to "jobsView" page.
I. "Rollback" flow from "Rollback" operation to "jobsView" page.
J. "back" flow from "viewJobDetails" page to "jobsView" page.


30. Go to the "jobsView" page, and double click it, and from the property panel, change the action for each button to be as follow:

A. "View" button action = "view"
B. "Create" button action = "create"
C. "Delete" button action = "delete"
D. "Edit" button action = "edit"


31. In the "jobForm" page, add a new button and name it cancel, and the action = cancel, imediate=true.


32. In the "viewJobDetails" page add a new button and name it back, and the action = back.


33. Right click the adf-config unbounded task flow and click run, if prompted to choose the run configuration choose "jobsView" page to be the start page.

34. Screen shots for the application:



Done.

Configuring logging for ADF application

In this post i will show you how to configure ADF logger that logs your messages/errors to a specific log file.  Here are the steps needed to do the configuration.

1. In JDeveloper right click IntegratedWeblogicServer instance, and choose Configure Oracle Diagnostic logging for "IntegratedWeblogicServer".



2. Choose the root logger, and in structure window expand log_handlers, copy log_handler named "old-handler".

3. Paste the copied log_handler and name it XX-custom-handler, from property window change .



4. Choose the path property and change its default value.



5. In the overview tab of logging.xml file, click the add symbol to add a persistent logger. In the logger name select the class file or package for which you want to use this logger. example : xx.oracle.app select a level based on the severity you need.
 




6. Expand the Root logger and choose the newly created logger, and in the handler declarations window press the add icon, and choose the custom handler.



7. Now select your project in the application window, and double click it to change the run configuration java options -> Choose the default run configuration -> Edit -> Java options and add the following option "-Djbo.debugoutput=adflogger".







8. Now you can use the ADFLogger util to create a logger instance that logs to you log file.


Done.

Tuesday, February 4, 2014

How to prepare for an interview - 17

Back to a new set of problems. If you didn't read previous posts start from here. Read previous post here.

Remember you should discuss these solutions with me, and refer if there are mistakes or other good solutions.

Problems

161. Print a binary tree in infix order. Recursive and iterative.


162. Recursively reverse a Linked List.


163. Implement the div operator without using / or %.


164. How to traverse a binary tree in order iteratively.


165. Print out all combinations of k numbers out of 1...N e.g. when k = 2, n = 4 Print out 12, 13, 14, 23, 24, 34.


166. Given a function for a fair coin, write a function for a biased coin that returns heads 1/n times (n is a param).


167. Given a binary tree, print out the elements in order. Without recursion.


168. Explain the difference between a LEFT and RIGHT SQL JOIN.


169. Extract the max 1000 record out of an array.


170. Code a text justification routine (Given a line length insert white space so text is uniformly displayed within the given length).


Done.

Read next post. Share this post to your Facebook, Twitter, LinkedIn.

How to prepare for an interview - 16

Back to a new set of problems. If you didn't read previous posts start from here. Read previous post here.

Remember you should discuss these solutions with me, and refer if there are mistakes or other good solutions.

Problems

151. Given an array of integers, now we want to erase all 0's (can be other value), and we want the result array condensed, meaning no empty cell in the array.


152. Given a list of words with a same size and a big string that contains one of the permutation of all the words combined(say p), find the start index of the string p in the big string.


153. Print out all prime numbers in a given string. abc2134kd31 -> 2, 13, 3, 3.


154. Generate a new array from an array of numbers. Start from the beginning. Put the number of some number first, and then that number, For example, from array 1, 1, 2, 3, 3, 1 You should get 2, 1, 1, 2, 2, 3, 1, 1.


155. Implement a function rotateArray(vector<int> arr, int r) which rotates the array by r places. Eg 1 2 3 4 5 on being rotated by 2 gives 4 5 1 2 3.


156. Implement a function string balanceParanthesis(string s); which given a string s consisting of some parenthesis returns a string s1 in which parenthesis are balanced and differences between s and s1 are minimum. Eg - "(ab(xy)u)2)" -> "(ab(xy)u)2" - ")))(((" -> "".


157. Write a C function to define strcmp(char *s1, char *s2) to return negative if s1 is smaller, positive if s2 is greater and 0 if they are equal.


158. Write a function that computes log2() using sqrt().


159. Design and implement an algorithm that would correct typos: for example, if an extra letter is added, what would you do?


160. Implement a power function to raise a double to an int power, including negative powers.


Done.

Read next post. Share this post to your Facebook, Twitter, LinkedIn.

How to prepare for an interview - 15

Back to a new set of problems. If you didn't read previous posts start from here. Read previous post here.

Remember you should discuss these solutions with me, and refer if there are mistakes or other good solutions.

Problems

141. Use basic arithmetic operations (+-*/) to implement sqrt function.


142. Intersection of n sets without using a hash table.


143. Given a matrix with 1's and 0's, find the number of groups of 1's. A group is defined by horiz/vertically adjacent 1's.


144. Given a file with 3-letter words, print all 3x3 with each row, column and diagonal being one of the words from given file.


145. Given n+1 buckets with n of them with ball inside and move(a,b) function, that moves ball from bucket a to bucket b. Each ball has a different number from [1,n] on it. Move balls, so each bucket has a ball with matching number in it.


146. Find the center of graph(vertex, that is connected with every other vertex, but edges are directed to the center of graph).


147. Insert a node in a singly linked circular list given any node in the list.


148. Given two sorted arrays, please merge them into a single array and still sorted. how to determine the size of array?


149. Multiply two big integers which don't fit into an built-in integer type. How would you represent big numbers as a data structure? Write the function to multiply two big integers.


150. Given set of coins and each coin has its unique probability to be head up, say double[] probs stores the probability values for all coins, print out all different cases and accordingly probability.


Done.

Read next post. Share this post to your Facebook, Twitter, LinkedIn.

How to prepare for an interview - 14

Back to a new set of problems. If you didn't read previous posts start from here. Read previous post here.

Remember you should discuss these solutions with me, and refer if there are mistakes or other good solutions.

Problems

131. How would you store and search 1 million names?

We can use HashTable. Or use External sorting to split the names and then merge them searching for the needed word.

132. Function to compute the number of ways to climb a flight of n steps. Taking 1, 2, or 3 steps at a time. Do it in Linear time and constant space.

Example:

Input:     n = 3.
Output:
     1 1 1
     1 2
     2 1
     3
     Ans = 4


133. Interweave a linked list. Do it in Linear time and constant space.

Input: A->B->C->D->E
Output: A->E->B->D->C


134. Merge 'k' sorted arrays, each array may have max 'n' elements.


135. You have 9 balls, one of which weighs less than the others, but identical in appearance. If you had one weighing scale, how would you find out which ball weighs less? What would be the time complexity.


136. Implement the "see and tell" algorithm with a given seed number x and a number of iterations y. Output the result on iteration y.


137. A period of time where users login and logout, given a sets of login and logout time pairs, write a function that can show the number of users online at any given time.


138. Given a sorted array, write a program to decide if two elements sum up to a third.


139. Determine the 10 most frequent words given a terabyte of strings.


140. Giving lots of intervals [ai, bi], find a point intersect with the most number of intervals.


Done.

Read next post. Share this post to your Facebook, Twitter, LinkedIn.

How to prepare for an interview - 13

Back to a new set of problems. If you didn't read previous posts start from here. Read previous post here.

Remember you should discuss these solutions with me, and refer if there are mistakes or other good solutions.

Problems

121. Divide two numbers a and b.


122. Sort a binary tree and give the complixty of that.


123. Find all sub sets of size k from given set.


124. Given a sorted array and number x, return the index of this number in the array and if not exist return the index it should be inserted in.


125. Implement a read/write lock, given a mutex that has lock() and trylock() interface.


126. Prints the best collection of N coins that minimize the average number of minimum coins needed to generate values from 1 to M. So, if M = 100, and N = 4, then if we use the set {1, 5, 10, 25} to generate each value from 1 to 100, so that for each value the number of coins are minimized, i.e. 1 = 1 (1 coin), 2 = 1 + 1 (2 coins),..., 6 = 1 + 5 (2 coins), ..., 24 = 10 + 10 + 1 + 1 + 1 + 1 (6 coins), and we take the average of these coins, we would see that the average comes out to ~4.7. But if we instead use {1, 5, 18, 25}, the average would come out to be 3.7. We are to find that set of N coins, and print them, that produce the minimum average.


127. Implement a stack using only queue(s).


128. Print a bst in a sorted order.


129. Write a function that returns the largest sum you can get by adding together numbers in non-adjacent indices from the array. I.e. you if you include the things stored in arr[i] in your sum, you can't include what is stored in arr[i-1] or arr[i+1].


130. Given a m*n grid starting from (1, 1). At any point (x, y), you have two choices for the next move:
     1) move to (x+y, y);
     2) move to (x, y+x);
From point (1, 1), how to move to (m, n) in least moves? (or there's no such a path).


Done.

Read next post. Share this post to your Facebook, Twitter, LinkedIn.