Author: vyemialyanchyk
Date: 2010-03-16 14:47:52 -0400 (Tue, 16 Mar 2010)
New Revision: 20851
Added:
branches/hibernatetools-multiversion/
branches/hibernatetools-multiversion/hibernatetools/
branches/hibernatetools-multiversion/hibernatetools/plugins/
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/ELTransformer.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/Formatter.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/QLFormatHelper.java
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/.classpath
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConcoleConfigurationAdapter.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigurationListener.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsAdapter.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsListener.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/ConfigurationNode.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/NodeFactory.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-6070 - initial step
Copied: branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse
(from rev 20798, trunk/hibernatetools/plugins/org.hibernate.eclipse)
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/.classpath
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/.classpath 2010-03-12 13:16:53 UTC
(rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/.classpath 2010-03-16
18:47:52 UTC (rev 20851)
@@ -6,7 +6,7 @@
<classpathentry exported="true" kind="lib"
path="lib/hibernate/asm.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/asm-attrs.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/dom4j-1.6.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/hibernate/hibernate3.jar"
sourcepath="C:/Temp/_hibernate/hibernate-core-3.3.2.GA-sources.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/hibernate/hibernate3.jar"
sourcepath="D:/Temp/_hibernate/hibernate-core-3.3.2.GA-sources.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/jboss-cache.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/jboss-common.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/jboss-jmx.jar"/>
@@ -18,18 +18,18 @@
<classpathentry exported="true" kind="lib"
path="lib/hibernate/proxool-0.8.3.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/swarmcache-1.0rc2.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/bsh-core-2.0b4.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-annotations.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-annotations.jar"
sourcepath="D:/Temp/_hibernate/hibernate-annotations-3.4.0.GA-sources.jar
"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/jgroups-2.2.8.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/antlr-2.7.6.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-entitymanager.jar"
sourcepath="C:/Temp/_hibernate/hibernate-entitymanager-3.4.0.GA-sources.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-entitymanager.jar"
sourcepath="D:/Temp/_hibernate/hibernate-entitymanager-3.4.0.GA-sources.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/javassist.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-validator.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/log4j-1.2.15.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/hibernate/hibernate-jmx.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/hibernate/hibernate-jmx.jar"
sourcepath="D:/Temp/_hibernate/hibernate-jmx-3.3.2.GA-sources.jar "/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/commons-collections-3.1.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/slf4j-api-1.5.8.jar"
sourcepath="D:/Temp/_hibernate/slf4j-api-1.5.8-sources.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/cglib-2.2.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-commons-annotations.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/annotations/hibernate-commons-annotations.jar"
sourcepath="D:/Temp/_hibernate/hibernate-commons-annotations-3.1.0.GA-sources.jar
"/>
<classpathentry exported="true" kind="lib"
path="lib/annotations/ejb3-persistence.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/c3p0-0.9.1.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/commons-logging-1.0.4.jar"/>
@@ -38,7 +38,7 @@
<classpathentry exported="true" kind="lib"
path="lib/hibernate/ehcache-1.2.3.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/hibernate/slf4j-log4j12-1.5.8.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/tools/freemarker.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/tools/hibernate-tools.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/tools/hibernate-tools.jar"
sourcepath="C:/RHDS/hibernate/branches/Branch_3_2/HibernateExt_without_changes"/>
<classpathentry exported="true" kind="lib"
path="lib/tools/jtidy-r8-20060801.jar"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF 2010-03-16
18:47:52 UTC (rev 20851)
@@ -288,6 +288,7 @@
org.hibernate.console.execution,
org.hibernate.console.node,
org.hibernate.console.preferences,
+ org.hibernate.console.stubs,
org.hibernate.context,
org.hibernate.criterion,
org.hibernate.dialect,
@@ -517,6 +518,7 @@
pojo
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.console,
+ org.eclipse.ui.views,
org.eclipse.jface,
org.eclipse.jdt.apt.core,
org.eclipse.datatools.connectivity
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -24,10 +24,10 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
+import org.hibernate.console.stubs.SessionStub;
/**
* @author MAX
@@ -37,8 +37,8 @@
PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private int id;
- private Session session;
- private final ConsoleConfiguration cfg;
+ private SessionStub sessionStub;
+ private final String consoleConfigName;
protected List<Object> list;
protected long queryTime = -1; //shows how long query runs
protected boolean sticky = true;
@@ -54,15 +54,14 @@
}
public int getResultSize() {
- if(list==null) {
+ if (list == null) {
return -1;
- } else {
- return list.size();
}
+ return list.size();
}
- public AbstractQueryPage(ConsoleConfiguration cfg, QueryInputModel model) {
- this.cfg = cfg;
+ public AbstractQueryPage(String consoleConfigName, QueryInputModel model) {
+ this.consoleConfigName = consoleConfigName;
this.model = model;
}
/**
@@ -73,14 +72,7 @@
}
public void release() {
- if (getSession().isOpen() ) {
- try {
- getSession().close();
- }
- catch (HibernateException e) {
- exceptions.add(e);
- }
- }
+ sessionStub.close(exceptions);
}
/**
@@ -104,12 +96,12 @@
this.sticky = sticky;
}
- public Session getSession() {
- return session;
+ public SessionStub getSessionStub() {
+ return sessionStub;
}
- public void setSession(Session s) {
- session = s;
+ public void setSessionStub(SessionStub s) {
+ sessionStub = s;
}
// currently notifications for exceptions and for list execution (hql)
@@ -139,9 +131,15 @@
pcs.firePropertyChange("exceptions", null, exceptions); //$NON-NLS-1$
}
- public ConsoleConfiguration getConsoleConfiguration() {
- return cfg;
+ public void addExceptions(List<Throwable> lstExceptions) {
+ for (Iterator<Throwable> it = lstExceptions.iterator(); it.hasNext();) {
+ addException(it.next());
+ }
}
+
+ public String getConsoleConfigName() {
+ return consoleConfigName;
+ }
public long getQueryTime(){
return queryTime;
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConcoleConfigurationAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConcoleConfigurationAdapter.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConcoleConfigurationAdapter.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -10,9 +10,6 @@
******************************************************************************/
package org.hibernate.console;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
/**
* This adapter class provides default implementations for the
* methods described by the <code>ConcoleConfigurationListener</code>
interface.
@@ -32,11 +29,9 @@
public void queryPageCreated(QueryPage qp) {}
- public void sessionFactoryBuilt(ConsoleConfiguration ccfg,
- SessionFactory builtSessionFactory) {}
+ public void sessionFactoryBuilt(ConsoleConfiguration ccfg) {}
- public void sessionFactoryClosing(ConsoleConfiguration configuration,
- SessionFactory aboutToCloseFactory) {}
+ public void sessionFactoryClosing(ConsoleConfiguration configuration) {}
public void configurationBuilt(ConsoleConfiguration ccfg){};
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -52,8 +52,6 @@
import org.eclipse.osgi.util.NLS;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy;
@@ -64,6 +62,8 @@
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
+import org.hibernate.console.stubs.SessionStub;
+import org.hibernate.console.stubs.SessionStubFactory;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.resolver.DialectFactory;
import org.hibernate.util.ConfigHelper;
@@ -83,7 +83,7 @@
/* TODO: move this out to the actual users of the configuraiton/sf ? */
private Configuration configuration;
- private SessionFactory sessionFactory;
+ private SessionStubFactory sessionStubFactory;
/** Unique name for this configuration */
public String getName() {
@@ -548,20 +548,32 @@
public void buildSessionFactory() {
execute(new ExecutionContext.Command() {
public Object execute() {
- if(sessionFactory!=null) {
+ if (sessionStubFactory != null) {
throw new
HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_factory_not_closed_before_build_new_factory);
}
- sessionFactory = getConfiguration().buildSessionFactory();
+ sessionStubFactory = new SessionStubFactory(executionContext, getConfiguration());
fireFactoryBuilt();
return null;
}
});
}
- public SessionFactory getSessionFactory() {
- return sessionFactory;
+ public SessionStubFactory getSessionStubFactory() {
+ return sessionStubFactory;
}
+ /**
+ * Given a ConsoleConfiguration and a query this method validates the query through
hibernate if a sessionfactory is available.
+ * @param query
+ * @param allowEL if true, EL syntax will be replaced as a named variable
+ * @throws HibernteException if something is wrong with the query
+ */
+ public void checkQuery(String query, boolean allowEL) {
+ if (isSessionFactoryCreated()) {
+ sessionStubFactory.checkQuery(query, allowEL);
+ }
+ }
+
int execcount;
List<ConsoleConfigurationListener> consoleCfgListeners = new
ArrayList<ConsoleConfigurationListener>();
@@ -570,14 +582,14 @@
return executeHQLQuery(hql, new QueryInputModel());
}
- public QueryPage executeHQLQuery(final String hql, final QueryInputModel
queryParameters) {
+ public QueryPage executeHQLQuery(final String hql, final QueryInputModel model) {
return (QueryPage) executionContext.execute(new ExecutionContext.Command() {
public Object execute() {
- Session session = getSessionFactory().openSession();
- QueryPage qp = new HQLQueryPage(ConsoleConfiguration.this,hql,queryParameters);
- qp.setSession(session);
+ SessionStub sessionStub = getSessionStubFactory().openSession();
+ QueryPage qp = new HQLQueryPage(ConsoleConfiguration.this.getName(), hql, model);
+ qp.setSessionStub(sessionStub);
qp.setId(++execcount);
fireQueryPageCreated(qp);
@@ -591,9 +603,9 @@
return (QueryPage) executionContext.execute(new ExecutionContext.Command() {
public Object execute() {
- Session session = getSessionFactory().openSession();
- QueryPage qp = new JavaPage(ConsoleConfiguration.this,queryString,model);
- qp.setSession(session);
+ SessionStub sessionStub = getSessionStubFactory().openSession();
+ QueryPage qp = new JavaPage(ConsoleConfiguration.this.getName(), queryString,
model);
+ qp.setSessionStub(sessionStub);
qp.setId(++execcount);
fireQueryPageCreated(qp);
@@ -623,13 +635,13 @@
private void fireFactoryBuilt() {
for (ConsoleConfigurationListener view : consoleCfgListeners) {
- view.sessionFactoryBuilt(this, sessionFactory);
+ view.sessionFactoryBuilt(this);
}
}
- private void fireFactoryClosing(SessionFactory sessionFactory2) {
+ private void fireFactoryClosing(SessionStubFactory ssf) {
for (ConsoleConfigurationListener view : consoleCfgListeners) {
- view.sessionFactoryClosing(this, sessionFactory2);
+ view.sessionFactoryClosing(this);
}
}
@@ -647,9 +659,21 @@
public boolean isSessionFactoryCreated() {
- return sessionFactory!=null;
+ return sessionStubFactory != null &&
sessionStubFactory.isSessionFactoryCreated();
}
+ public String generateSQL(final String query) {
+ String res = ""; //$NON-NLS-1$
+ if (sessionStubFactory != null && executionContext != null) {
+ res = (String)executionContext.execute(new ExecutionContext.Command() {
+ public Object execute() {
+ return sessionStubFactory.generateSQL(query);
+ }
+ });
+ }
+ return res;
+ }
+
public ConsoleConfigurationPreferences getPreferences() {
return prefs;
}
@@ -695,10 +719,10 @@
}
public void closeSessionFactory() {
- if(sessionFactory!=null) {
- fireFactoryClosing(sessionFactory);
- sessionFactory.close();
- sessionFactory = null;
+ if (sessionStubFactory != null) {
+ fireFactoryClosing(sessionStubFactory);
+ sessionStubFactory.close();
+ sessionStubFactory = null;
}
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigurationListener.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigurationListener.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfigurationListener.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -21,9 +21,6 @@
*/
package org.hibernate.console;
-import org.hibernate.SessionFactory;
-
-
/**
*
*/
@@ -33,16 +30,14 @@
/**
* called when the factory has just been created
- * @param builtSessionFactory TODO
*/
- public void sessionFactoryBuilt(ConsoleConfiguration ccfg, SessionFactory
builtSessionFactory);
+ public void sessionFactoryBuilt(ConsoleConfiguration ccfg);
/**
* Called when this sessionFactory is about to be closed. Used for listeners to clean up
resources related to this sessionfactory (such as closing sessions)
* @param configuration
- * @param closedSessionFactory TODO
*/
- public void sessionFactoryClosing(ConsoleConfiguration configuration, SessionFactory
aboutToCloseFactory);
+ public void sessionFactoryClosing(ConsoleConfiguration configuration);
public void configurationBuilt(ConsoleConfiguration ccfg);
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -33,6 +33,10 @@
public static String StandAloneConsoleConfigurationPreferences_errors_while_parsing;
public static String PluginFileAppender_missing_plugin_state_location;
public static String PluginLogAppender_missing_layout_for_appender;
+ public static String EntityPropertySource_identifier;
+ public static String EntityPropertySource_properties;
+ public static String DynamicSQLPreviewView_caused_by;
+ public static String DynamicSQLPreviewView_manipulation_of;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, ConsoleMessages.class);
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties 2010-03-16
18:47:52 UTC (rev 20851)
@@ -26,4 +26,8 @@
StandAloneConsoleConfigurationPreferences_errors_while_parsing=Errors while parsing
PluginFileAppender_missing_plugin_state_location=Missing Plugin State Location.
PluginLogAppender_missing_layout_for_appender=Missing layout for appender
-ConsoleConfiguration_connection_profile_not_found=Connection profile not found:
''{0}''.
\ No newline at end of file
+ConsoleConfiguration_connection_profile_not_found=Connection profile not found:
''{0}''.
+EntityPropertySource_identifier=Identifier
+EntityPropertySource_properties=Properties
+DynamicSQLPreviewView_caused_by=\nCaused by:\n
+DynamicSQLPreviewView_manipulation_of=Manipulation of
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -21,94 +21,49 @@
*/
package org.hibernate.console;
+import java.sql.Time;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.type.Type;
+import org.hibernate.console.stubs.SessionStub;
-
public class HQLQueryPage extends AbstractQueryPage {
- private Query query;
private String queryString;
public List<Object> getList() {
- if (query==null) return Collections.emptyList();
- if (list == null) {
- try {
-
- //list = query.list();
- list = new ArrayList<Object>();
- setupParameters(query, model);
- 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);
- }
- pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
- }
- catch (HibernateException e) {
- list = Collections.emptyList();
- addException(e);
- } catch (IllegalArgumentException e) {
- list = Collections.emptyList();
- addException(e);
- }
+ if (list != null) {
+ return list;
}
+ evalQuery();
return list;
}
-
-
- 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];
- try {
- int pos = Integer.parseInt(parameter.getName());
- query2.setParameter(pos, calcValue( parameter ), parameter.getType());
- } catch(NumberFormatException nfe) {
- query2.setParameter(parameter.getName(), calcValue( parameter ),
parameter.getType());
- }
- }
- }
- private Object calcValue(ConsoleQueryParameter parameter) {
- return parameter.getValueForQuery();
- }
-
/**
* @param session
* @param string
* @param queryParameters
*/
- public HQLQueryPage(ConsoleConfiguration cfg, String string, QueryInputModel model) {
- super(cfg, model);
+ public HQLQueryPage(String consoleConfigName, String string, QueryInputModel model) {
+ super(consoleConfigName, model);
queryString = string;
setTabName(getQueryString().replace('\n', ' ').replace('\r',
' '));
}
- public void setSession(Session s) {
- super.setSession(s);
- try {
- query = this.getSession().createQuery(queryString);
- } catch (HibernateException e) {
- addException(e);
- } catch (Exception e) {
- addException( e );
- }
+ @Override
+ public void setSessionStub(SessionStub s) {
+ super.setSessionStub(s);
+ evalQuery();
}
+
+ protected void evalQuery() {
+ List<Throwable> arrExceptions = new ArrayList<Throwable>();
+ Time qt = new Time(queryTime);
+ list = getSessionStub().evalQuery(queryString, model, qt, arrExceptions);
+ queryTime = qt.getTime();
+ addExceptions(arrExceptions);
+ pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
+ }
/**
* @return
@@ -122,46 +77,9 @@
}
public List<String> getPathNames() {
- 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) {
- addException(he);
- }
-
- return l;
+ List<Throwable> arrExceptions = new ArrayList<Throwable>();
+ List<String> list = getSessionStub().evalQueryPathNames(queryString, model,
arrExceptions);
+ addExceptions(arrExceptions);
+ return list;
}
}
\ No newline at end of file
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -21,141 +21,68 @@
*/
package org.hibernate.console;
+import java.sql.Time;
import java.util.ArrayList;
-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.engine.SessionImplementor;
+import org.hibernate.console.stubs.SessionStub;
-import bsh.EvalError;
-import bsh.Interpreter;
-
/**
* @author MAX
- *
- *
*/
public class JavaPage extends AbstractQueryPage {
- private String criteriaCode;
+ private String criteriaCode;
- Criteria criteria = null;
-
- private Interpreter ip;
-
- /**
- * @param model
- * @param session2
- */
- public JavaPage(ConsoleConfiguration cfg, String criteriaCode, QueryInputModel model)
{
- super(cfg, model);
- this.criteriaCode = criteriaCode;
+ /**
+ * @param model
+ * @param session2
+ */
+ public JavaPage(String consoleConfigName, String criteriaCode, QueryInputModel model) {
+ super(consoleConfigName, model);
+ this.criteriaCode = criteriaCode;
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);
- }
+ @Override
+ public void setSessionStub(SessionStub s) {
+ super.setSessionStub(s);
+ evalCriteria();
}
- @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.
- 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;
- }
-
- @SuppressWarnings("unchecked")
public List<Object> getList() {
- if(list!=null) return list;
- try {
- if(criteria!=null) {
- long startTime = System.currentTimeMillis();
- list = criteria.list();
- queryTime = System.currentTimeMillis() - startTime;
- }
- else {
- return Collections.emptyList();
- }
- }
- catch (HibernateException e) {
- list = Collections.emptyList();
- addException(e);
- }
- return list;
- }
+ if (list != null) {
+ return list;
+ }
+ evalCriteria();
+ return list;
+ }
+ protected void evalCriteria() {
+ List<Throwable> arrExceptions = new ArrayList<Throwable>();
+ Time qt = new Time(queryTime);
+ list = getSessionStub().evalCriteria(criteriaCode, model, qt, arrExceptions);
+ queryTime = qt.getTime();
+ addExceptions(arrExceptions);
+ pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
+ }
+
public List<String> getPathNames() {
- List<String> l = new ArrayList<String>();
- l.add(ConsoleMessages.JavaPage_no_info);
- return l;
- }
+ List<String> l = new ArrayList<String>();
+ l.add(ConsoleMessages.JavaPage_no_info);
+ return l;
+ }
- public String getQueryString() {
- return criteriaCode;
- }
+ public String getQueryString() {
+ return criteriaCode;
+ }
+
public void setQueryString(String queryString) {
this.criteriaCode = queryString;
list = null;
- ip = null;
}
- public void release() {
-
- super.release();
- }
+ public void release() {
+ super.release();
+ }
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -50,7 +50,6 @@
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
-import org.hibernate.SessionFactory;
import org.hibernate.console.node.BaseNode;
import org.hibernate.console.node.ConfigurationListNode;
import org.w3c.dom.Document;
@@ -68,18 +67,18 @@
private Map<String, ConsoleConfiguration> configurations;
private ConsoleConfigurationListener sfListener = new ConcoleConfigurationAdapter() {
- public void sessionFactoryClosing(final ConsoleConfiguration configuration, final
SessionFactory closingFactory) {
+ public void sessionFactoryClosing(final ConsoleConfiguration configuration) {
fireNotification(new Notification() {
public void notify(KnownConfigurationsListener listener) {
- listener.sessionFactoryClosing(configuration, closingFactory);
+ listener.sessionFactoryClosing(configuration);
}
});
}
- public void sessionFactoryBuilt(final ConsoleConfiguration ccfg, final SessionFactory
builtSessionFactory) {
+ public void sessionFactoryBuilt(final ConsoleConfiguration ccfg) {
fireNotification(new Notification() {
public void notify(KnownConfigurationsListener listener) {
- listener.sessionFactoryBuilt(ccfg, builtSessionFactory);
+ listener.sessionFactoryBuilt(ccfg);
}
});
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsAdapter.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsAdapter.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.hibernate.console;
-import org.hibernate.SessionFactory;
/**
* This adapter class provides default implementations for the
@@ -36,11 +35,9 @@
public void configurationRemoved(ConsoleConfiguration root,
boolean forUpdate) {}
- public void sessionFactoryBuilt(ConsoleConfiguration ccfg,
- SessionFactory builtFactory) {}
+ public void sessionFactoryBuilt(ConsoleConfiguration ccfg) {}
- public void sessionFactoryClosing(ConsoleConfiguration configuration,
- SessionFactory closingFactory) {}
+ public void sessionFactoryClosing(ConsoleConfiguration configuration) {}
public void configurationReset(ConsoleConfiguration ccfg){}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsListener.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsListener.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurationsListener.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -21,17 +21,15 @@
*/
package org.hibernate.console;
-import org.hibernate.SessionFactory;
-
public interface KnownConfigurationsListener {
public void configurationAdded(ConsoleConfiguration root);
public void configurationBuilt(ConsoleConfiguration ccfg);
- public void sessionFactoryBuilt(ConsoleConfiguration ccfg, SessionFactory
builtFactory);
+ public void sessionFactoryBuilt(ConsoleConfiguration ccfg);
- public void sessionFactoryClosing(ConsoleConfiguration configuration, SessionFactory
closingFactory);
+ public void sessionFactoryClosing(ConsoleConfiguration configuration);
public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate);
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -24,8 +24,9 @@
import java.beans.PropertyChangeListener;
import java.util.List;
-import org.hibernate.Session;
+import org.hibernate.console.stubs.SessionStub;
+
/**
* @author MAX
*
@@ -71,10 +72,10 @@
*/
public abstract void setSticky(boolean b);
- public Session getSession();
- public void setSession(Session session);
+ public SessionStub getSessionStub();
+ public void setSessionStub(SessionStub sessionStub);
- public ConsoleConfiguration getConsoleConfiguration();
+ public String getConsoleConfigName();
public void addPropertyChangeListener(PropertyChangeListener listener);
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/ConfigurationNode.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/ConfigurationNode.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/ConfigurationNode.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -21,7 +21,6 @@
*/
package org.hibernate.console.node;
-import org.hibernate.SessionFactory;
import org.hibernate.console.ConcoleConfigurationAdapter;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ConsoleMessages;
@@ -40,11 +39,11 @@
super(null,parent);
this.configuration = configuration;
configuration.addConsoleConfigurationListener(new ConcoleConfigurationAdapter() {
- public void sessionFactoryBuilt(ConsoleConfiguration ccfg, SessionFactory
builtSessionFactory) {
+ public void sessionFactoryBuilt(ConsoleConfiguration ccfg) {
clear();
}
- public void sessionFactoryClosing(ConsoleConfiguration configuration, SessionFactory
closedSessionFactory) {
+ public void sessionFactoryClosing(ConsoleConfiguration configuration) {
clear();
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/NodeFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/NodeFactory.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/NodeFactory.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -21,18 +21,15 @@
*/
package org.hibernate.console.node;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import net.sf.cglib.proxy.Enhancer;
import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.ImageConstants;
+import org.hibernate.console.stubs.SessionStub;
import org.hibernate.mapping.Table;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata;
@@ -45,43 +42,33 @@
*/
public class NodeFactory {
- private Map<String, ClassMetadata> classMetaData;
- private List<String> classes;
- private Map<String, CollectionMetadata> collectionMetaData;
- private ConsoleConfiguration consoleConfiguration;
+ //private Map<String, ClassMetadata> classMetaData;
+ //private List<String> classes;
+ //private Map<String, CollectionMetadata> collectionMetaData;
+ private ConsoleConfiguration consoleConfig;
-
-
-
-
/**
* @param c
*/
public NodeFactory(ConsoleConfiguration c) throws HibernateException {
- setConsoleConfiguration(c);
+ setConsoleConfig(c);
}
- @SuppressWarnings("unchecked")
- private void setConsoleConfiguration(ConsoleConfiguration c) {
- consoleConfiguration = c;
- SessionFactory sf = c.getSessionFactory();
- classMetaData = sf.getAllClassMetadata();
- collectionMetaData = sf.getAllCollectionMetadata();
- classes = new ArrayList<String>();
- classes.addAll(classMetaData.keySet());
+ private void setConsoleConfig(ConsoleConfiguration c) {
+ consoleConfig = c;
}
public ConfigurationEntitiesNode createConfigurationEntitiesNode(String name) {
Enhancer e = ProxyFactory.createEnhancer(ConfigurationEntitiesNode.class);
return (ConfigurationEntitiesNode) e.create(new Class[] { String.class,
NodeFactory.class, List.class },
- new Object[] { name, this, classes });
+ new Object[] { name, this, consoleConfig.getSessionStubFactory().getClasses()
});
//return new RootNode(this, classes);
}
- public BaseNode createObjectNode(Session session, Object o) throws HibernateException
{
- ClassMetadata md = getMetaData(session.getEntityName(o) );
+ public BaseNode createObjectNode(SessionStub sessionStub, Object o) throws
HibernateException {
+ ClassMetadata md = getMetaData(sessionStub.getEntityName(o));
return internalCreateClassNode(null, md.getEntityName(), md, o, false);
//return new ClassNode(this,null,md.getEntityName(),md,o,true);
}
@@ -100,15 +87,15 @@
}
public ClassMetadata getMetaData(String clazz) {
- return classMetaData.get(clazz);
+ return consoleConfig.getSessionStubFactory().getClassMetaData().get(clazz);
}
public ClassMetadata getMetaData(Class<?> clazz) {
- return getMetaData(clazz.getName() );
+ return consoleConfig.getSessionStubFactory().getClassMetaData().get(clazz.getName());
}
public CollectionMetadata getCollectionMetaData(String role) {
- return collectionMetaData.get(role);
+ return consoleConfig.getSessionStubFactory().getCollectionMetaData().get(role);
}
public BaseNode createPropertyNode(BaseNode parent, int idx, ClassMetadata metadata) {
@@ -191,7 +178,7 @@
public ConsoleConfiguration getConsoleConfiguration() {
- return consoleConfiguration;
+ return consoleConfig;
}
public static TableNode createTableNode(BaseNode parent, Table table) {
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java
(from rev 20798,
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/CollectionPropertySource.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/stubs/CollectionPropertySource.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.console.stubs;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+public class CollectionPropertySource implements IPropertySource {
+
+ private Collection<?> collection;
+
+ IPropertyDescriptor[] descriptors = null;
+
+ Map<Object, Object> values = new WeakHashMap<Object, Object>();
+
+ public CollectionPropertySource(Collection<?> propertyValue) {
+ collection = propertyValue;
+ }
+
+ public Object getEditableValue() {
+ return null;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if (descriptors == null) {
+ PropertyDescriptor[] properties = new PropertyDescriptor[collection.size()];
+ for (int i = 0; i < properties.length; i++) {
+ properties[i] = new PropertyDescriptor(Integer.valueOf(i), "#" + i);
//$NON-NLS-1$
+ }
+ descriptors = properties;
+ }
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ Object value = values.get(id);
+ if (value == null) {
+ Integer i = (Integer) id;
+ Iterator<?> iterator = collection.iterator();
+ int base = 0;
+
+ while (iterator.hasNext()) {
+
+ value = iterator.next();
+
+ if (base == i.intValue()) {
+ values.put(id, value);
+ return value;
+ } else {
+ value = null;
+ }
+ base++;
+ }
+ }
+
+ return value;
+ }
+
+ public boolean isPropertySet(Object id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void resetPropertyValue(Object id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+
+ }
+
+}
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/ELTransformer.java
(from rev 20798,
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/ELTransformer.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/ELTransformer.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -0,0 +1,28 @@
+package org.hibernate.console.util;
+
+public class ELTransformer {
+
+ /**
+ * transform any #{el expressions} into named parameters so HQL validation won't
fail on it.
+ *
+ * @param hql
+ * @return
+ */
+ static public String removeEL(String hql) {
+ int elStart = hql.indexOf("#{"); //$NON-NLS-1$
+ int next = hql.indexOf("}", elStart); //$NON-NLS-1$
+
+ while (elStart != -1 && next != -1) {
+ String result = hql.substring(0, elStart);
+ result += ":_" + hql.substring(elStart + 2,
next).replaceAll("[^\\p{javaJavaIdentifierStart}]", "_") +
"_"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result += hql.substring(next + 1);
+
+ hql = result;
+
+ elStart = hql.indexOf("#{"); //$NON-NLS-1$
+ next = hql.indexOf("}", elStart); //$NON-NLS-1$
+ }
+
+ return hql;
+ }
+}
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/Formatter.java
(from rev 20798,
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/Formatter.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/Formatter.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/Formatter.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -0,0 +1,375 @@
+package org.hibernate.console.util;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Old formatter from previous Hibernate versions which allowed a bit more control, i.e.
we want *less* spaces not more.
+ * In here to simplify migration from 3.2 to 3.3 where this class changed.
+ *
+ */
+@SuppressWarnings({ "unchecked", "nls" })
+public class Formatter {
+
+ private static final Set BEGIN_CLAUSES = new HashSet();
+ private static final Set END_CLAUSES = new HashSet();
+ private static final Set LOGICAL = new HashSet();
+ private static final Set QUANTIFIERS = new HashSet();
+ private static final Set DML = new HashSet();
+ private static final Set MISC = new HashSet();
+ static {
+
+ BEGIN_CLAUSES.add("left");
+ BEGIN_CLAUSES.add("right");
+ BEGIN_CLAUSES.add("inner");
+ BEGIN_CLAUSES.add("outer");
+ BEGIN_CLAUSES.add("group");
+ BEGIN_CLAUSES.add("order");
+
+ END_CLAUSES.add("where");
+ END_CLAUSES.add("set");
+ END_CLAUSES.add("having");
+ END_CLAUSES.add("join");
+ END_CLAUSES.add("from");
+ END_CLAUSES.add("by");
+ END_CLAUSES.add("join");
+ END_CLAUSES.add("into");
+ END_CLAUSES.add("union");
+
+ LOGICAL.add("and");
+ LOGICAL.add("or");
+ LOGICAL.add("when");
+ LOGICAL.add("else");
+ LOGICAL.add("end");
+
+ QUANTIFIERS.add("in");
+ QUANTIFIERS.add("all");
+ QUANTIFIERS.add("exists");
+ QUANTIFIERS.add("some");
+ QUANTIFIERS.add("any");
+
+ DML.add("insert");
+ DML.add("update");
+ DML.add("delete");
+
+ MISC.add("select");
+ MISC.add("on");
+ //MISC.add("values");
+
+ }
+
+ String indentString = " ";
+ String initial = "\n ";
+
+ boolean beginLine = true;
+ boolean afterBeginBeforeEnd = false;
+ boolean afterByOrSetOrFromOrSelect = false;
+ boolean afterValues = false;
+ boolean afterOn = false;
+ boolean afterBetween = false;
+ boolean afterInsert = false;
+ int inFunction = 0;
+ int parensSinceSelect = 0;
+ private LinkedList parenCounts = new LinkedList();
+ private LinkedList afterByOrFromOrSelects = new LinkedList();
+
+ int indent = 1;
+
+ StringBuffer result = new StringBuffer();
+ StringTokenizer tokens;
+ String lastToken;
+ String token;
+ String lcToken;
+
+ public Formatter(String sql) {
+ tokens = new StringTokenizer(
+ sql,
+ "()+*/-=<>'`\"[]," + StringHelper.WHITESPACE,
+ true
+ );
+ }
+
+ public Formatter setInitialString(String initial) {
+ this.initial = initial;
+ return this;
+ }
+
+ public Formatter setIndentString(String indent) {
+ this.indentString = indent;
+ return this;
+ }
+
+ public String format() {
+
+ result.append(initial);
+
+ while ( tokens.hasMoreTokens() ) {
+ token = tokens.nextToken();
+ lcToken = token.toLowerCase();
+
+ if ( "'".equals(token) ) {
+ String t;
+ do {
+ t = tokens.nextToken();
+ token += t;
+ }
+ while ( !"'".equals(t) && tokens.hasMoreTokens() ); // cannot
handle single quotes
+ }
+ else if ( "\"".equals(token) ) {
+ String t;
+ do {
+ t = tokens.nextToken();
+ token += t;
+ }
+ while ( !"\"".equals(t) );
+ }
+
+ if ( afterByOrSetOrFromOrSelect && ",".equals(token) ) {
+ commaAfterByOrFromOrSelect();
+ }
+ else if ( afterOn && ",".equals(token) ) {
+ commaAfterOn();
+ }
+
+ else if ( "(".equals(token) ) {
+ openParen();
+ }
+ else if ( ")".equals(token) ) {
+ closeParen();
+ }
+
+ else if ( BEGIN_CLAUSES.contains(lcToken) ) {
+ beginNewClause();
+ }
+
+ else if ( END_CLAUSES.contains(lcToken) ) {
+ endNewClause();
+ }
+
+ else if ( "select".equals(lcToken) ) {
+ select();
+ }
+
+ else if ( DML.contains(lcToken) ) {
+ updateOrInsertOrDelete();
+ }
+
+ else if ( "values".equals(lcToken) ) {
+ values();
+ }
+
+ else if ( "on".equals(lcToken) ) {
+ on();
+ }
+
+ else if ( afterBetween && lcToken.equals("and") ) {
+ misc();
+ afterBetween = false;
+ }
+
+ else if ( LOGICAL.contains(lcToken) ) {
+ logical();
+ }
+
+ else if ( isWhitespace(token) ) {
+ white();
+ }
+
+ else {
+ misc();
+ }
+
+ if ( !isWhitespace( token ) ) lastToken = lcToken;
+
+ }
+ return result.toString();
+ }
+
+ private void commaAfterOn() {
+ out();
+ indent--;
+ newline();
+ afterOn = false;
+ afterByOrSetOrFromOrSelect = true;
+ }
+
+ private void commaAfterByOrFromOrSelect() {
+ out();
+ newline();
+ }
+
+ private void logical() {
+ if ( "end".equals(lcToken) ) indent--;
+ newline();
+ out();
+ beginLine = false;
+ }
+
+ private void on() {
+ indent++;
+ afterOn = true;
+ newline();
+ out();
+ beginLine = false;
+ }
+
+ private void misc() {
+ out();
+ if ( "between".equals(lcToken) ) {
+ afterBetween = true;
+ }
+ if (afterInsert) {
+ newline();
+ afterInsert = false;
+ }
+ else {
+ beginLine = false;
+ if ( "case".equals(lcToken) ) {
+ indent++;
+ }
+ }
+ }
+
+ private void white() {
+ if ( !beginLine ) {
+ result.append(" ");
+ }
+ }
+
+ private void updateOrInsertOrDelete() {
+ out();
+ indent++;
+ beginLine = false;
+ if ( "update".equals(lcToken) ) newline();
+ if ( "insert".equals(lcToken) ) afterInsert = true;
+ }
+
+ private void select() {
+ out();
+ indent++;
+ newline();
+ parenCounts.addLast( new Integer(parensSinceSelect) );
+ afterByOrFromOrSelects.addLast( new Boolean(afterByOrSetOrFromOrSelect) );
+ parensSinceSelect = 0;
+ afterByOrSetOrFromOrSelect = true;
+ }
+
+ private void out() {
+ result.append(token);
+ }
+
+ private void endNewClause() {
+ if (!afterBeginBeforeEnd) {
+ indent--;
+ if (afterOn) {
+ indent--;
+ afterOn=false;
+ }
+ newline();
+ }
+ out();
+ if ( !"union".equals(lcToken) ) indent++;
+ newline();
+ afterBeginBeforeEnd = false;
+ afterByOrSetOrFromOrSelect = "by".equals(lcToken)
+ || "set".equals(lcToken)
+ || "from".equals(lcToken);
+ }
+
+ private void beginNewClause() {
+ if (!afterBeginBeforeEnd) {
+ if (afterOn) {
+ indent--;
+ afterOn=false;
+ }
+ indent--;
+ newline();
+ }
+ out();
+ beginLine = false;
+ afterBeginBeforeEnd = true;
+ }
+
+ private void values() {
+ indent--;
+ newline();
+ out();
+ indent++;
+ newline();
+ afterValues = true;
+ }
+
+ private void closeParen() {
+ parensSinceSelect--;
+ if (parensSinceSelect<0) {
+ indent--;
+ parensSinceSelect = ( (Integer) parenCounts.removeLast() ).intValue();
+ afterByOrSetOrFromOrSelect = ( (Boolean) afterByOrFromOrSelects.removeLast()
).booleanValue();
+ }
+ if ( inFunction>0 ) {
+ inFunction--;
+ out();
+ }
+ else {
+ if (!afterByOrSetOrFromOrSelect) {
+ indent--;
+ newline();
+ }
+ out();
+ }
+ beginLine = false;
+ }
+
+ private void openParen() {
+ if ( isFunctionName( lastToken ) || inFunction>0 ) {
+ inFunction++;
+ }
+ beginLine = false;
+ if ( inFunction>0 ) {
+ out();
+ }
+ else {
+ out();
+ if (!afterByOrSetOrFromOrSelect) {
+ indent++;
+ newline();
+ beginLine = true;
+ }
+ }
+ parensSinceSelect++;
+ }
+
+ private static boolean isFunctionName(String tok) {
+ final char begin = tok.charAt(0);
+ final boolean isIdentifier = Character.isJavaIdentifierStart( begin ) ||
'"'==begin;
+ return isIdentifier &&
+ !LOGICAL.contains(tok) &&
+ !END_CLAUSES.contains(tok) &&
+ !QUANTIFIERS.contains(tok) &&
+ !DML.contains(tok) &&
+ !MISC.contains(tok);
+ }
+
+ private static boolean isWhitespace(String token) {
+ return StringHelper.WHITESPACE.indexOf(token)>=0;
+ }
+
+ private void newline() {
+ result.append("\n");
+ for ( int i=0; i<indent; i++ ) {
+ result.append(indentString);
+ }
+ beginLine = true;
+ }
+
+ public static void main(String[] args) {
+ if ( args.length>0 ) System.out.println(
+ new Formatter( StringHelper.join(" ", args) ).format()
+ );
+ }
+
+}
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/QLFormatHelper.java
(from rev 20798,
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/QLFormatHelper.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/QLFormatHelper.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/util/QLFormatHelper.java 2010-03-16
18:47:52 UTC (rev 20851)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.console.util;
+
+public class QLFormatHelper {
+
+ static public String formatForScreen(String query) {
+ return new Formatter(query).setInitialString("").setIndentString("
").format(); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}