use of com.wplatform.ddal.dbobject.schema.Sequence in project jdbc-shards by wplatform.
the class Table method addDependencies.
/**
* Add all objects that this table depends on to the hash set.
*
* @param dependencies the current set of dependencies
*/
public void addDependencies(HashSet<DbObject> dependencies) {
if (dependencies.contains(this)) {
// avoid endless recursion
return;
}
if (sequences != null) {
for (Sequence s : sequences) {
dependencies.add(s);
}
}
ExpressionVisitor visitor = ExpressionVisitor.getDependenciesVisitor(dependencies);
for (Column col : columns) {
col.isEverything(visitor);
}
dependencies.add(this);
}
use of com.wplatform.ddal.dbobject.schema.Sequence in project jdbc-shards by wplatform.
the class Parser method parseColumnForTable.
private Column parseColumnForTable(String columnName, boolean defaultNullable) {
Column column;
boolean isIdentity = false;
if (readIf("IDENTITY") || readIf("BIGSERIAL")) {
column = new Column(columnName, Value.LONG);
column.setOriginalSQL("IDENTITY");
parseAutoIncrement(column);
// PostgreSQL compatibility
if (!database.getMode().serialColumnIsNotPK) {
column.setPrimaryKey(true);
}
} else if (readIf("SERIAL")) {
column = new Column(columnName, Value.INT);
column.setOriginalSQL("SERIAL");
parseAutoIncrement(column);
// PostgreSQL compatibility
if (!database.getMode().serialColumnIsNotPK) {
column.setPrimaryKey(true);
}
} else {
column = parseColumnWithType(columnName);
}
if (readIf("NOT")) {
read("NULL");
column.setNullable(false);
} else if (readIf("NULL")) {
column.setNullable(true);
} else {
// domains may be defined as not nullable
column.setNullable(defaultNullable & column.isNullable());
}
if (readIf("AS")) {
if (isIdentity) {
getSyntaxError();
}
Expression expr = readExpression();
column.setComputedExpression(expr);
} else if (readIf("DEFAULT")) {
Expression defaultExpression = readExpression();
column.setDefaultExpression(session, defaultExpression);
} else if (readIf("GENERATED")) {
if (!readIf("ALWAYS")) {
read("BY");
read("DEFAULT");
}
read("AS");
read("IDENTITY");
long start = 1, increment = 1;
if (readIf("(")) {
read("START");
readIf("WITH");
start = readLong();
readIf(",");
if (readIf("INCREMENT")) {
readIf("BY");
increment = readLong();
}
read(")");
}
column.setPrimaryKey(true);
column.setAutoIncrement(true, start, increment);
}
if (readIf("NOT")) {
read("NULL");
column.setNullable(false);
} else {
readIf("NULL");
}
if (readIf("AUTO_INCREMENT") || readIf("BIGSERIAL") || readIf("SERIAL")) {
parseAutoIncrement(column);
if (readIf("NOT")) {
read("NULL");
}
} else if (readIf("IDENTITY")) {
parseAutoIncrement(column);
column.setPrimaryKey(true);
if (readIf("NOT")) {
read("NULL");
}
}
if (readIf("NULL_TO_DEFAULT")) {
column.setConvertNullToDefault(true);
}
if (readIf("SEQUENCE")) {
Sequence sequence = readSequence();
column.setSequence(sequence);
}
if (readIf("SELECTIVITY")) {
int value = readPositiveInt();
column.setSelectivity(value);
}
String comment = readCommentIf();
if (comment != null) {
column.setComment(comment);
}
return column;
}
use of com.wplatform.ddal.dbobject.schema.Sequence in project jdbc-shards by wplatform.
the class Parser method readSequence.
private Sequence readSequence() {
// same algorithm as readTableOrView
String sequenceName = readIdentifierWithSchema(null);
if (schemaName != null) {
return getSchema().getSequence(sequenceName);
}
Sequence sequence = findSequence(session.getCurrentSchemaName(), sequenceName);
if (sequence != null) {
return sequence;
}
throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName);
}
use of com.wplatform.ddal.dbobject.schema.Sequence in project jdbc-shards by wplatform.
the class Parser method findSequence.
private Sequence findSequence(String schema, String sequenceName) {
Sequence sequence = database.getSchema(schema).findSequence(sequenceName);
if (sequence != null) {
return sequence;
}
String[] schemaNames = session.getSchemaSearchPath();
if (schemaNames != null) {
for (String n : schemaNames) {
sequence = database.getSchema(n).findSequence(sequenceName);
if (sequence != null) {
return sequence;
}
}
}
return null;
}
use of com.wplatform.ddal.dbobject.schema.Sequence in project jdbc-shards by wplatform.
the class Function method getSequence.
private Sequence getSequence(Session session, Value v0, Value v1) {
String schemaName, sequenceName;
if (v1 == null) {
Parser p = new Parser(session);
String sql = v0.getString();
Expression expr = p.parseExpression(sql);
if (expr instanceof ExpressionColumn) {
ExpressionColumn seq = (ExpressionColumn) expr;
schemaName = seq.getOriginalTableAliasName();
if (schemaName == null) {
schemaName = session.getCurrentSchemaName();
sequenceName = sql;
} else {
sequenceName = seq.getColumnName();
}
} else {
throw DbException.getSyntaxError(sql, 1);
}
} else {
schemaName = v0.getString();
sequenceName = v1.getString();
}
Schema s = database.findSchema(schemaName);
if (s == null) {
schemaName = StringUtils.toUpperEnglish(schemaName);
s = database.getSchema(schemaName);
}
Sequence seq = s.findSequence(sequenceName);
if (seq == null) {
sequenceName = StringUtils.toUpperEnglish(sequenceName);
seq = s.getSequence(sequenceName);
}
return seq;
}
Aggregations