Exemplo n.º 1
0
 /**
  * Generate "CREATE" SQL statement for the view.
  *
  * @param orReplace if true, then include the OR REPLACE clause
  * @param force if true, then include the FORCE clause
  * @return the SQL statement
  */
 public String getCreateSQL(boolean orReplace, boolean force) {
   StatementBuilder buff = new StatementBuilder("CREATE ");
   if (orReplace) {
     buff.append("OR REPLACE ");
   }
   if (force) {
     buff.append("FORCE ");
   }
   buff.append("VIEW ");
   buff.append(getSQL());
   if (comment != null) {
     buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
   }
   if (columns.length > 0) {
     buff.append('(');
     for (Column c : columns) {
       buff.appendExceptFirst(", ");
       buff.append(c.getSQL());
     }
     buff.append(')');
   } else if (columnNames != null) {
     buff.append('(');
     for (String n : columnNames) {
       buff.appendExceptFirst(", ");
       buff.append(n);
     }
     buff.append(')');
   }
   return buff.append(" AS\n").append(querySQL).toString();
 }
Exemplo n.º 2
0
 @Override
 public String getSQL() {
   String s;
   if (type == Value.CLOB) {
     s = getString();
     return StringUtils.quoteStringSQL(s);
   }
   byte[] buff = getBytes();
   s = StringUtils.convertBytesToHex(buff);
   return "X'" + s + "'";
 }
Exemplo n.º 3
0
 public String getCreateSQL() {
   StringBuilder buff = new StringBuilder("CREATE FORCE ALIAS ");
   buff.append(getSQL());
   if (deterministic) {
     buff.append(" DETERMINISTIC");
   }
   if (source != null) {
     buff.append(" AS ").append(StringUtils.quoteStringSQL(source));
   } else {
     buff.append(" FOR ").append(Parser.quoteIdentifier(className + "." + methodName));
   }
   return buff.toString();
 }
Exemplo n.º 4
0
 @Override
 public String getCreateSQLForCopy(Table targetTable, String quotedName) {
   StringBuilder buff = new StringBuilder("CREATE ");
   buff.append(indexType.getSQL());
   buff.append(' ');
   if (table.isHidden()) {
     buff.append("IF NOT EXISTS ");
   }
   buff.append(quotedName);
   buff.append(" ON ").append(targetTable.getSQL());
   if (comment != null) {
     buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
   }
   buff.append('(').append(getColumnListSQL()).append(')');
   return buff.toString();
 }
Exemplo n.º 5
0
 private void connectServer(ConnectionInfo ci) {
   String name = ci.getName();
   if (name.startsWith("//")) {
     name = name.substring("//".length());
   }
   int idx = name.indexOf('/');
   if (idx < 0) {
     throw ci.getFormatException();
   }
   databaseName = name.substring(idx + 1);
   String server = name.substring(0, idx);
   traceSystem = new TraceSystem(null);
   String traceLevelFile = ci.getProperty(SetTypes.TRACE_LEVEL_FILE, null);
   if (traceLevelFile != null) {
     int level = Integer.parseInt(traceLevelFile);
     String prefix = getFilePrefix(SysProperties.CLIENT_TRACE_DIRECTORY);
     try {
       traceSystem.setLevelFile(level);
       if (level > 0 && level < 4) {
         String file = FileUtils.createTempFile(prefix, Constants.SUFFIX_TRACE_FILE, false, false);
         traceSystem.setFileName(file);
       }
     } catch (IOException e) {
       throw DbException.convertIOException(e, prefix);
     }
   }
   String traceLevelSystemOut = ci.getProperty(SetTypes.TRACE_LEVEL_SYSTEM_OUT, null);
   if (traceLevelSystemOut != null) {
     int level = Integer.parseInt(traceLevelSystemOut);
     traceSystem.setLevelSystemOut(level);
   }
   trace = traceSystem.getTrace(Trace.JDBC);
   String serverList = null;
   if (server.indexOf(',') >= 0) {
     serverList = StringUtils.quoteStringSQL(server);
     ci.setProperty("CLUSTER", Constants.CLUSTERING_ENABLED);
   }
   autoReconnect = Boolean.parseBoolean(ci.getProperty("AUTO_RECONNECT", "false"));
   // AUTO_SERVER implies AUTO_RECONNECT
   boolean autoServer = Boolean.parseBoolean(ci.getProperty("AUTO_SERVER", "false"));
   if (autoServer && serverList != null) {
     throw DbException.getUnsupportedException("autoServer && serverList != null");
   }
   autoReconnect |= autoServer;
   if (autoReconnect) {
     String className = ci.getProperty("DATABASE_EVENT_LISTENER");
     if (className != null) {
       className = StringUtils.trim(className, true, true, "'");
       try {
         eventListener = (DatabaseEventListener) JdbcUtils.loadUserClass(className).newInstance();
       } catch (Throwable e) {
         throw DbException.convert(e);
       }
     }
   }
   cipher = ci.getProperty("CIPHER");
   if (cipher != null) {
     fileEncryptionKey = MathUtils.secureRandomBytes(32);
   }
   String[] servers = StringUtils.arraySplit(server, ',', true);
   int len = servers.length;
   transferList.clear();
   sessionId = StringUtils.convertBytesToHex(MathUtils.secureRandomBytes(32));
   // TODO cluster: support more than 2 connections
   boolean switchOffCluster = false;
   try {
     for (int i = 0; i < len; i++) {
       String s = servers[i];
       try {
         Transfer trans = initTransfer(ci, databaseName, s);
         transferList.add(trans);
       } catch (IOException e) {
         if (len == 1) {
           throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, e, e + ": " + s);
         }
         switchOffCluster = true;
       }
     }
     checkClosed();
     if (switchOffCluster) {
       switchOffCluster();
     }
     checkClusterDisableAutoCommit(serverList);
   } catch (DbException e) {
     traceSystem.close();
     throw e;
   }
 }