DEV Community

Salad Lam
Salad Lam

Posted on

Quarkus notes (2)

About quarkus-app/quarkus/transformed-bytecode.jar file

Java reflection is not well supported on native executable code generation. But some libraries such as JPA are highly dependent on Java reflection. So some classes will be decompiled, added codes which were originally done by Java reflection, and then compiled and packed into transformed-bytecode.jar.

Following is the original code of a JPA entity.

@Entity
@Table(name = "users")
@UserDefinition
public class User {

    @Id
    @Username
    private String username;
    @Column(nullable = false)
    @Password
    private String password;
    @Column
    private Integer enabled;
    @ManyToMany
    @JoinTable(name = "user_authority", joinColumns = @JoinColumn(name = "username"), inverseJoinColumns = @JoinColumn(name = "authority_id"))
    private Set<Authority> authorities;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getEnabled() {
        return enabled;
    }

    public void setEnabled(Integer enabled) {
        this.enabled = enabled;
    }

    public Set<Authority> getAuthorities() {
        return authorities;
    }

    public void setAuthorities(Set<Authority> authorities) {
        this.authorities = authorities;
    }

    @Roles
    public String authorities() {
        return StringUtils.join(authorities, ",");
    }

}
Enter fullscreen mode Exit fullscreen mode

Code is transformed as following.

@Entity
@Table(
    name = "users"
)
@UserDefinition
@EnhancementInfo(
    version = "6.6.4.Final"
)
public class User implements ManagedEntity, PersistentAttributeInterceptable, ExtendedSelfDirtinessTracker {
    @Id
    @Username
    String username;
    @Column(
        nullable = false
    )
    @Password
    String password;
    @Column
    Integer enabled;
    @ManyToMany
    @JoinTable(
        name = "user_authority",
        joinColumns = {@JoinColumn(
    name = "username"
)},
        inverseJoinColumns = {@JoinColumn(
    name = "authority_id"
)}
    )
    Set<Authority> authorities;
    @Transient
    private transient EntityEntry $$_hibernate_entityEntryHolder;
    @Transient
    private transient ManagedEntity $$_hibernate_previousManagedEntity;
    @Transient
    private transient ManagedEntity $$_hibernate_nextManagedEntity;
    @Transient
    private transient boolean $$_hibernate_useTracker;
    @Transient
    private transient PersistentAttributeInterceptor $$_hibernate_attributeInterceptor;
    @Transient
    private transient DirtyTracker $$_hibernate_tracker;
    @Transient
    private transient CollectionTracker $$_hibernate_collectionTracker;

    public User() {
    }

    public String getUsername() {
        return this.$$_hibernate_read_username();
    }

    public void setUsername(String username) {
        this.$$_hibernate_write_username(username);
    }

    public String getPassword() {
        return this.$$_hibernate_read_password();
    }

    public void setPassword(String password) {
        this.$$_hibernate_write_password(password);
    }

    public Integer getEnabled() {
        return this.$$_hibernate_read_enabled();
    }

    public void setEnabled(Integer enabled) {
        this.$$_hibernate_write_enabled(enabled);
    }

    public Set<Authority> getAuthorities() {
        return this.$$_hibernate_read_authorities();
    }

    public void setAuthorities(Set<Authority> authorities) {
        this.$$_hibernate_write_authorities(authorities);
    }

    @Roles
    public String authorities() {
        return StringUtils.join(this.$$_hibernate_read_authorities(), ",");
    }

    public Object $$_hibernate_getEntityInstance() {
        return this;
    }

    public EntityEntry $$_hibernate_getEntityEntry() {
        return this.$$_hibernate_entityEntryHolder;
    }

    public void $$_hibernate_setEntityEntry(EntityEntry var1) {
        this.$$_hibernate_entityEntryHolder = var1;
    }

    public ManagedEntity $$_hibernate_getPreviousManagedEntity() {
        return this.$$_hibernate_previousManagedEntity;
    }

    public void $$_hibernate_setPreviousManagedEntity(ManagedEntity var1) {
        this.$$_hibernate_previousManagedEntity = var1;
    }

    public ManagedEntity $$_hibernate_getNextManagedEntity() {
        return this.$$_hibernate_nextManagedEntity;
    }

    public void $$_hibernate_setNextManagedEntity(ManagedEntity var1) {
        this.$$_hibernate_nextManagedEntity = var1;
    }

    public boolean $$_hibernate_useTracker() {
        return this.$$_hibernate_useTracker;
    }

    public void $$_hibernate_setUseTracker(boolean var1) {
        this.$$_hibernate_useTracker = var1;
    }

    public PersistentAttributeInterceptor $$_hibernate_getInterceptor() {
        return this.$$_hibernate_attributeInterceptor;
    }

    public void $$_hibernate_setInterceptor(PersistentAttributeInterceptor var1) {
        this.$$_hibernate_attributeInterceptor = var1;
    }

    public void $$_hibernate_trackChange(String var1) {
        if (this.$$_hibernate_tracker == null) {
            this.$$_hibernate_tracker = new SimpleFieldTracker();
        }

        this.$$_hibernate_tracker.add(var1);
    }

    public String[] $$_hibernate_getDirtyAttributes() {
        Object var1 = null;
        String[] var2;
        if (this.$$_hibernate_collectionTracker == null) {
            var2 = this.$$_hibernate_tracker == null ? ArrayHelper.EMPTY_STRING_ARRAY : this.$$_hibernate_tracker.get();
        } else {
            if (this.$$_hibernate_tracker == null) {
                this.$$_hibernate_tracker = new SimpleFieldTracker();
            }

            this.$$_hibernate_getCollectionFieldDirtyNames(this.$$_hibernate_tracker);
            var2 = this.$$_hibernate_tracker.get();
        }

        return var2;
    }

    public boolean $$_hibernate_hasDirtyAttributes() {
        boolean var1 = false;
        var1 = this.$$_hibernate_tracker != null && !this.$$_hibernate_tracker.isEmpty() || this.$$_hibernate_areCollectionFieldsDirty();
        return var1;
    }

    public void $$_hibernate_clearDirtyAttributes() {
        if (this.$$_hibernate_tracker != null) {
            this.$$_hibernate_tracker.clear();
        }

        this.$$_hibernate_clearDirtyCollectionNames();
    }

    public void $$_hibernate_suspendDirtyTracking(boolean var1) {
        if (this.$$_hibernate_tracker == null) {
            this.$$_hibernate_tracker = new SimpleFieldTracker();
        }

        this.$$_hibernate_tracker.suspend(var1);
    }

    public CollectionTracker $$_hibernate_getCollectionTracker() {
        return this.$$_hibernate_collectionTracker;
    }

    public boolean $$_hibernate_areCollectionFieldsDirty() {
        boolean var1 = false;
        if (!var1 && this.$$_hibernate_collectionTracker != null) {
            int var2 = this.$$_hibernate_collectionTracker.getSize("authorities");
            if (this.authorities == null && var2 != -1) {
                var1 = true;
            } else if (this.authorities != null && (!(this.authorities instanceof PersistentCollection) || ((PersistentCollection)this.authorities).wasInitialized()) && var2 != this.authorities.size()) {
                var1 = true;
            }
        }

        return var1;
    }

    public void $$_hibernate_getCollectionFieldDirtyNames(DirtyTracker var1) {
        if (this.$$_hibernate_collectionTracker != null) {
            int var2 = this.$$_hibernate_collectionTracker.getSize("authorities");
            if (this.authorities == null && var2 != -1) {
                var1.add("authorities");
            } else if (this.authorities != null && (!(this.authorities instanceof PersistentCollection) || ((PersistentCollection)this.authorities).wasInitialized()) && var2 != this.authorities.size()) {
                var1.add("authorities");
            }
        }

    }

    public void $$_hibernate_clearDirtyCollectionNames() {
        if (this.$$_hibernate_collectionTracker == null) {
            this.$$_hibernate_collectionTracker = new SimpleCollectionTracker();
        }

        this.$$_hibernate_removeDirtyFields((LazyAttributeLoadingInterceptor)null);
    }

    public void $$_hibernate_removeDirtyFields(LazyAttributeLoadingInterceptor var1) {
        if (this.$$_hibernate_attributeInterceptor instanceof LazyAttributeLoadingInterceptor) {
            var1 = (LazyAttributeLoadingInterceptor)this.$$_hibernate_attributeInterceptor;
        }

        if (var1 == null || var1.isAttributeLoaded("authorities")) {
            if (this.authorities != null && (!(this.authorities instanceof PersistentCollection) || ((PersistentCollection)this.authorities).wasInitialized())) {
                this.$$_hibernate_collectionTracker.add("authorities", this.authorities.size());
            } else {
                this.$$_hibernate_collectionTracker.add("authorities", -1);
            }
        }

    }

    public String $$_hibernate_read_username() {
        if (this.$$_hibernate_getInterceptor() != null) {
            this.username = (String)this.$$_hibernate_getInterceptor().readObject(this, "username", this.username);
        }

        return this.username;
    }

    public void $$_hibernate_write_username(String var1) {
        if (this.$$_hibernate_getInterceptor() != null) {
            this.username = (String)this.$$_hibernate_getInterceptor().writeObject(this, "username", this.username, var1);
        } else {
            this.username = var1;
        }
    }

    public String $$_hibernate_read_password() {
        if (this.$$_hibernate_getInterceptor() != null) {
            this.password = (String)this.$$_hibernate_getInterceptor().readObject(this, "password", this.password);
        }

        return this.password;
    }

    public void $$_hibernate_write_password(String var1) {
        if (!InlineDirtyCheckerEqualsHelper.areEquals(this, "password", var1, this.password)) {
            this.$$_hibernate_trackChange("password");
        }

        if (this.$$_hibernate_getInterceptor() != null) {
            this.password = (String)this.$$_hibernate_getInterceptor().writeObject(this, "password", this.password, var1);
        } else {
            this.password = var1;
        }
    }

    public Integer $$_hibernate_read_enabled() {
        if (this.$$_hibernate_getInterceptor() != null) {
            this.enabled = (Integer)this.$$_hibernate_getInterceptor().readObject(this, "enabled", this.enabled);
        }

        return this.enabled;
    }

    public void $$_hibernate_write_enabled(Integer var1) {
        if (!InlineDirtyCheckerEqualsHelper.areEquals(this, "enabled", var1, this.enabled)) {
            this.$$_hibernate_trackChange("enabled");
        }

        if (this.$$_hibernate_getInterceptor() != null) {
            this.enabled = (Integer)this.$$_hibernate_getInterceptor().writeObject(this, "enabled", this.enabled, var1);
        } else {
            this.enabled = var1;
        }
    }

    public Set $$_hibernate_read_authorities() {
        if (this.$$_hibernate_getInterceptor() != null) {
            this.authorities = (Set)this.$$_hibernate_getInterceptor().readObject(this, "authorities", this.authorities);
        }

        return this.authorities;
    }

    public void $$_hibernate_write_authorities(Set var1) {
        if (this.$$_hibernate_getInterceptor() != null) {
            this.authorities = (Set)this.$$_hibernate_getInterceptor().writeObject(this, "authorities", this.authorities, var1);
        } else {
            this.authorities = var1;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

About XXX$$accessor class

Some classes and their methods are defined in package-private, so they are inaccessible in many case. For example class io.quarkus.liquibase.deployment.LiquibaseProcessor.

class LiquibaseProcessor {

    @BuildStep
    FeatureBuildItem feature() {
        return new FeatureBuildItem(Feature.LIQUIBASE);
    }

    // ...
}
Enter fullscreen mode Exit fullscreen mode

So a synthetic XXX$$accessor class is generated so that public method is provided for accessing instances of these classes.

@io.quarkus.Generated("Quarkus annotation processor")
public final class LiquibaseProcessor$$accessor {
    private LiquibaseProcessor$$accessor() {}
    public static Object construct() {
        return new LiquibaseProcessor();
    }
}
Enter fullscreen mode Exit fullscreen mode

The class can be located by io.quarkus.deployment.AccessorFinder.

About quarkus/bootstrap/dev-app-model.dat and quarkus/bootstrap/test-app-model.dat files

Files are read/write by io.quarkus.bootstrap.BootstrapAppModelFactory#resolveAppModel.

Data is mainly serialized io.quarkus.bootstrap.model.DefaultApplicationModel instance, which contain jar files used in the application of development and test mode.

Top comments (0)