jpql editor: cconnect before execution jpql_editor73
authorSergey B. Petrov <sj-nb@netbeans.org>
Mon, 30 Jul 2012 16:45:31 +0400
branchjpql_editor73
changeset 2346652708ea8c8b73
parent 234664 b8d2589de1f4
child 234666 875a5641ab54
jpql editor: cconnect before execution
j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/jpqleditor/JPQLEditorController.java
j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/jpqleditor/lexer/JPQLLexer.java
     1.1 --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/jpqleditor/JPQLEditorController.java	Thu Jul 26 19:05:28 2012 +0400
     1.2 +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/jpqleditor/JPQLEditorController.java	Mon Jul 30 16:45:31 2012 +0400
     1.3 @@ -66,6 +66,7 @@
     1.4  //import org.netbeans.modules.hibernate.util.HibernateUtil;
     1.5  import org.openide.nodes.Node;
     1.6  import org.openide.util.Exceptions;
     1.7 +import org.openide.util.Mutex;
     1.8  import org.openide.util.NbBundle;
     1.9  
    1.10  /**
    1.11 @@ -90,12 +91,20 @@
    1.12          final List<URL> localResourcesURLList = new ArrayList<URL>();
    1.13  
    1.14          //connection open
    1.15 -        DatabaseConnection dbconn = findDatabaseConnection(pu, pe.getProject());
    1.16 -        if(dbconn != null) {
    1.17 -            dbconn.getJDBCConnection().;
    1.18 +        final DatabaseConnection dbconn = findDatabaseConnection(pu, pe.getProject());
    1.19 +        if (dbconn != null) {
    1.20 +            if (dbconn.getJDBCConnection() == null) {
    1.21 +                Mutex.EVENT.readAccess(new Mutex.Action<DatabaseConnection>() {
    1.22 +                    @Override
    1.23 +                    public DatabaseConnection run() {
    1.24 +                        ConnectionManager.getDefault().showConnectionDialog(dbconn);
    1.25 +                        return dbconn;
    1.26 +                    }
    1.27 +                });
    1.28 +            }
    1.29          }
    1.30          //
    1.31 -        
    1.32 +
    1.33          final ClassLoader defClassLoader = Thread.currentThread().getContextClassLoader();
    1.34          try {
    1.35              ph.progress(10);
    1.36 @@ -105,12 +114,11 @@
    1.37              localResourcesURLList.add(pe.getLocation().getParent().toURL());
    1.38              localResourcesURLList.add(pe.getLocation().toURL());
    1.39              localResourcesURLList.add(pe.getLocation().getFileObject("persistence.xml").toURL());
    1.40 -            
    1.41 +
    1.42              ClassLoader customClassLoader = pe.getProjectClassLoader(
    1.43                      localResourcesURLList.toArray(new URL[]{}));
    1.44              Thread.currentThread().setContextClassLoader(customClassLoader);
    1.45              Thread t = new Thread() {
    1.46 -
    1.47                  @Override
    1.48                  public void run() {
    1.49                      //Thread.currentThread().setContextClassLoader(customClassLoader);
    1.50 @@ -139,8 +147,8 @@
    1.51                          public void run() {
    1.52                              editorTopComponent.setResult(jpqlResult0, customClassLoader0);
    1.53                          }
    1.54 -                    });    
    1.55 -                    
    1.56 +                    });
    1.57 +
    1.58                      Thread.currentThread().setContextClassLoader(defClassLoader);
    1.59                  }
    1.60              };
    1.61 @@ -161,32 +169,32 @@
    1.62  
    1.63          editorTopComponent.fillPersistenceConfigurations(activatedNodes);
    1.64      }
    1.65 -        
    1.66 +
    1.67      private DatabaseConnection findDatabaseConnection(PersistenceUnit pu, Project project) {
    1.68 -        
    1.69 +
    1.70          // try to find a connection specified using the PU properties
    1.71          DatabaseConnection dbcon = ProviderUtil.getConnection(pu);
    1.72          if (dbcon != null) {
    1.73              return dbcon;
    1.74          }
    1.75 -        
    1.76 +
    1.77          // try to find a datasource-based connection, but only for a FileObject-based context,
    1.78          // otherwise we don't have a J2eeModuleProvider to retrieve the DS's from
    1.79          String datasourceName = ProviderUtil.getDatasourceName(pu);
    1.80          if (datasourceName == null) {
    1.81              return null;
    1.82          }
    1.83 -  
    1.84 +
    1.85          if (project == null) {
    1.86              return null;
    1.87          }
    1.88          JPADataSource datasource = null;
    1.89          JPADataSourceProvider dsProvider = project.getLookup().lookup(JPADataSourceProvider.class);
    1.90 -        if (dsProvider == null){
    1.91 +        if (dsProvider == null) {
    1.92              return null;
    1.93          }
    1.94 -        for (JPADataSource each : dsProvider.getDataSources()){
    1.95 -            if (datasourceName.equals(each.getJndiName())){
    1.96 +        for (JPADataSource each : dsProvider.getDataSources()) {
    1.97 +            if (datasourceName.equals(each.getJndiName())) {
    1.98                  datasource = each;
    1.99              }
   1.100          }
   1.101 @@ -200,6 +208,7 @@
   1.102          }
   1.103          return null;
   1.104      }
   1.105 +
   1.106      private static List<DatabaseConnection> findDatabaseConnections(JPADataSource datasource) {
   1.107          // copied from j2ee.common.DatasourceHelper (can't depend on that)
   1.108          if (datasource == null) {
   1.109 @@ -222,8 +231,6 @@
   1.110              return Collections.emptyList();
   1.111          }
   1.112      }
   1.113 -
   1.114 -
   1.115  //    public SessionFactory getHibernateSessionFactoryForThisContext(FileObject configFileObject,
   1.116  //            Set<FileObject> mappingFOList,
   1.117  //            List<Class> annotatedClassList,
     2.1 --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/jpqleditor/lexer/JPQLLexer.java	Thu Jul 26 19:05:28 2012 +0400
     2.2 +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/jpqleditor/lexer/JPQLLexer.java	Mon Jul 30 16:45:31 2012 +0400
     2.3 @@ -107,9 +107,9 @@
     2.4                                  return tokenFactory.createToken(lookupId, //XXX: \n handling for exotic identifiers?
     2.5                                          input.readLength(), PartType.START);
     2.6                          }
     2.7 -                case '=':
     2.8 -                    input.backup(1);
     2.9 -                    return token(JPQLTokenId.EQ);
    2.10 +//                case '=':
    2.11 +//                    input.backup(1);
    2.12 +//                    return token(JPQLTokenId.EQ);
    2.13  
    2.14                  case '>':
    2.15                      switch (input.read()) {