Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate Path constructor argument instead of BeanPath #31

Closed
subes opened this issue Oct 17, 2011 · 6 comments
Closed

generate Path constructor argument instead of BeanPath #31

subes opened this issue Oct 17, 2011 · 6 comments
Labels

Comments

@subes
Copy link

@subes subes commented Oct 17, 2011

Hi,

I tried to generate a superclass which fails during compilation because the wrong constructor argument got generated. See following comments for the code...

@subes
Copy link
Author

@subes subes commented Oct 17, 2011

Here is the base class that gets the wrong constructor generated:

package de.invesdwin.gemeinsam.beans.internal;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;

import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;

import com.mysema.query.annotations.QuerySupertype;

@ThreadSafe
@QuerySupertype
public abstract class APropertyChangeSupported implements Comparable<Object>, Cloneable, Serializable {

    private static final long serialVersionUID = 1L;

    private transient PropertyChangeSupport propertyChangeSupport;

    private synchronized PropertyChangeSupport lazyGetPropertyChangeSupport(final boolean initializeIfNull) {
        if (initializeIfNull && propertyChangeSupport == null) {
            propertyChangeSupport = new PropertyChangeSupport(this);
        }
        return propertyChangeSupport;
    }

    public final void addPropertyChangeListener(final PropertyChangeListener listener) {
        if (listener != null) {
            lazyGetPropertyChangeSupport(true).addPropertyChangeListener(listener);
        }
    }

    public final void addPropertyChangeListener(final String property, final PropertyChangeListener listener) {
        if (listener != null) {
            lazyGetPropertyChangeSupport(true).addPropertyChangeListener(property, listener);
        }
    }

    public final void removePropertyChangeListener(final PropertyChangeListener listener) {
        final PropertyChangeSupport ref = lazyGetPropertyChangeSupport(false);
        if (ref != null) {
            ref.removePropertyChangeListener(listener);
        }
    }

    public final void removePropertyChangeListener(final String property, final PropertyChangeListener listener) {
        final PropertyChangeSupport ref = lazyGetPropertyChangeSupport(false);
        if (ref != null) {
            ref.removePropertyChangeListener(property, listener);
        }
    }

    public final boolean hasListeners(final String propertyName) {
        final PropertyChangeSupport ref = lazyGetPropertyChangeSupport(false);
        return ref != null && ref.hasListeners(propertyName);
    }

    protected final void fireIndexedPropertyChange(final String propertyName, final int index, final Object oldValue,
            final Object newValue) {
        final PropertyChangeSupport ref = lazyGetPropertyChangeSupport(false);
        if (ref != null) {
            ref.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
        }
    }

    protected final void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) {
        final PropertyChangeSupport ref = lazyGetPropertyChangeSupport(false);
        if (ref != null) {
            ref.firePropertyChange(propertyName, oldValue, newValue);
        }
    }
}
@subes
Copy link
Author

@subes subes commented Oct 17, 2011

Here is the second class which extends the first one and gets a query class generated that cannot be compiled:

package de.invesdwin.gemeinsam.beans;

import java.beans.PropertyDescriptor;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import javax.annotation.concurrent.ThreadSafe;
import javax.persistence.Transient;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.lang3.builder.CompareToBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.mysema.query.annotations.QuerySupertype;

import de.invesdwin.gemeinsam.beans.internal.APropertyChangeSupported;
import de.invesdwin.gemeinsam.lang.Strings;
import de.invesdwin.gemeinsam.log.Err;

@ThreadSafe
@QuerySupertype
public abstract class AValueObject extends APropertyChangeSupported implements Comparable<Object>, Cloneable,
        Serializable {

    private static final long serialVersionUID = 1L;

    private static final BeanUtilsBean BEAN_UTILS = new BeanUtilsBean();

    static {
        //Defaults für BeanUtils setzen.
        BEAN_UTILS.getConvertUtils().register(false, true, 0);
    }

    @Override
    public String toString() {
        return Strings.asStringReflective(this);
    }

    public String prettyToString() {
        return Strings.asStringReflectivePretty(this);
    }

    @Transient
    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public boolean equals(final Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    @Override
    public int compareTo(final Object o) {
        return CompareToBuilder.reflectionCompare(this, o);
    }

    public void mergeFrom(final Object o) {
        mergeFrom(o, true);
    }

    public void mergeFrom(final Object o, final boolean ueberschreiben) {
        for (final PropertyDescriptor dortDesc : BEAN_UTILS.getPropertyUtils().getPropertyDescriptors(o)) {
            try {
                final Object valueDort = dortDesc.getReadMethod().invoke(o);
                if (valueDort != null) {
                    final PropertyDescriptor thisDesc = BEAN_UTILS.getPropertyUtils().getPropertyDescriptor(this,
                            dortDesc.getName());
                    if (thisDesc == null) {
                        continue;
                    }

                    boolean copy = true;
                    final Object valueHier = thisDesc.getReadMethod().invoke(this);
                    if (valueHier != null) {
                        if (valueHier instanceof AValueObject) {
                            ((AValueObject) valueHier).mergeFrom(valueDort, ueberschreiben);
                            copy = false;
                        } else {
                            copy = ueberschreiben;
                        }
                    }

                    if (copy) {
                        BEAN_UTILS.copyProperty(this, dortDesc.getName(), valueDort);
                    }
                }
            } catch (final Throwable e) { //SUPPRESS CHECKSTYLE empty statement
                //ignore (kein setter für property class etc, oder getter ohne setter)
            }
        }
    }

    @Override
    public AValueObject clone() { //SUPPRESS CHECKSTYLE super.clone()
        ObjectOutputStream out = null;
        ObjectInputStream in = null;
        try {
            final ByteArrayOutputStream outStore = new ByteArrayOutputStream();
            out = new ObjectOutputStream(outStore);
            out.writeObject(this);
            final ByteArrayInputStream inStore = new ByteArrayInputStream(outStore.toByteArray());
            in = new ObjectInputStream(inStore);
            return (AValueObject) in.readObject();
        } catch (final IOException e) {
            throw Err.process(e);
        } catch (final ClassNotFoundException e) {
            throw Err.process(e);
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (final IOException e) {
                throw Err.process(e);
            }
        }
    }

}
@subes
Copy link
Author

@subes subes commented Oct 17, 2011

Here the generated query class that cannot be compiled:

package de.invesdwin.gemeinsam.beans;


import com.mysema.query.types.*;
import com.mysema.query.types.path.*;

import javax.annotation.Generated;


/**
 * QAValueObject is a Querydsl query type for AValueObject
 */
@Generated("com.mysema.query.codegen.SupertypeSerializer")
public class QAValueObject extends ComparablePath<AValueObject> {

    private static final long serialVersionUID = 331184104;

    public final de.invesdwin.gemeinsam.beans.internal.QAPropertyChangeSupported _super = new de.invesdwin.gemeinsam.beans.internal.QAPropertyChangeSupported(this);

    public QAValueObject(BeanPath<? extends AValueObject> entity) {
        super(entity.getType(), entity.getMetadata());
    }

    public QAValueObject(PathMetadata<?> metadata) {
        super(AValueObject.class, metadata);
    }

}

Because of this line:

    public final de.invesdwin.gemeinsam.beans.internal.QAPropertyChangeSupported _super = new de.invesdwin.gemeinsam.beans.internal.QAPropertyChangeSupported(this);

Which fails because of the following error:

[JAVAC] Compiling 3 source files to Z:\Entwicklung\inv-finanzdaten\trunk\03_module\de.invesdwin.gemeinsam\dist\default-work
[JAVAC] Z:\Entwicklung\inv-finanzdaten\trunk\03_module\de.invesdwin.gemeinsam\gen\de\invesdwin\gemeinsam\beans\QAValueObject.java:18: error: no suitable constructor found for QAPropertyChangeSupported(QAValueObject)
[JAVAC]     public final de.invesdwin.gemeinsam.beans.internal.QAPropertyChangeSupported _super = new de.invesdwin.gemeinsam.beans.internal.QAPropertyChangeSupported(this);
[JAVAC]                                                                                           ^
[JAVAC]     constructor QAPropertyChangeSupported.QAPropertyChangeSupported(PathMetadata<?>) is not applicable
[JAVAC]       (actual argument QAValueObject cannot be converted to PathMetadata<?> by method invocation conversion)
[JAVAC]     constructor QAPropertyChangeSupported.QAPropertyChangeSupported(BeanPath<? extends APropertyChangeSupported>) is not applicable
[JAVAC]       (actual argument QAValueObject cannot be converted to BeanPath<? extends APropertyChangeSupported> by method invocation conversion)
[JAVAC] 1 error
@subes
Copy link
Author

@subes subes commented Oct 17, 2011

This is the wrongly generated query superclass:

package de.invesdwin.gemeinsam.beans.internal;

import com.mysema.query.types.*;
import com.mysema.query.types.path.*;

import javax.annotation.Generated;


/**
 * QAPropertyChangeSupported is a Querydsl query type for APropertyChangeSupported
 */
@Generated("com.mysema.query.codegen.SupertypeSerializer")
public class QAPropertyChangeSupported extends ComparablePath<APropertyChangeSupported> {

    private static final long serialVersionUID = 309350304;

    public QAPropertyChangeSupported(BeanPath<? extends APropertyChangeSupported> entity) {
        super(entity.getType(), entity.getMetadata());
    }

    public QAPropertyChangeSupported(PathMetadata<?> metadata) {
        super(APropertyChangeSupported.class, metadata);
    }

}
@subes
Copy link
Author

@subes subes commented Oct 17, 2011

I can fix this by changing the constructor parameter from BeanPath to Path:

package de.invesdwin.gemeinsam.beans.internal;

import javax.annotation.Generated;

import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata;
import com.mysema.query.types.path.ComparablePath;

/**
 * QAPropertyChangeSupported is a Querydsl query type for APropertyChangeSupported
 */
@Generated("com.mysema.query.codegen.SupertypeSerializer")
public class QAPropertyChangeSupported extends ComparablePath<APropertyChangeSupported> {

    private static final long serialVersionUID = 309350304;

    public QAPropertyChangeSupported(final Path<? extends APropertyChangeSupported> entity) {
        super(entity.getType(), entity.getMetadata());
    }

    public QAPropertyChangeSupported(final PathMetadata<?> metadata) {
        super(APropertyChangeSupported.class, metadata);
    }

}
@timowest
Copy link
Member

@timowest timowest commented Oct 23, 2011

Released in 2.2.4

@timowest timowest closed this Oct 23, 2011
jwgmeligmeyling pushed a commit that referenced this issue Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants