private ResultSetMetaData getCheckedMetaData() throws SQLException {
   ResultSetMetaData meta = getMetaData();
   if (meta == null) {
     throw DbException.getUnsupportedException("Supported only for calling stored procedures");
   }
   return meta;
 }
 private void copyData() {
   if (table.isTemporary()) {
     throw DbException.getUnsupportedException("TEMP TABLE");
   }
   Database db = session.getDatabase();
   String baseName = table.getName();
   String tempName = db.getTempTableName(baseName, session);
   Column[] columns = table.getColumns();
   ArrayList<Column> newColumns = New.arrayList();
   Table newTable = cloneTableStructure(columns, db, tempName, newColumns);
   try {
     // check if a view would become invalid
     // (because the column to drop is referenced or so)
     checkViews(table, newTable);
   } catch (DbException e) {
     execute("DROP TABLE " + newTable.getName(), true);
     throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, e, getSQL(), e.getMessage());
   }
   String tableName = table.getName();
   ArrayList<TableView> views = table.getViews();
   if (views != null) {
     views = New.arrayList(views);
     for (TableView view : views) {
       table.removeView(view);
     }
   }
   execute("DROP TABLE " + table.getSQL() + " IGNORE", true);
   db.renameSchemaObject(session, newTable, tableName);
   for (DbObject child : newTable.getChildren()) {
     if (child instanceof Sequence) {
       continue;
     }
     String name = child.getName();
     if (name == null || child.getCreateSQL() == null) {
       continue;
     }
     if (name.startsWith(tempName + "_")) {
       name = name.substring(tempName.length() + 1);
       SchemaObject so = (SchemaObject) child;
       if (so instanceof Constraint) {
         if (so.getSchema().findConstraint(session, name) != null) {
           name = so.getSchema().getUniqueConstraintName(session, newTable);
         }
       } else if (so instanceof Index) {
         if (so.getSchema().findIndex(session, name) != null) {
           name = so.getSchema().getUniqueIndexName(session, newTable, name);
         }
       }
       db.renameSchemaObject(session, so, name);
     }
   }
   if (views != null) {
     for (TableView view : views) {
       String sql = view.getCreateSQL(true, true);
       execute(sql, true);
     }
   }
 }
Ejemplo n.º 3
0
 /**
  * Check that the index columns are not CLOB or BLOB.
  *
  * @param columns the columns
  */
 protected static void checkIndexColumnTypes(IndexColumn[] columns) {
   for (IndexColumn c : columns) {
     int type = c.column.getType();
     if (type == Value.CLOB || type == Value.BLOB) {
       throw DbException.getUnsupportedException(
           "Index on BLOB or CLOB column: " + c.column.getCreateSQL());
     }
   }
 }
Ejemplo n.º 4
0
 public Index addIndex(
     Session session,
     String indexName,
     int indexId,
     IndexColumn[] cols,
     IndexType indexType,
     boolean create,
     String indexComment) {
   throw DbException.getUnsupportedException("VIEW");
 }
Ejemplo n.º 5
0
 public synchronized void rename(String oldName, String newName) {
   try {
     long parentOld = getId(oldName, true);
     long parentNew = getId(newName, true);
     if (parentOld != parentNew) {
       throw DbException.getUnsupportedException("different parents");
     }
     newName = getFileName(newName);
     long id = getId(oldName, false);
     PreparedStatement prep = prepare("UPDATE FILES SET NAME=? WHERE ID=?");
     prep.setString(1, newName);
     prep.setLong(2, id);
     prep.execute();
     commit();
   } catch (SQLException e) {
     rollback();
     throw convert(e);
   }
 }
 @Override
 public int update() {
   session.commit(true);
   Database db = session.getDatabase();
   session.getUser().checkRight(oldTable, Right.ALL);
   Table t = getSchema().findTableOrView(session, newTableName);
   if (t != null && hidden && newTableName.equals(oldTable.getName())) {
     if (!t.isHidden()) {
       t.setHidden(hidden);
       oldTable.setHidden(true);
       db.updateMeta(session, oldTable);
     }
     return 0;
   }
   if (t != null || newTableName.equals(oldTable.getName())) {
     throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, newTableName);
   }
   if (oldTable.isTemporary()) {
     throw DbException.getUnsupportedException("temp table");
   }
   db.renameSchemaObject(session, oldTable, newTableName);
   return 0;
 }
Ejemplo n.º 7
0
  private void handleOnDuplicate(DbException de) {
    if (de.getErrorCode() != ErrorCode.DUPLICATE_KEY_1) {
      throw de;
    }
    if (duplicateKeyAssignmentMap == null || duplicateKeyAssignmentMap.isEmpty()) {
      throw de;
    }

    ArrayList<String> variableNames = new ArrayList<String>(duplicateKeyAssignmentMap.size());
    for (int i = 0; i < columns.length; i++) {
      String key =
          session.getCurrentSchemaName() + "." + table.getName() + "." + columns[i].getName();
      variableNames.add(key);
      session.setVariable(key, list.get(getCurrentRowNumber() - 1)[i].getValue(session));
    }

    Update command = new Update(session);
    command.setTableFilter(new TableFilter(session, table, null, true, null));
    for (Column column : duplicateKeyAssignmentMap.keySet()) {
      command.setAssignment(column, duplicateKeyAssignmentMap.get(column));
    }

    Index foundIndex = searchForUpdateIndex();

    if (foundIndex != null) {
      command.setCondition(prepareUpdateCondition(foundIndex));
    } else {
      throw DbException.getUnsupportedException(
          "Unable to apply ON DUPLICATE KEY UPDATE, no index found!");
    }

    command.prepare();
    command.update();
    for (String variableName : variableNames) {
      session.setVariable(variableName, ValueNull.INSTANCE);
    }
  }
Ejemplo n.º 8
0
 @Override
 public boolean previous() {
   throw DbException.getUnsupportedException("previous");
 }
Ejemplo n.º 9
0
 public void checkRename() {
   throw DbException.getUnsupportedException("AGGREGATE");
 }
Ejemplo n.º 10
0
 @Override
 public Row getRow(Session session, long key) {
   throw DbException.getUnsupportedException(toString());
 }
Ejemplo n.º 11
0
 @Override
 public void setPowerOffCount(int count) {
   throw DbException.getUnsupportedException("remote");
 }
Ejemplo n.º 12
0
 /** {@inheritDoc} */
 @Override
 public void truncate(Session ses) {
   throw DbException.getUnsupportedException("truncate");
 }
Ejemplo n.º 13
0
 /** {@inheritDoc} */
 @Override
 public Cursor findFirstOrLast(Session ses, boolean first) {
   throw DbException.getUnsupportedException("findFirstOrLast");
 }
Ejemplo n.º 14
0
 @Override
 public void checkRename() {
   throw DbException.getUnsupportedException("SYSTEM_RANGE");
 }
Ejemplo n.º 15
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;
   }
 }
Ejemplo n.º 16
0
 public void remove(Session session) {
   throw DbException.getUnsupportedException("META");
 }
Ejemplo n.º 17
0
 public Cursor findFirstOrLast(Session session, boolean first) {
   throw DbException.getUnsupportedException("META");
 }
Ejemplo n.º 18
0
 public void add(Session session, Row row) {
   throw DbException.getUnsupportedException("META");
 }
Ejemplo n.º 19
0
 private void checkMap(Map<String, Class<?>> map) {
   if (map != null && map.size() > 0) {
     throw DbException.getUnsupportedException("map.size > 0");
   }
 }
Ejemplo n.º 20
0
 @Override
 public int update() {
   session.commit(true);
   session.getUser().checkAdmin();
   Database db = session.getDatabase();
   TableView view = null;
   Table old = getSchema().findTableOrView(session, viewName);
   if (old != null) {
     if (ifNotExists) {
       return 0;
     }
     if (!orReplace || !Table.VIEW.equals(old.getTableType())) {
       throw DbException.get(ErrorCode.VIEW_ALREADY_EXISTS_1, viewName);
     }
     view = (TableView) old;
   }
   int id = getObjectId();
   String querySQL;
   if (select == null) {
     querySQL = selectSQL;
   } else {
     ArrayList<Parameter> params = select.getParameters();
     if (params != null && params.size() > 0) {
       throw DbException.getUnsupportedException("parameters in views");
     }
     querySQL = select.getPlanSQL();
   }
   // The view creates a Prepared command object, which belongs to a
   // session, so we pass the system session down.
   Session sysSession = db.getSystemSession();
   synchronized (sysSession) {
     try {
       if (view == null) {
         Schema schema = session.getDatabase().getSchema(session.getCurrentSchemaName());
         sysSession.setCurrentSchema(schema);
         Column[] columnTemplates = null;
         if (columnNames != null) {
           columnTemplates = new Column[columnNames.length];
           for (int i = 0; i < columnNames.length; ++i) {
             columnTemplates[i] = new Column(columnNames[i], Value.UNKNOWN);
           }
         }
         view =
             new TableView(
                 getSchema(), id, viewName, querySQL, null, columnTemplates, sysSession, false);
       } else {
         view.replace(querySQL, columnNames, sysSession, false, force);
         view.setModified();
       }
     } finally {
       sysSession.setCurrentSchema(db.getSchema(Constants.SCHEMA_MAIN));
     }
   }
   if (comment != null) {
     view.setComment(comment);
   }
   if (old == null) {
     db.addSchemaObject(session, view);
   } else {
     db.updateMeta(session, view);
   }
   return 0;
 }
Ejemplo n.º 21
0
 public void deleteRecursive(String fileName, boolean tryOnly) {
   throw DbException.getUnsupportedException("db");
 }
Ejemplo n.º 22
0
 protected LocalResult queryWithoutCache(int maxRows, ResultTarget target) {
   int limitRows = maxRows == 0 ? -1 : maxRows;
   if (limitExpr != null) {
     Value v = limitExpr.getValue(session);
     int l = v == ValueNull.INSTANCE ? -1 : v.getInt();
     if (limitRows < 0) {
       limitRows = l;
     } else if (l >= 0) {
       limitRows = Math.min(l, limitRows);
     }
   }
   int columnCount = expressions.size();
   LocalResult result = null;
   if (target == null || !session.getDatabase().getSettings().optimizeInsertFromSelect) {
     result = createLocalResult(result);
   }
   if (sort != null && (!sortUsingIndex || distinct)) {
     result = createLocalResult(result);
     result.setSortOrder(sort);
   }
   if (distinct && !isDistinctQuery) {
     result = createLocalResult(result);
     result.setDistinct();
   }
   if (randomAccessResult) {
     result = createLocalResult(result);
     result.setRandomAccess();
   }
   if (isGroupQuery && !isGroupSortedQuery) {
     result = createLocalResult(result);
   }
   if (limitRows >= 0 || offsetExpr != null) {
     result = createLocalResult(result);
   }
   topTableFilter.startQuery(session);
   topTableFilter.reset();
   boolean exclusive = isForUpdate && !isForUpdateMvcc;
   if (isForUpdateMvcc) {
     if (isGroupQuery) {
       throw DbException.getUnsupportedException("FOR UPDATE && GROUP");
     } else if (distinct) {
       throw DbException.getUnsupportedException("FOR UPDATE && DISTINCT");
     } else if (isQuickAggregateQuery) {
       throw DbException.getUnsupportedException("FOR UPDATE && AGGREGATE");
     } else if (topTableFilter.getJoin() != null) {
       throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
     } else if (topTableFilter.getJoin() != null) {
       throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
     }
   }
   topTableFilter.lock(session, exclusive, exclusive);
   ResultTarget to = result != null ? result : target;
   if (limitRows != 0) {
     if (isQuickAggregateQuery) {
       queryQuick(columnCount, to);
     } else if (isGroupQuery) {
       if (isGroupSortedQuery) {
         queryGroupSorted(columnCount, to);
       } else {
         queryGroup(columnCount, result);
       }
     } else if (isDistinctQuery) {
       queryDistinct(to, limitRows);
     } else {
       queryFlat(columnCount, to, limitRows);
     }
   }
   if (offsetExpr != null) {
     result.setOffset(offsetExpr.getValue(session).getInt());
   }
   if (limitRows >= 0) {
     result.setLimit(limitRows);
   }
   if (result != null) {
     result.done();
     if (target != null) {
       while (result.next()) {
         target.addRow(result.currentRow());
       }
       result.close();
       return null;
     }
     return result;
   }
   return null;
 }
Ejemplo n.º 23
0
 public void truncate(Session session) {
   throw DbException.getUnsupportedException("META");
 }
Ejemplo n.º 24
0
 /** {@inheritDoc} */
 @Override
 public void checkRename() {
   throw DbException.getUnsupportedException("rename");
 }
Ejemplo n.º 25
0
 public void checkRename() {
   throw DbException.getUnsupportedException("META");
 }
Ejemplo n.º 26
0
 /** {@inheritDoc} */
 @Override
 public void add(Session ses, Row row) {
   throw DbException.getUnsupportedException("add");
 }
Ejemplo n.º 27
0
 @Override
 public void addRow(Session session, Row row) {
   throw DbException.getUnsupportedException("SYSTEM_RANGE");
 }
Ejemplo n.º 28
0
 /** {@inheritDoc} */
 @Override
 public void remove(Session ses, Row row) {
   throw DbException.getUnsupportedException("remove row");
 }
Ejemplo n.º 29
0
 @Override
 public void truncate(Session session) {
   throw DbException.getUnsupportedException("SYSTEM_RANGE");
 }
Ejemplo n.º 30
0
 /** {@inheritDoc} */
 @Override
 public void remove(Session ses) {
   throw DbException.getUnsupportedException("remove index");
 }