@Override public String identifier(String identifier) { return database.identifier(identifier); }
private Schema getSchema(String schemaName) { if (schemaName == null) { return null; } Schema schema = database.findSchema(schemaName); if (schema == null) { if (equalsToken("SESSION", schemaName)) { // for local temporary tables schema = database.getSchema(session.getCurrentSchemaName()); } else if (database.getMode().sysDummy1 && "SYSIBM".equals(schemaName)) { // IBM DB2 and Apache Derby compatibility: SYSIBM.SYSDUMMY1 } else { throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName); } } return schema; }
public SessionFactory build() { beforeBuild(); System.getProperties().putAll(configuration.settings); Database database = new Database(configuration); Engine engine = new Engine(database); return engine; }
/** * Initialize some attributes of this object. * * @param db the database * @param objectId the object id * @param name the name * @param traceModule the trace module name */ protected void initDbObjectBase(Database db, String name) { this.database = db; this.id = db.allocateObjectId(); this.objectName = name; this.trace = database.getTrace(Trace.DATABASE); }
case EQUAL: case EQUAL_NULL_SAFE: result = database.areEqual(l, r); break; case NOT_EQUAL: case NOT_EQUAL_NULL_SAFE: result = !database.areEqual(l, r); break; case BIGGER_EQUAL: result = database.compare(l, r) >= 0; break; case BIGGER: result = database.compare(l, r) > 0; break; case SMALLER_EQUAL: result = database.compare(l, r) <= 0; break; case SMALLER: result = database.compare(l, r) < 0; break; default:
public Database(Configuration configuration) { this.configuration = configuration; this.compareMode = CompareMode.getInstance(null, 0); this.dbSettings = getDbSettings(configuration.settings); this.mode = Mode.getInstance(dbSettings.sqlMode); this.traceSystem = new TraceSystem(); this.trace = traceSystem.getTrace(Trace.DATABASE); this.queryExecutor = createQueryExecutor(); this.repository = bindRepository(); this.executorFactory = new ExecutorFactoryImpl(); openDatabase(); }
String schema = matadataNode.getSchema(); try { JdbcRepository dsRepository = (JdbcRepository) database.getRepository(); DataSource dataSource = dsRepository.getDataSourceByShardName(shardName); conn = dataSource.getConnection(); tableName = database.identifier(tableName); if (catalog != null) { catalog = database.identifier(catalog); schema = database.identifier(schema);
@Override public QueryResult process(String query) { Session session = target.getSession().getDbSession(); QueryResult result = new QueryResult(0); List<SQLStatement> stmts = SQLUtils.parseStatements(query, JdbcConstants.MYSQL); for (SQLStatement stmt : stmts) { if (stmt instanceof SQLUseStatement) { SQLUseStatement s = (SQLUseStatement) stmt; String database = SQLUtils.toMySqlString(s.getDatabase()); database = database.replaceAll("['|`]", ""); Schema schema = session.getDatabase().findSchema(session.getDatabase().identifier(database)); if (schema == null) { throw ServerException.get(ErrorCode.ER_BAD_DB_ERROR, "Unknown database " + database); } result.setWarnings((short) 1); result.setMessage("The database is immutable, there is no need to use the 'use' command"); } else { throw ServerException.get(ErrorCode.ER_NOT_ALLOWED_COMMAND, "not allowed command:" + query); } } return result; }
@Override public Session createSession(Properties ci) { String userName = ci.getProperty("user"); String password = ci.getProperty("password"); if (userName == null) { userName = Database.SYSTEM_USER_NAME; } User user = database.findUser(userName); if (user == null) { // users is the last thing we add, so if no user is around, // the database is new (or not initialized correctly) user = new User(database, userName); user.setAdmin(true); user.setPassword(password); database.addDatabaseObject(user); } User userObject = database.getUser(userName); Session session = database.createSession(userObject); return session; }
sequenceName = v1.getString(); Schema s = database.findSchema(schemaName); if (s == null) { schemaName = StringUtils.toUpperEnglish(schemaName); s = database.getSchema(schemaName);
break; case LOG: if (database.getMode().logIsLogBase10) { result = ValueDouble.get(Math.log10(v0.getDouble())); } else { case CHAR: result = ValueString.get(String.valueOf((char) v0.getInt()), database.getMode().treatEmptyStringsAsNull); break; case CHAR_LENGTH: database.getMode().treatEmptyStringsAsNull); if (separator != null && result == ValueNull.INSTANCE) { result = ValueString.get("", database.getMode().treatEmptyStringsAsNull); database.getMode().treatEmptyStringsAsNull); break; case LOWER: database.getMode().treatEmptyStringsAsNull); break; case RAWTOHEX: result = ValueString.get(rawToHex(v0.getString()), database.getMode().treatEmptyStringsAsNull); break; case SOUNDEX:
/** * Get the schema. If the schema does not exist, an exception is thrown. * * @param schemaName the name of the schema * @return the schema * @throws DbException no schema with that name exists */ public Schema getSchema(String schemaName) { Schema schema = findSchema(schemaName); if (schema == null) { throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName); } return schema; }
schemas.put(infoSchema.getName(), infoSchema); Session sysSession = createSession(systemUser); try { for (TableRule tableRule : configuration.tableRules) { tableMate.check(); this.addSchemaObject(tableMate); this.addSchemaObject(sequence);
result = ValueString.get(insert(v0.getString(), v1.getInt(), v2.getInt(), v3.getString()), database.getMode().treatEmptyStringsAsNull); database.getMode().treatEmptyStringsAsNull); break; case LOCATE: { int count = Math.max(0, v1.getInt()); result = ValueString.get(repeat(v0.getString(), count), database.getMode().treatEmptyStringsAsNull); break; String s2 = (v2 == null) ? "" : v2.getString(); result = ValueString.get(replace(s0, s1, s2), database.getMode().treatEmptyStringsAsNull); break; database.getMode().treatEmptyStringsAsNull); break; case LTRIM: result = ValueString.get(StringUtils.trim(v0.getString(), true, false, v1 == null ? " " : v1.getString()), database.getMode().treatEmptyStringsAsNull); break; case TRIM: result = ValueString.get(StringUtils.trim(v0.getString(), true, true, v1 == null ? " " : v1.getString()), database.getMode().treatEmptyStringsAsNull);
@Override public void run() { if (database != null) { database.close(); } } }
/** * Get the current object id, or get a new id from the database. The object * id is used when creating new database object (CREATE statement). * * @return the object id */ protected int getObjectId() { int id = objectId; if (id == 0) { id = session.getDatabase().allocateObjectId(); } else { objectId = 0; } return id; }
@Override public void updateAggregate(Session session) { Value now = columnResolver.getValue(column); Select select = columnResolver.getSelect(); if (select == null) { throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL()); } HashMap<Expression, Object> values = select.getCurrentGroup(); if (values == null) { // this is a different level (the enclosing query) return; } Value v = (Value) values.get(this); if (v == null) { values.put(this, now); } else { if (!database.areEqual(now, v)) { throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL()); } } }
public void configure(Properties params) { JdbcRepository repo = (JdbcRepository) database.getRepository(); String shardName = params.getProperty("shard", repo.getPublicDB()); String catalog = params.getProperty("catalog"); String schema = params.getProperty("schema"); String tableName = params.getProperty("tableName", DEF_TABLE); tableName = database.identifier(tableName); if (catalog != null) { catalog = database.identifier(catalog); } if (schema != null) { schema = database.identifier(schema); } tableNode = new ObjectNode(shardName, catalog, schema, tableName, null); nameValue = StringUtils.toLowerEnglish(getName()); nameColumnName = params.getProperty("nameColumnName", DEF_NAME_COLUMN); valueColumnName = params.getProperty("valueColumnName", DEF_VALUE_COLUMN); nameColumnLength = getIntProperty(params, "nameColumnLength", DEF_NAMECOLUMNLENGTH_LENGTH); incrementSize = getIntProperty(params, "cacheSize", (int) getCacheSize()); initialValue = getIntProperty(params, "initialValue", DEFAULT_INITIAL_VALUE); this.selectQuery = buildSelectQuery(); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery(); this.dataSource = repo.getDataSourceByShardName(shardName); this.optimizer = new HiloOptimizer(incrementSize); this.createTableIfNotExits(); }
Schema s = database.findSchema(objectName); if ((!SysProperties.OLD_STYLE_OUTER_JOIN || s != null) && readIf("(")) { if (readIf("(")) { schema = objectName; return readFunction(database.getSchema(schema), name); } else if (readIf(".")) { schema = objectName;
private Table getDualTable(boolean noColumns) { Schema main = database.findSchema(Constants.SCHEMA_MAIN); Expression one = ValueExpression.get(ValueLong.get(1)); return new RangeTable(main, one, one, noColumns); }