Search in sources :

Example 11 with ICfg2HbmTool

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

the class FacadeFactoryTest method testCreateCfg2HbmTool.

@Test
public void testCreateCfg2HbmTool() {
    Cfg2HbmTool cfg2HbmTool = new Cfg2HbmTool();
    ICfg2HbmTool facade = facadeFactory.createCfg2HbmTool(cfg2HbmTool);
    Assert.assertSame(cfg2HbmTool, ((IFacade) facade).getTarget());
}
Also used : ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) Test(org.junit.Test)

Example 12 with ICfg2HbmTool

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

the class ServiceImplTest method testNewCfg2HbmTool.

@Test
public void testNewCfg2HbmTool() {
    ICfg2HbmTool cfg2HbmTool = service.newCfg2HbmTool();
    Assert.assertNotNull(cfg2HbmTool);
    Object target = ((IFacade) cfg2HbmTool).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof Cfg2HbmTool);
}
Also used : ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 13 with ICfg2HbmTool

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

the class ServiceImplTest method testNewCfg2HbmTool.

@Test
public void testNewCfg2HbmTool() {
    ICfg2HbmTool cfg2HbmTool = service.newCfg2HbmTool();
    Assert.assertNotNull(cfg2HbmTool);
    Object target = ((IFacade) cfg2HbmTool).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof Cfg2HbmTool);
}
Also used : ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 14 with ICfg2HbmTool

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

the class OpenMappingUtils method generateHbmPropertyPattern.

/**
 * Generates a property xml tag search pattern, which corresponds hibernate hbm syntax.
 *
 * @param property
 * @return a search patterns
 */
public static String generateHbmPropertyPattern(IProperty property, IService service) {
    final ICfg2HbmTool tool = service.newCfg2HbmTool();
    // $NON-NLS-1$
    String toolTag = "";
    IPersistentClass pc = property.getPersistentClass();
    if (pc != null && (property.equals(pc.getIdentifierProperty()))) {
        if (property.isComposite()) {
            // $NON-NLS-1$
            toolTag = "composite-id";
        } else {
            // $NON-NLS-1$
            toolTag = "id";
        }
    } else {
        toolTag = tool.getTag(property);
        if ("component".equals(toolTag) && "embedded".equals(property.getPropertyAccessorName())) {
            // $NON-NLS-1$//$NON-NLS-2$
            // $NON-NLS-1$
            toolTag = "properties";
        }
    }
    return createPattern(toolTag, HIBERNATE_TAG_NAME, property.getName());
}
Also used : ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 15 with ICfg2HbmTool

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

the class OpenMappingUtils method findSelectRegion.

/**
 * Finds a document region, which corresponds of given property.
 * @param proj
 * @param findAdapter
 * @param property
 * @return a proper document region
 */
public static IRegion findSelectRegion(IJavaProject proj, FindReplaceDocumentAdapter findAdapter, IProperty property, IService service) {
    Assert.isNotNull(property.getPersistentClass());
    IRegion classRegion = findSelectRegion(proj, findAdapter, property.getPersistentClass(), service);
    IRegion res = null;
    if (classRegion == null) {
        return res;
    }
    // in case if we could not find property - we select class
    res = classRegion;
    final ICfg2HbmTool tool = service.newCfg2HbmTool();
    final IPersistentClass persistentClass = property.getPersistentClass();
    final String tagName = tool.getTag(persistentClass);
    IRegion finalRegion = null;
    IRegion propRegion = null;
    int startOffset = classRegion.getOffset() + classRegion.getLength();
    try {
        // $NON-NLS-1$
        String tagClose = "</" + tagName;
        finalRegion = findAdapter.find(startOffset, tagClose, true, true, false, false);
        if (finalRegion == null) {
            // $NON-NLS-1$
            tagClose = "</" + EJB_TAG_ENTITY;
            finalRegion = findAdapter.find(startOffset, tagClose, true, true, false, false);
        }
        propRegion = findAdapter.find(startOffset, generateHbmPropertyPattern(property, service), true, true, false, true);
        if (propRegion == null) {
            propRegion = findAdapter.find(startOffset, generateEjbPropertyPattern(property), true, true, false, true);
        }
    } catch (BadLocationException e) {
    // ignore
    }
    String className = persistentClass.getClassName();
    while (propRegion == null) {
        className = ProjectUtils.getParentTypename(proj, className);
        if (className == null) {
            break;
        }
        classRegion = findSelectRegion(proj, findAdapter, className);
        if (classRegion == null) {
            break;
        }
        startOffset = classRegion.getOffset() + classRegion.getLength();
        try {
            // $NON-NLS-1$
            String tagClose = "</" + EJB_TAG_MAPPED_SUPERCLASS;
            finalRegion = findAdapter.find(startOffset, tagClose, true, true, false, false);
            propRegion = findAdapter.find(startOffset, generateEjbPropertyPattern(property), true, true, false, true);
        } catch (BadLocationException e) {
        // ignore
        }
    }
    if (propRegion != null) {
        int length = property.getName().length();
        int offset = propRegion.getOffset() + propRegion.getLength() - length - 1;
        res = new Region(offset, length);
        if (finalRegion != null && propRegion.getOffset() > finalRegion.getOffset()) {
            res = null;
        }
    }
    return res;
}
Also used : ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) IRegion(org.eclipse.jface.text.IRegion) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ICfg2HbmTool (org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool)15 Cfg2HbmTool (org.hibernate.tool.hbm2x.Cfg2HbmTool)12 Test (org.junit.Test)12 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)2 ArrayList (java.util.ArrayList)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1