use of com.predic8.schema.Schema in project h2database by h2database.
the class DropDatabase method dropAllObjects.
private void dropAllObjects() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
db.lockMeta(session);
// There can be dependencies between tables e.g. using computed columns,
// so we might need to loop over them multiple times.
boolean runLoopAgain;
do {
ArrayList<Table> tables = db.getAllTablesAndViews(false);
ArrayList<Table> toRemove = New.arrayList();
for (Table t : tables) {
if (t.getName() != null && TableType.VIEW == t.getTableType()) {
toRemove.add(t);
}
}
for (Table t : tables) {
if (t.getName() != null && TableType.TABLE_LINK == t.getTableType()) {
toRemove.add(t);
}
}
for (Table t : tables) {
if (t.getName() != null && TableType.TABLE == t.getTableType() && !t.isHidden()) {
toRemove.add(t);
}
}
for (Table t : tables) {
if (t.getName() != null && TableType.EXTERNAL_TABLE_ENGINE == t.getTableType() && !t.isHidden()) {
toRemove.add(t);
}
}
runLoopAgain = false;
for (Table t : toRemove) {
if (t.getName() == null) {
// ignore, already dead
} else if (db.getDependentTable(t, t) == null) {
db.removeSchemaObject(session, t);
} else {
runLoopAgain = true;
}
}
} while (runLoopAgain);
// TODO session-local temp tables are not removed
for (Schema schema : db.getAllSchemas()) {
if (schema.canDrop()) {
db.removeDatabaseObject(session, schema);
}
}
ArrayList<SchemaObject> list = New.arrayList();
for (SchemaObject obj : db.getAllSchemaObjects(DbObject.SEQUENCE)) {
// ones that belong to session-local temp tables.
if (!((Sequence) obj).getBelongsToTable()) {
list.add(obj);
}
}
// maybe constraints and triggers on system tables will be allowed in
// the future
list.addAll(db.getAllSchemaObjects(DbObject.CONSTRAINT));
list.addAll(db.getAllSchemaObjects(DbObject.TRIGGER));
list.addAll(db.getAllSchemaObjects(DbObject.CONSTANT));
list.addAll(db.getAllSchemaObjects(DbObject.FUNCTION_ALIAS));
for (SchemaObject obj : list) {
if (obj.isHidden()) {
continue;
}
db.removeSchemaObject(session, obj);
}
for (User user : db.getAllUsers()) {
if (user != session.getUser()) {
db.removeDatabaseObject(session, user);
}
}
for (Role role : db.getAllRoles()) {
String sql = role.getCreateSQL();
// the role PUBLIC must not be dropped
if (sql != null) {
db.removeDatabaseObject(session, role);
}
}
ArrayList<DbObject> dbObjects = New.arrayList();
dbObjects.addAll(db.getAllRights());
dbObjects.addAll(db.getAllAggregates());
dbObjects.addAll(db.getAllUserDataTypes());
for (DbObject obj : dbObjects) {
String sql = obj.getCreateSQL();
// the role PUBLIC must not be dropped
if (sql != null) {
db.removeDatabaseObject(session, obj);
}
}
}
use of com.predic8.schema.Schema in project h2database by h2database.
the class CreateSchema method update.
@Override
public int update() {
session.getUser().checkSchemaAdmin();
session.commit(true);
Database db = session.getDatabase();
User user = db.getUser(authorization);
// during DB startup, the Right/Role records have not yet been loaded
if (!db.isStarting()) {
user.checkSchemaAdmin();
}
if (db.findSchema(schemaName) != null) {
if (ifNotExists) {
return 0;
}
throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, schemaName);
}
int id = getObjectId();
Schema schema = new Schema(db, id, schemaName, user, false);
schema.setTableEngineParams(tableEngineParams);
db.addDatabaseObject(session, schema);
return 0;
}
use of com.predic8.schema.Schema in project h2database by h2database.
the class ExpressionColumn method optimize.
@Override
public Expression optimize(Session session) {
if (columnResolver == null) {
Schema schema = session.getDatabase().findSchema(tableAlias == null ? session.getCurrentSchemaName() : tableAlias);
if (schema != null) {
Constant constant = schema.findConstant(columnName);
if (constant != null) {
return constant.getValue();
}
}
String name = columnName;
if (tableAlias != null) {
name = tableAlias + "." + name;
if (schemaName != null) {
name = schemaName + "." + name;
}
}
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, name);
}
return columnResolver.optimize(this, column);
}
use of com.predic8.schema.Schema in project ignite by apache.
the class GridSqlQueryParser method parseCreateIndex.
/**
* Parse {@code CREATE INDEX} statement.
*
* @param createIdx {@code CREATE INDEX} statement.
* @see <a href="http://h2database.com/html/grammar.html#create_index">H2 {@code CREATE INDEX} spec.</a>
*/
private GridSqlCreateIndex parseCreateIndex(CreateIndex createIdx) {
if (CREATE_INDEX_HASH.get(createIdx) || CREATE_INDEX_PRIMARY_KEY.get(createIdx) || CREATE_INDEX_UNIQUE.get(createIdx)) {
throw new IgniteSQLException("Only SPATIAL modifier is supported for CREATE INDEX", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
GridSqlCreateIndex res = new GridSqlCreateIndex();
Schema schema = SCHEMA_COMMAND_SCHEMA.get(createIdx);
String tblName = CREATE_INDEX_TABLE_NAME.get(createIdx);
res.schemaName(schema.getName());
res.tableName(tblName);
res.ifNotExists(CREATE_INDEX_IF_NOT_EXISTS.get(createIdx));
QueryIndex idx = new QueryIndex();
idx.setName(CREATE_INDEX_NAME.get(createIdx));
idx.setIndexType(CREATE_INDEX_SPATIAL.get(createIdx) ? QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED);
IndexColumn[] cols = CREATE_INDEX_COLUMNS.get(createIdx);
LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>(cols.length);
for (IndexColumn col : CREATE_INDEX_COLUMNS.get(createIdx)) {
int sortType = INDEX_COLUMN_SORT_TYPE.get(col);
if ((sortType & SortOrder.NULLS_FIRST) != 0 || (sortType & SortOrder.NULLS_LAST) != 0) {
throw new IgniteSQLException("NULLS FIRST and NULLS LAST modifiers are not supported for index columns", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
Boolean prev = flds.put(INDEX_COLUMN_NAME.get(col), (sortType & SortOrder.DESCENDING) == 0);
if (prev != null) {
String prevCol = INDEX_COLUMN_NAME.get(col) + " " + (prev ? "ASC" : "DESC");
throw new IgniteSQLException("Already defined column in index: " + prevCol, IgniteQueryErrorCode.COLUMN_ALREADY_EXISTS);
}
}
idx.setFields(flds);
res.index(idx);
return res;
}
use of com.predic8.schema.Schema in project core by s4.
the class EventClock method update.
public void update(EventWrapper eventWrapper) {
long eventTime = -1;
String streamName = eventWrapper.getStreamName();
String fieldName = eventClockStreamsMap.get(streamName);
if (fieldName != null) {
Object event = eventWrapper.getEvent();
Schema schema = schemaContainer.getSchema(event.getClass());
Property property = schema.getProperties().get(fieldName);
if (property != null && (property.getType().equals(Long.TYPE) || property.getType().equals(Long.class))) {
try {
eventTime = (Long) property.getGetterMethod().invoke(event);
updateTime(eventTime);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
Aggregations