/** * Creates a new DbDataUtil instance using the specified Connection and the Schema * from the ConnectionInfo * @param connection Connection instance * @param ConnectionInfo to get the Schema to use * @Deprecated Use constructor with EntityManager */ public DbDataUtil(JuConnUtil connUtil, ConnectionInfo connectionInfo) { this(connUtil, connectionInfo.getSchema()); }
/** * Checks if the ConnectionInfo with the specified name is available. * @param name Name of the ConnectionInfo * @return True if the ConnectionInfo exists, false otherwise */ public boolean hasConnectionInfo(String name) { for (ConnectionInfo connectionInfo : getAvailableConnectionInfos()) { if (connectionInfo.getName().equals(name)) return true; } return false; } }
public void setConnectionInfo(ConnectionInfo connectionInfo) { this.setUrl(connectionInfo.getConnectionString()); this.setUsername(connectionInfo.getUserName()); this.setPassword(connectionInfo.getPassword()); this.connectionInfo = connectionInfo; }
if (connectionInfo.getConnectionString().startsWith("jdbc:derby:")) { className = "org.apache.derby.jdbc.EmbeddedXADataSource"; } else if (connectionInfo.getConnectionString().startsWith("jdbc:h2:")) { className = "org.h2.jdbcx.JdbcDataSource"; } else if (connectionInfo.getConnectionString().startsWith("jdbc:hsqldb:")) { className = "org.hsqldb.jdbcDriver"; } else if (connectionInfo.getConnectionString().startsWith("jdbc:mysql:")) { className = "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"; } else if (connectionInfo.getConnectionString().startsWith("jdbc:oracle:")) { className = "oracle.jdbc.xa.client.OracleXADataSource"; String dbName = connectionInfo.getConnectionString(); if (dbName.startsWith("jdbc:derby:")) { dbName = dbName.substring("jdbc:derby:".length()); props.put("URL", connectionInfo.getConnectionString()); if (StringUtils.isNotEmpty(connectionInfo.getUserName())) { props.put("user", connectionInfo.getUserName()); if (StringUtils.isNotEmpty(connectionInfo.getPassword())) { props.put("password", connectionInfo.getPassword()); this.setUniqueName(connectionInfo.getName());
@Override public String getUserName() { return this.getConnectionInfo().getUserName(); }
@Override public Image getImage() { return this.getConnectionInfo().getImage(); }
@Override public Icon getIcon() { return this.getConnectionInfo().getIcon(); }
@Override public String getConnectionString() { return this.getConnectionInfo().getConnectionString(); }
@Override public String getPassword() { return this.getConnectionInfo().getPassword(); }
@Override public String toString() { return JuStringUtils.toString(DbPersistenceStorage.class, "connectionName", this.connectionInfo.getName()); } }
@Override public String getSchema() { return this.getConnectionInfo().getSchema(); }
@Override public String getName() { return this.getConnectionInfo().getName(); }
@Override public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException { ResultSet rs = dbmd.getTables(connectionInfo.getSchema(), null, null, new String[]{"TABLE"}); List<String> tableNames = new ArrayList<>(); while (rs.next()) { String tableName = rs.getString("TABLE_NAME").toUpperCase(); // We check if the TableName already exists in the list as // Oracle seems to return the same table names multiple times on some // Schemas... if (!tableNames.contains(tableName)) { tableNames.add(tableName); } } rs.close(); Collections.sort(tableNames); return tableNames; } });
@Override public String toString() { return JuStringUtils.toString(this, "connectionInfoName", this.connectionInfo == null ? null : ObjectUtils.toString(this.connectionInfo.getName())); } }
@Override public int compareTo(ConnectionInfo o) { return ObjectUtils.compare(this.getName(), o == null ? null : o.getName()); }
/** * Sets the ConnectionInfo to be used by its name. If it doesn't exist, a * runtime exception is thrown * <p> * If we set the ConnectionInfo within a transaction, it will be applied to the next * Transaction that is started - or to any database interaction without a transaction. * @param connectionInfoName New ConnectionInfo name */ public void setConnectionInfoByName(String connectionInfoName) { for (ConnectionInfo connectionInfo : availableConnectionInfos) { if (connectionInfoName.equals(connectionInfo.getName())) { setConnectionInfo(connectionInfo); return; } } throw new JuDbException("No ConnectionInfo available by the name " + connectionInfoName); }
@Override public int compareTo(ConnectionInfo o) { return ObjectUtils.compare(this.getName(), o == null ? null : o.getName()); }