Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.j256.ormlite.db;
 
 import java.util.List;

Utility class which helps with managing database specific classes.

Author(s):
graywatson
public class DatabaseTypeUtils {
	private static List<DatabaseTypedatabaseTypes = new ArrayList<DatabaseType>();
	static {
		// new drivers need to be added here
	}

For static methods only.
	private DatabaseTypeUtils() {
	}

Creates and returns a com.j256.ormlite.db.DatabaseType for the database URL.

Throws:
java.lang.IllegalArgumentException if the url format is not recognized, the database type is unknown, or the class could not be constructed.
	public static DatabaseType createDatabaseType(String databaseUrl) {
		String dbTypePart = extractDbType(databaseUrl);
		for (DatabaseType databaseType : ) {
			if (databaseType.isDatabaseUrlThisType(databaseUrldbTypePart)) {
				return databaseType;
			}
		}
		throw new IllegalArgumentException("Unknown database-type url part '" + dbTypePart + "' in: " + databaseUrl);
	}
	private static String extractDbType(String databaseUrl) {
		if (!databaseUrl.startsWith("jdbc:")) {
			throw new IllegalArgumentException("Database URL was expected to start with jdbc: but was " + databaseUrl);
		}
		String[] urlParts = databaseUrl.split(":");
		if (urlParts.length < 2) {
			throw new IllegalArgumentException("Database URL was expected to be in the form: jdbc:db-type:... but was "
databaseUrl);
		}
		return urlParts[1];
	}
New to GrepCode? Check out our FAQ X