Integration Notes

[Machine Vision, Illumination] [Java, J2EE][LabVIEW ] [ORACLE ] [C++ ] [C#] [Aspect-Oriented Programming] [Embedded] [XP Agile CI]
IP and reverse IP
Reverse IP lookup
Interfaces
C * Pro
- Pro*C/C++ generates data structures and calls to its runtime library: SQLLIB.
- Pro*C/C++ does NOT use Oracle Call Interface (OCI)
C* Pro syntax
Oracle-.NET forum
Xtractor XML DB engine
Comparisons
Oracle 10g vs. DB2
Xtractor XML DB engine
oo
[What's new in Oracle 11g]
  • Support for Oracle Grid Computing
  • Support for JDK 1.5 and JDK 1.6 (strictfp, Assert, Generics, Enhanced for Loop Autoboxing/Unboxing, Typesafe Enums, Varargs, Static Import, Annotation)
  • Enhanced SQLJ Profile Print Option
  • Outline Generation - Execution Plan Fixing
  • SQLJ Support for Global Transactions
    • Connection Contexts
    • Execution Contexts
    • You can use SQLJ in writing multithreaded applications. However, any use of multithreading in your SQLJ application is subject to the limitations of your JDBC driver or proprietary database access vehicle. This includes any synchronization limitations.
    • Advanced Transaction Control: #sql { SET TRANSACTION , };
    • SQLJ and JDBC InteroperabilityOracle JDBCSQLJ statements are typically used for static SQL operations. Oracle Database 11g has extensions to support dynamic SQL as well, but another alternative is to use JDBC code within your SQLJ application for dynamic operations, which would be more portable.
    • The Oracle SQLJ implementation includes extensions to support dynamic SQL, operations that are not predefined and can change in real time.
      Dynamic SQL expressions embedded in SQLJ statements are referred to as meta bind expressions.
      Using JDBC code is still an option for dynamic SQL in Oracle Database 11g and might be preferable if code portability is a concern, but SQLJ support for dynamic SQL permits use of SQLJ as a single, simplified API for data access.
  • Oracle Audit Vault: The audit trail goes into a one-way "lockbox." No one, not even a highly skilled DBA, can alter that audit trail once it's in the lockbox. People can view it, but no one can change it or delete it.
  • Hot Patching: you can run your patches, including security fixes, without affecting production.
  • Oracle Database 11g is the ability to store data in compressed format—called advanced table compression.
  • Query Result Cache.
Following is an example of how to use the getConnection() method.

import java.sql.*;
...
DefaultContext ctx = new DefaultContext 
      ("jdbc:oracle:thin:@localhost:1521/myservice", "scott", "tiger", true);
...
(SQLJ operations through SQLJ ctx connection context instance)
...
Connection conn = ctx.getConnection();
...
(JDBC operations through JDBC conn connection instance)
...
To retrieve the underlying JDBC connection of your default SQLJ connection, you can use getConnection() directly from 
a DefaultContext.getDefaultContext() call, where getDefaultContext() returns a DefaultContext instance that you had 
previously initialized as your default connection and getConnection() returns its underlying JDBC connection instance. 
In this case, because you do not have to use the DefaultContext instance explicitly, you can also use 
the Oracle.connect() method. This method implicitly creates the instance and makes it the default connection.

import java.sql.*;
...
Connection conn = Oracle.connect
   ("jdbc:oracle:thin:@localhost:1521/myservice", 
    "scott", "tiger").getConnection();
...
(JDBC operations through JDBC conn connection instance)
...
Example: JDBC and SQLJ Connection Interoperability for Dynamic SQL

Following is a sample method that uses the underlying JDBC connection 
instance of the default SQLJ connection context instance 
to perform dynamic SQL operations in JDBC. The dynamic operations are performed using JDBC java.sql.Connection, 
java.sql.PreparedStatement, and java.sql.ResultSet objects. 
Alternatively, you can use Oracle SQLJ extensions for dynamic SQL operations.

import java.sql.*;

public static void projectsDue(boolean dueThisMonth) throws SQLException {

   // Get JDBC connection from previously initialized SQLJ DefaultContext.
   Connection conn = DefaultContext.getDefaultContext().getConnection();

   String query = "SELECT name, start_date + duration " +
                  "FROM projects WHERE start_date + duration >= sysdate";
   if (dueThisMonth)
      query += " AND to_char(start_date + duration, 'fmMonth') " +
               " = to_char(sysdate, 'fmMonth') ";

   PreparedStatement pstmt = conn.prepareStatement(query);
   ResultSet rs = pstmt.executeQuery();
   while (rs.next()) {
      System.out.println("Project: " + rs.getString(1) + " Deadline: " +
                         rs.getDate(2));
   }
   rs.close();
   pstmt.close();
}



What's new in 10g
  • JHeadstart with JSF support: JSF ADF Faces pages: Instead of generating UIX pages, generates ADF Faces pages (in .jspx format).
  • Generation of Faces-config. JSF is used as the Controller instead of Struts.
    As a result, managed bean definitions and navigation rules are generated in the faces-config, instead of the old struts-config generation.
  • Oracle TopLink: Mapping support for XDB XML Type mappings
  • Isolated client-session cache and cache expiration
  • Use of JAXB validation and compiler (Java Architecture for XML Binding).
  • Support for Object-XML projects and mappings
  • JDeveloper:Preconfigured OC4J (OC4J:containers, APIs, services mandated by the J2EE specification.)
  • Java Persistence API
  • EJB 3.0 Inheritance support
ORACLE CHEET SHEET
Oracle 9i SYNTAX
PL/SQL commandline variable declaration
var v2 varchar2(200);
var v3 varchar2(200);
select sysdate from dual;
EXEC QUERY_TESTED('V00177', 'ST70', 'ST70', 'ST70', 'ST70', :v2,:v3);
print v2;
print v3;
PL/SQL logged user based security (column security)
create or replace view scott.emp_jp_view
as
select
a.empno,
decode(b.username,'GREG',a.ename,'***') ename,
decode(b.username,'GREG',a.job,'***') job,
decode(b.username,'GREG',a.mgr,0) mgr,
a.hiredate,
decode(b.username,'GREG',a.sal,0) sal,
a.comm,
a.deptno
from scott.emp a,
(select sys_context('USERENV','SESSION_USER') username from dual) b;
connect scott/tiger
select * from scott.emp_jp_view;
connect GREG/greg
select * from scott.emp_jp_view;
JP Vijaykumar
PL/SQL logged user based security (row security)
connect scott/tiger;
create or replace view scott.emp_jp_view as
select a.empno, a.ename, a.job, a.mgr, a.hiredate,a.sal,a.comm,a.deptno
from scott.emp a,
(select sys_context('USERENV','SESSION_USER') username from dual) loggedEmployee
where a.ename = loggedEmployee.username;
/*Grant select on scott.emp_jp_view to loggedEmployee; not needed in 9i */
connect greg/greg
select * from scott.emp_jp_view;
connect scott/tiger
select * from scott.emp_jp_view;
PL/SQL make sequence and set counter
CREATE OR REPLACE PROCEDURE ABS.RETURN_LAST_TESTED( RTESTPLANRUN OUT INTEGER)
AS
BEGIN
SELECT GEN_TESTPLANRUN.NEXTVAL INTO RTESTPLANRUN FROM DUAL;
END;
alter sequence ABS.GEN_TESTPLANRUN increment by 20000000;
SELECT ABS.GEN_TESTPLANRUN.NEXTVAL FROM DUAL;
alter sequence ABS.GEN_TESTPLANRUN increment by 1;
SELECT ABS.GEN_TESTPLANRUN.NEXTVAL FROM DUAL;
PL/SQL extract metadata from Oracle 9i database

IS
-- Define local variables
h NUMBER; -- handle returned by 'OPEN'
th NUMBER; -- handle returned by 'ADD_TRANSFORM'
doc CLOB; -- metadata is returned in a CLOB
BEGIN
-- Specify the object type.
h := DBMS_METADATA .OPEN('TABLE');
-- Use filters to specify the schema.
DBMS_METADATA.SET_FILTER(h,'SCHEMA','ABS');
-- Request that the metadata be transformed into creation DDL.
th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL');
-- Fetch the objects.
LOOP
doc := DBMS_METADATA.FETCH_CLOB(h);
-- When there are no more objects to be retrieved, FETCH_CLOB returns NULL.
EXIT WHEN doc IS NULL;
-- Store the metadata in a table.
INSERT INTO ABS.my_metadataABS(md) VALUES (doc);
COMMIT;
END LOOP;
-- Release resources.
DBMS_METADATA.CLOSE(h);
/*

first execute the below in SQL worksheet
DROP TABLE ABS.my_metadataABS;
CREATE TABLE ABS.my_metadataABS (md clob);
CREATE OR REPLACE PROCEDURE get_tables_md IS
-- Define local va riables
h NUMBER; -- handle returned by 'OPEN'
th NUMBER; -- handle returned by 'ADD_TRANSFORM'
doc CLOB; -- metadata is returned in a CLOB
BEGIN
-- Specify the object type.
h := DBMS_METADATA.OPEN('TABLE');
-- Use filters to specify the schema.
DBMS_METADATA.SET_FILTER(h,'SCHEMA','M22');
-- Request that the metadata be transformed into creation DDL.
th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL');
-- Fetch the objects.
LOOP
doc := DBMS_METADATA.FETCH_CLOB(h);
-- When there are no more objects to be retrieved, FETCH_CLOB returns NULL.
EXIT WHEN doc IS NULL;
-- Store the metadata in a table.
INSERT INTO ABS.my_metadataABS(md) VALUES (doc);
COMMIT;
END LOOP;

-- Release resources.
DBMS_METADATA.CLOSE(h);
END;
*/

/*
Then invoke running this:
CONNECT ABS/abs@IBM0050
EXECUTE GET_TABLES_ABS;
SET LONG 9000000
SET PAGES 0
SELECT * FROM ABS.my_metadataABS;
*/
END;
SQL frequent commands
TNSPING GREG1

C:>sqlplus scott/tiger
connect / as sysdba

Starting the instance:oradim -new -sid %ORACLE_SID% -pfile c:\path\to\some\init.ora

Manual Database Creation Tasks when Copying existing database and keeping old database.
  • Creating Directories
  • Exporting an Existing Database [optional]
  • Modifying the Initialization Parameter File
  • Creating and Starting an Oracle Service (oradim)
  • Putting the CREATE DATABASE Statement in a Script
  • Running the CREATE DATABASE Script
  • Importing a Database [optional]
  • Updating ORACLE_SID in the Registry (Only if you change the default SID)
  • Backing Up the New Database
  • Oracle9i Database Administrator ´s Guide Release 2 (9.2) for Windows
    [9i DBA Guide (local)] [10g Concepts (local)]


    Feedback:




    NetBeans vs. Eclipse
    EclipseNetBeans
    Target engine
    The NetBeans/Sun combination works well out of the box and lets you get started a little more quickly than the Eclipse/WebTools combination.NetBeans is a better choice if you use the Sun application server in production, while Eclipse works better with WebSphere. Network World Inc.


    ORM
    Object Relational Mapping
    Java & Hibernate vs. Ruby & ActiveRecord
    HibernateRuby on Rails
    HomeMVC, similar to Struts or Webwork but written in scripting language Ruby
    tutorials
    Home
    • Elad Kehat
      • When it comes to simplicity and speed of development, ActiveRecord beats Hibernate hands down.
      • ActiveRecord lacks expressiveness
    • Patrick Peak
      • The ActiveRecord (Rails) will likely be easier to understand and work with, but past a certain point more advanced/complex usages will likely be difficult or just not possible.
      • Hibernate features a flexible and more powerful. Hibernate supports transitive persistence
      • Both Rails and Hibernate support lazy loading associations, but Hibernate allows you to choose which associations are lazy.
      • Hibernate adds quite a few more mapping types, including different inheritance strategies, custom user types, and maps of entity or simple types.
      • If you stick to the simple cases like single tables with a few associations, and you name your tables and columns right, Rails will likely do just fine, but for more complicated object models, Hibernate will be a better choice.
      • Rails and Hibernate are very different when it comes to query languages. While its not possible to do an exhaustive comparison of their query languages, generally selects for single objects/tables will be quicker and easier for Rails, and anything join related is better suited for Hibernate.
      • Rails use SQL, which is familiar to most developers, while Hibernate offers HQL a OO query language that developers will need to learn. In addition, Hibernate offers quite a few more tuning opportunities, providing the necessary ORM mechanisms, like outer join fetching, configurable lazy fetching and second level caching.

    Ajax, Java and PHP snippets.

    [Ajax ] [Java IE ] [Java IE ]

    Integration Notes

    [Machine Vision, Illumination] [Java, J2EE] [LabVIEW] [ORACLE] [C++] [C#] [Aspect-Oriented Programming] [Embedded] [XP Agile CI] [Software Testing]