Search in sources :

Example 86 with IConfiguration

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

the class ServiceImpl method newSchemaExport.

@Override
public ISchemaExport newSchemaExport(IConfiguration hcfg) {
    ISchemaExport result = null;
    if (hcfg instanceof IFacade) {
        Configuration configuration = (Configuration) ((IFacade) hcfg).getTarget();
        MetadataImplementor metadata = (MetadataImplementor) MetadataHelper.getMetadata(configuration);
        SchemaExport schemaExport = new SchemaExport(metadata);
        result = facadeFactory.createSchemaExport(schemaExport);
    }
    return result;
}
Also used : Configuration(org.hibernate.cfg.Configuration) JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 87 with IConfiguration

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

the class ServiceImpl method newAnnotationConfiguration.

@Override
public IConfiguration newAnnotationConfiguration() {
    getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
    Configuration configuration = new Configuration();
    return facadeFactory.createConfiguration(configuration);
}
Also used : Configuration(org.hibernate.cfg.Configuration) JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 88 with IConfiguration

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

the class ColumnFacadeImpl method getSqlType.

@Override
public String getSqlType(IConfiguration configuration) {
    Column targetColumn = (Column) getTarget();
    Configuration configurationTarget = (Configuration) ((IFacade) configuration).getTarget();
    Properties properties = configurationTarget.getProperties();
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
    ssrb.applySettings(properties);
    StandardServiceRegistry ssr = ssrb.build();
    DialectFactory df = ssr.getService(DialectFactory.class);
    Dialect dialectTarget = df.buildDialect(properties, null);
    return targetColumn.getSqlType(dialectTarget, MetadataHelper.getMetadata(configurationTarget));
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Column(org.hibernate.mapping.Column) Dialect(org.hibernate.dialect.Dialect) DialectFactory(org.hibernate.engine.jdbc.dialect.spi.DialectFactory) Properties(java.util.Properties) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 89 with IConfiguration

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

the class ConfigurationFacadeImpl method configure.

@Override
public IConfiguration configure(Document document) {
    File tempFile = null;
    IConfiguration result = null;
    try {
        tempFile = File.createTempFile(document.toString(), "cfg.xml");
        DOMSource domSource = new DOMSource(document);
        StringWriter stringWriter = new StringWriter();
        StreamResult stream = new StreamResult(stringWriter);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, stream);
        FileWriter fileWriter = new FileWriter(tempFile);
        fileWriter.write(stringWriter.toString());
        fileWriter.close();
        result = configure(tempFile);
    } catch (IOException | TransformerException e) {
        throw new RuntimeException("Problem while configuring", e);
    } finally {
        tempFile.delete();
    }
    return result;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 90 with IConfiguration

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

the class ServiceImpl method newJpaConfiguration.

@Override
public IConfiguration newJpaConfiguration(String entityResolver, String persistenceUnit, Map<Object, Object> overrides) {
    getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
    Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
    if (StringHelper.isNotEmpty(entityResolver)) {
        try {
            Class<?> resolver = ReflectHelper.classForName(entityResolver, this.getClass());
            Object object = resolver.newInstance();
            ejb3Configuration.setEntityResolver((EntityResolver) object);
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            throw new HibernateException(e);
        }
    }
    ejb3Configuration.configure(persistenceUnit, overrides);
    Configuration configuration = ejb3Configuration.getHibernateConfiguration();
    return facadeFactory.createConfiguration(configuration);
}
Also used : Ejb3Configuration(org.hibernate.ejb.Ejb3Configuration) Configuration(org.hibernate.cfg.Configuration) JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) AnnotationConfiguration(org.hibernate.cfg.AnnotationConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) Ejb3Configuration(org.hibernate.ejb.Ejb3Configuration)

Aggregations

IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)137 Test (org.junit.Test)72 Configuration (org.hibernate.cfg.Configuration)65 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)29 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)25 File (java.io.File)19 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)17 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)16 Properties (java.util.Properties)13 CoreException (org.eclipse.core.runtime.CoreException)10 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)10 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)9 FileWriter (java.io.FileWriter)8 IOException (java.io.IOException)8 JDBCReader (org.hibernate.cfg.reveng.JDBCReader)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)7 PartInitException (org.eclipse.ui.PartInitException)7 Ejb3Configuration (org.hibernate.ejb.Ejb3Configuration)7