JBoss Tools SVN: r35471 - trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands.
by jbosstools-commits@lists.jboss.org
Author: koen.aers(a)jboss.com
Date: 2011-10-07 13:42:47 -0400 (Fri, 07 Oct 2011)
New Revision: 35471
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java
Log:
JBIDE-9660: the Forge runtime can now be started by the Cmd+4 shortcut
Modified: trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java 2011-10-07 15:22:45 UTC (rev 35470)
+++ trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java 2011-10-07 17:42:47 UTC (rev 35471)
@@ -2,34 +2,80 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jboss.tools.forge.core.process.ForgeRuntime;
+import org.jboss.tools.forge.ui.ForgeUIPlugin;
import org.jboss.tools.forge.ui.dialog.ForgeCommandListDialog;
import org.jboss.tools.forge.ui.part.ForgeView;
public class ForgeCommandListHandler extends AbstractHandler {
public Object execute(ExecutionEvent executionEvent) {
-
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(executionEvent);
if (window == null) {
return null;
+ }
+ ForgeRuntime runtime = getForgeRuntime(window);
+ if (isStarting(runtime)) {
+ showWaitUntilStartedMessage();
+ } else if (!(isRunning(runtime))) {
+ askUserToStartRuntime(window);
}
+ if (runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) {
+ new ForgeCommandListDialog(window, runtime).open();
+ }
+ return null;
+ }
+
+ private boolean isStarting(ForgeRuntime runtime) {
+ return runtime != null && ForgeRuntime.STATE_STARTING.equals(runtime.getState());
+ }
+
+ private boolean isRunning(ForgeRuntime runtime) {
+ return runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState());
+ }
+
+ private ForgeRuntime getForgeRuntime(IWorkbenchWindow window) {
IViewPart part = window.getActivePage().findView(ForgeView.ID);
- if (part == null || !(part instanceof ForgeView)) {
+ if (part != null && part instanceof ForgeView) {
+ return ((ForgeView)part).getRuntime();
+ } else {
return null;
}
-
- ForgeRuntime runtime = ((ForgeView)part).getRuntime();
- if (runtime == null || !(ForgeRuntime.STATE_RUNNING.equals(runtime.getState()))) {
- return null;
+ }
+
+ private void showWaitUntilStartedMessage() {
+ MessageDialog.openInformation(null, "Forge Starting", "Forge is starting. Please wait until the Forge runtime is started");
+ }
+
+ private void askUserToStartRuntime(final IWorkbenchWindow window) {
+ boolean start = MessageDialog.open(
+ MessageDialog.QUESTION,
+ null,
+ "Forge Not Running",
+ "Forge is not running. Do you want to start the Forge runtime?",
+ SWT.NONE);
+ if (start) {
+ Display.getCurrent().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ IViewPart part = window.getActivePage().showView(ForgeView.ID);
+ if (part != null && part instanceof ForgeView) {
+ ((ForgeView)part).startForge();
+ }
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+ });
}
-
- new ForgeCommandListDialog(window, runtime).open();
-
- return null;
}
}
\ No newline at end of file
13 years, 3 months
JBoss Tools SVN: r35470 - in workspace/yradtsevich/browsersim/swt-browsersim: demo and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2011-10-07 11:22:45 -0400 (Fri, 07 Oct 2011)
New Revision: 35470
Added:
workspace/yradtsevich/browsersim/swt-browsersim/demo/
workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.htm
workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.js
workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.swf
Log:
https://issues.jboss.org/browse/JBIDE-9539
SWT based Browsersim prototype
Added: workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.htm
===================================================================
--- workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.htm (rev 0)
+++ workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.htm 2011-10-07 15:22:45 UTC (rev 35470)
@@ -0,0 +1,15 @@
+<!-- saved from url=(0014)about:internet -->
+<HTML>
+<BODY>
+<center><OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="940" HEIGHT="1044" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=7,0,0,0">
+<PARAM NAME=movie VALUE="swt-browsersim.swf">
+<PARAM NAME=play VALUE=true>
+<PARAM NAME=loop VALUE=false>
+<PARAM NAME=wmode VALUE=transparent>
+<PARAM NAME=quality VALUE=low>
+<EMBED SRC="swt-browsersim.swf" WIDTH=940 HEIGHT=1044 quality=low loop=false wmode=transparent TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=Sh...">
+</EMBED>
+</OBJECT></center>
+<SCRIPT src='swt-browsersim.js'></script>
+</BODY>
+</HTML>
Added: workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.js
===================================================================
--- workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.js (rev 0)
+++ workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.js 2011-10-07 15:22:45 UTC (rev 35470)
@@ -0,0 +1,3 @@
+obj=document.getElementsByTagName('object');
+for (var i=0; i<obj.length; ++i)
+ obj[i].outerHTML=obj[i].outerHTML;
Added: workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.swf
===================================================================
(Binary files differ)
Property changes on: workspace/yradtsevich/browsersim/swt-browsersim/demo/swt-browsersim.swf
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
13 years, 3 months
JBoss Tools SVN: r35468 - in trunk/central/plugins/org.jboss.tools.central: src/org/jboss/tools/central/dialogs and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: fbricon
Date: 2011-10-07 09:40:33 -0400 (Fri, 07 Oct 2011)
New Revision: 35468
Modified:
trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
Log:
Fixed example project icon
Modified: trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF 2011-10-07 11:56:47 UTC (rev 35467)
+++ trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF 2011-10-07 13:40:33 UTC (rev 35468)
@@ -21,7 +21,7 @@
org.eclipse.mylyn.commons.core;bundle-version="3.6.0",
org.eclipse.mylyn.discovery.ui;bundle-version="3.6.0",
org.eclipse.mylyn.discovery.core;bundle-version="3.6.0",
- org.eclipse.mylyn.commons.ui;bundle-version="[3.6.0,3.7.0)",
+ org.eclipse.mylyn.commons.ui;bundle-version="[3.6.0,3.8.0)",
org.eclipse.equinox.p2.ui.sdk;bundle-version="1.0.200",
org.eclipse.equinox.p2.core;bundle-version="2.1.0",
org.eclipse.equinox.p2.engine;bundle-version="2.1.0"
Modified: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java 2011-10-07 11:56:47 UTC (rev 35467)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java 2011-10-07 13:40:33 UTC (rev 35468)
@@ -19,13 +19,9 @@
import org.apache.commons.lang.StringEscapeUtils;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.WorkspaceJob;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.operation.ModalContext;
@@ -64,9 +60,7 @@
import org.jboss.tools.central.actions.JBossRuntimeDetectionPreferencesHandler;
import org.jboss.tools.central.editors.DescriptionToolTip;
import org.jboss.tools.central.model.Tutorial;
-import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
-import org.jboss.tools.project.examples.model.IImportProjectExample;
import org.jboss.tools.project.examples.model.Project;
import org.jboss.tools.project.examples.model.ProjectFix;
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
Modified: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-10-07 11:56:47 UTC (rev 35467)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-10-07 13:40:33 UTC (rev 35468)
@@ -731,7 +731,7 @@
}
protected void configureTutorialText(FormText tutorialText, final Tutorial tutorial) {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append(JBossCentralActivator.FORM_START_TAG);
//boolean haveImage = tutorial.getIconPath() != null && JBossCentralActivator.getDefault().getImage(tutorial.getIconPath()) != null;
//if (haveImage) {
@@ -760,7 +760,7 @@
if (project.getUnsatisfiedFixes().size() > 0) {
image = JBossCentralActivator.getDefault().getImage("/icons/nwarning.gif");
} else {
- image = JBossCentralActivator.getDefault().getImage("/icons/import_obj.png");
+ image = JBossCentralActivator.getDefault().getImage(tutorial.getIconPath());
}
tutorialText.setImage("image", image);
tutorialText.addHyperlinkListener(new HyperlinkAdapter() {
@@ -805,7 +805,7 @@
td.indent = 2;
Point size = newsComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
td.maxWidth = size.x - 2;
- formText.setText(text, true, true);
+ //formText.setText(text, true, true);
//Display display = Display.getCurrent();
//formText.setFont(getLinkFont(display));
formText.setFont("default", JFaceResources.getDefaultFont());
13 years, 3 months
JBoss Tools SVN: r35466 - trunk/as/plugins/org.jboss.tools.openshift.express.ui/icons.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-10-07 07:09:54 -0400 (Fri, 07 Oct 2011)
New Revision: 35466
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/icons/openshift-logo-white-icon.png
Log:
[JBIDE-9860] transformed icon to be transparent
Modified: trunk/as/plugins/org.jboss.tools.openshift.express.ui/icons/openshift-logo-white-icon.png
===================================================================
(Binary files differ)
13 years, 3 months
JBoss Tools SVN: r35465 - trunk/as/plugins/org.jboss.tools.openshift.express.ui.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-10-07 07:03:07 -0400 (Fri, 07 Oct 2011)
New Revision: 35465
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
Log:
[JBIDE-9793] corrected cathegory and wizard naming
Modified: trunk/as/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.tools.openshift.express.ui/plugin.xml 2011-10-07 08:07:08 UTC (rev 35464)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/plugin.xml 2011-10-07 11:03:07 UTC (rev 35465)
@@ -5,14 +5,14 @@
point="org.eclipse.ui.newWizards">
<category
id="org.jboss.ide.eclipse.as.openshift.express.ui.wizard.category"
- name="Openshift Express">
+ name="OpenShift">
</category>
<wizard
category="org.jboss.ide.eclipse.as.openshift.express.ui.wizard.category"
class="org.jboss.tools.openshift.express.internal.ui.wizard.ServerAdapterWizard"
icon="icons/openshift-logo-white-icon.png"
id="org.jboss.ide.eclipse.as.openshift.express.ui.wizard.NewServerAdapter"
- name="New Server Adapter">
+ name="OpenShift Express Application">
</wizard>
</extension>
<extension
13 years, 3 months
JBoss Tools SVN: r35464 - in branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console: ext and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2011-10-07 04:07:08 -0400 (Fri, 07 Oct 2011)
New Revision: 35464
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java
Log:
Execute Criteria Query
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2011-10-07 08:06:58 UTC (rev 35463)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2011-10-07 08:07:08 UTC (rev 35464)
@@ -327,12 +327,17 @@
public QueryPage executeBSHQuery(final String queryString, final QueryInputModel model) {
return (QueryPage)execute(new Command() {
public Object execute() {
- Session session = getSessionFactory().openSession();
+ /*Session session = getSessionFactory().openSession();
QueryPage qp = new JavaPage(ConsoleConfiguration.this,queryString,model);
qp.setSession(session);
qp.setId(++execcount);
fireQueryPageCreated(qp);
+ return qp;*/
+
+ QueryPage qp = new org.hibernate.console.ext.JavaPage(ConsoleConfiguration.this,queryString,model);
+ qp.setId(++execcount);
+ fireQueryPageCreated(qp);
return qp;
}
});
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2011-10-07 08:06:58 UTC (rev 35463)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2011-10-07 08:07:08 UTC (rev 35464)
@@ -43,21 +43,24 @@
private void updateQueryResults(){
try {
list = new ArrayList<Object>();
- long startTime = System.currentTimeMillis();
queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
.executeHQLQuery(queryString, model);
- Iterator<?> iter = queryResult.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
- queryTime = System.currentTimeMillis() - startTime;
- while (iter.hasNext() ) {
- Object element = iter.next();
- list.add(element);
+ if (!queryResult.hasExceptions()){
+ Iterator<?> iter = queryResult.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
+ queryTime = queryResult.getQueryTime();
+ while (iter.hasNext() ) {
+ Object element = iter.next();
+ list.add(element);
+ }
+ pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
+ } else {
+ for (Exception e : queryResult.getExceptions()) {
+ addException(e);
+ }
}
- pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
} catch (HibernateException e) {
- list = Collections.emptyList();
addException(e);
} catch (IllegalArgumentException e) {
- list = Collections.emptyList();
addException(e);
}
}
@@ -90,6 +93,7 @@
public void setQueryString(String queryString) {
this.queryString = queryString;
list = null;
+ queryResult = null;
}
}
\ No newline at end of file
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2011-10-07 08:06:58 UTC (rev 35463)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2011-10-07 08:07:08 UTC (rev 35464)
@@ -28,7 +28,7 @@
public boolean closeSessionFactory();
public boolean reset();
-
+ //TODO do we really need this?
public String getHibernateVersion();
public QueryResult executeHQLQuery(final String hql, final QueryInputModel queryParameters);
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2011-10-07 08:06:58 UTC (rev 35463)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2011-10-07 08:07:08 UTC (rev 35464)
@@ -14,20 +14,13 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.console.AbstractQueryPage;
import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.QueryInputModel;
-import org.hibernate.engine.SessionImplementor;
-import bsh.EvalError;
-import bsh.Interpreter;
-
/**
* @author Dmitry Geraskov
*
@@ -37,10 +30,6 @@
private String criteriaCode;
private QueryResult queryResult;
- Criteria criteria = null;
-
- private Interpreter ip;
-
/**
* @param model
* @param session2
@@ -51,92 +40,42 @@
setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
}
- @SuppressWarnings("unchecked")
- public void setSession(Session s) {
- super.setSession(s);
- try {
- if(criteriaCode.indexOf( "System.exit" )>=0) { // TODO: externalize run so we don't need this bogus check! //$NON-NLS-1$
- list = Collections.emptyList();
- addException( new IllegalArgumentException(ConsoleMessages.JavaPage_not_allowed) );
- return;
- }
- ip = setupInterpreter(getSession() );
- Object o = ip.eval(criteriaCode);
- // ugly! TODO: make un-ugly!
- if(o instanceof Criteria) {
- criteria = (Criteria) o;
- if(model.getMaxResults()!=null) {
- criteria.setMaxResults( model.getMaxResults().intValue() );
- }
- } else if (o instanceof List<?>) {
- list = (List<Object>) o;
- if(model.getMaxResults()!=null) {
- list = list.subList( 0, Math.min( list.size(), model.getMaxResults().intValue() ) );
- }
- } else {
- list = new ArrayList<Object>();
- list.add(o);
- }
- }
- catch (EvalError e) {
- addException(e);
- }
- catch (HibernateException e) {
- addException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- private Interpreter setupInterpreter(Session session) throws EvalError, HibernateException {
- Interpreter interpreter = new Interpreter();
-
- interpreter.set("session", session); //$NON-NLS-1$
- interpreter.setClassLoader( Thread.currentThread().getContextClassLoader() );
- SessionImplementor si = (SessionImplementor)session;
-
- Map<String, ?> map = si.getFactory().getAllClassMetadata();
-
- Iterator<String> iterator = map.keySet().iterator();
- //TODO: filter non classes.
- StringBuilder imports = new StringBuilder(35*(2+map.size()));
- while (iterator.hasNext() ) {
- String element = iterator.next();
- imports.append("import ").append(element).append(";\n"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- imports.append("import org.hibernate.criterion.*;\n"); //$NON-NLS-1$
- imports.append("import org.hibernate.*;\n"); //$NON-NLS-1$
- // TODO: expose the parameters as values to be used in the code.
- interpreter.eval(imports.toString());
-
- return interpreter;
- }
-
- public List<Object> getList() {
+ public List<Object> getList() {
if (criteriaCode==null) return Collections.emptyList();
if (list == null) {
- try {
- list = new ArrayList<Object>();
- long startTime = System.currentTimeMillis();
- queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
- .executeCriteriaQuery(criteriaCode, model);
+ updateQueryResults();
+ }
+ return list;
+ }
+
+ private void updateQueryResults(){
+ try {
+ list = new ArrayList<Object>();
+ queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
+ .executeCriteriaQuery(criteriaCode, model);
+ if (!queryResult.hasExceptions()){
Iterator<?> iter = queryResult.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
- queryTime = System.currentTimeMillis() - startTime;
+ queryTime = queryResult.getQueryTime();
while (iter.hasNext() ) {
Object element = iter.next();
list.add(element);
}
pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
- } catch (HibernateException e) {
- list = Collections.emptyList();
- addException(e);
- } catch (IllegalArgumentException e) {
- list = Collections.emptyList();
- addException(e);
+ } else {
+ for (Exception e : queryResult.getExceptions()) {
+ addException(e);
+ }
}
+ } catch (HibernateException e) {
+ addException(e);
+ } catch (IllegalArgumentException e) {
+ addException(e);
}
- return list;
}
+
+ public void release() {
+ //session is not set, nothing to release
+ }
public List<String> getPathNames() {
try {
@@ -146,13 +85,21 @@
}
return null;
}
+
+ public void setSession(Session s) {
+ //do nothing
+ }
+
public String getQueryString() {
return criteriaCode;
}
- public void setQueryString(String queryString) {
- this.criteriaCode = queryString;
+
+ @Override
+ public void setQueryString(String criteriaCode) {
+ this.criteriaCode = criteriaCode;
list = null;
- ip = null;
+ queryResult = null;
}
+
}
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java 2011-10-07 08:06:58 UTC (rev 35463)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java 2011-10-07 08:07:08 UTC (rev 35464)
@@ -21,5 +21,13 @@
public List<Object> list();
public List<String> getPathNames();
+
+ public long getQueryTime();
+
+ public boolean hasExceptions();
+
+ public List<Exception> getExceptions();
+ public void setPathNames(List<String> pathNames);
+
}
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java 2011-10-07 08:06:58 UTC (rev 35463)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java 2011-10-07 08:07:08 UTC (rev 35464)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.hibernate.console.ext;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -19,12 +20,14 @@
*/
public class QueryResultImpl implements QueryResult {
- private List<Object> list;
+ private List<Object> list = new ArrayList<Object>();;
private List<String> pathNames = Collections.emptyList();
private long execTime;
+ private List<Exception> exceptions = new ArrayList<Exception>();
+
public QueryResultImpl(List<Object> list, long execTime){
this.list = list;
this.execTime = execTime;
@@ -34,6 +37,10 @@
this(list, execTime);
this.pathNames = pathNames;
}
+
+ public QueryResultImpl(Exception e){
+ exceptions.add(e);
+ }
@Override
public List<Object> list() {
@@ -44,9 +51,32 @@
public List<String> getPathNames() {
return pathNames;
}
+
+ @Override
+ public void setPathNames(List<String> pathNames) {
+ this.pathNames = pathNames;
+ }
public long getExecTime() {
return execTime;
}
+ @Override
+ public long getQueryTime() {
+ return execTime;
+ }
+
+ public void addException(Exception e){
+ exceptions.add(e);
+ }
+
+ public List<Exception> getExceptions(){
+ return this.exceptions;
+ }
+
+ @Override
+ public boolean hasExceptions() {
+ return getExceptions().size() > 0;
+ }
+
}
13 years, 3 months
JBoss Tools SVN: r35463 - in branches/dead/hibernatetools-multiversion2/plugins: org.jboss.tools.hibernate4_0 and 3 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2011-10-07 04:06:58 -0400 (Fri, 07 Oct 2011)
New Revision: 35463
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryExecutor.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/lib/bsh-core-2.0b4.jar
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryExecutor.java
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/.classpath
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/build.properties
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java
Log:
Execute Criteria Query
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java 2011-10-07 07:29:26 UTC (rev 35462)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java 2011-10-07 08:06:58 UTC (rev 35463)
@@ -3,22 +3,15 @@
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConfigurationFactory;
import org.hibernate.console.ConsoleConfigClassLoader;
import org.hibernate.console.ConsoleMessages;
-import org.hibernate.console.ConsoleQueryParameter;
import org.hibernate.console.QueryInputModel;
import org.hibernate.console.execution.DefaultExecutionContext;
import org.hibernate.console.execution.ExecutionContext;
@@ -30,7 +23,6 @@
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.console.preferences.PreferencesClassPathUtils;
import org.hibernate.eclipse.libs.FakeDelegatingDriver;
-import org.hibernate.type.Type;
public class HibernateExtension3_5 implements HibernateExtension {
@@ -53,111 +45,49 @@
}
@Override
- public QueryResult executeHQLQuery(final String hql,
- final QueryInputModel queryParameters) {
- System.out.println("Execute HQLQuery in " + getClass().getName());
- Session session = sessionFactory.openSession();
- Query query = session.createQuery(hql);
- List<Object> list = Collections.emptyList();
- long queryTime = 0;
+ public QueryResult executeHQLQuery(String hql,
+ QueryInputModel queryParameters) {
+ Session session = null;
try {
- list = new ArrayList<Object>();
- setupParameters(query, queryParameters);
- long startTime = System.currentTimeMillis();
- Iterator<?> iter = query.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
- queryTime = System.currentTimeMillis() - startTime;
- while (iter.hasNext() ) {
- Object element = iter.next();
- list.add(element);
+ try {
+ session = sessionFactory.openSession();
+ } catch (Exception e){
+ return new QueryResultImpl(e);
}
- }
- catch (HibernateException e) {
- e.printStackTrace();
+ return QueryExecutor.executeHQLQuery(session, hql, queryParameters);
+ } finally {
+ if (session != null && session.isOpen()){
+ try {
+ session.close();
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
}
- return new QueryResultImpl(list,
- getPathNames(query), queryTime);
}
-
- public List<String> getPathNames(Query query) {
- List<String> l = Collections.emptyList();
-
- try {
- if(query==null) return l;
- String[] returnAliases = null;
- try {
- returnAliases = query.getReturnAliases();
- } catch(NullPointerException e) {
- // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
- }
- if(returnAliases==null) {
- Type[] t;
- try {
- t = query.getReturnTypes();
- } catch(NullPointerException npe) {
- t = new Type[] { null };
- // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
- }
- l = new ArrayList<String>(t.length);
-
- for (int i = 0; i < t.length; i++) {
- Type type = t[i];
- if(type==null) {
- l.add("<multiple types>"); //$NON-NLS-1$
- } else {
- l.add(type.getName() );
- }
- }
- } else {
- String[] t = returnAliases;
- l = new ArrayList<String>(t.length);
-
- for (int i = 0; i < t.length; i++) {
- l.add(t[i]);
- }
- }
- } catch (HibernateException he) {
- he.printStackTrace();
- }
-
- return l;
- }
-
- private void setupParameters(Query query2, QueryInputModel model) {
-
- if(model.getMaxResults()!=null) {
- query2.setMaxResults( model.getMaxResults().intValue() );
- }
-
- ConsoleQueryParameter[] qp = model.getQueryParameters();
- for (int i = 0; i < qp.length; i++) {
- ConsoleQueryParameter parameter = qp[i];
-
+
+ @Override
+ public QueryResult executeCriteriaQuery(String criteriaCode,
+ QueryInputModel model) {
+ Session session = null;
+ try {
try {
- int pos = Integer.parseInt(parameter.getName());
- //FIXME no method to set positioned list value
- query2.setParameter(pos, calcValue( parameter ), parameter.getType());
- } catch(NumberFormatException nfe) {
- Object value = parameter.getValue();
- if (value != null && value.getClass().isArray()){
- Object[] values = (Object[])value;
- query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
- } else {
- query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
- }
+ session = sessionFactory.openSession();
+ } catch (Exception e){
+ return new QueryResultImpl(e);
}
- }
+ return QueryExecutor.executeCriteriaQuery(session, criteriaCode, model);
+ } finally {
+ if (session != null && session.isOpen()){
+ try {
+ session.close();
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
+ }
}
-
- private Object calcValue(ConsoleQueryParameter parameter) {
- return parameter.getValueForQuery();
- }
- @Override
- public QueryResult executeCriteriaQuery(String criteria,
- QueryInputModel queryParameters) {
- return null;
- }
-
/**
* @param ConsoleConfigurationPreferences the prefs to set
*/
Added: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryExecutor.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryExecutor.java (rev 0)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryExecutor.java 2011-10-07 08:06:58 UTC (rev 35463)
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_5;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.ConsoleQueryParameter;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.QueryResult;
+import org.hibernate.console.ext.QueryResultImpl;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.Type;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class QueryExecutor {
+
+ public static QueryResult executeHQLQuery(Session session, String hql,
+ QueryInputModel queryParameters) {
+
+ Query query = session.createQuery(hql);
+ List<Object> list = Collections.emptyList();
+ long queryTime = 0;
+
+ list = new ArrayList<Object>();
+ setupParameters(query, queryParameters);
+ long startTime = System.currentTimeMillis();
+ Iterator<?> iter = query.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
+ queryTime = System.currentTimeMillis() - startTime;
+ while (iter.hasNext() ) {
+ Object element = iter.next();
+ list.add(element);
+ }
+
+ QueryResultImpl result = new QueryResultImpl(list,
+ queryTime);
+ try{
+ result.setPathNames(getHQLPathNames(query));
+ } catch (HibernateException e){
+ result.addException(e);
+ }
+ return result;
+
+ }
+
+ public static QueryResult executeCriteriaQuery(Session session, String criteriaCode,
+ QueryInputModel model) {
+
+ try {
+ List<Object> list = Collections.emptyList();
+ long queryTime = 0;
+ if (criteriaCode.indexOf("System.exit") >= 0) { // TODO: externalize run so we don't need this bogus check! //$NON-NLS-1$
+ return new QueryResultImpl(new IllegalArgumentException(
+ ConsoleMessages.JavaPage_not_allowed));
+ } else {
+ Interpreter ip = setupInterpreter(session);
+ Object o = ip.eval(criteriaCode);
+ // ugly! TODO: make un-ugly!
+ if (o instanceof Criteria) {
+ Criteria criteria = (Criteria) o;
+ if (model.getMaxResults() != null) {
+ criteria.setMaxResults(model.getMaxResults().intValue());
+ }
+
+ long startTime = System.currentTimeMillis();
+ list = criteria.list();
+ queryTime = System.currentTimeMillis() - startTime;
+ } else if (o instanceof List<?>) {
+ list = (List<Object>) o;
+ if (model.getMaxResults() != null) {
+ list = list.subList(0, Math.min(list.size(), model
+ .getMaxResults().intValue()));
+ }
+ } else {
+ list = new ArrayList<Object>();
+ list.add(o);
+ }
+ }
+ return new QueryResultImpl(list,
+ Collections.singletonList(ConsoleMessages.JavaPage_no_info), queryTime);
+ } catch (EvalError e) {
+ return new QueryResultImpl(e);
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
+
+ private static List<String> getHQLPathNames(Query query) {
+ List<String> l = Collections.emptyList();
+
+ if(query==null) return l;
+ String[] returnAliases = null;
+ try {
+ returnAliases = query.getReturnAliases();
+ } catch(NullPointerException e) {
+ // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
+ }
+ if(returnAliases==null) {
+ Type[] t;
+ try {
+ t = query.getReturnTypes();
+ } catch(NullPointerException npe) {
+ t = new Type[] { null };
+ // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
+ }
+ l = new ArrayList<String>(t.length);
+
+ for (int i = 0; i < t.length; i++) {
+ Type type = t[i];
+ if(type==null) {
+ l.add("<multiple types>"); //$NON-NLS-1$
+ } else {
+ l.add(type.getName() );
+ }
+ }
+ } else {
+ String[] t = returnAliases;
+ l = new ArrayList<String>(t.length);
+
+ for (int i = 0; i < t.length; i++) {
+ l.add(t[i]);
+ }
+ }
+
+ return l;
+ }
+
+ private static void setupParameters(Query query2, QueryInputModel model) {
+ if(model.getMaxResults()!=null) {
+ query2.setMaxResults( model.getMaxResults().intValue() );
+ }
+ ConsoleQueryParameter[] qp = model.getQueryParameters();
+ for (int i = 0; i < qp.length; i++) {
+ ConsoleQueryParameter parameter = qp[i];
+
+ try {
+ int pos = Integer.parseInt(parameter.getName());
+ //FIXME no method to set positioned list value
+ query2.setParameter(pos, calcValue( parameter ), parameter.getType());
+ } catch(NumberFormatException nfe) {
+ Object value = parameter.getValue();
+ if (value != null && value.getClass().isArray()){
+ Object[] values = (Object[])value;
+ query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
+ } else {
+ query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
+ }
+ }
+ }
+ }
+
+ private static Object calcValue(ConsoleQueryParameter parameter) {
+ return parameter.getValueForQuery();
+ }
+
+
+ private static Interpreter setupInterpreter(Session session) throws EvalError, HibernateException {
+ Interpreter interpreter = new Interpreter();
+
+ interpreter.set("session", session); //$NON-NLS-1$
+ interpreter.setClassLoader( Thread.currentThread().getContextClassLoader() );
+ SessionImplementor si = (SessionImplementor)session;
+
+ Map<String, ?> map = si.getFactory().getAllClassMetadata();
+
+ Iterator<String> iterator = map.keySet().iterator();
+ //TODO: filter non classes.
+ String imports = ""; //$NON-NLS-1$
+ while (iterator.hasNext() ) {
+ String element = iterator.next();
+ imports += "import " + element + ";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ imports += "import org.hibernate.criterion.*;\n"; //$NON-NLS-1$
+ imports += "import org.hibernate.*;\n"; //$NON-NLS-1$
+ // TODO: expose the parameters as values to be used in the code.
+ interpreter.eval(imports);
+
+ return interpreter;
+ }
+
+}
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/.classpath
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/.classpath 2011-10-07 07:29:26 UTC (rev 35462)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/.classpath 2011-10-07 08:06:58 UTC (rev 35463)
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry exported="true" kind="lib" path="lib/bsh-core-2.0b4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/optional/ehcache/ehcache-core-2.4.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/optional/ehcache/hibernate-ehcache-4.0.0.CR3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/optional/infinispan/hibernate-infinispan-4.0.0.CR3.jar"/>
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF 2011-10-07 07:29:26 UTC (rev 35462)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF 2011-10-07 08:06:58 UTC (rev 35463)
@@ -24,4 +24,5 @@
lib/required/javassist-3.12.0.GA.jar,
lib/required/jta-1.1.jar,
lib/jpa/hibernate-entitymanager-4.0.0.CR3.jar,
+ lib/bsh-core-2.0b4.jar,
.
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/build.properties
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/build.properties 2011-10-07 07:29:26 UTC (rev 35462)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/build.properties 2011-10-07 08:06:58 UTC (rev 35463)
@@ -28,4 +28,5 @@
lib/optional/infinispan/jgroups-2.12.0.Final.jar,\
lib/optional/infinispan/rhq-pluginAnnotations-3.0.1.jar,\
lib/optional/proxool/hibernate-proxool-4.0.0.CR3.jar,\
- lib/optional/proxool/proxool-0.8.3.jar
+ lib/optional/proxool/proxool-0.8.3.jar,\
+ lib/bsh-core-2.0b4.jar
Added: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/lib/bsh-core-2.0b4.jar
===================================================================
(Binary files differ)
Property changes on: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/lib/bsh-core-2.0b4.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java 2011-10-07 07:29:26 UTC (rev 35462)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java 2011-10-07 08:06:58 UTC (rev 35463)
@@ -5,22 +5,16 @@
import java.security.PrivilegedAction;
import java.sql.DriverManager;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfigClassLoader;
import org.hibernate.console.ConsoleMessages;
-import org.hibernate.console.ConsoleQueryParameter;
import org.hibernate.console.QueryInputModel;
import org.hibernate.console.execution.DefaultExecutionContext;
import org.hibernate.console.execution.ExecutionContext;
@@ -34,7 +28,6 @@
import org.hibernate.service.BasicServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
-import org.hibernate.type.Type;
public class HibernateExtension4_0 implements HibernateExtension {
@@ -59,118 +52,51 @@
public String getHibernateVersion() {
return "4.0";
}
-
+
@Override
public QueryResult executeHQLQuery(String hql,
QueryInputModel queryParameters) {
- System.out.println("Execute HQLQuery in " + getClass().getName());
Session session = null;
try {
- session = sessionFactory.openSession();
- } catch (Exception e){
- e.printStackTrace();
- }
- Query query = session.createQuery(hql);
- List<Object> list = Collections.emptyList();
- long queryTime = 0;
- try {
- list = new ArrayList<Object>();
- setupParameters(query, queryParameters);
- long startTime = System.currentTimeMillis();
- Iterator<?> iter = query.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
- queryTime = System.currentTimeMillis() - startTime;
- while (iter.hasNext() ) {
- Object element = iter.next();
- list.add(element);
+ try {
+ session = sessionFactory.openSession();
+ } catch (Exception e){
+ return new QueryResultImpl(e);
}
- }
- catch (HibernateException e) {
- e.printStackTrace();
+ return QueryExecutor.executeHQLQuery(session, hql, queryParameters);
+ } finally {
+ if (session != null && session.isOpen()){
+ try {
+ session.close();
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
}
- return new QueryResultImpl(list,
- getPathNames(query), queryTime);
}
-
- public List<String> getPathNames(Query query) {
- List<String> l = Collections.emptyList();
-
- try {
- if(query==null) return l;
- String[] returnAliases = null;
- try {
- returnAliases = query.getReturnAliases();
- } catch(NullPointerException e) {
- // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
- }
- if(returnAliases==null) {
- Type[] t;
- try {
- t = query.getReturnTypes();
- } catch(NullPointerException npe) {
- t = new Type[] { null };
- // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
- }
- l = new ArrayList<String>(t.length);
-
- for (int i = 0; i < t.length; i++) {
- Type type = t[i];
- if(type==null) {
- l.add("<multiple types>"); //$NON-NLS-1$
- } else {
- l.add(type.getName() );
- }
- }
- } else {
- String[] t = returnAliases;
- l = new ArrayList<String>(t.length);
-
- for (int i = 0; i < t.length; i++) {
- l.add(t[i]);
- }
- }
- } catch (HibernateException he) {
- he.printStackTrace();
- }
-
- return l;
- }
-
- private void setupParameters(Query query2, QueryInputModel model) {
-
- if(model.getMaxResults()!=null) {
- query2.setMaxResults( model.getMaxResults().intValue() );
- }
-
- ConsoleQueryParameter[] qp = model.getQueryParameters();
- for (int i = 0; i < qp.length; i++) {
- ConsoleQueryParameter parameter = qp[i];
-
+
+ @Override
+ public QueryResult executeCriteriaQuery(String criteriaCode,
+ QueryInputModel model) {
+ Session session = null;
+ try {
try {
- int pos = Integer.parseInt(parameter.getName());
- //FIXME no method to set positioned list value
- query2.setParameter(pos, calcValue( parameter ), parameter.getType());
- } catch(NumberFormatException nfe) {
- Object value = parameter.getValue();
- if (value != null && value.getClass().isArray()){
- Object[] values = (Object[])value;
- query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
- } else {
- query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
- }
+ session = sessionFactory.openSession();
+ } catch (Exception e){
+ return new QueryResultImpl(e);
}
- }
+ return QueryExecutor.executeCriteriaQuery(session, criteriaCode, model);
+ } finally {
+ if (session != null && session.isOpen()){
+ try {
+ session.close();
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
+ }
}
-
- private Object calcValue(ConsoleQueryParameter parameter) {
- return parameter.getValueForQuery();
- }
- @Override
- public QueryResult executeCriteriaQuery(String criteria,
- QueryInputModel queryParameters) {
- return null;
- }
-
/**
* @param ConsoleConfigurationPreferences the prefs to set
*/
Added: branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryExecutor.java
===================================================================
--- branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryExecutor.java (rev 0)
+++ branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryExecutor.java 2011-10-07 08:06:58 UTC (rev 35463)
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate4_0;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.ConsoleQueryParameter;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.QueryResult;
+import org.hibernate.console.ext.QueryResultImpl;
+import org.hibernate.engine.spi.SessionImplementor;
+import org.hibernate.type.Type;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class QueryExecutor {
+
+ public static QueryResult executeHQLQuery(Session session, String hql,
+ QueryInputModel queryParameters) {
+
+ Query query = session.createQuery(hql);
+ List<Object> list = Collections.emptyList();
+ long queryTime = 0;
+
+ list = new ArrayList<Object>();
+ setupParameters(query, queryParameters);
+ long startTime = System.currentTimeMillis();
+ Iterator<?> iter = query.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
+ queryTime = System.currentTimeMillis() - startTime;
+ while (iter.hasNext() ) {
+ Object element = iter.next();
+ list.add(element);
+ }
+
+ QueryResultImpl result = new QueryResultImpl(list,
+ queryTime);
+ try{
+ result.setPathNames(getHQLPathNames(query));
+ } catch (HibernateException e){
+ result.addException(e);
+ }
+ return result;
+
+ }
+
+ public static QueryResult executeCriteriaQuery(Session session, String criteriaCode,
+ QueryInputModel model) {
+
+ try {
+ List<Object> list = Collections.emptyList();
+ long queryTime = 0;
+ if (criteriaCode.indexOf("System.exit") >= 0) { // TODO: externalize run so we don't need this bogus check! //$NON-NLS-1$
+ return new QueryResultImpl(new IllegalArgumentException(
+ ConsoleMessages.JavaPage_not_allowed));
+ } else {
+ Interpreter ip = setupInterpreter(session);
+ Object o = ip.eval(criteriaCode);
+ // ugly! TODO: make un-ugly!
+ if (o instanceof Criteria) {
+ Criteria criteria = (Criteria) o;
+ if (model.getMaxResults() != null) {
+ criteria.setMaxResults(model.getMaxResults().intValue());
+ }
+
+ long startTime = System.currentTimeMillis();
+ list = criteria.list();
+ queryTime = System.currentTimeMillis() - startTime;
+ } else if (o instanceof List<?>) {
+ list = (List<Object>) o;
+ if (model.getMaxResults() != null) {
+ list = list.subList(0, Math.min(list.size(), model
+ .getMaxResults().intValue()));
+ }
+ } else {
+ list = new ArrayList<Object>();
+ list.add(o);
+ }
+ }
+ return new QueryResultImpl(list,
+ Collections.singletonList(ConsoleMessages.JavaPage_no_info), queryTime);
+ } catch (EvalError e) {
+ return new QueryResultImpl(e);
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
+
+ private static List<String> getHQLPathNames(Query query) {
+ List<String> l = Collections.emptyList();
+
+ if(query==null) return l;
+ String[] returnAliases = null;
+ try {
+ returnAliases = query.getReturnAliases();
+ } catch(NullPointerException e) {
+ // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
+ }
+ if(returnAliases==null) {
+ Type[] t;
+ try {
+ t = query.getReturnTypes();
+ } catch(NullPointerException npe) {
+ t = new Type[] { null };
+ // ignore - http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
+ }
+ l = new ArrayList<String>(t.length);
+
+ for (int i = 0; i < t.length; i++) {
+ Type type = t[i];
+ if(type==null) {
+ l.add("<multiple types>"); //$NON-NLS-1$
+ } else {
+ l.add(type.getName() );
+ }
+ }
+ } else {
+ String[] t = returnAliases;
+ l = new ArrayList<String>(t.length);
+
+ for (int i = 0; i < t.length; i++) {
+ l.add(t[i]);
+ }
+ }
+
+ return l;
+ }
+
+ private static void setupParameters(Query query2, QueryInputModel model) {
+ if(model.getMaxResults()!=null) {
+ query2.setMaxResults( model.getMaxResults().intValue() );
+ }
+ ConsoleQueryParameter[] qp = model.getQueryParameters();
+ for (int i = 0; i < qp.length; i++) {
+ ConsoleQueryParameter parameter = qp[i];
+
+ try {
+ int pos = Integer.parseInt(parameter.getName());
+ //FIXME no method to set positioned list value
+ query2.setParameter(pos, calcValue( parameter ), parameter.getType());
+ } catch(NumberFormatException nfe) {
+ Object value = parameter.getValue();
+ if (value != null && value.getClass().isArray()){
+ Object[] values = (Object[])value;
+ query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
+ } else {
+ query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
+ }
+ }
+ }
+ }
+
+ private static Object calcValue(ConsoleQueryParameter parameter) {
+ return parameter.getValueForQuery();
+ }
+
+
+ private static Interpreter setupInterpreter(Session session) throws EvalError, HibernateException {
+ Interpreter interpreter = new Interpreter();
+
+ interpreter.set("session", session); //$NON-NLS-1$
+ interpreter.setClassLoader( Thread.currentThread().getContextClassLoader() );
+ SessionImplementor si = (SessionImplementor)session;
+
+ Map<String, ?> map = si.getFactory().getAllClassMetadata();
+
+ Iterator<String> iterator = map.keySet().iterator();
+ //TODO: filter non classes.
+ String imports = ""; //$NON-NLS-1$
+ while (iterator.hasNext() ) {
+ String element = iterator.next();
+ imports += "import " + element + ";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ imports += "import org.hibernate.criterion.*;\n"; //$NON-NLS-1$
+ imports += "import org.hibernate.*;\n"; //$NON-NLS-1$
+ // TODO: expose the parameters as values to be used in the code.
+ interpreter.eval(imports);
+
+ return interpreter;
+ }
+
+}
13 years, 3 months
JBoss Tools SVN: r35462 - trunk/common/features/org.jboss.tools.common.jdt.feature.
by jbosstools-commits@lists.jboss.org
Author: fbricon
Date: 2011-10-07 03:29:26 -0400 (Fri, 07 Oct 2011)
New Revision: 35462
Modified:
trunk/common/features/org.jboss.tools.common.jdt.feature/feature.xml
Log:
JBIDE-8972 : should work MUCH better if I commit the feature.xml referencing the new JDT plugins
Modified: trunk/common/features/org.jboss.tools.common.jdt.feature/feature.xml
===================================================================
--- trunk/common/features/org.jboss.tools.common.jdt.feature/feature.xml 2011-10-07 05:36:17 UTC (rev 35461)
+++ trunk/common/features/org.jboss.tools.common.jdt.feature/feature.xml 2011-10-07 07:29:26 UTC (rev 35462)
@@ -15,4 +15,6 @@
<plugin id="org.jboss.tools.common.jdt.debug" download-size="0" install-size="0" version="0.0.0" unpack="false" />
<plugin id="org.jboss.tools.common.jdt.debug.ui" download-size="0" install-size="0" version="0.0.0" unpack="false" />
+ <plugin id="org.jboss.tools.common.jdt" download-size="0" install-size="0" version="0.0.0" unpack="false" />
+ <plugin id="org.jboss.tools.common.jdt.ui" download-size="0" install-size="0" version="0.0.0" unpack="false" />
</feature>
13 years, 3 months