Oracle8i SQLJ Developer's Guide and Reference Release 3 (8.1.7) Part Number A83723-01 |
Library | Service | Contents | Index

## Naming Requirements and Restrictions

There are four areas to consider in discussing naming requirements, naming restrictions, and reserved words:

- the Java namespace, including additional restrictions imposed by SQLJ on the naming of local variables and classes

- the SQLJ namespace

- the SQL namespace

- source file names

### Java Namespace--Local Variable and Class Naming Restrictions

The Java namespace applies to all your standard Java statements and declarations, including the naming of Java classes and local variables. All standard Java naming restrictions apply, and you should avoid use of Java reserved words.

In addition, SQLJ places minor restrictions on the naming of local variables and classes.

Note: Naming restrictions particular to host variables are discussed in "Restrictions on Host Expressions".

#### Local Variable Naming Restrictions

Some of the functionality of the SQLJ translator results in minor restrictions in naming local variables.

The SQLJ translator replaces each SQLJ executable statement with a statement block, where the SQLJ executable statement is of the standard syntax:

    #sql { SQL operation };

SQLJ may use temporary variable declarations within a generated statement block. The name of any such temporary variables will include the following prefix:

     __sJT_

(There are two underscores at the beginning and one at the end.)

The following declarations are examples of those that might occur in a SQLJ-generated statement block:

    int __sJT_index;
    Object __sJT_key;
    java.sql.PreparedStatement __sJT_stmt;

The string `__sJT_` is a reserved prefix for SQLJ-generated variable names. SQLJ programmers must not use this string as a prefix for the following:

- names of variables declared in blocks that include executable SQL statements

- names of parameters to methods that contain executable SQL statements

- names of fields in classes that contain executable SQL statements, or whose subclasses or enclosed classes contain executable SQL statements

#### Class Naming Restrictions

Be aware of the following minor restrictions in naming classes in SQLJ applications:

- You must not declare class names that may conflict with SQLJ internal classes. In particular, a top-level class cannot have a name of the following form if`a` is the name of an existing class in the SQLJ application:

  `a_SJb` (where`a` and`b` are legal Java identifiers)

  For example, if your application class is `Foo` in file `Foo.sqlj`, SQLJ generates a profile-keys class called `Foo_SJProfileKeys`. Do not declare a class name that conflicts with this.

- A class containing SQLJ executable statements must not have a name that is the same as the first component of the name of any package that includes a Java type used in the application. Examples of class names to avoid are `java`, `sqlj`, and `oracle` (case-sensitive). As another example, if your SQLJ statements use host variables whose type is `abc.def.MyClass`, then you cannot use `abc` as the name of the class that uses these host variables.

  To avoid this restriction, follow Java naming conventions recommending that package names start in lowercase and class names start in uppercase.

### SQLJ Namespace

The SQLJ namespace refers to `#sql` class declarations and the portion of `#sql` executable statements outside the curly braces.

Note: Restrictions particular to the naming of iterator columns are discussed in "Using Named Iterators".

Avoid using the following SQLJ reserved words as class names for declared connection context classes or iterator classes, in `with` or `implements` clauses, or in iterator column type declaration lists:

- `iterator`

- `context`

- `with`

For example, do not have an iterator class or instance called `iterator` or a connection context class or instance called `context`.

Note, however, that it is permissible to have a stored function return variable whose name is any of these words.

### SQL Namespace

The SQL namespace refers to the portion of a SQLJ executable statement inside the curly braces. Normal SQL naming restrictions apply here.

Note, however, that host expressions follow rules of the Java namespace, not the SQL namespace. This applies to the name of a host variable and to everything between the outer parentheses of a host expression.

### File Name Requirements and Restrictions

SQLJ source files have the `.sqlj` file name extension. If the source file declares a public class (maximum of one), then the base name of the file must match the name of this class (case-sensitive). If the source file does not declare a public class, then the file name must still be a legal Java identifier, and it is recommended that the file name match the name of the first defined class.

For example, if you define the public class `MySource` in your source file, then your file name must be:

    MySource.sqlj

Note: These file naming requirements follow the Java Language Specification and are not SQLJ-specific. These requirements do not directly apply in the Oracle8i server, but it is still advisable to adhere to them.

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index