db.prev()

Syntax
long db.prev( long table_id [, long lock] )


Description
This reads the previous record from a specified table. It uses the current index to search the table. If there is no current record, the function returns an error message.


Arguments
table_id The table ID, as returned by db.bind().
lock By default, the record is not locked before reading. Use this optional argument to apply a lock to the record. The possible values are:
DB.LOCK lock record for update
DB.DELAYED.LOCK apply a delayed lock to the record; the lock is 
applied immediately before the update action


Return values
    0 success
<>0 error


Related Post:

db.permission()

Syntax
long db.permission( long table_id [, string field(18) [, ref string buffer(.)]] )


Description
Use this to check the access permissions that a user has to a specified table or table field. 


Arguments
table_id The table ID, as returned by db.bind().
field To check the permissions for a particular field, enter the field name here. If you do not specify a field here, or if you specify an empty string, the function returns the permissions for the table.
buffer A user's permissions for a table or table field can depend on the contents of a record. In this case, you must specify the record buffer of the table in the buffer argument. The function returns the user's permissions for the record in the record buffer. If a user's permissions depend on the contents of a record, and you do not specify the buffer argument, the function returns PERM.UNKNOWN.


Return values
The function returns a long that indicates the permissions that the user has on the table or on a specified field of that table. The return value consists of one of, or a combination of, the following codes:
NO.PERMISSION 1
PERM.READ 2
PERM.MODIFY 4
PERM.WRITE 8
PERM.DELETE 16
NO.RESTRICTION (PERM.READ+PERM.MODIFY+PERM.WRITE+PERM.DELETE)
PERM.UNKNOWN 32
So, if the value 6 is returned, the user is permitted to both read and modify the specified table or table field.


Related Post:

db.set.to.default()

Syntax
long db.set.to.default( long table_id )


Description
This sets bound variables in the program script to the default values defined in the data dictionary.


Arguments
table_id The table ID, as returned by db.bind().


Return values
    0 success
<>0 error


Related Post:

db.retry.point()

Syntax
void db.retry.point()


Description
This sets a retry point for the current transaction. The program returns to this point if an error occurs during the transaction; the transaction is then retried. When you include a retry point for a transaction, you must set it before the start of the transaction.


Related Post:

on.main.table()

Syntax
void on.main.table( function_name [, ...] )

Description
This copies the contents current record of the main table to the record buffer of that table, saves the record, and executes the specified function. After that the saved record buffer is restored. This enables you to perform actions on the record contents without affecting the values in the table.

Arguments
function_name The name of the function that must be executed. The function must be of type void.
. . .                         Use these optional arguments to pass one or more arguments to the function.

Context
4GL library function
You can use this function only in 4GL scripts. You cannot use it in the before.program section because the main table has not yet been defined at this point. The function is not relevant to programs of type 4.

Example
| Suppose you have a table to which you can add numbers only
| if a certain value is present in the main table


declaration:
long go_ahead


field.pctst999.number:
check.input:
on.main.table( check_number, 5 )
if not go_ahead then
set.input.error("pctst0003", 5)    |"Number %d not present"
endif


functions:
function void check_number( long number )
{
select pctst999.*
from pctst999
where pctst999.number = :number
as set with 1 rows


selectdo
go_ahead = TRUE
selectempty
go_ahead = FALSE
endselect
return


}


Related Post:

Java - States of Thread

The following diagram illustrates the various states that a Java thread can be in at any point during its life. It also illustrates which method calls cause a transition to another state. This diagram is not a complete finite state diagram, but rather an overview of the more interesting and common aspect of a thread's life. The remainder of this page discusses a Thread's life cycle in terms of its state.


New Thread

The following statement creates a new thread but does not start it, thereby leaving the thread in the "New Thread" state.

Thread myThread = new MyThreadClass();

When a thread is in the "New Thread" state, it is merely an empty Thread object. No system resources have been allocated for it yet. Thus when a thread is in this state, you can only start the thread or stop it. Calling any method besides start() or stop() when a thread is in this state makes no sense and causes an IllegalThreadStateException.

Runnable

Now consider these two lines of code:

Thread myThread = new MyThreadClass();
myThread.start();

The start() method creates the system resources necessary to run the thread, schedules the thread to run, and calls the thread's run() method. At this point the thread is in the "Runnable" state. This state is called "Runnable" rather than "Running" because the thread might not actually be running when it is in this state. Many computers have a single processor, making it impossible to run all "Runnable" threads at the same time. So, the Java runtime system must implement a scheduling scheme that shares the processor between all "Runnable" threads. (See Thread Priority for more information about scheduling.) However, for most purposes you can think of the "Runnable" state as simply "Running". When a thread is running--it's "Runnable" and is the current thread--the instructions in its run() method are executing sequentially.

Not Runnable

A thread enters the "Not Runnable" state when one of these four events occurs:
  • Someone invokes its sleep() method.
  • Someone invokes its suspend() method.
  • The thread uses its wait() method to wait on a condition variable.
  • The thread is blocking on I/O.
For example, the bold line in the following code snippet puts the current thread to sleep for 10 seconds (10,000 milliseconds):

try {
Thread.sleep(10000);
} catch (InterruptedException e){
}

During the 10 seconds that myThread is asleep, even if the processor becomes available myThread does not run. After the 10 seconds are up, myThread becomes "Runnable" again and, if the processor becomes available, runs.

For each of the entrances into the "Not Runnable" state shown in the figure, there is a specific and distinct escape route that returns the thread to the "Runnable" state. An escape route only works for its corresponding entrance. For example, if a thread has been put to sleep, then the specified number of milliseconds must elapse before the thread becomes "Runnable" again. Calling resume() on a sleeping thread has no effect.

The following indicates the escape route for every entrance into the "Not Runnable" state.
  • If a thread has been put to sleep, then the specified number of milliseconds must elapse.
  • If a thread has been suspended, then someone must call its resume() method.
  • If a thread is waiting on a condition variable, whatever object owns the variable must relinquish it by calling either notify() or notifyAll().
  • If a thread is blocked on I/O, then the I/O must complete.
Dead
A thread can die in two ways: either from natural causes, or by being killed (stopped). A thread dies naturally when its run() method exits normally. For example, the while loop in this method is a finite loop--it will iterate 100 times and then exit.

public void run() {
int i = 0;
while (i < 100) {
i++;
System.out.println("i = " + i);
}
}

A thread with this run() method will die naturally after the loop and the run() method completes.
You can also kill a thread at any time by calling its stop() method. The following code snippet creates and starts myThread then puts the current thread to sleep for 10 seconds. When the current thread wakes up, the bold line in the code segment kills myThread.

Thread myThread = new MyThreadClass();
myThread.start();
try {
Thread.sleep(10000);
} catch (InterruptedException e){
}
myThread.stop();

The stop() method throws a ThreadDeath object at the thread to kill it. Thus when a thread is killed in this manner it dies asynchronously. The thread will die when it actually receives the ThreadDeath exception.

The stop() method causes a sudden termination of a Thread's run() method. If the run() method performs critical or sensitive calculations, stop() may leave the program in an inconsistent or awkward state. Normally, you should not call Thread's stop() method but arrange for a gentler termination such as setting a flag to indicate to the run() method that it should exit.

IllegalThreadStateException

The runtime system throws an IllegalThreadStateException when you call a method on a thread and that thread's state does not allow for that method call. For example, IllegalThreadStateException is thrown when you invoke suspend() on a thread that is not "Runnable".

As shown in the various examples of threads so far in this lesson, when you call a thread method that can throw an exception, you must either catch and handle the exception, or specify that the calling method throws the uncaught exception.

The isAlive() Method

A final word about thread state: the programming interface for the Thread class includes a method called is Alive(). The isAlive() method returns true if the thread has been started and not stopped. Thus, if the isAlive() method returns false you know that the thread is either a "New Thread" or "Dead". If the isAlive() method returns true, you know that the thread is either "Runnable" or "Not Runnable". You cannot differentiate between a "New Thread" and a "Dead" thread; nor can you differentiate between a "Runnable" thread and a "Not Runnable" thread.

db.create.table()

Syntax
long db.create.table( table table_name [, long comp_nr] )


Description
This creates a new database table. 


Arguments
table_name The name for the new table.
comp_nr This optional argument specifies a company number for the table. The default company is the company of the user.


Return values
    0 success
<>0 error


Related Post:

db.unbind()

Syntax
long db.unbind( long table_id )


Description
This deletes the specified table pointer. 


Arguments
table_id The table pointer, as returned by db.bind().


Return values
    0 success
<>0 error


Related Post:

Thread methods in Java

On the previous post, we looked at how to create a thread in Java, via the Runnable and Thread objects. We mentioned that the Thread class provides control over threads. So on this page, we take a high-level look at the most important methods on this class.

Thread.sleep()

We actually saw a sneak preview of Thread.sleep() in our Java threading introduction. This static method asks the system to put the current thread to sleep for (approximately) the specified amount of time, effectively allowing us to implement a "pause". A thread can be interrupted from its sleep.
For more details, see: Thread.sleep() (separate page).

interrupt()

As mentioned, you can call a Thread object's interrupt() method to interrupt the corresponding thread if it is sleeping or waiting. The corresponding thread will "wake up" with an IOException at some point in the future. See thread interruption for more details.

setPriority() / getPriority()

Sets and queries some platform-specific priority assignment of the given thread. When calculating a priority value, it's good practice to always do so in relation to the constants Thread.MIN_PRIORITY, Thread.NORM_PRIORITY and Thread.MAX_PRIORITY. In practice, values go from 1 to 10, and map on to some machine-specific range of values: nice values in the case of Linux, and local thread priorities in the case of Windows. These are generally the range of values of "normal" user threads, and the OS will actually still run other threads beyond these values (so, for example, you can't preempt the mouse pointer thread by setting a thread to MAX_PRIORITY!).
Three main issues with thread priorities are that:
  • they don't always do what you might intuitively think they do;
  • their behaviour depends on the platform and Java version: e.g. in Linux, priorities don't work at all in Hotspot before Java 6, and the mapping of Java to OS priorities changed under Windows between Java 5 and Java 6;
  • in trying to use them for some purpose, you may actually interfere with more sensible scheduling decisions that the OS would have made anyway to achieve your purpose.
For more information, see the section on thread scheduling and the discussion on thread priorities, where the behaviour on different platforms is compared.

join()

The join() method is called on the Thread object representing enother thread. It tells the current thread to wait for the other thread to complete. To wait for multiple threads at a time, you can use a CountDownLatch.

Thread.yield()

This method effectively tells the system that the current thread is "willing to relinquish the CPU". What it actually does is quite system-dependent. For more details, see: Thread.yield() (separate page).

setName() / getName()

Threads have a name attached to them. By default, Java will attach a fairly dull name such as Thread-12. But for debugging purposes you might want to attach a more meaningful name such as Animation Thread, WorkerThread-10 etc. (Some of the variants of the Thread constructor actually allow you to pass in a name from the start, but you can always change it later.)

Other thread functions

There are occasionally other things that you may wish to do with a thread that don't correspond to a single method. In particular, there is no safe method to stop a thread, and instead you should simply let the corresponding run() method exit.

Which method is more preferable to create a thread?


When creating threads, there are two reasons why implementing the Runnable interface may be preferable to extending the Thread class:
  • Extending the Thread class means that the subclass cannot extend any other class, whereas a class implementing the Runnable interface has this option.
  • A class might only be interested in being runnable, and therefore, inheriting the full overhead of the Thread class would be excessive.

Creation of a thread


A thread can be created in two ways
a) By implementing the Runnable interface. The Runnable interface consists of only one method - the run method. The run method has a prototype of
public void run();
b) By extending the class Thread.

1) Implementing the Runnable Interface

The Runnable Interface Signature

public interface Runnable {

void run();

}

One way to create a thread in java is to implement the Runnable Interface and then instantiate an object of the class. We need to override the run() method into our class which is the only method that needs to be implemented. The run() method contains the logic of the thread.

The procedure for creating threads based on the Runnable interface is as follows:

1. A class implements the Runnable interface, providing the run() method that will be executed by the thread. An object of this class is a Runnable object.

2. An object of Thread class is created by passing a Runnable object as argument to the Thread constructor. The Thread object now has a Runnable object that implements the run() method.

3. The start() method is invoked on the Thread object created in the previous step. The start() method returns immediately after a thread has been spawned.

4. The thread ends when the run() method ends, either by normal completion or by throwing an uncaught exception.

Below is a program that illustrates instantiation and running of threads using the runnable interface instead of extending the Thread class. To start the thread you need to invoke the start() method on your object.

public class ThreadExample2 implements Runnable {
public void run() {
.../* Code which gets executed when
thread gets executed. */
}
public static void main(String args[]) {
ThreadExample2 Tt = new ThreadExample2();
Thread t = new Thread(Tt);
t.start();
}
}

Example - Creating thread by implementing Runnable


2) Extending Thread Class

The procedure for creating threads based on extending the Thread is as follows:

1. A class extending the Thread class overrides the run() method from the Thread class to define the code executed by the thread.

2. This subclass may call a Thread constructor explicitly in its constructors to initialize the thread, using the super() call.

3. The start() method inherited from the Thread class is invoked on the object of the class to make the thread eligible for running.

Below is a program that illustrates instantiation and running of threads by extending the Thread class instead of implementing the Runnable interface. To start the thread you need to invoke the start() method on your object.

public class ThreadExample extends Thread {
public void run() {
System.out.println("Thread started");
}
public static void main(String args[]) {
ThreadExample t = new ThreadExample();
t.start();
}
}

Example - Creation of Thread by extending the
Thread class.

Related Post:-

Threads in Java

Threads

Multithreading refers to two or more tasks executing concurrently within a single program. A thread is an independent path of execution within a program. Many threads can run concurrently within a program. Every thread in Java is created and controlled by the java.lang.Thread class. A Java program can have many threads, and these threads can run concurrently, either asynchronously or synchronously.


Thread Constructor Summary
Thread()
Allocates a new Thread object. Thread(Runnable target)
Allocates a new Thread object. Thread(Runnable target, String name)
Allocates a new Thread object.
Thread(String name)
Allocates a new Thread object. Thread(ThreadGroup group, Runnable target)
Allocates a new Thread object. Thread(ThreadGroup group, Runnable target, String name)
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group. Thread(ThreadGroup group, Runnable target, String name, long stackSize)
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, and has the specified stack size.
Thread(ThreadGroup group, String name)
Allocates a new Thread object.

Yahoo,facebook,flicker can read your personal data

Top social networking sites have accepted that they can read user's personal data through their android phones.
There are many phone applications which give authority to their developers to go through user's personal data like: text messages,images etc etc. Now a days it has become a major problem because internet is an inevitable part of our life, we can't even think about our life without internet because for small small work we use internet and this kind of problem will have severe effect on users.Many of People do not know about this thing when they agree to terms and conditions, at the same that actually give authority to the developers to go through their personal data.In 2007,  Apple founder Late Mr. Steve Jobs spoke of the dangers of officious apps. He warned that many want to take a lot of your personal data and suck it up.

db.drop.table()

Syntax
long db.drop.table( long table_id [, long ignore_refs] [, long comp_nr] )


Description
This deletes a specified table. Data and indices associated with the table are also deleted. Reference counters are automatically updated. 


Arguments
table_id The table ID, as returned by db.bind().
ignore_refs If you set this optional argument to DB.IGNORE.ALL.REFS, the data is deleted regardless of whether it is referenced by other tables.
comp_nr This optional argument specifies a company number for the table. The default company is the company of the user.


Return values
     0 success
<>0 error


Related Post:

db.delete()

Syntax
long db.delete( long table_id [, long mode [, long eflag]] )


Description
This deletes the current record. The record pointer is not changed, so the current record is undefined after the record has been deleted.


Arguments
table_id The table ID, as returned by db.bind().
mode Set this to DB.RETRY if retry points and the SELECT FOR UPDATE statement are being used. The actual database action is postponed until the transaction is committed.
eflag For some errors, it is possible to indicate the action the system must perform when the error occurs.


Return Value
   0 success
 >0 error


Related Post:

db.eq()

Syntax
long db.eq( long table_id [, long lock] )


Description
This reads from a specified table the record whose key value equals a certain predefined value. Before calling db.eq(), you must assign the required value to the key field. For example, the following code retrieves the item with item number 001 from the items table:


tiitm001.item = "001"
db.eq( ttiitm001 )


Arguments
table_id The table ID, as returned by db.bind().
lock By default, the record is not locked before reading. Use this optional argument to apply a lock to the record. The possible values are: 
  • DB.LOCK lock record for update
  • DB.DELAYED.LOCK apply a delayed lock to the record; the lock is                                                        applied immediately before the update action
Return values
     0 success
<>0 error


Related Post:

db.update()

Syntax
long db.update( long table_id [, long mode [, long eflag]] ) 


Description
This rewrites the current record. When updating a record with this function, you are permitted to update the primary key of the record.


Arguments
table_id      The table ID, as returned by db.bind().
mode      This has two possible values:
  • DB.RETRY Set this value if retry points and the SELECT FOR UPDATE statement are being used. The actual database action is postponed until the transaction is committed.
  • DB.DELAYED.LOCK This option is available only for records for which a delayed lock has been set with db.eq().
eflag    For some errors, it is possible to indicate the action the system must perform when the error occurs.

Return Value

  0 success
 >0 error


Related Post:

db.insert()

Syntax
long db.insert( long table_id [, long mode [, long eflag]] ) 

Description
This adds a new record to a specified table. The record pointer does not change.

Arguments
table_id The table ID, as returned by db.bind().
mode Set this to DB.RETRY if retry points and the SELECT FOR UPDATE statement are being used. The actual database action is postponed until the transaction is committed.
eflag For some errors, it is possible to indicate the action the system must perform when the error occurs. 


Return Value

    0 success
 >0 error

Related Post:

What are the steps performed while loading a Java class?


Ans: Phases of class loading

The are three phases of concrete class loading: physical loading, linking, and initializing.


1) In in first phase of physical loading required class file will be searched in specified classpaths. If the file is found it is read and the bytecode is loaded. This process gives a basic memory structure to the class object, such concepts like methods, fields, and other referenced classes are not known at this stage.

2) Linking can be broken down into three main stages, because it is complex phase:
1.Bytecode verification through class loader, which executes a number of checks on the bytecodes.
2.Class preparation. This stage prepares the necessary data structures that represent fields, methods and implemented interfaces that are defined within the class.
3.Resolving of all the other classes referenced by a particular class. The classes can be referenced in a number of ways:
Superclasses
- Interfaces
- Field types
- Types in method signatures
- Types of local variables used in methods

3) During the initializing phase any static initializers contained within a class are executed so that, static fields are initialized to their default values.
It is interesting, that class loading can be performed in a lazy manner and therefore some parts of the class loading process may be done on first use of the class rather than at load time.

Why there are two Date classes; one in java.util package and another in Java.sql?


Ans:From the JavaDoc of java.sql.Date: 
A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.


Explanation: A java.util.Date represents date and time of day, a java.sql.Date only represents a date (the complement of java.sql.Date is java.sql.Time, which only represents a time of day, but also extends java.util.Date).  

How is it possible for two String oblects with identical values not to be equal under the == operator?


Ans:The = = operator compares two objects to determine if they are the same object in memory i.e. present in the same memory location. It is possible for two String objects to have the same value, but located in different areas of memory.
= = compares references while .equals compares contents. The method public boolean equals(Object obj) is provided by the Object class and can be overridden. The default implementation returns true only if the object is compared with itself, which is equivalent to the equality operator = = being used to compare aliases to the object. String, BitSet, Date, and File override the equals() method. For two String objects, value equality means that they contain the same character sequence. For the Wrapper classes, value equality means that the primitive values are equal.
public class EqualsTest {


        public static void main(String[] args) {


                String s1 = “abc”;
                String s2 = s1;
                String s5 = “abc”;
                String s3 = new String(”abc”);
                String s4 = new String(”abc”);
                System.out.println(”== comparison : ” + (s1 == s5));
                System.out.println(”== comparison : ” + (s1 == s2));
                System.out.println(”Using equals method : ” + s1.equals(s2));
                System.out.println(”== comparison : ” + s3 == s4);
                System.out.println(”Using equals method : ” + s3.equals(s4));
        }
}
Output
== comparison : true
== comparison : true
Using equals method : true
false
Using equals method : true

db.bind()

Syntax
long db.bind( string table_name(9) [, ref string buffer(.) [, long comp_nr]] )


Description
This creates a pointer to a specified table. It returns a table ID that you use in other database calls to identify the table. The pointer is to a table with a particular company number and record buffer. You can create additional pointers to the same table by calling the function with a different company number and/or record buffer.


Arguments
table_name The table name.
buffer This optional argument specifies the record buffer to be used for the table. If you omit this argument, or if you specify an empty string, the default record buffer is used (that is, rcd.tppmmmxxx). 
comp_nr This optional argument specifies a company number for the table. The default company is the company of the user. If you include this argument, you must also include the buffer argument. So, if you want to specify a company other than the default company but want to use the default record buffer, specify the default buffer or an empty string in the buffer argument.


Note
When you create more than one pointer to a table, you must use a different record buffer for each one.

Related Post:

activate.search()

Syntax
void activate.search()

Description
This forces a random search action on the main table. You call the function immediately after input to a field during insertion of a new record (standard command ADD.SET or DUPL.OCCUR) or during MODIFY.SET (if the predefined variable modify.prim.key is set to TRUE).
When a new record is being added to the database, the standard program normally executes a search action in the main table after input to the field(s) of the primary index. If the key values entered belong to an existing record in the main table, the standard program displays all the fields of that record and stops adding the new record. Otherwise, the user must fill the remaining fields; then the record is added to the main table.

In some applications, not all parts of the primary index appear on the form. In this case, the search operation in the main table occurs when the user leaves the last input field of the occurrence. You can force an earlier search action by calling activate.search() after input to any field of the occurrence.

Related Post:

abort.transaction()

Syntax
long abort.transaction()


Description
This cancels the current database transaction. No changes are stored in the database. 
To commit a transaction and store changes made in the database, use commit.transaction() instead.


Return values
    0 success
<>0 error


Related Post:
  • Database Operations

commit.transaction()

Syntax
long commit.transaction()


Description
This ends the current transaction. All changes made during the transaction are stored in the database.
To cancel a transaction, use abort.transaction() instead.


Return values
     0 success
<>0 error


Related Post:

Database Operations

Use these functions for handling database input and output.


New features in BaanERP
In BaanERP, the functions db.curr(), db.first(), db.last(), db.next(), db.prev(),db.gt(), db.ge(), db.lt() and db.le() are implemented internally as SELECT statements. They are supported for backward compatibility only. In new applications, use queries instead.
In BaanERP, certain 4GL functions have Data Access Layer (DAL) equivalents. The following table lists these functions and their DAL equivalents. 


4GL function                                              DAL function
on.main.table()                                            with.object.set.do()
on.old.occ()                                                 with.old.object.values.do()
set.input.error()                                          dal.set.error.message()
                                                                    return(DALHOOKERROR)
skip.io()                                                      dal.set.error.message()
                                                                    return(DALHOOKERROR)
abort.io()                                                    dal.set.error.message()
                                                                    return(DALHOOKERROR)
db.update()                                               dal.update()
db.delete()                                                dal.destroy()
db.insert()                                                 dal.new()
If a DAL exists for a particular table, it is preferable to use the DAL functions. The older functions access the database directly. When you make changes to the database with these functions, logic integrity checks programmed in the DAL are not executed. When you make changes to the database with the DAL functions, the relevant DAL hooks are executed automatically. This ensures the logic integrity of the database. 


Table names and declarations
The naming syntax for tables, record buffers, and fields is:
 table tppmmmxxx                | table declaration
 rcd.tppmmmxxx                  | record buffer of table
 ppmmmxxx.ffffffff                 | logical field of table


where t stands for table, pp is the package code, mmm is the module code, xxx is the table number, and ffffffff  is a field name.
If a table is used in a script, it must be declared with the statement:
table tppmmmxxx
Declaration of a table implies declaration of all its fields and its record buffer. These do not need to be declared separately.
There are no functions for opening or closing a table. A table is automatically opened the first time it is accessed. It is automatically closed when the program ends.

List of Database operations:

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More