1 16 package scriptella.spi; 17 18 25 public abstract class AbstractConnection implements Connection { 26 private DialectIdentifier dialectIdentifier; 27 private boolean readonly; 28 protected final StatementCounter counter = new StatementCounter(); 30 31 34 protected AbstractConnection() { 35 } 36 37 42 protected AbstractConnection(DialectIdentifier dialectIdentifier, ConnectionParameters parameters) { 43 this(parameters); 44 if (dialectIdentifier==null) { 45 throw new IllegalArgumentException ("Dialect identifier cannot be null"); 46 } 47 this.dialectIdentifier = dialectIdentifier; 48 } 49 50 54 protected AbstractConnection(ConnectionParameters parameters) { 55 if (parameters==null) { 56 throw new IllegalArgumentException ("Connection parameters cannot be null"); 57 } 58 readonly=parameters.getBooleanProperty("readonly"); 60 } 61 62 63 public DialectIdentifier getDialectIdentifier() { 64 return dialectIdentifier; 65 } 66 67 protected void setDialectIdentifier(DialectIdentifier dialectIdentifier) { 68 this.dialectIdentifier = dialectIdentifier; 69 } 70 71 public long getExecutedStatementsCount() { 72 return counter.statements; } 74 75 82 public boolean isReadonly() { 83 return readonly; 84 } 85 86 public void commit() throws ProviderException { 87 } 88 89 public void rollback() throws ProviderException, UnsupportedOperationException { 90 throw new UnsupportedOperationException ("Transactions are not supported by "+toString()); 91 } 92 93 public String toString() { 94 String simpleName = getClass().getSimpleName(); 95 return simpleName.length() == 0 ? "connection" : simpleName; 96 } 97 98 101 public static class StatementCounter { 102 105 public volatile long statements; 106 } 107 } 108 | Popular Tags |