Java class size in PermGen space

There is a lot of Q&A about the size of a Java object, which is easy enough to understand. But I'm interested in knowing the size of the Java class in the PermGen space.

The reason I am surprised is because I am writing a code generator generating many classes. Essentially, I generate two classes for each table / view in the database. Now I also want to model foreign key relationships. Instead of supporting a complex serializable object structure (think of a table with a unique key referenced by several foreign keys belonging to other tables that have different foreign keys, etc.), I would prefer to create one class for UNIQUE KEY and one class behind FOREIGN KEY .

Here are my questions:

  • How much overhead for class loader and PermGen space will I create with this?
  • Is there a difference between public , static and private classes as member classes?
  • Do you see a better way to generate foreign key information in the source code?
+6
source share
1 answer

I found another solution without spending as much memory as generating one class per KEY . I am generating one class that looks something like this:

 public class References { // First, initialise all unique keys public static final UniqueKey<TAuthorRecord> SysPk_14655 = createUniqueKey(TAuthor.T_AUTHOR, TAuthor.ID); // Then initialise all foreign keys public static final Reference<TBookRecord, TAuthorRecord> SysFk_14666 = createReference(SysPk_14655, TBook.T_BOOK, TBook.AUTHOR_ID); public static final Reference<TBookRecord, TAuthorRecord> SysFk_14667 = createReference(SysPk_14655, TBook.T_BOOK, TBook.CO_AUTHOR_ID); // Factory method for unique keys protected static <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, TableField<R, ?>... fields) { // Factory method for foreign keys referencing unique keys protected static <R extends Record, U extends Record> Reference<R, U> createReference(UniqueKey<U> key, Table<R> table, TableField<R, ?>... fields) { } 

Actual tables from the generated table classes can reference and use the above keys. I looked at the JPA annotations suggested by BobG in one of his comments. But I did not find them very useful for description:

  • Multi-field keys ( @IdClass needs a type as a parameter, and I want to avoid this type)
  • Multi-field links (how to do this?)
  • Multiple links from one table to another using different keys
  • Unique keys that share many properties with a primary key.

Some comments mention why I should create such a generator, because there are many installed frameworks. I am doing this for http://www.jooq.org . And I feel that jOOQ fills the gap in today's database abstraction capabilities.

+1
source

Source: https://habr.com/ru/post/887134/


All Articles