001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (C) 2012 Paul Ferraro 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package net.sf.hajdbc; 019 020import java.sql.Driver; 021import java.util.regex.Matcher; 022import java.util.regex.Pattern; 023 024/** 025 * @author Paul Ferraro 026 */ 027public abstract class AbstractDriver implements Driver 028{ 029 /** 030 * {@inheritDoc} 031 * @see java.sql.Driver#acceptsURL(java.lang.String) 032 */ 033 @Override 034 public boolean acceptsURL(String url) 035 { 036 return (this.parse(url) != null); 037 } 038 039 protected abstract Pattern getUrlPattern(); 040 041 protected String parse(String url) 042 { 043 Matcher matcher = this.getUrlPattern().matcher(url); 044 045 if (!matcher.matches()) 046 { 047 return null; 048 } 049 050 return matcher.group(1); 051 } 052 053 /** 054 * {@inheritDoc} 055 * @see java.sql.Driver#jdbcCompliant() 056 */ 057 @Override 058 public boolean jdbcCompliant() 059 { 060 return false; 061 } 062 063 /** 064 * @see java.sql.Driver#getMajorVersion() 065 */ 066 @Override 067 public int getMajorVersion() 068 { 069 return Version.CURRENT.getMajor(); 070 } 071 072 /** 073 * @see java.sql.Driver#getMinorVersion() 074 */ 075 @Override 076 public int getMinorVersion() 077 { 078 return Version.CURRENT.getMinor(); 079 } 080}