📄 table.java
字号:
}
}
}
public void checkColumnIsNotReferenced(Column col) throws SQLException {
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint constraint = (Constraint) constraints.get(i);
if (constraint.containsColumn(col)) {
throw Message.getSQLException(ErrorCode.COLUMN_MAY_BE_REFERENCED_1, constraint.getSQL());
}
}
ObjectArray indexes = getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) {
Index index = (Index) indexes.get(i);
if (index.getColumns().length == 1) {
continue;
}
if (index.getCreateSQL() == null) {
continue;
}
if (index.getColumnIndex(col) >= 0) {
throw Message.getSQLException(ErrorCode.COLUMN_MAY_BE_REFERENCED_1, index.getSQL());
}
}
}
public Row getTemplateRow() {
return new Row(new Value[columns.length], memoryPerRow);
}
public SearchRow getTemplateSimpleRow(boolean singleColumn) {
if (singleColumn) {
return new SimpleRowValue(columns.length);
} else {
return new SimpleRow(new Value[columns.length]);
}
}
public Row getNullRow() {
synchronized (this) {
if (nullRow == null) {
nullRow = new Row(new Value[columns.length], 0);
for (int i = 0; i < columns.length; i++) {
nullRow.setValue(i, ValueNull.INSTANCE);
}
}
return nullRow;
}
}
public Column[] getColumns() {
return columns;
}
public int getType() {
return DbObject.TABLE_OR_VIEW;
}
public Column getColumn(int index) {
return columns[index];
}
public Column getColumn(String columnName) throws SQLException {
Column column = (Column) columnMap.get(columnName);
if (column == null) {
throw Message.getSQLException(ErrorCode.COLUMN_NOT_FOUND_1, columnName);
}
return column;
}
/**
* @param masks - null means 'always false'
*/
public PlanItem getBestPlanItem(Session session, int[] masks) throws SQLException {
PlanItem item = new PlanItem();
item.setIndex(getScanIndex(session));
item.cost = item.getIndex().getCost(session, null);
ObjectArray indexes = getIndexes();
for (int i = 1; indexes != null && masks != null && i < indexes.size(); i++) {
Index index = (Index) indexes.get(i);
double cost = index.getCost(session, masks);
if (cost < item.cost) {
item.cost = cost;
item.setIndex(index);
}
}
return item;
}
public Index findPrimaryKey() throws SQLException {
ObjectArray indexes = getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) {
Index idx = (Index) indexes.get(i);
if (idx.getIndexType().isPrimaryKey()) {
return idx;
}
}
return null;
}
public Index getPrimaryKey() throws SQLException {
Index index = findPrimaryKey();
if (index != null) {
return index;
}
throw Message.getSQLException(ErrorCode.INDEX_NOT_FOUND_1, Constants.PREFIX_PRIMARY_KEY);
}
public void validateConvertUpdateSequence(Session session, Row row) throws SQLException {
for (int i = 0; i < columns.length; i++) {
Value value = row.getValue(i);
Column column = columns[i];
Value v2;
if (column.getComputed()) {
v2 = column.computeValue(session, row);
} else {
v2 = column.validateConvertUpdateSequence(session, value);
}
if (v2 != value) {
row.setValue(i, v2);
}
}
}
public boolean isPersistent() {
return persistent;
}
private void remove(ObjectArray list, DbObject obj) {
if (list != null) {
int i = list.indexOf(obj);
if (i >= 0) {
list.remove(i);
}
}
}
public void removeIndex(Index index) {
ObjectArray indexes = getIndexes();
if (indexes != null) {
remove(indexes, index);
if (index.getIndexType().isPrimaryKey()) {
Column[] cols = index.getColumns();
for (int i = 0; i < cols.length; i++) {
cols[i].setPrimaryKey(false);
}
}
}
}
public void removeView(TableView view) {
remove(views, view);
}
public void removeConstraint(Constraint constraint) {
remove(constraints, constraint);
}
public void removeSequence(Session session, Sequence sequence) {
remove(sequences, sequence);
}
public void removeTrigger(Session session, TriggerObject trigger) {
remove(triggers, trigger);
}
public void addView(TableView view) {
views = add(views, view);
}
public void addConstraint(Constraint constraint) {
if (constraints == null || constraints.indexOf(constraint) < 0) {
constraints = add(constraints, constraint);
}
}
public ObjectArray getConstraints() {
return constraints;
}
public void addSequence(Sequence sequence) {
sequences = add(sequences, sequence);
}
public void addTrigger(TriggerObject trigger) {
triggers = add(triggers, trigger);
}
private ObjectArray add(ObjectArray list, DbObject obj) {
if (list == null) {
list = new ObjectArray();
}
// self constraints are two entries in the list
// if(Database.CHECK) {
// if(list.indexOf(obj) >= 0) {
// throw Message.internal(
// "object already in list: " + obj.getName());
// }
// }
list.add(obj);
return list;
}
public void fireBefore(Session session) throws SQLException {
// TODO trigger: for sql server compatibility,
// should send list of rows, not just 'the event'
fire(session, true);
}
public void fireAfter(Session session) throws SQLException {
fire(session, false);
}
private void fire(Session session, boolean beforeAction) throws SQLException {
if (triggers != null) {
for (int i = 0; i < triggers.size(); i++) {
TriggerObject trigger = (TriggerObject) triggers.get(i);
trigger.fire(session, beforeAction);
}
}
}
public boolean fireRow() {
return (constraints != null && constraints.size() > 0) || (triggers != null && triggers.size() > 0);
}
public void fireBeforeRow(Session session, Row oldRow, Row newRow) throws SQLException {
fireRow(session, oldRow, newRow, true);
fireConstraints(session, oldRow, newRow, true);
}
private void fireConstraints(Session session, Row oldRow, Row newRow, boolean before) throws SQLException {
if (constraints != null) {
for (int i = 0; i < constraints.size(); i++) {
Constraint constraint = (Constraint) constraints.get(i);
if (constraint.isBefore() == before) {
constraint.checkRow(session, this, oldRow, newRow);
}
}
}
}
public void fireAfterRow(Session session, Row oldRow, Row newRow) throws SQLException {
fireRow(session, oldRow, newRow, false);
fireConstraints(session, oldRow, newRow, false);
}
private void fireRow(Session session, Row oldRow, Row newRow, boolean beforeAction) throws SQLException {
if (triggers != null) {
for (int i = 0; i < triggers.size(); i++) {
TriggerObject trigger = (TriggerObject) triggers.get(i);
trigger.fireRow(session, oldRow, newRow, beforeAction);
}
}
}
public Column[] getColumns(String[] columnNames) throws SQLException {
Column[] cols = new Column[columnNames.length];
for (int i = 0; i < cols.length; i++) {
cols[i] = getColumn(columnNames[i]);
}
return cols;
}
public boolean getGlobalTemporary() {
return false;
}
public boolean canTruncate() {
return false;
}
public void setCheckForeignKeyConstraints(Session session, boolean enabled, boolean checkExisting)
throws SQLException {
if (enabled && checkExisting) {
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint c = (Constraint) constraints.get(i);
c.checkExistingData(session);
}
}
checkForeignKeyConstraints = enabled;
}
public boolean getCheckForeignKeyConstraints() {
return checkForeignKeyConstraints;
}
public Index getIndexForColumn(Column column, boolean first) {
ObjectArray indexes = getIndexes();
for (int i = 1; indexes != null && i < indexes.size(); i++) {
Index index = (Index) indexes.get(i);
if (index.canGetFirstOrLast()) {
IndexColumn idxCol = index.getIndexColumns()[0];
if ((idxCol.sortType & SortOrder.DESCENDING) != 0 && (idxCol.sortType & SortOrder.NULLS_FIRST) == 0) {
// for descending sorted columns, if the NULLs
// are at the end, it does not work for some index types
continue;
}
int idx = index.getColumnIndex(column);
if (idx == 0) {
return index;
}
}
}
return null;
}
public boolean isOnCommitDrop() {
return onCommitDrop;
}
public void setOnCommitDrop(boolean onCommitDrop) {
this.onCommitDrop = onCommitDrop;
}
public boolean isOnCommitTruncate() {
return onCommitTruncate;
}
public void setOnCommitTruncate(boolean onCommitTruncate) {
this.onCommitTruncate = onCommitTruncate;
}
public boolean isClustered() {
return false;
}
/**
* If the index is still required by a constraint, transfer the ownership to
* it. Otherwise, the index is removed.
*
* @param session the session
* @param index the index that is no longer required
*/
public void removeIndexOrTransferOwnership(Session session, Index index) throws SQLException {
boolean stillNeeded = false;
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint cons = (Constraint) constraints.get(i);
if (cons.usesIndex(index)) {
cons.setIndexOwner(index);
database.update(session, cons);
stillNeeded = true;
}
}
if (!stillNeeded) {
database.removeSchemaObject(session, index);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -