Search in sources :

Example 1 with JPADomainExporter

use of com.querydsl.jpa.codegen.JPADomainExporter in project querydsl by querydsl.

the class AntJPADomainExporter method execute.

/**
     * Exports the named persistence unit's metamodel to Querydsl query types.  Expects to be
     * called by Ant via name convention using a method with signature public void execute().
     */
public void execute() {
    // We can assume we have the named persistence unit and its mapping file in our classpath,
    // but we may have to allow some properties in that persistence unit to be overridden before
    // we can successfully get that persistence unit's metamodel.
    Map<String, String> properties = (configuration != null) ? configuration.getProperties() : null;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName, properties);
    // Now we can get the persistence unit's metamodel and export it to Querydsl query types.
    Metamodel configuration = emf.getMetamodel();
    JPADomainExporter exporter = new JPADomainExporter(namePrefix, nameSuffix, new File(targetFolder), configuration);
    try {
        exporter.execute();
        generatedFiles = exporter.getGeneratedFiles();
    } catch (IOException e) {
        throw new RuntimeException("Error in JPADomainExporter", e);
    }
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) IOException(java.io.IOException) Metamodel(javax.persistence.metamodel.Metamodel) File(java.io.File) JPADomainExporter(com.querydsl.jpa.codegen.JPADomainExporter)

Aggregations

JPADomainExporter (com.querydsl.jpa.codegen.JPADomainExporter)1 File (java.io.File)1 IOException (java.io.IOException)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 Metamodel (javax.persistence.metamodel.Metamodel)1