use of org.gridgain.internal.h2.table.Column in project h2database by h2database.
the class ConstraintReferential method checkRowRefTable.
private void checkRowRefTable(SessionLocal session, Row oldRow, Row newRow) {
if (oldRow == null) {
// this is an insert
return;
}
if (newRow != null && isEqual(oldRow, newRow)) {
// on an update, if both old and new are the same, don't do anything
return;
}
if (newRow == null) {
// this is a delete
if (deleteAction == ConstraintActionType.RESTRICT) {
checkRow(session, oldRow);
} else {
int i = deleteAction == ConstraintActionType.CASCADE ? 0 : columns.length;
Prepared deleteCommand = getDelete(session);
setWhere(deleteCommand, i, oldRow);
updateWithSkipCheck(deleteCommand);
}
} else {
// this is an update
if (updateAction == ConstraintActionType.RESTRICT) {
checkRow(session, oldRow);
} else {
Prepared updateCommand = getUpdate(session);
if (updateAction == ConstraintActionType.CASCADE) {
ArrayList<Parameter> params = updateCommand.getParameters();
for (int i = 0, len = columns.length; i < len; i++) {
Parameter param = params.get(i);
Column refCol = refColumns[i].column;
param.setValue(newRow.getValue(refCol.getColumnId()));
}
}
setWhere(updateCommand, columns.length, oldRow);
updateWithSkipCheck(updateCommand);
}
}
}
use of org.gridgain.internal.h2.table.Column in project h2database by h2database.
the class DatabaseMetaLocal method addPrivilege.
private void addPrivilege(SimpleResult result, Value catalogValue, Value schemaValue, Value tableValue, Value granteeValue, String right, boolean isAdmin, CompareLike columnLike, Column[] columns) {
if (columns == null) {
result.addRow(// TABLE_CAT
catalogValue, // TABLE_SCHEM
schemaValue, // TABLE_NAME
tableValue, // GRANTOR
ValueNull.INSTANCE, // GRANTEE
granteeValue, // PRIVILEGE
getString(right), // IS_GRANTABLE
isAdmin ? YES : NO);
} else {
for (Column column : columns) {
String columnName = column.getName();
if (columnLike != null && !columnLike.test(columnName)) {
continue;
}
result.addRow(// TABLE_CAT
catalogValue, // TABLE_SCHEM
schemaValue, // TABLE_NAME
tableValue, // COLUMN_NAME
getString(columnName), // GRANTOR
ValueNull.INSTANCE, // GRANTEE
granteeValue, // PRIVILEGE
getString(right), // IS_GRANTABLE
isAdmin ? YES : NO);
}
}
}
use of org.gridgain.internal.h2.table.Column in project h2database by h2database.
the class Parser method parseAlterTableDrop.
private Prepared parseAlterTableDrop(Schema schema, String tableName, boolean ifTableExists) {
if (readIf(CONSTRAINT)) {
boolean ifExists = readIfExists(false);
String constraintName = readIdentifierWithSchema(schema.getName());
ifExists = readIfExists(ifExists);
checkSchema(schema);
AlterTableDropConstraint command = new AlterTableDropConstraint(session, getSchema(), ifExists);
command.setTableName(tableName);
command.setIfTableExists(ifTableExists);
command.setConstraintName(constraintName);
ConstraintActionType dropAction = parseCascadeOrRestrict();
if (dropAction != null) {
command.setDropAction(dropAction);
}
return command;
} else if (readIf(PRIMARY)) {
read(KEY);
Table table = tableIfTableExists(schema, tableName, ifTableExists);
if (table == null) {
return new NoOperation(session);
}
Index idx = table.getPrimaryKey();
DropIndex command = new DropIndex(session, schema);
command.setIndexName(idx.getName());
return command;
} else if (database.getMode().alterTableExtensionsMySQL) {
Prepared command = parseAlterTableDropCompatibility(schema, tableName, ifTableExists);
if (command != null) {
return command;
}
}
readIf("COLUMN");
boolean ifExists = readIfExists(false);
ArrayList<Column> columnsToRemove = new ArrayList<>();
Table table = tableIfTableExists(schema, tableName, ifTableExists);
// For Oracle compatibility - open bracket required
boolean openingBracketDetected = readIf(OPEN_PAREN);
do {
String columnName = readIdentifier();
if (table != null) {
Column column = table.getColumn(columnName, ifExists);
if (column != null) {
columnsToRemove.add(column);
}
}
} while (readIf(COMMA));
if (openingBracketDetected) {
// For Oracle compatibility - close bracket
read(CLOSE_PAREN);
}
if (table == null || columnsToRemove.isEmpty()) {
return new NoOperation(session);
}
AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
command.setType(CommandInterface.ALTER_TABLE_DROP_COLUMN);
command.setTableName(tableName);
command.setIfTableExists(ifTableExists);
command.setColumnsToRemove(columnsToRemove);
return command;
}
use of org.gridgain.internal.h2.table.Column in project h2database by h2database.
the class Parser method getColumnWithDomain.
private static Column getColumnWithDomain(String columnName, Domain domain) {
Column column = new Column(columnName, domain.getDataType());
column.setComment(domain.getComment());
column.setDomain(domain);
return column;
}
use of org.gridgain.internal.h2.table.Column in project h2database by h2database.
the class Parser method parseColumnForTable.
private Column parseColumnForTable(String columnName, boolean defaultNullable) {
Column column;
Mode mode = database.getMode();
if (mode.identityDataType && readIf("IDENTITY")) {
column = new Column(columnName, TypeInfo.TYPE_BIGINT);
parseCompatibilityIdentityOptions(column);
column.setPrimaryKey(true);
} else if (mode.serialDataTypes && readIf("BIGSERIAL")) {
column = new Column(columnName, TypeInfo.TYPE_BIGINT);
column.setIdentityOptions(new SequenceOptions(), false);
} else if (mode.serialDataTypes && readIf("SERIAL")) {
column = new Column(columnName, TypeInfo.TYPE_INTEGER);
column.setIdentityOptions(new SequenceOptions(), false);
} else {
column = parseColumnWithType(columnName);
}
if (readIf("INVISIBLE")) {
column.setVisible(false);
} else if (readIf("VISIBLE")) {
column.setVisible(true);
}
boolean defaultOnNull = false;
NullConstraintType nullConstraint = parseNotNullConstraint();
defaultIdentityGeneration: if (!column.isIdentity()) {
if (readIf(AS)) {
column.setGeneratedExpression(readExpression());
} else if (readIf(DEFAULT)) {
if (readIf(ON)) {
read(NULL);
defaultOnNull = true;
break defaultIdentityGeneration;
}
column.setDefaultExpression(session, readExpression());
} else if (readIf("GENERATED")) {
boolean always = readIf("ALWAYS");
if (!always) {
read("BY");
read(DEFAULT);
}
read(AS);
if (readIf("IDENTITY")) {
SequenceOptions options = new SequenceOptions();
if (readIf(OPEN_PAREN)) {
parseSequenceOptions(options, null, false, false);
read(CLOSE_PAREN);
}
column.setIdentityOptions(options, always);
break defaultIdentityGeneration;
} else if (!always) {
throw getSyntaxError();
} else {
column.setGeneratedExpression(readExpression());
}
}
if (!column.isGenerated() && readIf(ON)) {
read("UPDATE");
column.setOnUpdateExpression(session, readExpression());
}
nullConstraint = parseNotNullConstraint(nullConstraint);
if (parseCompatibilityIdentity(column, mode)) {
nullConstraint = parseNotNullConstraint(nullConstraint);
}
}
switch(nullConstraint) {
case NULL_IS_ALLOWED:
if (column.isIdentity()) {
throw DbException.get(ErrorCode.COLUMN_MUST_NOT_BE_NULLABLE_1, column.getName());
}
column.setNullable(true);
break;
case NULL_IS_NOT_ALLOWED:
column.setNullable(false);
break;
case NO_NULL_CONSTRAINT_FOUND:
if (!column.isIdentity()) {
column.setNullable(defaultNullable);
}
break;
default:
throw DbException.get(ErrorCode.UNKNOWN_MODE_1, "Internal Error - unhandled case: " + nullConstraint.name());
}
if (!defaultOnNull) {
if (readIf(DEFAULT)) {
read(ON);
read(NULL);
defaultOnNull = true;
} else if (readIf("NULL_TO_DEFAULT")) {
defaultOnNull = true;
}
}
if (defaultOnNull) {
column.setDefaultOnNull(true);
}
if (!column.isGenerated()) {
if (readIf("SEQUENCE")) {
column.setSequence(readSequence(), column.isGeneratedAlways());
}
}
if (readIf("SELECTIVITY")) {
column.setSelectivity(readNonNegativeInt());
}
if (mode.getEnum() == ModeEnum.MySQL) {
if (readIf("CHARACTER")) {
readIf(SET);
readMySQLCharset();
}
if (readIf("COLLATE")) {
readMySQLCharset();
}
}
String comment = readCommentIf();
if (comment != null) {
column.setComment(comment);
}
return column;
}
Aggregations