Initializes database driver for databases with JDBC driver version lower than 4.0

@param databaseType Name of target database from JDBC connection string
962915
static void initializeDatabaseDriver(String databaseType) {
    String driverClass = System.getProperty(JDBC_DRIVER_CLASS_KEY_PREFIX + databaseType);
    if (driverClass != null) {
      Log.debug("Loading " + driverClass + " to initialize database of type " + databaseType);
      try {
        Class.forName(driverClass);
      } catch (ClassNotFoundException e) {
        throw new RuntimeException("Connection to '" + databaseType + "' database is not possible due to missing JDBC driver. " +
                "User specified driver class: " + driverClass, e);
      }
      return;
    }
    // use built-in defaults
    switch (databaseType) {
      case HIVE_DB_TYPE:
        try {
          Class.forName(HIVE_JDBC_DRIVER_CLASS);
        } catch (ClassNotFoundException e) {
          throw new RuntimeException("Connection to HIVE database is not possible due to missing JDBC driver.", e);
        }
        break;
      case NETEZZA_DB_TYPE:
        try {
          Class.forName(NETEZZA_JDBC_DRIVER_CLASS);
        } catch (ClassNotFoundException e) {
          throw new RuntimeException("Connection to Netezza database is not possible due to missing JDBC driver.", e);
        }
        break;
      default:
        //nothing to do
    }
  }
1155666
public static function useCurrentDatabaseDriver($databaseInstance): void
    {
        static::throwExceptionIfHasStarted();

        $driver = new Database();
        $driver->setCurrentDatabase($databaseInstance);

        static::$driver = $driver;
    }
129899
public void setDBEngineVersions(java.util.Collection<DBEngineVersion> dBEngineVersions) {
        if (dBEngineVersions == null) {
            this.dBEngineVersions = null;
            return;
        }

        this.dBEngineVersions = new java.util.ArrayList<DBEngineVersion>(dBEngineVersions);
    }
531038
public static DatabaseType createDatabaseType(String databaseUrl) {
		String dbTypePart = extractDbType(databaseUrl);
		for (DatabaseType databaseType : databaseTypes) {
			if (databaseType.isDatabaseUrlThisType(databaseUrl, dbTypePart)) {
				return databaseType;
			}
		}
		throw new IllegalArgumentException("Unknown database-type url part '" + dbTypePart + "' in: " + databaseUrl);
	}
1188446
protected void registerColumnType(String columnType, int jdbcType) {
        columnTypeMatchers.add(new ColumnTypeMatcher(columnType));
        jdbcTypes.put(columnType, jdbcType);
    }
928514
public void setJdbcTargets(java.util.Collection<JdbcTarget> jdbcTargets) {
        if (jdbcTargets == null) {
            this.jdbcTargets = null;
            return;
        }

        this.jdbcTargets = new java.util.ArrayList<JdbcTarget>(jdbcTargets);
    }
479471
public void initialize() throws SQLException {
		if (!Boolean.parseBoolean(System.getProperty(AUTO_CREATE_TABLES))) {
			return;
		}

		if (configuredDaos == null) {
			throw new SQLException("configuredDaos was not set in " + getClass().getSimpleName());
		}

		// find all of the daos and create the tables
		for (Dao<?, ?> dao : configuredDaos) {
			Class<?> clazz = dao.getDataClass();
			try {
				DatabaseTableConfig<?> tableConfig = null;
				if (dao instanceof BaseDaoImpl) {
					tableConfig = ((BaseDaoImpl<?, ?>) dao).getTableConfig();
				}
				if (tableConfig == null) {
					tableConfig = DatabaseTableConfig.fromClass(connectionSource.getDatabaseType(), clazz);
				}
				TableUtils.createTable(connectionSource, tableConfig);
				createdClasses.add(tableConfig);
			} catch (Exception e) {
				// we don't stop because the table might already exist
				System.err.println("Was unable to auto-create table for " + clazz);
				e.printStackTrace();
			}
		}
	}
1041207
public int insert(DatabaseType databaseType, DatabaseConnection databaseConnection, T data, ObjectCache objectCache)
			throws SQLException {
		KeyHolder keyHolder = null;
		if (idField != null) {
			boolean assignId;
			if (idField.isAllowGeneratedIdInsert() && !idField.isObjectsFieldValueDefault(data)) {
				assignId = false;
			} else {
				assignId = true;
			}
			if (idField.isSelfGeneratedId() && idField.isGeneratedId()) {
				if (assignId) {
					idField.assignField(connectionSource, data, idField.generateId(), false, objectCache);
				}
			} else if (idField.isGeneratedIdSequence() && databaseType.isSelectSequenceBeforeInsert()) {
				if (assignId) {
					assignSequenceId(databaseConnection, data, objectCache);
				}
			} else if (idField.isGeneratedId()) {
				if (assignId) {
					// get the id back from the database
					keyHolder = new KeyHolder(idField.getColumnName());
				}
			} else {
				// the id should have been set by the caller already
			}
		}

		try {
			// implement {@link DatabaseField#foreignAutoCreate()}, need to do this _before_ getFieldObjects() below
			if (tableInfo.isForeignAutoCreate()) {
				for (FieldType fieldType : tableInfo.getFieldTypes()) {
					if (!fieldType.isForeignAutoCreate()) {
						continue;
					}
					// get the field value
					Object foreignObj = fieldType.extractRawJavaFieldValue(data);
					if (foreignObj != null && fieldType.getForeignIdField().isObjectsFieldValueDefault(foreignObj)) {
						fieldType.createWithForeignDao(foreignObj);
					}
				}
			}

			Object[] args = getFieldObjects(data);
			Object versionDefaultValue = null;
			// implement {@link DatabaseField#version()}
			if (versionFieldTypeIndex >= 0 && args[versionFieldTypeIndex] == null) {
				// if the version is null then we need to initialize it before create
				FieldType versionFieldType = argFieldTypes[versionFieldTypeIndex];
				versionDefaultValue = versionFieldType.moveToNextValue(null);
				args[versionFieldTypeIndex] = versionFieldType.convertJavaFieldToSqlArgValue(versionDefaultValue);
			}

			int rowC;
			try {
				rowC = databaseConnection.insert(statement, args, argFieldTypes, keyHolder);
			} catch (SQLException e) {
				// NOTE: don't log full exception here
				logger.debug("insert data with statement '{}' and {} args, threw exception: {}", statement, args.length,
						e);
				if (args.length > 0) {
					// need to do the (Object) cast to force args to be a single object
					logger.trace("insert arguments: {}", (Object) args);
				}
				throw e;
			}
			logger.debug("insert data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC);
			if (args.length > 0) {
				// need to do the (Object) cast to force args to be a single object
				logger.trace("insert arguments: {}", (Object) args);
			}
			if (rowC > 0) {
				if (versionDefaultValue != null) {
					argFieldTypes[versionFieldTypeIndex].assignField(connectionSource, data, versionDefaultValue, false,
							null);
				}
				if (keyHolder != null) {
					// assign the key returned by the database to the object's id field after it was inserted
					Number key = keyHolder.getKey();
					if (key == null) {
						// may never happen but let's be careful out there
						throw new SQLException(
								"generated-id key was not set by the update call, maybe a schema mismatch between entity and database table?");
					}
					if (key.longValue() == 0L) {
						// sanity check because the generated-key returned is 0 by default, may never happen
						throw new SQLException(
								"generated-id key must not be 0 value, maybe a schema mismatch between entity and database table?");
					}
					assignIdValue(data, key, "keyholder", objectCache);
				}
				/*
				 * If we have a cache and if all of the foreign-collection fields have been assigned then add to cache.
				 * However, if one of the foreign collections has not be assigned then don't add it to the cache.
				 */
				if (objectCache != null && foreignCollectionsAreAssigned(tableInfo.getForeignCollections(), data)) {
					Object id = idField.extractJavaFieldValue(data);
					objectCache.put(clazz, id, data);
				}
			}

			return rowC;
		} catch (SQLException e) {
			throw SqlExceptionUtil.create("Unable to run insert stmt on object " + data + ": " + statement, e);
		}
	}
44754
public static function setDbType($dbType) {
        $dbTypeCast = (string) $dbType;
        
        if (array_search($dbTypeCast, self::$dbList) === false) {
            throw new DBException('Illegal database type provided to DB Service');
        }
        
        self::$dbType = $dbTypeCast;
    }
1199284
private void setTypeMappers(TypeMapper[] typeMappers) throws SQLException {

        if (typeMappers.length > 0) {
            Map<String, Class<?>> mappers = _connection.getTypeMap();
            for (TypeMapper t : typeMappers) {
                mappers.put(t.UDTName(), t.mapperClass());
            }
            _connection.setTypeMap(mappers);
        }
    }
700223
public static DatabaseType getDatabaseType(final String url) {
        switch (getDriverClassName(url)) {
            case "com.mysql.cj.jdbc.Driver":
            case "com.mysql.jdbc.Driver":
                return DatabaseType.MySQL;
            case "org.postgresql.Driver":
                return DatabaseType.PostgreSQL;
            case "oracle.jdbc.driver.OracleDriver":
                return DatabaseType.Oracle;
            case "com.microsoft.sqlserver.jdbc.SQLServerDriver":
                return DatabaseType.SQLServer;
            case "org.h2.Driver":
                return DatabaseType.H2;
            default:
                throw new ShardingException("Cannot resolve JDBC url `%s`", url);
        }
    }
561179
public void extractFieldTypes(DatabaseType databaseType) throws SQLException {
		if (fieldTypes == null) {
			if (fieldConfigs == null) {
				fieldTypes = extractFieldTypes(databaseType, dataClass, tableName);
			} else {
				fieldTypes = convertFieldConfigs(databaseType, tableName, fieldConfigs);
			}
		}
	}
969711
public void init(DatabaseOwner databaseOwner, String strDbName, int iDatabaseType, Map<String, Object> properties)
    {
        super.init(databaseOwner, strDbName, iDatabaseType, properties);

        this.setProperty(DBConstants.READ_ONLY_DB, DBConstants.TRUE);   // This is always read-only
    }
1224763
public static DatabaseProtocolFrontendEngine newInstance(final DatabaseType databaseType) {
        for (DatabaseProtocolFrontendEngine each : NewInstanceServiceLoader.newServiceInstances(DatabaseProtocolFrontendEngine.class)) {
            if (DatabaseType.valueFrom(each.getDatabaseType()) == databaseType) {
                return each;
            }
        }
        throw new UnsupportedOperationException(String.format("Cannot support database type '%s'", databaseType));
    }
1130831
public void setDBInstances(java.util.Collection<DBInstance> dBInstances) {
        if (dBInstances == null) {
            this.dBInstances = null;
            return;
        }

        this.dBInstances = new java.util.ArrayList<DBInstance>(dBInstances);
    }
438038
private static synchronized void addDatabaseObject(String type,
            String path, Database db) {

        // A VoltDB extension to work around ENG-6044
        /* disable 15 lines ...
        Object  key = path;

        HashMap databaseMap;

        if (type == DatabaseURL.S_FILE) {
            databaseMap = fileDatabaseMap;
            key         = filePathToKey(path);
        } else if (type == DatabaseURL.S_RES) {
            databaseMap = resDatabaseMap;
        } else if (type == DatabaseURL.S_MEM) {
            databaseMap = memDatabaseMap;
        } else {
            throw Error.runtimeError(ErrorCode.U_S0500,
                                     "DatabaseManager.addDatabaseObject()");
        }
           ... disabled 15 lines */

        assert(type == DatabaseURL.S_MEM);
        java.util.HashMap<String, Database> databaseMap = memDatabaseMap;
        String key = path;
        // End of VoltDB extension

        databaseIDMap.put(db.databaseID, db);
        databaseMap.put(key, db);
    }
1269720
public static void initialize()
        throws CacheReloadException
    {
        Context.getDbType().initialize(AbstractDataModelObject.class);
        AttributeType.initialize(AbstractDataModelObject.class);
        SQLTable.initialize(AbstractDataModelObject.class);
        Type.initialize(AbstractDataModelObject.class);
        Dimension.initialize(AbstractDataModelObject.class);
        Attribute.initialize(AbstractDataModelObject.class);
        Status.initialize(AbstractDataModelObject.class);
    }