Coder Social home page Coder Social logo

datanucleus / datanucleus-jdo-query Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 5.0 163 KB

DataNucleus annotation processor for generating "Q" classes for use with JDOQLTyped queries

Home Page: http://www.datanucleus.org/products/accessplatform/jdo/query.html#jdoql_typed

Java 100.00%
jdo jdo-typed-query

datanucleus-jdo-query's People

Contributors

andyjefferson avatar renataogarcia avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

datanucleus-jdo-query's Issues

Add explicit handling for primitive wrappers

We currently just have explicit handling for primitives and java.math.BigXXX classes. We should treat primitive wrappers explicitly too, since the javax.lang.model.type classes treat them as different to primitive for some reason

Support generics on Optional field in generated class

Currently when we have an Optional<String> field in the persistent class we just create a field in the Q class like this
OptionalExpression myField = new OptionalExpressionImpl(this, "myField");

We should create
OptionalExpression<String> myField = new OptionalExpressionImpl<String>(this, "myField");

Support JSR0380 annotations (Bean Validation 2.0)

If entities contain JSR0303 annotations the generated Q... classes are invalid:

@NotNull
private UUID id;

leads to:

public final ObjectExpression<(@javax.validation.constraints.NotNull :: java.util.UUID)> id;

and annotations are not allowed there.

Rework fix to #5 to avoid conflict with other types

The fix for issue 5 tried to trap the case of an annotated member having the annotation in the TypeMirror (for some reason). All that was done was convert to its element, then the underlying type (which removed the annotations). This can impact on detection of other types, so we need to be more careful in the trap.

Filter not able to process "NOT EQUAL TO".

Hi.
I tried to execute a code like this, and I got a stack trace.

JDOPersistenceManager jdopm = (JDOPersistenceManager) pm;
QProductClass cand = QProductClass.candidate();
JDOQLTypedQuery<Product> tq = jdopm.newJDOQLTypedQuery(Product.class);
List<Product> prods = tq.filter(cand.name.ne(value)).executeList();

The stacktrace;

Jan 03, 2018 8:01:14 PM com.hop.tub.servlets.TuListDataServlet doPost
SEVERE: null
org.neo4j.graphdb.QueryExecutionException: Unknown operation '!=' (you probably meant to use '<>',   which is the operator for inequality testing) (line 1, column 95 (offset: 94))
"START this=node:DN_TYPES(class="com.hop.tub.neo4j.jdo.model.Product") WHERE (this.name != "ampiclox") RETURN this"
                                                                                           ^
at org.neo4j.kernel.impl.query.QueryExecutionKernelException.asUserException(QueryExecutionKernelException.java:35)
at org.neo4j.kernel.impl.factory.ClassicCoreSPI.executeQuery(ClassicCoreSPI.java:84)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.execute(GraphDatabaseFacade.java:369)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.execute(GraphDatabaseFacade.java:359)
at org.datanucleus.store.neo4j.Neo4jUtils.executeCypherQuery(Neo4jUtils.java:319)
at org.datanucleus.store.neo4j[DEBUG] 2018-01-03 20:01:14.011 [qtp1955990522-86] Transaction - Transaction rolled back in 3 ms

.eq() works but .ne() does not work. Any help?

And is there any way to search if an object contains a value?

Adding jdo-query to maven based project causes compile error

I'm in the midst of setting up a JavaFX project with Datanucleu + JDO + JDOQL. I've got the first two parts working without issue, I've got a connection to the database, I can read and write no issues. When I go to add the JDOQL step, along with the maven plugin the compile fails with the following error.

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project projectName: Fatal error compiling: java.lang.NoClassDefFoundError: javax/jdo/annotations/PersistenceCapable: javax.jdo.annotations.PersistenceCapable -> [Help 1]

I'm running OpenJDK 13, JavaFX 14 and the latest version of most datanucleus plugins/dependencies. I've got the persistence XML configured and that picks up alright, I'm setting properties inside that file as well.

I'm at a complete loss as to what the issue might be, I've compared my code to the examples and it seems basically identical. It seems like it can't find the dependencies for the JDO annotations, which doesn't make sense because it worked before adding this plugin. At this point, I'm thinking it is possibly a bug in the latest version(I have tried a few of the older versions as well)

Any guidance would be great!

Here is my POM.XML

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.redacted</groupId>
    <artifactId>redacted</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <config.files.dir>${basedir}/src/main/resources</config.files.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <openjfx.Version>14</openjfx.Version>
        <openjfx.Maven.Version>0.0.4</openjfx.Maven.Version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>[5.1.6, 5.9)</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jdo</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-rdbms</artifactId>
            <version>[5.1.6, 5.9)</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>javax.jdo</artifactId>
            <version>3.2.0-m13</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-jdo-query</artifactId>
            <version>[5.0.9, )</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>[1.2.17, )</version>
        </dependency>
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.30.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${openjfx.Version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${openjfx.Version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit5</artifactId>
            <version>4.0.16-alpha</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>datanucleus-maven-plugin</artifactId>
                <version>5.2.1</version>
                <configuration>
                    <persistenceUnitName>CentralUnit</persistenceUnitName>
                    <api>JDO</api>
<!--                    <props>${config.files.dir}/datanucleus.properties</props>-->
                    <log4jConfiguration>${config.files.dir}/log4j.properties</log4jConfiguration>
                    <verbose>true</verbose>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>com.redacted.App.Main</mainClass>
                    <systemProperties>
                        <systemProperty>
                            <key>log4j.configuration</key>
                            <value>file:${config.files.dir}/log4j.properties</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                    <compilerArgument>-AqueryMode=FIELD</compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${basedir}</directory>
                            <includes>
                                <include>*.log</include>
                                <include>*.ods</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>${openjfx.Maven.Version}</version>
                <configuration>
                    <mainClass>es.deusto.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
        </plugins>
    </build>
</project>


My persistnce.XML

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1">

    <!-- JDO tutorial "unit" -->
    <persistence-unit name="CentralUnit">
        <class>es.deusto.User</class>
        <exclude-unlisted-classes/>
        <properties>
            <property name="javax.jdo.option.ConnectionURL" value="jdbc:sqlite:src/main/resources/database.db"/>
            <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
            <property name="datanucleus.schema.autoCreateAll" value="true"/>
            <property name="datanucleus.validateTables" value="true"/>
            <property name="datanucleus.validateConstraints" value="true"/>
            <property name="datanucleus.metadata.validate" value="false"/>
        </properties>
    </persistence-unit>
</persistence>

My User class

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import java.util.Date;


@PersistenceCapable
//@Inheritance(strategy= InheritanceStrategy.NEW_TABLE)
public class User {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
    protected long id;


    protected String firstName;
    protected String lastName;
    protected String notes;
    protected String phoneNumber;
    protected Date birthDate;
    protected Date dateJoined;
    protected Date createdAt;
    protected Date updatedAt;


    protected User(){};
//Omitted all the getters and setters```

Support detection of XML metadata and generate classes for those

The annotation processor mechanism is designed for annotated classes (hint: look at the name of the interface and its package). That said, if you set
@SupportedAnnotationTypes("*")
then it will be called for every class. We could try to find all XML metadata files, parse them, and generate the query class for each XML defined class.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.