File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes realtional transactions and java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "realtional transactions and java" Watch "realtional transactions and java" New topic
Author

realtional transactions and java

Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
hi everybody, im stuck with this problem i found in my database management book, i dont actually have a clue about it. is says i can use C++ or java but ive no idea on C++ so thought id stick to java. anyway the question is as follows:
Given transactions T1, T2 and T3

Transaction T1 Transaction T2 Transaction T3

read_item(X); read_item(Z); read_item(Y);
write_item(X); read_item(Z); read_item(Y);
read_item(Y); write_item(Y); write_item(Y);
write_item(Y); read_item(X); write_item(Z);
write_item(X);

1) Write a program to create all possible serial schedules for T1, T2 and T3.

After the program is written there are a series of questions to answer and more programs to write, but can anybody give me a solution to get me going???
thanks in advance
Chris
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
please note it did not align properly in the message, but the
write_item(X); in Transaction1 should be at the bottom of Transaction2
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
You may create a class called Transaction having non static methods read_item and Write_item.
Then create three instances of Transaction t1, t2 & t3.
In another method called permutations find all the permutations by filtering out non logical series.

1) Write a program to create all possible serial schedules for T1, T2 and T3.

You can have an array or another class to represent schedule
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
hi all,
Been working on this same problem for a while now. iv got some code but it obviously needs tweaking.
Again, any help is v.much appreciated.
So far i have:

public class getNext()
{
int t1 = N - 1;
while (Value[t1-1] >= Value[t1]) i = i-1;

int t2 = N;
while (Value[t2-1] <= Value[t1-1]) j = j-1;

int t3 = N + 1;
while (Value[t3-1] <= Value[t1-1) t3 = t3-1;

swap(t1-1, t2-1, t3-1);

t1++; t2 = N;

while (t1 < t2)
{
swap(t1-1, t2-1);
t1++;
t2--;
}
}
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
Ok, so far ive got that first question done but now the second one wants me to create all possible schedules, not serial schedules. Now i need a do while loop instead of a while loop this time, so im guessing its gona be:
do
{


}
while(getNext);

Anybody help out with what goes in the do part???

Code is as follows:

class Trans1
{
private static int [] Value = {1,2,3};
private static int T = 3;
public Trans T1 = new Trans();
public Trans T2 = new Trans();
public Trans T3 = new Trans();

//---Methods---//

private static void swap(int i, int j)
{
int temp;

temp = Value[i];
Value[i] = Value[j];
Value[j] = temp;
}
private static boolean getNext()
{
int i = T - 1;

while (Value[i-1] >= Value[i])
{
i = i-1;
if (i == 0)
return false;
}

int j = T;


while (Value[j-1] <= Value[i-1]) j = j-1;


// swap values at positions (i-1) and (j-1)
swap(i-1, j-1);


i++;
j = T;

while (i < j)
{
swap (i - 1, j-1);
i++;
j--;
}
return true;
}
public static void main (String[] args)
{int i;
while (getNext())
{
for (i=0; i< T;
i++)
{
System.out.print(Value[i]);
}
System.out.println("");
}
}
}
 
Don't get me started about those stupid light bulbs.
 
subject: realtional transactions and java