henbeibi

Tuesday, September 26, 2006

ソフトウェアメトリクス解説(005)

Number Of Parameters(NOP)

This metric is a count of the number of parameters to a method. Methods with a large Number Of Parameters often indicate that classes are missing from the model.

Most methods that have a large Number Of Parameters can be simplified by grouping parameters into a number of related sets and making classes from those sets. It will often be the case that when this is done, those new classes attract behaviour that previously existed (uncomfortably) in other classes. The result will be the formation of semantically rich abstractions that encapsulate a coherent set of operations. This leads to an increase in maintainability.

Labels:

ソフトウェアメトリクス解説(004)

Weighted Methods Per Class(WMC)

This metric is the sum of complexities of methods defined in a class. It therefore represents the complexity of a class as a whole and this measure can be used to indicate the development and maintenance effort for the class.

Classes with a large Weighted Methods Per Class value can often be refactored into two or more classes.

あるクラスのメソッドの重さ(複雑さの総和)を 計測します。WMCが高いほど、複雑であり、メンテナンスのコストが かかることを示唆します。

Labels:

ソフトウェアメトリクス解説(003)

Efferent Couplings
いわゆる結合度。つまり、計測対象のクラスが参照しているクラスの数であり、呼び出し関係にあるメソッドの結び付きの強さを表す指標です。
結合度が高くなると複数のクラスやパッケージ間で依存度が上がってしまうため、保守やメンテナンス、仕様変更などの対応がしづらくなります。また、設計的な観点からしても、複雑で分かりづらいものになってしまいます。

結合度を意識することにより、保守性やプログラム構造および設計の理解のしやすさを改善することができます。既存のシステムに対しては、結合度が高くなっているクラスやパッケージ間に着目し、数値を低くするように調整を行えると、結果的に保守性や設計の改善を行うことができるでしょう。

Labels:

ソフトウェアメトリクス解説(002)

Lack of Cohesion in Methods(Henderson-Sellers)
つまり、メソッドの凝集度です。

凝 集度の測定とは、クラスやパッケージ内の機能要素と情報要素間の関連性の高さを測るものです。オブジェクト指向言語において、着目しているクラスに、互い に関連するメンバ変数とメソッドが十分に集まっている、つまり局所化されているのであれば、そのクラスのメンバ変数1つ当たりへアクセスするメソッドの数 は多くなります。

簡単にいってしまうと、メンバ変数1つ当たりへアクセスするメソッドの数が少ないとLCOM*は1へ近づき、多ければLCOM*は0へ近づきます。つまり、LCOM*の値が小さいほど凝集度が高いといえます。

LCOM*は次の式で定義されます:




ここで、

Ajは、着目しているクラスのj番目のメンバ変数

aは、着目しているクラスのメンバ変数の個数

mは、着目しているクラスのメソッドの個数

μ(Aj)は、メンバ変数Ajにアクセスしているメソッドの個数


を表しています。

簡単にいってしまうと、メンバ変数1つ当たりへアクセスするメソッドの数が少ないとLCOM*は1へ近づき、多ければLCOM*は0へ近づきます。つまり、LCOM*の値が小さいほど凝集度が高いといえます。

話を具体的にするためにJavaを想定して説明しましょう。次のようなクラスを考えます。

class SampleClass {
private int a1, a2, a3, a4;

public void m1() {
a1=0; a2=1;
}
public void m2() {
a1=1; a2=2;
}
public void m3() {
a3=0; a4=3;
}
public void m4() {
a3=1; a4=2;
}

このとき、LCOM*の計算式に登場する各項の値は次のとおりです。

a=|A|=メンバ変数の数=4

m=|M|=メソッドの数=4

μ(a1)=a1にアクセスするメソッドの数=2

μ(a2)=a2にアクセスするメソッドの数=2

μ(a3)=a3にアクセスするメソッドの数=2

μ(a4)=a4にアクセスするメソッドの数=2

 よって、このクラスのLCOM*は、

 LCOM*=(((1/4) * (2+2+2+2))ー4)/(1 ? 4)=0.666……

となります。

ここでよく見てみると、{a1, a2, m1, m2}のグループと{a3, a4, m3, m4}のグループは互いに何の関係もないことが分かります。ということは、これらのグループごとにクラスを分けることによって、それぞれのグループの局所化が進み、凝集度が向上するはずです。これらのグループごとにクラスを分割した場合のLCOM*は、それぞれ次のようになります。

クラス1のLCOM*=0

クラス2のLCOM*=0

Labels:

ソフトウェアメトリクス解説(001)


McCabe's cyclomatic complexity
サイクロマチック、つまり、循環的複雑度

e: プログラム中に存在する基本ブロック
基本ブロック:分岐と合流を含まない計算過程.図1では矢印部分.
n: プログラム中に存在する分岐点と合流点の数
分岐点:if や while 文,合流点:if 文の終わり,while 文の終わり 図1では,◯印部分.
p: サブルーチン数(含む自分自身のルーチン)
 とすると,複雑度 C は以下のように計算され,図1の場合,3つの閉領域 (丸数字の 1 - 3) と1つの開領域 (丸数字の 4) を数えた結果を表します.
C = e - n + 2p



Labels:

Thursday, September 21, 2006

Oracle10g Administration(002)

Planning for Database Creation

1:Plan the database tables and indexes and estimate the amount of space they will require.

2:Plan the layout of the underlying operating system files your database will comprise. Proper distribution of files can improve database performance dramatically by distributing the I/O during file access. You can distribute I/O in several ways when you install Oracle software and create your database. For example, you can place redo log files on separate disks or use striping. You can situate datafiles to reduce contention. And you can control data density (number of rows to a data block).

3:Consider using Oracle-managed files and Automatic Storage Management to create and manage the operating system files that make up your database storage.

Labels:

Tuesday, September 19, 2006

Oracle10g Administration(001)

Checking Your Current Release Number
To identify the release of Oracle Database that is currently installed and to see the release levels of other database components you are using, query the data dictionary view PRODUCT_COMPONENT_VERSION. A sample query follows.

COL PRODUCT FORMAT A40
COL VERSION FORMAT A15
COL STATUS FORMAT A15
SELECT * FROM PRODUCT_COMPONENT_VERSION;

Labels:

Great New Features of Oracle10g(3)

Oracle Database Implementation of Regular Expressions
Oracle Database implements regular expression support with a set of Oracle Database SQL functions and conditions that enable you to search and manipulate string data. You can use these functions in any environment that supports Oracle Database SQL. You can use these functions on a text literal, bind variable, or any column that holds character data such as CHAR, NCHAR, CLOB, NCLOB, NVARCHAR2, and VARCHAR2 (but not LONG).

1:REGEXP_LIKE(condition)

Searches a character column for a pattern. Use this function in the WHERE clause of a query to return rows matching a regular expression. The condition is also valid in a constraint or as a PL/SQL function returning a boolean. The following WHERE clause filters employees with a first name of Steven or Stephen:
WHERE REGEXP_LIKE(first_name, '^Ste(v|ph)en$')

2:REGEXP_REPLACE(function)

Searches for a pattern in a character column and replaces each occurrence of tha pattern with the specified string. The following function puts a space after each character in the country_name column:
REGEXP_REPLACE(country_name, '(.)', '\1 ')


3:REGEXP_INSTR(function)

Searches a string for a given occurrence of a regular expression pattern and returns an integer indicating the position in the string where the match is found. You specify which occurrence you want to find and the start position. For example, the following performs a boolean test for a valid email address inthe email column:
REGEXP_INSTR(email, '\w+@\w+(\.\w+)+') > 0

4:REGEXP_SUBSTR(function)

Returns the substring matching the regular expression pattern that you specify. The following function uses the x flag to match the first string by ignoring spaces in the regular expression:
REGEXP_SUBSTR('oracle', 'o r a c l e', 1, 1, 'x')

Migrating a Database to Automatic Storage Management
With a new installation of Oracle Database and Automatic Storage Management (ASM), you initially create your database in ASM. If you have an existing Oracle database that stores database files in the operating system file system or on raw devices, you can migrate some or all of these database files to ASM.

There are two ways to migrate database files to ASM:

■ Manually, using RMAN
For detailed instructions on migrating a database to ASM using RMAN, see Oracle Database Backup and Recovery Advanced User's Guide. You can also use RMAN to migrate a single tablespace or datafile to ASM.

■ With the Migrate Database To ASM wizard in Enterprise Manager You access the wizard from the Administration page, under the Change Database heading. Refer to the Enterprise Manager online help for instructions on using the wizard.

Labels:

Great New Features of Oracle10g(2)

Shrinking Database Segments Online
You use online segment shrink to reclaim fragmented free space below the high water mark in an Oracle Database segment. The benefits of segment shrink are these:
■ Compaction of data leads to better cache utilization, which in turn leads to better
online transaction processing (OLTP) performance.
■ The compacted data requires fewer blocks to be scanned in full table scans, which in turns leads to better decision support system (DSS) performance.

Segment shrink is an online, in-place operation. DML operations and queries can be issued during the data movement phase of segment shrink. Concurrent DML operation are blocked for a short time at the end of the shrink operation, when the space is deallocated. Indexes are maintained during the shrink operation an remain usable after the operation is complete. Segment shrink does not require extra disk space to be allocated.

Segment shrink reclaims unused space both above and below the high water mark. In contrast, space deallocation reclaims unused space only above the high water mark. In shrink operations, by default, the database compacts the segment, adjusts the high water mark, and releases the reclaimed space.

Segment shrink requires that rows be moved to new locations. Therefore, you must first enable row movement in the object you want to shrink and disable any rowid-based triggers defined on the object. You enable row movement in a table with the ALTER TABLE ... ENABLE ROW MOVEMENT command.

Shrink operations can be performed only on segments in locally managed tablespaces with automatic segment space management (ASSM). Within an ASSM tablespace, all segment types are eligible for online segment shrink except these:
■ IOT mapping tables
■ Tables with rowid based materialized views
■ Tables with function-based indexes


You can shrink space in a table, index-organized table, index, partition, subpartition, materialized view, or materialized view log. You do this using ALTER TABLE, ALTER INDEX, ALTER MATERIALIZED VIEW, or ALTER MATERIALIZED VIEW LOG statement with the SHRINK SPACE clause. Refer to Oracle Database SQL Reference for the syntax and additional information on shrinking a database object, including restrictions.

Two optional clauses let you control how the shrink operation proceeds:

■ The COMPACT clause lets you divide the shrink segment operation into two phases. When you specify COMPACT, Oracle Database defragments the segment space and compacts the table rows but postpones the resetting of the high water mark and the deallocation of the space until a future time. This option is useful if you have long-running queries that might span the operation and attempt to read from blocks that have been reclaimed. The defragmentation and compaction results are saved to disk, so the data movement does not have to be redone during the second phase. You can reissue the SHRINK SPACE clause without the COMPACT clause during off-peak hours to complete the second phase.

■ The CASCADE clause extends the segment shrink operation to all dependent segments of the object. For example, if you specify CASCADE when shrinking a table segment, all indexes of the table will also be shrunk. (You need not specify CASCADE to shrink the partitions of a partitioned table.) To see a list of dependent segments of a given object, you can run the OBJECT_DEPENDENT_SEGMENTS procedure of the DBMS_SPACE package.

As with other DDL operations, segment shrink causes subsequent SQL statements to be reparsed because of invalidation of cursors unless you specify the COMPACT clause.

Examples
Shrink a table and all of its dependent segments (including LOB segments):
ALTER TABLE employees SHRINK SPACE CASCADE;

Shrink a LOB segment only:
ALTER TABLE employees MODIFY LOB (perf_review) (SHRINK SPACE);

Shrink a single partition of a partitioned table:
ALTER TABLE customers MODIFY PARTITION cust_P1 SHRINK SPACE;

Shrink an IOT index segment and the overflow segment:
ALTER TABLE cities SHRINK SPACE CASCADE;

Shrink an IOT overflow segment only:
ALTER TABLE cities OVERFLOW SHRINK SPACE;

Labels:

Friday, September 15, 2006

Great New Features of Oracle10g(1)

Start Up and Shut Down of Database OCI API
This feature adds API calls for starting and stopping a database from inside an application.
This enables ISVs and testers to start up and shut down databases without using SQL*Plus or other tools. This streamlines the testing process for application developers.

Unicode Data Type Literal Enhancement
This feature supports SQL string literal INSERT and UPDATE operations on NCHAR without data loss regardless of what the database character set happens to be.
Multilingual Unicode data can now be added without restrictions such as having to provide hex Unicode values. The support for this feature is available in SQL, PL/SQL, OCI, and JDBC.
This feature prevents data loss when performing INSERT and UPDATE operations on NCHAR.

Transliteration for Japanese Kana Conversion
This feature provides a transliteration mechanism to support various Japanese Kana conversions in different forms. The TRANSLITERATE function for the UTL_I18N PL/SQL package is provided for transliteration in this release.
This feature performs Japanese Kana conversions.

JDBC Runtime Connection Load Balancing
This feature provides dynamic routing of connection requests to the least loaded instance. The JDBC connection cache manager uses Real Application Clusters (RAC) workload metrics and the specified load balancing policy to choose the best instance to process the connection request.
The benefit is efficient RAC and Grid database resource utilization by even distribution of the workload across RAC instances based on workload metrics and distribution policies.


Support for JDBC 3.0 ResultSet Holdability
By default, the database automatically closes cursors and result sets upon transaction commit. A holdable cursor, or holdable resultset, is not closed when the transaction that contains the cursor is committed thereby reducing hard parses and library latches.
JDBC 3.0 ResultSet holdability is specified using the createStatement(), prepareStatement(), or prepareCall() methods and one of the following two constants: HOLD_CURSORS_OVER_COMMIT or CLOSE_CURSORS_AT_COMMIT. Oracle Database supports HOLD_CURSORS_OVER_COMMIT. Any other value passed as an argument is ignored.
Keeping cursors open when a transaction is committed increases the performance of JDBC applications or J2EE components.

Support for JDBC 3.0 Retrieval of Auto-Generated Key
During a SQL INSERT command, this feature retrieves the value of the
pseudo-column, ROWID, of the newly inserted row.
This feature allows JDBC applications and J2EE components to retrieve the key (ROWID) of the newly inserted row during the same database operation (INSERT). As a result, a network round-trip to the database is saved and the performance is increased.

Rules Manager
Rules Manager is a new feature of Oracle Database 10g Release 2. It enables developers to create applications that process and respond to events of any complexity using rules and policies defined in the database. It can evaluate events using data from the application and from database tables. It stores intermediate results to quickly evaluate the next event in a long running composite event (an event made up of two or more simple events). Rules are defined using XML and SQL and can have complex conditions using conjunctions and disjunctions, and specify a set of events, time, and non-occurrence of event with or without a deadline. Event policies control how rules are processed and the duration of an event. Rules can trigger actions that are user-defined procedures running inside an Oracle Database or actions in another application.
The benefit of this feature is that rules that are managed in Oracle Database keep pace with changing business conditions and are always up-to-date; rules are easily changed with SQL and are not included in your application or loaded into a memory-based rules repository. Rules can be evaluated efficiently with th complete business context stored in your Oracle Database and data provided by your application. Event response is flexible; rules can trigger actions in Oracle Database or your application.
Additional advantages of Oracle Database over other approaches include:
■ Manageability, by storing rules and event policies with your application data.
■ Performance, by evaluating rules and coordinating multiple events and application threads with the full capabilities of Oracle Database.
■ Scalability, by evaluating sets of rules of any size.

Labels:

Thursday, September 14, 2006

My Logo

This is my logo my wife made for me. Very COOL!!!!!!! Posted by Picasa

Labels:

Obfuscating PL/SQL Code With the wrap Utility

The wrap utility processes an input SQL file and obfuscates only the PL/SQL units in the file, such as a package specification, package body, function, procedure, type specification, or type body. It does not obfuscate PL/SQL content in anonymous blocks or triggers or non-PL/SQL code.

To run the wrap utility, enter the wrap command at your operating system prompt using the following syntax:

wrap iname=input_file [oname=output_file]

Note:Do not use any spaces around the equal signs.

input_file is the name of a file containing SQL statements, that you typically run using SQL*Plus. If you omit the file extension, an extension of .sql is assumed. For example, the following commands are equivalent:

wrap iname=/mydir/myfile
wrap iname=/mydir/myfile.sql

You can also specify a different file extension:

wrap iname=/mydir/myfile.src

output_file is the name of the obfuscated file that is created. The oname option is optional, because the output file name defaults to that of the input file and its extension defaults to .plb. For example, the following commands are equivalent:

wrap iname=/mydir/myfile
wrap iname=/mydir/myfile.sql oname=/mydir/myfile.plb

You can use the option oname to specify a different file name and extension:
wrap iname=/mydir/myfile oname=/yourdir/yourfile.out

Labels:

Obfuscation of Dynamically Generated PL/SQL Source Code

Obfuscation, or wrapping, of a PL/SQL unit is the process of hiding the PL/SQL
source code. Wrapping can be done with the wrap utility and DBMS_DDL subprograms. The wrap utility is run from the command line and processes an inputSQL file, such as a SQL*Plus installation script. The DBMS_DDL subprograms wrap a single PL/SQL unit, such as a single CREATE PROCEDURE command, that has been generated dynamically.

The advantages of obfuscating, or hiding, the source code of PL/SQL units with the wrap utility or wrap subprograms of the DBMS_DDL package are:

■ It is difficult for other developers to misuse your application, or business competitors to see your algorithms.

■ Your source code is not visible through the USER_SOURCE, ALL_SOURCE, or DBA_SOURCE data dictionary views.

■ SQL*Plus can process the obfuscated source files.

■ The Import and Export utilities accept wrapped files. You can back up or move wrapped procedures.


When obfuscating (wrapping) PL/SQL units note the following:

■ When wrapping a package or object type, wrap only the body, not the specification. This allows other developers see the information they need to use the package or type, but they cannot see its implementation.

■ PL/SQL source inside wrapped files cannot be edited. To change wrapped PL/SQL code, edit the original source file and wrap it again. You can either hold off on wrapping your code until it is ready for shipment to end-users, or include the wrapping operation as part of your build environment.

■ To be sure that all the important parts of your source code are obfuscated, view the wrapped file in a text editor before distributing it.

The following are limitations when obfuscating PL/SQL source code:


■ Although wrapping a compilation unit helps to hide the algorithm and makes reverse-engineering difficult, Oracle Corporation does not recommend it as a secure method for hiding passwords or table names. Obfuscating a PL/SQL unit prevents most users from examining the source code, but might not stop all attempts.

■ The wrapping does not obfuscate the source code for triggers. To hide the workings of a trigger, you can write a one-line trigger that calls a wrapped procedure.

■ Wrapping only detects tokenization errors, such as a runaway string, when obfuscating PL/SQL code. Wrapping does not detect syntax or semantic errors, such as tables or views that do not exist. Those errors are detected during PL/SQL compilation or when executing the output file in SQL*Plus.

■ Obfuscated PL/SQL program units cannot be imported into a database of a previous (lower) release. Wrapped compilation units are upward-compatible between Oracle releases, but are not downward-compatible. For example, you can load files processed by the V8.1.5 wrap utility into a V8.1.6 Oracle database, but you cannot load files processed by the V8.1.6 wrap utility into a V8.1.5 Oracle database.

Limitations of the wrap Utility:

■ Because the source code is parsed by the PL/SQL compiler, not by SQL*Plus, you cannot include substitution variables using the SQL*Plus DEFINE notation inside the PL/SQL code. You can use substitution variables in other SQL statements that are not obfuscated.

■ Most of the comments are removed in wrapped files.

Limitations of the DBMS_DDL wrap Function:

■ If you invoke DBMS_SQL.PARSE (when using an overload where the statement formal has datatype VARCHAR2A or VARCHAR2S for text which exceeds 32767 bytes) on the output of DBMS_DDL.WRAP, then you need to set the LFFLG parameter to FALSE. Otherwise DBMS_SQL.PARSE adds newlines to the wrapped unit which corrupts the unit.


Labels:

Tuesday, September 12, 2006

What is OSGi

OSGi = Open Service Gateway Initiative

Over the past few years it has specified a Java-based service platform that can be remotely managed. The core part of the specifications is a framework that defines an application life cycle model and a service registry. Based on this framework, a large number of OSGi Services have been defined: Log, Configuration management, Preferences, Http Service (runs servlets), XML parsing, Device Access, Package Admin, Permission Admin, Start Level, User Admin, IO Connector, Wire Admin, Jini, UPnP Exporter, Application Tracking, Signed Bundles, Declarative Services, Power Management, Device Management, Security Policies, Diagnostic/Monitoring and Framework Layering.

Labels: