-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: MiddlegenPopulator (slowness, Out of Memory)
PostPosted: Fri Aug 20, 2004 4:58 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I analyze MiddlegenPopulator - it is slow when I set any table and I have big schema

Problem is in function markFksToUnwantedTables

Function visit all tables and seek foreign key with getExportedKeys,
but DatabaseMetadata have getImportedKeys, too

I change function to :

private void markFksToUnwantedTables(Map wantedTables) throws MiddlegenException {
try {
for (Iterator tableIterator = _middlegen.getTables().iterator(); tableIterator.hasNext(); ) {
DbTable pkTable = (DbTable)tableIterator.next();
ResultSet importedKeyRs = null;
if (pkTable.getTableElement().getOwnerSynonymName() != null) {
importedKeyRs = getMetaData().getImportedKeys(_catalog, pkTable.getTableElement().getOwnerSynonymName(), pkTable.getSqlName());
}
else {
importedKeyRs = getMetaData().getImportedKeys(_catalog, _schema, pkTable.getSqlName());
}
while (importedKeyRs.next()) {
String fkTableName = importedKeyRs.getString("FKTABLE_NAME");
String fkColumnName = importedKeyRs.getString("FKCOLUMN_NAME");
// Mark the fk field as an fk anyway. This will be useful for column sorting for example
// if _middlegen.containsTable ... is unnecessary, it is always true
if (_middlegen.containsTable(fkTableName)) {
DbTable fkTable = _middlegen.getTable(fkTableName);
DbColumn fkColumn = (DbColumn)fkTable.getColumn(fkColumnName);
fkColumn.setFk(true);
}
}
}
} catch (SQLException e) {
String databaseStructure = getDatabaseStructure();
_log.error(e.getMessage(), e);
throw new MiddlegenException("Couldn't get list of tables from database. Probably a JDBC driver problem." + databaseStructure);
}
}


Now, my build execute in seconds, but before this it be > 5 minutes and throw OutOfMemory exception
sometimes

I don't sure that is it my logic correct

regards


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 2:37 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I test logic with my schema (400+ tables, 600+ fk keys)

There is little error in previous method.
Method is correct now and results is same with new and od one
- with old method gui display is 6 minutes, with new 45 seconds
- new method's memory request is smaller and I don't need ANT_OPTS clause now

It is correct method ;

private void markFksToUnwantedTables(Map wantedTables) throws MiddlegenException {
try {
for (Iterator tableIterator = _middlegen.getTables().iterator(); tableIterator.hasNext(); ) {
DbTable pkTable = (DbTable)tableIterator.next();
ResultSet importedKeyRs = null;
if (pkTable.getTableElement().getOwnerSynonymName() != null) {
importedKeyRs = getMetaData().getImportedKeys(_catalog, pkTable.getTableElement().getOwnerSynonymName(), pkTable.getSqlName());
}
else {
importedKeyRs = getMetaData().getImportedKeys(_catalog, _schema, pkTable.getSqlName());
}
while (importedKeyRs.next()) {
String fkTableName = importedKeyRs.getString("FKTABLE_NAME");
String pkTableName = importedKeyRs.getString("PKTABLE_NAME");
String fkColumnName = importedKeyRs.getString("FKCOLUMN_NAME");
// Mark the fk field as an fk anyway. This will be useful for column sorting for example
if (!_middlegen.containsTable(pkTableName)) {
DbTable fkTable = _middlegen.getTable(fkTableName);
DbColumn fkColumn = (DbColumn)fkTable.getColumn(fkColumnName);
fkColumn.setFk(true);
System.out.println("nema greske" + fkTableName + " " + fkColumnName + " " + pkTableName);
}

}
}
} catch (SQLException e) {
// schemaRs and catalogRs are only used for error reporting if we get an exception
String databaseStructure = getDatabaseStructure();
_log.error(e.getMessage(), e);
throw new MiddlegenException("Couldn't get list of tables from database. Probably a JDBC driver problem." + databaseStructure);
}
}

regards


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 28, 2004 6:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Thanks - I'll have a look at it.
Maybe sending a patch to me david@hibernate.org is better still.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 28, 2004 9:36 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
David,
It is only added function - called from populate instead same function withou parameter
I can't send patch, unfortunatly - I am set middlegen-hibernate like eclipse project and make yet another patch in MiddlegenPopulator and format it in eclipse (patch is new MiddlegenPopulator)

I find yet problem - when exists synonym on table in same schema

I can send You complete new MiddlegenPopulator

regards


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 4:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
OK that would be cool.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 5:10 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
David,
I send you my complete source for middlegen


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 7:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have not had a chance to look at it yet but will do ASAP.
Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.