Giter Site home page Giter Site logo

codegen's Introduction

Querydsl

Querydsl is a framework which enables the construction of type-safe SQL-like queries for multiple backends including JPA, MongoDB and SQL in Java.

Instead of writing queries as inline strings or externalizing them into XML files they are constructed via a fluent API.

Website shields.io Build Status Coverage Status Stackoverflow Maven Central

Getting started

Use these tutorials to get started

Examples

Querydsl example projects

Support

Free support is provided in the Discussion Section and on StackOverflow. Please do not post questions as issue. Such issues will be closed immediately.

How to build

Querydsl provides releases via public Maven repositories, but you can also build the sources yourself like this

$ mvn -Pquickbuild,{projectname} clean install

Where projectname is one of the Maven profiles (e.g. jpa, sql, mongodb, etc. or all)

For more information visit the project homepage at https://querydsl.github.io.

Docker Compose setup

For running tests, a Docker Compose setup is provided. It comes with the following databases:

  • Oracle Express Edition 11g
  • PostgreSQL 9.1.10
  • MySQL 5.5.34
  • Cubrid 9.2

You will need to install Docker and docker-compose.

To launch the database containers:

$ docker-compose up -d

All of the databases' default ports are forwarded to the host machine.

How to contribute

GitHub pull requests are the way to contribute to Querydsl.

If you are unsure about the details of a contribution, ask on the Querydsl Google Group or create a ticket on GitHub.

Slack

If you want to join Slack workspace for Querydsl contributors join by following this link.

codegen's People

Contributors

bouil avatar johnktims avatar jtsay362 avatar mcuelenaere avatar ractive avatar shredder121 avatar timowest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codegen's Issues

CodegenException when using TomcatEmbeddedWebappClassLoader (fx. Spring Boot)

I am having an issue wen running my application with QueryDSL on OpenJDK.

I have 2 classes that I generate QueryDsl classes for. One(Project) is a MongoEntity class that I annotated with @QueryEntity and the other(Service) is a POJO also with @QueryEntity.

I use com.querydsl.apt.QuerydslAnnotationProcessor for generating the classes.

When I compile and run it locally everything works fine. This is using the following JDK:


java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

But when built for production using this JDK:

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

...and then run in a container with this JDK:

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

...then I get this exception for the Service class, but not the Project class:

com.mysema.codegen.CodegenException: Compilation of public class Q_2124358794_1275614662_1275614662_1195259493 {

    public static Iterable<dk.codezoo.meerkat.model.Service> eval(Iterable<dk.codezoo.meerkat.model.Service> service_, String a1) {
java.util.List<dk.codezoo.meerkat.model.Service> rv = new java.util.ArrayList<dk.codezoo.meerkat.model.Service>();
for (dk.codezoo.meerkat.model.Service service : service_) {
    try {
        if (service.getName().toLowerCase().contains(a1)) {
            rv.add(service);
        }
    } catch (NullPointerException npe) { }
}
return rv;    }

}

 failed.
warning: Supported source version 'RELEASE_6' from annotation processor 'org.jvnet.hudson.annotation_indexer.AnnotationProcessorImpl' less than -source '1.8'
/Q_2124358794_1275614662_1275614662_1195259493.java:3: error: package dk.codezoo.meerkat.model does not exist
    public static Iterable<dk.codezoo.meerkat.model.Service> eval(Iterable<dk.codezoo.meerkat.model.Service> service_, String a1) {
                                                                                                   ^
/Q_2124358794_1275614662_1275614662_1195259493.java:3: error: package dk.codezoo.meerkat.model does not exist
    public static Iterable<dk.codezoo.meerkat.model.Service> eval(Iterable<dk.codezoo.meerkat.model.Service> service_, String a1) {
                                                   ^
2 errors
1 warning

	at com.mysema.codegen.JDKEvaluatorFactory.compile(JDKEvaluatorFactory.java:74)
	at com.mysema.codegen.AbstractEvaluatorFactory.createEvaluator(AbstractEvaluatorFactory.java:128)
	at com.querydsl.collections.DefaultEvaluatorFactory.createEvaluator(DefaultEvaluatorFactory.java:151)
	at com.querydsl.collections.DefaultQueryEngine.evaluateSingleSource(DefaultQueryEngine.java:166)
	at com.querydsl.collections.DefaultQueryEngine.list(DefaultQueryEngine.java:80)
	at com.querydsl.collections.AbstractCollQuery.fetch(AbstractCollQuery.java:182)
	at dk.codezoo.meerkat.orchestration.DockerOrchestrationClient$DockerServiceClient.findAll(DockerOrchestrationClient.java:108)
	at dk.codezoo.meerkat.service.ServiceService.findAll(ServiceService.java:64)
	at dk.codezoo.meerkat.controller.ServiceController.list(ServiceController.java:62)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:215)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:176)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

hashCode and equals in model package

Is there a reason for hashCode and equals methods in model package to be implemented and yet not using all the fields in the classes?

Would it not be better to either remove them or regenerate them with comparing/hashing all the fields?

It breaks for example scala case class code generation in querydsl. I'm going to work around it there. But it should be fixed here.

compiler error for field names ending with '_' in ScalaWriter

When a field name ends with _ (and likely any other symbol), the ScalaWriter class generates parameters that look like fieldName_: String. Since there is no space between the _ and the :, the scala compiler assumes the : is part of the variable name and throws a syntax error.
The fix is to just put a space before the : I imagine. Here is a guess at the relevant lines in ScalaWriter:

ScalaWriter.scala line 353:

   public ScalaWriter field(Type type, String name) throws IOException {
        line(VAR, escape(name), ": ", getGenericName(true, type));
        return compact ? this : nl();
    }
    private ScalaWriter field(String modifier, Type type, String name) throws IOException {
        line(modifier, escape(name), ": ", getGenericName(true, type));
        return compact ? this : nl();
    }
    private ScalaWriter field(String modifier, Type type, String name, String value)
            throws IOException {
        line(modifier, escape(name), ": ", getGenericName(true, type), ASSIGN, value);
        return compact ? this : nl();
    }

I was exploring the use of generated case classes when I came across this bug, that won't work for me for unrelated reasons, but I won't be able to test any fixes here. I just thought I'd point out the bug.

Kevin

EvaluatorFactory has a hard dependency on URLClassLoader (OSGi-incompatible)

I had problems running querydsl-collections on ServiceMix because the EvaluatorFactory in mysema/codegen has a hard dependency on URLClassLoader. OSGi containers use bundle class loaders, which aren't compatible with URLClassLoaders. I have developed a patch to extract the EvaluatorFactory interface and have written a new implementation that uses ECJ (Eclipse Compiler for Java). It will work with any ClassLoader. I have also written patches to convert mysema/querydsl/querydsl-codegen and mysema/querydsl/querydsl-collections to use this new factory. These patches meet my needs with a hard-coded implementation in the DefaultEvaluatorFactory, but if there are any preferences for how to make the implementation configurable, please let me know and I'll shoot over the patches.

ecj 4.2.1 support

hi
any plans for add to codegen org.eclipse.jdt.core.compiler:ecj 4.2.1 support?
i have this problem:
org.eclipse.jdt.internal.compiler.tool.EclipseFileManager was removed from ecj
and there is a missing method org.eclipse.jdt.internal.compiler.env.ICompilationUnit#ignoreOptionalProblems() in
src/main/java/com/mysema/codegen/ECJEvaluatorFactory.
thanks in avdance
regards

Java compiler receives broken classpath when invoked within Spring Boot jar application

Original problem description, reproduction code and discussion is here: querydsl/querydsl#1407

Basically,

If Spring Boot application gets run with java -jar, classloader returns "nested jar" classpath entries, like

0 = {URL@2237} "jar:file:/Users/villuv/src/misc/springboot-querydsl-bug/target/springboot-querydsl-bug-1.0-SNAPSHOT.jar!/"
1 = {URL@2238} "jar:file:/Users/villuv/src/misc/springboot-querydsl-bug/target/springboot-querydsl-bug-1.0-SNAPSHOT.jar!/lib/spring-boot-starter-1.2.4.RELEASE.jar!/"
...

Now, this here https://github.com/querydsl/codegen/blob/master/src/main/java/com/mysema/codegen/SimpleCompiler.java#L69 deals with composing the classpath parameter for the compiler. And it seems to be unable to handle those "deep jar URLs" correctly. For example, classpath entry from classloader:

jar:file:/Users/villuv/src/misc/springboot-querydsl-bug/target/springboot-querydsl-bug-1.0-SNAPSHOT.jar!/

decodedPath becomes

file:/Users/villuv/src/misc/springboot-querydsl-bug/target/springboot-querydsl-bug-1.0-SNAPSHOT.jar!/

And following thing gets added to paths

/Users/villuv/src/misc/springboot-querydsl-bug/target/file:/Users/villuv/src/misc/springboot-querydsl-bug/target/springboot-querydsl-bug-1.0-SNAPSHOT.jar!

Notice that it keeps the file: scheme name in the middle of it and also prepends a full path even though the URL already is a full path.
Next up, pathJoiner will concatenate all these entries together, using : as path separator character. This means, classpath string that gets given to the compiler can't be decoded correctly.

DefaultEvaluatorFactory has a hard dependency on EvaluatorFactory

DefaultEvaluatorFactory internally creates an instance of EvaluatorFactory with no way to override it with a custom subclass of EvaluatorFactory, short of subclassing DefaultEvaluatorFactory and copy-pasting all its methods.

Please provide a constuctor for DefaultEvaluatorFactory that accepts a custom instance of EvaluatorFactory.

Guava version

@timowest Is it a good idea to equalize the guava version to the one used in the main Querydsl modules?

Upgrade to new findbugs groupId

Findbugs libraries (annotations and jsr305) have been relocated from net.sourceforge.findbugs to com.google.code.findbugs.

This causes duplicates/conflicts between libraries depending on codegen, such as querydsl-jpa, and up-to-date libraries such as guava.

Sincerely,

Stéphane Landelle

SQL Foreign key generation: Duplicates

Hello,

When generating my Q sources for SQL queryDsl, my foreign keys contain duplicates.

For instance:
public final com.querydsl.sql.ForeignKey lnk14051 = createForeignKey(Arrays.asList(cdRmrkDnr, cdRmrkDnr, cdRmrkDnr, cdRmrkDnr, cdRmrkDnr, cdRmrkDnr), Arrays.asList("DNR", "DNR", "DNR", "DNR", "DNR", "DNR"));

But it should jus tlook like:
public final com.querydsl.sql.ForeignKey lnk14051 = createForeignKey(Arrays.asList(cdRmrkDnr), Arrays.asList("DNR"));

After a bit of deeper diving into the code, I was wondering if it has something to do with missing config parameters (maybe something to do with 'Catalog' ... to limit the amount of found foreignkeys in the metadata)

I'm using plugin:

`

		<plugin>
			<groupId>com.querydsl</groupId>
			<artifactId>querydsl-maven-plugin</artifactId>
			<version>${querydsl.version}</version>
			<executions>
				<execution>
					<goals>
						<goal>export</goal>
					</goals>
				</execution>
			</executions>
			<configuration>
				<jdbcDriver>com.ibm.db2.jcc.DB2Driver</jdbcDriver>
				<jdbcUrl>jdbc:db2://server:port/dbname</jdbcUrl>
				<jdbcUser>user</jdbcUser>
				<jdbcPassword>password</jdbcPassword>
				<schemaPattern>NK</schemaPattern>
				<tableNamePattern>TNK14%</tableNamePattern>
				<targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
			</configuration>
			<dependencies>
				<dependency>
					<groupId>com.ibm.db2</groupId>
					<artifactId>db2jcc4</artifactId>
					<version>4.22.29</version>
				</dependency>
			</dependencies>
		</plugin>

`

Any help would be highly appreciated :)

Update org.eclipse.jdt.core.compiler.ecj

Hi,
i use the querydsl-apt lib with a springboot application and vaadin 8 for frontend. In vaadin 8 they have updated to the last gwt release and the gwt lib uses some jdt libs.
So in some cases gwt needs to compile a widgetset. But this is not possible because this lib uses an older jdt plugin and breaks the gwt compiler. Current workaround, after some hours of research, is to exclude the ecj lib via maven. This seems to work in my case.
Is it possible to update the ecj version to the actual version?

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.