use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class OpenSourceAction method run.
public void run() {
IStructuredSelection sel = getStructuredSelection();
if (!(sel instanceof TreeSelection)) {
return;
}
TreePath[] paths = ((TreeSelection) sel).getPaths();
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
Object lastSegment = path.getLastSegment();
IPersistentClass persClass = getPersistentClass(lastSegment);
ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
String fullyQualifiedName = null;
if (lastSegment instanceof IProperty) {
Object prevSegment = path.getParentPath().getLastSegment();
if (prevSegment instanceof IProperty && ((IProperty) prevSegment).isComposite()) {
fullyQualifiedName = ((IValue) ((IProperty) prevSegment).getValue()).getComponentClassName();
}
}
if (fullyQualifiedName == null && persClass != null) {
fullyQualifiedName = persClass.getClassName();
}
try {
run(consoleConfig, lastSegment, fullyQualifiedName);
} catch (JavaModelException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
} catch (PartInitException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_open_source_file, e);
} catch (FileNotFoundException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
}
}
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class CriteriaEditor method getImports.
private String[] getImports() {
final ConsoleConfiguration consoleConfiguration = getConsoleConfiguration();
if (!consoleConfiguration.hasConfiguration()) {
try {
consoleConfiguration.build();
consoleConfiguration.buildMappings();
} catch (Exception e) {
String mess = NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc, consoleConfiguration.getName());
HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
}
}
Set<String> imports = new HashSet<String>();
IConfiguration configuration = consoleConfiguration.getConfiguration();
if (configuration != null) {
Iterator<IPersistentClass> classMappings = configuration.getClassMappings();
while (classMappings.hasNext()) {
IPersistentClass clazz = classMappings.next();
String className = clazz.getClassName();
if (className != null) {
imports.add(className);
}
}
}
// $NON-NLS-1$
imports.add("org.hibernate.*");
// $NON-NLS-1$
imports.add("org.hibernate.criterion.*");
return imports.toArray(new String[imports.size()]);
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class ConfigurationViewAdapter method getPersistentClasses.
public List<PersistentClassViewAdapter> getPersistentClasses() {
if (persistentClasses == null) {
Iterator<IPersistentClass> classMappings = cfg.getClassMappings();
persistentClasses = new HashMap<String, PersistentClassViewAdapter>();
while (classMappings.hasNext()) {
IPersistentClass clazz = classMappings.next();
persistentClasses.put(clazz.getEntityName(), new PersistentClassViewAdapter(this, clazz));
}
Iterator<PersistentClassViewAdapter> iterator = persistentClasses.values().iterator();
while (iterator.hasNext()) {
PersistentClassViewAdapter element = iterator.next();
element.getSourceAssociations();
}
}
return new ArrayList<PersistentClassViewAdapter>(persistentClasses.values());
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class TypeVisitor method visit.
@Override
public boolean visit(ParameterizedType type) {
// $NON-NLS-1$
Assert.isNotNull(type, "Type object cannot be null");
// $NON-NLS-1$
Assert.isNotNull(entityInfo, "EntityInfo object cannot be null");
ITypeBinding tb = type.resolveBinding();
// Unresolved binding. Omit the property.
if (tb == null)
return false;
rootClass = rootClasses.get(entityInfo.getFullyQualifiedName());
// $NON-NLS-1$
Assert.isNotNull(rootClass, "RootClass not found.");
ITypeBinding[] interfaces = Utils.getAllInterfaces(tb);
IValue value = buildCollectionValue(interfaces);
if (value != null) {
if (ref != null && rootClasses.get(ref.fullyQualifiedName) != null) {
IValue oValue = service.newOneToMany(rootClass);
IPersistentClass associatedClass = rootClasses.get(ref.fullyQualifiedName);
oValue.setAssociatedClass(associatedClass);
oValue.setReferencedEntityName(associatedClass.getEntityName());
// Set another table
value.setCollectionTable(associatedClass.getTable());
value.setElement(oValue);
} else {
IValue elementValue = buildSimpleValue(tb.getTypeArguments()[0].getQualifiedName());
elementValue.setTable(rootClass.getTable());
value.setElement(elementValue);
// TODO what to set?
value.setCollectionTable(rootClass.getTable());
}
if (value.isList()) {
value.setIndex(service.newSimpleValue());
} else if (value.isMap()) {
IValue map_key = service.newSimpleValue();
// FIXME: is it possible to map Map<SourceType, String>?
// Or only Map<String, SourceType>
map_key.setTypeName(tb.getTypeArguments()[0].getBinaryName());
value.setIndex(map_key);
}
}
if (value == null) {
value = buildSimpleValue(tb.getBinaryName());
}
buildProperty(value);
if (!(value.isSimpleValue())) {
// $NON-NLS-1$
prop.setCascade("none");
}
// do not visit children
return false;
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class TypeVisitor method createHierarhyStructure.
/**
* Replace <class> element on <joined-subclass> or <subclass>.
* @param project
* @param rootClasses
* @return
*/
private Collection<IPersistentClass> createHierarhyStructure(IJavaProject project, Map<String, IPersistentClass> rootClasses) {
IService service = getService(project);
Map<String, IPersistentClass> pcCopy = new HashMap<String, IPersistentClass>();
for (Map.Entry<String, IPersistentClass> entry : rootClasses.entrySet()) {
pcCopy.put(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, IPersistentClass> entry : pcCopy.entrySet()) {
IPersistentClass pc = null;
try {
pc = getMappedSuperclass(project, pcCopy, entry.getValue());
IPersistentClass subclass = null;
if (pc != null) {
if (pc.isAbstract()) {
subclass = service.newSingleTableSubclass(pc);
if (pc.isInstanceOfRootClass() && pc.getDiscriminator() == null) {
IValue discr = service.newSimpleValue();
// $NON-NLS-1$
discr.setTypeName("string");
// $NON-NLS-1$
discr.addColumn(service.newColumn("DISCR_COL"));
pc.setDiscriminator(discr);
}
} else {
subclass = service.newJoinedSubclass(pc);
}
} else {
pc = getMappedImplementedInterface(project, pcCopy, entry.getValue());
if (pc != null) {
subclass = service.newSingleTableSubclass(pc);
}
}
if (subclass != null) {
IPersistentClass pastClass = pcCopy.get(entry.getKey());
subclass.setClassName(pastClass.getClassName());
subclass.setEntityName(pastClass.getEntityName());
subclass.setDiscriminatorValue(StringHelper.unqualify(pastClass.getClassName()));
subclass.setAbstract(pastClass.isAbstract());
if (subclass.isInstanceOfJoinedSubclass()) {
subclass.setTable(service.newTable(StringHelper.unqualify(pastClass.getClassName()).toUpperCase()));
subclass.setKey(pc.getIdentifierProperty().getValue());
}
if (pastClass.getIdentifierProperty() != null) {
subclass.addProperty(pastClass.getIdentifierProperty());
}
Iterator<IProperty> it = pastClass.getPropertyIterator();
while (it.hasNext()) {
subclass.addProperty(it.next());
}
entry.setValue(subclass);
}
} catch (JavaModelException e) {
HibernateConsolePlugin.getDefault().log(e);
}
}
return pcCopy.values();
}
Aggregations