selectBuf.append(columns).append(" from ").append(tableName).append(";");
selectBuf.append(columnsFromAttributesAsArray(attributes, _quoteSource).componentsJoinedByString(", ")).append(" from "); if (_quoteSource) { selectBuf.append("\"" + tableName + "\""); } else { selectBuf.append(tableName); } EOQualifier qualifier = entity.restrictingQualifier(); if (qualifier != null) { EOAdaptor adaptor = EOAdaptor.adaptorWithName("JDBC"); adaptor.setConnectionDictionary(sourceDictionary); EOSQLExpressionFactory factory = adaptor.expressionFactory(); EOSQLExpression sqlExpression = factory.createExpression(entity); String sqlString = EOQualifierSQLGeneration.Support._sqlStringForSQLExpression(qualifier, sqlExpression); selectBuf.append(" where ").append(sqlString); } selectBuf.append(";");
		protected void copyEntity(EOEntity entity) throws SQLException {			EOAttribute[] attributes = attributesArray(entity.attributes());			String tableName = entity.externalName();			String[] columnNames = columnsFromAttributes(attributes, true);			String[] columnNamesWithoutQuotes = columnsFromAttributes(attributes, false);			String columns = columnsFromAttributesAsArray(attributes, true).componentsJoinedByString(", ");			// build the select statement, this selects -all- rows			StringBuffer selectBuf = new StringBuffer();			selectBuf.append("select ");			selectBuf.append(columns).append(" from ").append(tableName).append(";");			String sql = selectBuf.toString();			Statement stmt = source.createStatement();			StringBuffer insertBuf = new StringBuffer();			insertBuf.append("insert into ").append("" + tableName + "").append(" (").append(columns).append(") values (");			for (int i = columnNames.length; i-- > 0;) {				insertBuf.append("?");				if (i > 0) {					insertBuf.append(", ");				}			}			insertBuf.append(");");			String insertSql = insertBuf.toString();			PreparedStatement upps = dest.prepareStatement(insertSql);			try {				ResultSet rows = stmt.executeQuery(sql);				// transfer each row by first setting the values				int rowsCount = 0;				while (rows.next()) {					rowsCount++;					if (rows.getRow() % 1000 == 0) {						log.info("table " + tableName + ", inserted " + rows.getRow() + " rows");					}					NSMutableSet tempfilesToDelete = new NSMutableSet();					// call upps.setInt, upps.setBinaryStream, ...					for (int i = 0; i < columnNamesWithoutQuotes.length; i++) {						// first we need to get the type						String columnName = columnNamesWithoutQuotes[i];						int type = rows.getMetaData().getColumnType(i + 1);						Object o = rows.getObject(columnName);						if (log.isDebugEnabled()) {							if (o != null) {								log.info("column=" + columnName + ", value class=" + o.getClass().getName() + ", value=" + o);							}							else {								log.info("column=" + columnName + ", value class unknown, value is null");							}						}						if (o instanceof Blob) {							Blob b = (Blob) o;							InputStream bis = b.getBinaryStream();							// stream this to a file, we need the length...							File tempFile = null;							try {								tempFile = File.createTempFile("TempJDBC", ".blob");								ERXFileUtilities.writeInputStreamToFile(bis, tempFile);							}							catch (IOException e5) {								log.error("could not create tempFile for row " + rows.getRow() + " and column " + columnName + ", setting column value to null!");								upps.setNull(i + 1, type);								if (tempFile != null)									if (!tempFile.delete())										tempFile.delete();								continue;							}							FileInputStream fis;							try {								fis = new FileInputStream(tempFile);							}							catch (FileNotFoundException e6) {								log.error("could not create FileInputStream from tempFile for row " + rows.getRow() + " and column " + columnName + ", setting column value to null!");								upps.setNull(i + 1, type);								if (tempFile != null)									if (!tempFile.delete())										tempFile.delete();								continue;							}							upps.setBinaryStream(i + 1, fis, (int) tempFile.length());							tempfilesToDelete.addObject(tempFile);						}						else if (o != null) {							upps.setObject(i + 1, o);						}						else {							upps.setNull(i + 1, type);						}					}					upps.executeUpdate();					upps.clearParameters();					for (Enumeration e = tempfilesToDelete.objectEnumerator(); e.hasMoreElements();) {						File f = (File) e.nextElement();						if (!f.delete())							f.delete();					}					if (rows.getRow() % 1000 == 0) {						log.info("committing at count=" + rowsCount);						dest.commit();						log.info("committing done");					}				}				log.info("table " + tableName + ", inserted " + rowsCount + " rows");				rows.close();			}			catch (SQLException e2) {				log.error("could not get next from resultset", e2);			}		}