/** * Gets a connection to the PostgreSQL database. The database is identified by the DataSource * properties serverName, databaseName, and portNumber. The user to connect as is identified by * the DataSource properties user and password. * * @return A valid database connection. * @throws SQLException Occurs when the database connection cannot be established. */ public Connection getConnection() throws SQLException { return getConnection(user, password); }
/** * Adds custom properties for this DataSource to the properties defined in the superclass. */ public Reference getReference() throws NamingException { Reference ref = super.getReference(); ref.add(new StringRefAddr("dataSourceName", dataSourceName)); if (initialConnections > 0) { ref.add(new StringRefAddr("initialConnections", Integer.toString(initialConnections))); } if (maxConnections > 0) { ref.add(new StringRefAddr("maxConnections", Integer.toString(maxConnections))); } return ref; }
/** * Generates a {@link DriverManager} URL from the other properties supplied. * * @return {@link DriverManager} URL from the other properties supplied */ public String getURL() { return getUrl(); }
public void initializeFrom(BaseDataSource source) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); source.writeBaseObject(oos); oos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); readBaseObject(ois); }
/** * Gets a connection to the PostgreSQL database. The database is identified by the DataSource * properties serverName, databaseName, and portNumber. The user to connect as is identified by * the arguments user and password, which override the DataSource properties by the same name. * * @param user user * @param password password * @return A valid database connection. * @throws SQLException Occurs when the database connection cannot be established. */ public Connection getConnection(String user, String password) throws SQLException { try { Connection con = DriverManager.getConnection(getUrl(), user, password); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}", new Object[]{getDescription(), user, getUrl()}); } return con; } catch (SQLException e) { LOGGER.log(Level.FINE, "Failed to create a {0} for {1} at {2}: {3}", new Object[]{getDescription(), user, getUrl(), e}); throw e; } }
private void configureBaseDataSource(BaseDataSource ds, Properties props) throws SQLException { if (props.containsKey(JDBC_URL)) { ds.setUrl(props.getProperty(JDBC_URL)); } if (props.containsKey(JDBC_SERVER_NAME)) { ds.setServerName(props.getProperty(JDBC_SERVER_NAME)); } if (props.containsKey(JDBC_PORT_NUMBER)) { ds.setPortNumber(Integer.parseInt(props.getProperty(JDBC_PORT_NUMBER))); } if (props.containsKey(JDBC_DATABASE_NAME)) { ds.setDatabaseName(props.getProperty(JDBC_DATABASE_NAME)); } if (props.containsKey(JDBC_USER)) { ds.setUser(props.getProperty(JDBC_USER)); } if (props.containsKey(JDBC_PASSWORD)) { ds.setPassword(props.getProperty(JDBC_PASSWORD)); } for (Entry<Object, Object> entry : props.entrySet()) { ds.setProperty((String) entry.getKey(), (String) entry.getValue()); } }
protected Object loadBaseDataSource(BaseDataSource ds, Reference ref) { ds.setDatabaseName(getProperty(ref, "databaseName")); ds.setPassword(getProperty(ref, "password")); String port = getProperty(ref, "portNumber"); if (port != null) { ds.setPortNumber(Integer.parseInt(port)); } ds.setServerName(getProperty(ref, "serverName")); ds.setUser(getProperty(ref, "user")); String prepareThreshold = getProperty(ref, "prepareThreshold"); if (prepareThreshold != null) ds.setPrepareThreshold(Integer.parseInt(prepareThreshold)); return ds; }
/** * Ensures the DataSource properties are not changed after the DataSource has been used. * * @throws IllegalStateException The User cannot be changed after the DataSource has been used. */ public void setUser(String user) { if (initialized) { throw new IllegalStateException( "Cannot set Data Source properties after DataSource has been used"); } super.setUser(user); }
/** * Ensures the DataSource properties are not changed after the DataSource has been used. * * @throws IllegalStateException The Password cannot be changed after the DataSource has been * used. */ public void setPassword(String password) { if (initialized) { throw new IllegalStateException( "Cannot set Data Source properties after DataSource has been used"); } super.setPassword(password); }
/** * Ensures the DataSource properties are not changed after the DataSource has been used. * * @throws IllegalStateException The Database Name cannot be changed after the DataSource has been * used. */ public void setDatabaseName(String databaseName) { if (initialized) { throw new IllegalStateException( "Cannot set Data Source properties after DataSource has been used"); } super.setDatabaseName(databaseName); }
/** * Ensures the DataSource properties are not changed after the DataSource has been used. * * @throws IllegalStateException The Port Number cannot be changed after the DataSource has been * used. */ public void setPortNumber(int portNumber) { if (initialized) { throw new IllegalStateException( "Cannot set Data Source properties after DataSource has been used"); } super.setPortNumber(portNumber); }
/** * Ensures the DataSource properties are not changed after the DataSource has been used. * * @throws IllegalStateException The Server Name cannot be changed after the DataSource has been * used. */ public void setServerName(String serverName) { if (initialized) { throw new IllegalStateException( "Cannot set Data Source properties after DataSource has been used"); } super.setServerName(serverName); }
public Reference getReference() throws NamingException Reference ref = createReference(); ref.add(new StringRefAddr("serverName", serverName)); if (portNumber != 0)
protected Object loadBaseDataSource(BaseDataSource ds, Reference ref) { ds.setDatabaseName(getProperty(ref, "databaseName")); ds.setPassword(getProperty(ref, "password")); String port = getProperty(ref, "portNumber"); if (port != null) { ds.setPortNumber(Integer.parseInt(port)); } ds.setServerName(getProperty(ref, "serverName")); ds.setUser(getProperty(ref, "user")); String prepareThreshold = getProperty(ref, "prepareThreshold"); if (prepareThreshold != null) ds.setPrepareThreshold(Integer.parseInt(prepareThreshold)); return ds; }
public void initializeFrom(BaseDataSource source) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); source.writeBaseObject(oos); oos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); readBaseObject(ois); }
/** * Ensures the DataSource properties are not changed after the DataSource has * been used. * * @throws java.lang.IllegalStateException * The User cannot be changed after the DataSource has been * used. */ public void setUser(String user) { if (initialized) { throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used"); } super.setUser(user); }
/** * Ensures the DataSource properties are not changed after the DataSource has * been used. * * @throws java.lang.IllegalStateException * The Password cannot be changed after the DataSource has been * used. */ public void setPassword(String password) { if (initialized) { throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used"); } super.setPassword(password); }
/** * Ensures the DataSource properties are not changed after the DataSource has * been used. * * @throws java.lang.IllegalStateException * The Database Name cannot be changed after the DataSource has been * used. */ public void setDatabaseName(String databaseName) { if (initialized) { throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used"); } super.setDatabaseName(databaseName); }
/** * Ensures the DataSource properties are not changed after the DataSource has * been used. * * @throws java.lang.IllegalStateException * The Port Number cannot be changed after the DataSource has been * used. */ public void setPortNumber(int portNumber) { if (initialized) { throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used"); } super.setPortNumber(portNumber); }
/** * Ensures the DataSource properties are not changed after the DataSource has * been used. * * @throws java.lang.IllegalStateException * The Server Name cannot be changed after the DataSource has been * used. */ public void setServerName(String serverName) { if (initialized) { throw new IllegalStateException("Cannot set Data Source properties after DataSource has been used"); } super.setServerName(serverName); }