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); } } }
/** * 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()); } } }
public Index addIndex( Session session, String indexName, int indexId, IndexColumn[] cols, IndexType indexType, boolean create, String indexComment) { throw DbException.getUnsupportedException("VIEW"); }
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; }
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); } }
@Override public boolean previous() { throw DbException.getUnsupportedException("previous"); }
public void checkRename() { throw DbException.getUnsupportedException("AGGREGATE"); }
@Override public Row getRow(Session session, long key) { throw DbException.getUnsupportedException(toString()); }
@Override public void setPowerOffCount(int count) { throw DbException.getUnsupportedException("remote"); }
/** {@inheritDoc} */ @Override public void truncate(Session ses) { throw DbException.getUnsupportedException("truncate"); }
/** {@inheritDoc} */ @Override public Cursor findFirstOrLast(Session ses, boolean first) { throw DbException.getUnsupportedException("findFirstOrLast"); }
@Override public void checkRename() { throw DbException.getUnsupportedException("SYSTEM_RANGE"); }
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; } }
public void remove(Session session) { throw DbException.getUnsupportedException("META"); }
public Cursor findFirstOrLast(Session session, boolean first) { throw DbException.getUnsupportedException("META"); }
public void add(Session session, Row row) { throw DbException.getUnsupportedException("META"); }
private void checkMap(Map<String, Class<?>> map) { if (map != null && map.size() > 0) { throw DbException.getUnsupportedException("map.size > 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; }
public void deleteRecursive(String fileName, boolean tryOnly) { throw DbException.getUnsupportedException("db"); }
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; }
public void truncate(Session session) { throw DbException.getUnsupportedException("META"); }
/** {@inheritDoc} */ @Override public void checkRename() { throw DbException.getUnsupportedException("rename"); }
public void checkRename() { throw DbException.getUnsupportedException("META"); }
/** {@inheritDoc} */ @Override public void add(Session ses, Row row) { throw DbException.getUnsupportedException("add"); }
@Override public void addRow(Session session, Row row) { throw DbException.getUnsupportedException("SYSTEM_RANGE"); }
/** {@inheritDoc} */ @Override public void remove(Session ses, Row row) { throw DbException.getUnsupportedException("remove row"); }
@Override public void truncate(Session session) { throw DbException.getUnsupportedException("SYSTEM_RANGE"); }
/** {@inheritDoc} */ @Override public void remove(Session ses) { throw DbException.getUnsupportedException("remove index"); }