Search in sources :

Example 6 with IQueryExporter

use of org.jboss.tools.hibernate.runtime.spi.IQueryExporter in project jbosstools-hibernate by jbosstools.

the class ExporterFactory method createConfiguredExporter.

/**
 * Creates exporter with the specified settings; also resolves any relevant properties via Eclipse VariablesPlugin.
 * @param collector
 * @throws CoreException in case of resolve variables issues.
 */
public IExporter createConfiguredExporter(IConfiguration cfg, String defaultOutputDirectory, String customTemplatePath, Properties globalProperties, Set<String> outputDirectories, IArtifactCollector collector, IService service) throws CoreException {
    IExporter exporter = getExporterDefinition().createExporterInstance(service);
    Properties extract = new Properties();
    Properties props = new Properties();
    props.putAll(globalProperties);
    props.putAll(getProperties());
    extractExporterProperties(getExporterDefinitionId(), props, extract);
    cfg.addProperties(props);
    exporter.setArtifactCollector(collector);
    String outputPath = defaultOutputDirectory;
    if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
        outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
    }
    String resolvedOutputDir = resolve(outputPath);
    String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
    if (outputPath != null && loc == null) {
        String out = NLS.bind(HibernateConsoleMessages.ExporterFactory_output_dir_in_does_not_exist, resolvedOutputDir, getExporterDefinition().getDescription());
        throw new HibernateConsoleRuntimeException(out);
    }
    if (StringHelper.isNotEmpty(loc)) {
        // only set if something valid found
        outputDirectories.add(loc);
        exporter.setOutputDirectory(new File(loc));
    }
    exporter.setConfiguration(cfg);
    List<String> templatePathList = new ArrayList<String>();
    if (extract.containsKey(ExporterFactoryStrings.TEMPLATE_PATH)) {
        String resolveTemplatePath = resolve(extract.getProperty(ExporterFactoryStrings.TEMPLATE_PATH));
        // $NON-NLS-1$
        StringTokenizer st = new StringTokenizer(resolveTemplatePath, ";");
        // $NON-NLS-1$
        String out = "";
        while (st.hasMoreTokens()) {
            String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
            if (locationAsStringPath == null) {
                out += NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist, resolveTemplatePath, getExporterDefinition().getDescription()) + '\n';
            } else {
                templatePathList.add(locationAsStringPath);
            }
        }
        if (out.length() > 0) {
            out = out.substring(0, out.length() - 1);
            throw new HibernateConsoleRuntimeException(out);
        }
    }
    if (StringHelper.isNotEmpty(customTemplatePath)) {
        String resolvedCustomTemplatePath = resolve(customTemplatePath);
        // $NON-NLS-1$
        StringTokenizer st = new StringTokenizer(resolvedCustomTemplatePath, ";");
        // $NON-NLS-1$
        String out = "";
        while (st.hasMoreTokens()) {
            String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
            if (locationAsStringPath != null) {
                templatePathList.add(locationAsStringPath);
            } else {
                out = NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist, resolvedCustomTemplatePath, getExporterDefinition().getDescription());
            }
        }
        if (!("".equals(out))) {
            // $NON-NLS-1$
            out = out.substring(0, out.length() - 1);
            throw new HibernateConsoleRuntimeException(out);
        }
    }
    exporter.setTemplatePath(templatePathList.toArray(new String[templatePathList.size()]));
    // special handling for GenericExporter (TODO: be delegated via plugin.xml)
    if (getExporterDefinitionId().equals("org.hibernate.tools.hbmtemplate")) {
        // $NON-NLS-1$
        IGenericExporter ge = exporter.getGenericExporter();
        ge.setFilePattern(extract.getProperty(ExporterFactoryStrings.FILE_PATTERN));
        ge.setTemplateName(extract.getProperty(ExporterFactoryStrings.TEMPLATE_NAME));
        ge.setForEach(extract.getProperty(ExporterFactoryStrings.FOR_EACH));
    }
    // special handling for Hbm2DDLExporter
    if (getExporterDefinitionId().equals("org.hibernate.tools.hbm2ddl")) {
        // $NON-NLS-1$
        IHbm2DDLExporter ddlExporter = exporter.getHbm2DDLExporter();
        // avoid users to delete their databases with a single click
        ddlExporter.setExport(Boolean.parseBoolean(extract.getProperty(ExporterFactoryStrings.EXPORTTODATABASE)));
    }
    // special handling for QueryExporter
    if (getExporterDefinitionId().equals("org.hibernate.tools.query")) {
        // $NON-NLS-1$
        IQueryExporter queryExporter = exporter.getQueryExporter();
        List<String> queryStrings = new ArrayList<String>();
        // $NON-NLS-1$
        queryStrings.add(extract.getProperty(ExporterFactoryStrings.QUERY_STRING, ""));
        queryExporter.setQueries(queryStrings);
        queryExporter.setFilename(extract.getProperty(ExporterFactoryStrings.OUTPUTFILENAME));
    }
    return exporter;
}
Also used : StringTokenizer(java.util.StringTokenizer) IHbm2DDLExporter(org.jboss.tools.hibernate.runtime.spi.IHbm2DDLExporter) ArrayList(java.util.ArrayList) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) IExporter(org.jboss.tools.hibernate.runtime.spi.IExporter) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) Properties(java.util.Properties) File(java.io.File) IGenericExporter(org.jboss.tools.hibernate.runtime.spi.IGenericExporter)

Example 7 with IQueryExporter

use of org.jboss.tools.hibernate.runtime.spi.IQueryExporter in project jbosstools-hibernate by jbosstools.

the class ExporterFacadeTest method testGetQueryExporter.

@Test
public void testGetQueryExporter() {
    IQueryExporter queryExporter = exporterFacade.getQueryExporter();
    assertNull(queryExporter);
    exporterTarget = new QueryExporter();
    exporterFacade = new AbstractExporterFacade(FACADE_FACTORY, exporterTarget) {
    };
    queryExporter = exporterFacade.getQueryExporter();
    assertNotNull(queryExporter);
    assertSame(exporterTarget, ((IFacade) queryExporter).getTarget());
}
Also used : QueryExporter(org.hibernate.tool.hbm2x.QueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) AbstractExporterFacade(org.jboss.tools.hibernate.runtime.common.AbstractExporterFacade) Test(org.junit.jupiter.api.Test)

Example 8 with IQueryExporter

use of org.jboss.tools.hibernate.runtime.spi.IQueryExporter in project jbosstools-hibernate by jbosstools.

the class ExporterFacadeTest method testGetQueryExporter.

@Test
public void testGetQueryExporter() {
    IQueryExporter queryExporter = exporterFacade.getQueryExporter();
    assertNull(queryExporter);
    exporterTarget = new QueryExporter();
    exporterFacade = new AbstractExporterFacade(FACADE_FACTORY, exporterTarget) {
    };
    queryExporter = exporterFacade.getQueryExporter();
    assertNotNull(queryExporter);
    assertSame(exporterTarget, ((IFacade) queryExporter).getTarget());
}
Also used : QueryExporter(org.hibernate.tool.hbm2x.QueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) AbstractExporterFacade(org.jboss.tools.hibernate.runtime.common.AbstractExporterFacade) Test(org.junit.jupiter.api.Test)

Example 9 with IQueryExporter

use of org.jboss.tools.hibernate.runtime.spi.IQueryExporter in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateQueryExporter.

@Test
public void testCreateQueryExporter() {
    QueryExporter queryExporter = new QueryExporter();
    IQueryExporter facade = facadeFactory.createQueryExporter(queryExporter);
    assertSame(queryExporter, ((IFacade) facade).getTarget());
}
Also used : QueryExporter(org.hibernate.tool.hbm2x.QueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) Test(org.junit.jupiter.api.Test)

Example 10 with IQueryExporter

use of org.jboss.tools.hibernate.runtime.spi.IQueryExporter in project jbosstools-hibernate by jbosstools.

the class ExporterFacadeTest method testGetQueryExporter.

@Test
public void testGetQueryExporter() {
    IQueryExporter queryExporter = exporterFacade.getQueryExporter();
    assertNull(queryExporter);
    exporterTarget = new QueryExporter();
    exporterFacade = new ExporterFacadeImpl(FACADE_FACTORY, exporterTarget);
    queryExporter = exporterFacade.getQueryExporter();
    assertNotNull(queryExporter);
    assertSame(exporterTarget, ((IFacade) queryExporter).getTarget());
}
Also used : QueryExporter(org.hibernate.tool.hbm2x.QueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) IQueryExporter(org.jboss.tools.hibernate.runtime.spi.IQueryExporter) Test(org.junit.jupiter.api.Test)

Aggregations

IQueryExporter (org.jboss.tools.hibernate.runtime.spi.IQueryExporter)25 QueryExporter (org.hibernate.tool.hbm2x.QueryExporter)22 Test (org.junit.jupiter.api.Test)22 AbstractExporterFacade (org.jboss.tools.hibernate.runtime.common.AbstractExporterFacade)7 QueryExporter (org.hibernate.tool.internal.export.query.QueryExporter)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 StringTokenizer (java.util.StringTokenizer)1 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)1 IExporter (org.jboss.tools.hibernate.runtime.spi.IExporter)1 IGenericExporter (org.jboss.tools.hibernate.runtime.spi.IGenericExporter)1 IHbm2DDLExporter (org.jboss.tools.hibernate.runtime.spi.IHbm2DDLExporter)1