Thursday, December 4, 2008

Oracle Database Partitioning

http://www.oracle.com/solutions/business_intelligence/partitioning.html

Partition for Improved Performance
Partitioning enables tables and indexes to be split into smaller, more manageable components and is a key requirement for any large database with high performance and high availability requirements. Oracle Database 11g offers the widest choice of partitioning methods including interval, reference, list, and range in addition to composite partitions of two methods such as order date (range) and region (list) or region (list) and customer type (list). Oracle Partitioning—an option to Oracle Database 11g Enterprise Edition—is also foundation of Oracle's Information Lifecycle Management strategy, which aligns the business value of information to cost-effective storage tiers for large data warehousing and transaction processing applications.

 

Oracle Information Lifecycle Management (ILM) is a set of automated solutions that work with Oracle Database 11g to enable you to use multi-tier storage to dramatically lower the cost of storing application data. Oracle Partitioning seamlessly moves data to the appropriate storage tier based on its activity level. Oracle Advanced Compression works across all storage tiers to reduce the amount of disk space data requires. Oracle ILM brings these automated solutions together to streamline data management, improve performance for mission-critical systems, and greatly reduce the cost of storage.

Thursday, September 11, 2008

Code of resizing an iframe

The src of the iframe must be in the same domain as the url of the page containing it. Here is the demo code.


Source of http://www.jesse.com/resizeiframe.html:




<iframe id="iframe-homepage" name="iframe-homepage"
src=http://subdomain.jesse.com/iframe.html width="100%" height="100%" target="iframe-homepage"
frameborder="0" scrolling="no" onload="resizeIframe('iframe-homepage')">
</iframe>


<script type="text/javascript">
setInterval("resizeIframe('iframe-homepage')", 2000);
</script>



<script type="text/javascript">
// utilities functions
function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;

if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}
</script>

Sunday, June 1, 2008

Connecting to Oracle via JDBC

  • What is JDBC and what is it used for?
    JDBC is a set of classes and interfaces written in Java to allow other Java programs to send SQL statements to a relational database management system.

    Oracle provides three categories of JDBC drivers:

    • JDBC Thin Driver (No local Net8 installation required/ handy for applets)
    • JDBC OCI for writing stand-alone Java applications
    • JDBC KPRB driver (default connection) for Java Stored Procedures and Database JSP's.
    Oracle's JDBC Thin driver uses Java sockets to connect directly to Oracle. It provides its own TCP/IP version of Oracle's Net8 (SQL*Net) protocol. Because it is 100% Java, this driver is platform independent and can also run from a Web Browser (applets).

    Oracle's JDBC OCI drivers uses Oracle OCI (Oracle Call Interface) to interact with an Oracle database. You must use a JDBC OCI driver appropriate to your Oracle client installation. The OCI driver works through either SQL*Net or Net8.

    • JDBC OCI7 works with an Oracle7 client.
    • JDBC OCI8 works with an Oracle8 client.
    Either of these client versions can access Oracle7 or Oracle8 servers.

    The JDBC OCI drivers allow you to call the OCI directly from Java, thereby providing a high degree of compatibility with a specific Version of Oracle. Because they use native methods, they are platform specific.

    Oracle's JDBC KBPR driver is mainly used for writing Java stored procedures, triggers and database JSPs. It uses the default/ current database session and thus requires no additional database username, password or URL.

    All three drivers support the same syntax and API's. Oracle needs three drivers to support different deployment options. Looking at source code, they will only differ in the way you connect to the database. Remember, you must use a JDBC version that matches the version of your Java Development Kit.

  • Back to top of file
    How does one connect with the JDBC Thin Driver?
    The the JDBC thin driver provides the only way to access Oracle from the Web (applets). It is smaller and faster than the OCI drivers, and doesn't require a pre-installed version of the JDBC drivers.
    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws SQLException
    {
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@hostname:1526:orcl", "scott", "tiger");
    // @machineName:port:SID, userid, password

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    stmt.close();
    }
    }



  • Back to top of file



    How does one connect with the JDBC OCI Driver?

    One must have Net8 (SQL*Net) installed and working before attempting to use one of the OCI drivers.

    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws SQLException
    {
    try {
    Class.forName ("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }

    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:oci8:@hostname_orcl", "scott", "tiger");
    // or oci7 @TNSNames_Entry, userid, password

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    stmt.close();
    }
    }



  • Back to top of file



    How does one connect with the JDBC KPRB Driver?

    One can obtain a handle to the default or current connection (KPRB driver) by calling the OracleDriver.defaultConenction() method. Please note that you do not need to specify a database URL, username or password as you are already connected to a database session. Remember not to close the default connection. Closing the default connection might throw an exception in future releases of Oracle.

    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws SQLException
    {
    Connection conn = (new oracle.jdbc.driver.OracleDriver()).defaultConnection();

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    stmt.close();
    }
    }



  • Back to top of file


  • ref: http://www.orafaq.com/faqjdbc.htm#JDBC

    Wednesday, April 9, 2008

    ActiveRecord-JDBC-Adapter Code Hacking

    Activerecord-JDBC-Adapter RDoc : http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/

    SVN: http://jruby-extras.rubyforge.org/svn/trunk/activerecord-jdbc/

    Project Home Page

     

    1.  lib/active_record/connection_adapters/jdbc_adapter.rb

    Class
    ActiveRecord::ConnectionAdapters::JdbcDriver  < Object

    • load and initialize JDBC Drivers

    Methods

    connection create driver_class load new

     

     Class
    ActiveRecord::ConnectionAdapters::JdbcColumn < Column

    • defines column type conversion,  default value etc. For subclass to override.

    Methods

    default_value init_column new simplified_type type_cast_code

     

    Class
    ActiveRecord::ConnectionAdapters::JdbcAdapter < AbstractAdapter

    • extends AbstractAdapter, defines basic DML functions
    • needs to be sub-classed for specific DBs.

    Methods

    _execute begin_db_transaction commit_db_transaction disconnect! execute indexes jdbc_columns jdbc_insert jdbc_select_all modify_types native_sql_to_type new reconnect! rollback_db_transaction select_one select_rows supports_migrations? tables write_large_object

     

    2. lib/jdbc_adapter/jdbc_oracle.rb

    Module
    ::JdbcSpec::Oracle

    • defines Oracle specific DDL and DML functions by calling self-defined Java class in JdbcAdapterInternalService.java which wraps generic JDBC DML/DDL operations.
    • extends ActiveRecord::ConnectionAdapters::JdbcAdapter through adapter_selector() and ADAPTER_TYPES.
    Methods

    _execute adapter_selector add_order_by_for_association_limiting! column_selector distinct indexes modify_types recreate_database table_alias_length

     

    Module
    ::JdbcSpec::Oracle::Column

    • extends ActiveRecord::ConnectionAdapters::JdbcColumn through column_selector() and COLUMN_TYPES.
    • defines data type conversion between Oracle and Ruby by overriding methods (type_cast and type_cast_code) in Column class.

    ActiveRecord Code Hacking

     

    Class ActiveRecord::Schema < Migration

    In: lib/active_record/schema.rb

    Allows programmers to programmatically define a schema in a portable DSL. This means you can define tables, indexes, etc. without using SQL directly, so your applications can more easily support multiple databases.

     

    Class ActiveRecord::Observer < Object

    In: lib/active_record/observer.rb

    Observer classes respond to lifecycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn’t pertain to the core responsibility of the class. Example:

      class CommentObserver < ActiveRecord::Observer
    def after_save(comment)
    Notifications.deliver_comment("admin@do.com", "New comment was posted", comment)
    end
    end


     




    Class ActiveRecord::ConnectionAdapters::AbstractAdapter < Object



    In: lib/active_record/connection_adapters/abstract_adapter.rb



    All the concrete database adapters follow the interface laid down in this class. You can use this interface directly by borrowing the database connection from the Base with Base.connection.



    Included Modules




    These 3 modules should be overridden by sub-class of AbstractAdapter.



    Included Classes


    Class ActiveRecord::ConnectionAdapters::Column < Object



    In: lib/active_record/connection_adapters/abstract/schema_definitions.rb



    An abstract definition of a column in a table.



    Methods



  • binary_to_string


  • human_name


  • klass


  • new


  • number?


  • string_to_binary


  • string_to_date


  • string_to_dummy_time


  • string_to_time


  • value_to_boolean


  • text?


  • type_cast(value) : Casts value (which is a String) to an appropriate instance.


  • type_cast_code : Generates the ruby code for evaluating the column's value.


  • simplified_type(field_type) : treat similar rails' data types(:date, :datetime, :text, etc.) as the same.
  • Thursday, April 3, 2008

    Git - Fast Version Control System

    Git is a popular version control system designed to handle very large projects with speed and efficiency; it is used mainly for various open source projects, most notably the Linux kernel. 

    Git is distributed version control system focused on speed, effectivity and real-world usability on large projects. Its highlights include:

    • Strong support for non-linear development. Git supports rapid and convenient branching and merging, and includes powerful tools for visualizing and navigating a non-linear development history.
    • Distributed development. Like most other modern version control systems, Git gives each developer a local copy of the entire development history, and changes are copied from one such repository to another. These changes are imported as additional development branches, and can be merged in the same way as a locally developed branch. Repositories can be easily accessed via the efficient Git protocol (optionally wrapped in ssh) or simply using HTTP - you can publish your repository anywhere without any special webserver configuration required.
    • Efficient handling of large projects. Git is very fast and scales well even when working with large projects and long histories. It is commonly an order of magnitude faster than most other revision control systems, and several orders of magnitude faster on some operations. It also uses an extremely efficient packed format for long-term revision storage that currently tops any other open source version control system.
    • Cryptographic authentication of history. The Git history is stored in such a way that the name of a particular revision (a "commit" in Git terms) depends upon the complete development history leading up to that commit. Once it is published, it is not possible to change the old versions without it being noticed. Also, tags can be cryptographically signed.
    • Toolkit design. Following the Unix tradition, Git is a collection of many small tools written in C, and a number of scripts that provide convenient wrappers. It is easy to chain the components together to do other clever things.

    Git - Fast Version Control System

    Friday, March 28, 2008

    JRuby Resource

    JRuby project home http://xircles.codehaus.org/projects/jruby

    Svn of JRuby
    http://svn.codehaus.org/jruby/

    Svn of Activerecord-jdbc-adapter
    http://jruby-extras.rubyforge.org/svn/trunk/activerecord-jdbc/

    JRuby Mailing List:

    dev@jruby.codehaus.org
    user@jruby.codehaus.org


    JRuby Activerecord-jdbc-adapter Issue Tracker: http://jira.codehaus.org/browse/JRUBY/component/12786

    Activerecord-jdbc-adapter Documentation

    Getting_Started with JRuby  http://wiki.jruby.org/wiki/Getting_Started

     

    Cygwin的中文显示乱码问题:
        在Cygwin下,输出的中文系统信息经常显示为乱码,这是因为输出的字符编码设置有问题。可以在.bash_profile中添加如下环境变量来解决:
        export OUTPUT_CHARSET="cp936"

     

    在cygwin中全新安装rubygem前必须:
       unset RUBYOPT
    安装cygwin后默认设置了$RUBYOPT以指定ruby加载rubygems,但此时rubygems并未安装, 因崦执行ruby会报错.

    Thursday, March 27, 2008

    Apache Derby

     

    What is Apache Derby?

    Apache Derby, an Apache DB subproject, is an open source relational database implemented entirely in Java and available under the Apache License, Version 2.0. Some key advantages include:

    • Derby has a small footprint -- about 2 megabytes for the base engine and embedded JDBC driver.
    • Derby is based on the Java, JDBC, and SQL standards.
    • Derby provides an embedded JDBC driver that lets you embed Derby in any Java-based solution.
    • Derby also supports the more familiar client/server mode with the Derby Network Client JDBC driver and Derby Network Server.
    • Derby is easy to install, deploy, and use.

    If you're new to Derby, check out the Quick Start page.

    Apache Derby

     
    free hit counter
    hit counter