Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to iterate nested lists in java

User_19BPUNov 29 2011 — edited Nov 30 2011
Hi,

How to iterate nested lists in java? This is an example

private List<CustomerVO> getCustomerList(){
List<CustomerVO> list1 = new ArrayList<CustomerVO>();
List<CustomerVO> list2 = new ArrayList<CustomerVO>();
List<CustomerVO> list3 = new ArrayList<CustomerVO>();

CustomerVO customerVO1 = new CustomerVO();
customerVO1.setFirstName("Micheal")
customerVO1.setLastName("Bob")
list1.add(customerVO1);


CustomerVO customerVO2 = new CustomerVO();
customerVO2.setFirstName("Frank")
customerVO2.setLastName("Duke")
list2.add(customerVO2);

list3.addAll(list1);
list3.addAll(list2);

}


main() {

List<CustomerVO> customerList = getCustomerList();

// How to iterate and get the respective details from both List1 and List2?

for(List<CustomerVO> : customerList) // LIST1 .. this is not working

for(CustomerVO custVO1: customerList){ //LIST1 VO

..

..
}


}

Here how to get the values from list1 and list2?

Thanks.

Comments

Charles Lamb
Hello Katta,

Are you using transactions, and if so, are you committing the transactions?

Regards,

Charles Lamb
527078
Hi Charles,

I'm using transactions & committing the transactions. Please go through the following code.

EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setTransactional(true);
envConfig.setAllowCreate(true);

DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(true);

Environment env = new Environment(dbHome, envConfig);
Transaction txn = null;
Database index, blocks;

try {
txn = env.beginTransaction(null, null);
index = env.openDatabase(txn, "__index__", dbConfig);
blocks = env.openDatabase(txn, "__blocks__", dbConfig);
} catch (DatabaseException e) {
if (txn != null)
{
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
txn = null;
}
try{
txn = env.beginTransaction(null, null);
indexDir = new JEDirectory(txn, index, blocks);
System.out.println("INDEXING INFO: Start Indexing updated content.");

IndexWriter indexWriter = new IndexWriter(indexDir,new StandardAnalyzer(), false);
indexWriter.setUseCompoundFile(false);
// configure the writer
indexWriter.setMergeFactor(1000);
indexWriter.setMaxMergeDocs(9999999);
indexWriter.setMaxBufferedDocs(1000);

// call the updateLuceneIndex method
updateLuceneIndex(indexWriter );

indexWriter.optimize();
indexWriter.close();

System.out.println("INDEXING INFO: Optimizing Index finished......");
} catch (IOException e)
{
txn.abort();
txn = null;
e.printStackTrace();
throw e;
} finally
{
if (txn != null)
txn.commit();

index.close();
blocks.close();
env.close();
}


Thanks,

Katta.
Charles Lamb
Hi Katta,

Can you please do a DbDump of the database before and after to see if anything has been added to it when you run this? You can do this with

java com.sleepycat.je.util.DbDump -h <envdir> -s <dbname>

Thanks.

Charles Lamb
527078
Hi Charles ,

Even if i run DbDump before and after lucene incremental update there is no change in the db size.I did the following way.

Step:

1. java com.sleepycat.je.util.DbDump -h D:\berkely\kindex -s __blocks__

2. java com.sleepycat.je.util.DbDump -h D:\berkely\kindex -s __index__

3. java com.tg.lucene.UpdateLuceneIndex D:\berkely\dbEnvHome update

4. java com.sleepycat.je.util.DbDump -h D:\berkely\kindex -s __blocks__

5.java com.sleepycat.je.util.DbDump -h D:\berkely\kindex -s __index__

Please can you explain what DbDump does. How it reduce the size. I indexed Country data(list of countries in my table), it took 360KB. After that in update, i deleted 2 countries data from that db, and optimized it. But the size grown to 770KB. While deleting data why it's size is growing instead of shrinking.


Thanks,

Katta.
Charles Lamb
Hi Katta, JE has a log based storage system, so deletes will write to the log. You may want to read the following FAQ's for more information on why you're seeing the log grow during deletes: http://forums.oracle.com/forums/thread.jspa?messageID=1411144&tstart=0#1411144.
527078
Hi,

The suggested link on JE log & FAQ taking me to the same page.Still i'm unable to get the solution for JE log grow during deletes.

Thanx,

Katta.
512799
Try this link:

http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html#14

Ron
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 28 2011
Added on Nov 29 2011
11 comments
3,965 views