当前位置: 首页>>代码示例>>Java>>正文


Java CopyManager.copyOut方法代码示例

本文整理汇总了Java中org.postgresql.copy.CopyManager.copyOut方法的典型用法代码示例。如果您正苦于以下问题:Java CopyManager.copyOut方法的具体用法?Java CopyManager.copyOut怎么用?Java CopyManager.copyOut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.postgresql.copy.CopyManager的用法示例。


在下文中一共展示了CopyManager.copyOut方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
@Override
public void execute(Connection connection,
                    TypeConverterStore converterStore,
                    SqlCache sqlCache,
                    DataSourceAdapter dataSourceAdapter) throws Exception {
    String theSql = sql == null ? sqlCache.get(filename) : sql;
    PGConnection pgConn = dataSourceAdapter.unwrapPgConnection(connection);
    CopyManager copyManager = (pgConn).getCopyAPI();
    fileWriter = new FileWriter(copyFile);
    copyManager.copyOut(theSql, fileWriter);
}
 
开发者ID:manniwood,项目名称:cl4pg,代码行数:12,代码来源:CopyFileOut.java

示例2: load

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
/**
 * Loads known usages from checklistbank backbone.
 */
public IdLookupImpl load(ClbConfiguration clb, boolean includeDeleted) throws SQLException, IOException {
  try (Connection c = clb.connect()) {
    final CopyManager cm = new CopyManager((BaseConnection) c);
    final String delClause = includeDeleted ? "" : " AND deleted is null";

    // first read bulk of regular usages - we add pro parte usage later
    LOG.info("Reading existing nub usages {}from postgres ...", includeDeleted ? "incl. deleted " : "");
    try (Writer writer = new UsageWriter()) {
      cm.copyOut("COPY ("
          + "SELECT u.id, coalesce(NULLIF(trim(n.canonical_name), ''), n.scientific_name), n.authorship, n.year, u.rank, u.kingdom_fk, deleted is not null"
          + " FROM name_usage u join name n ON name_fk=n.id"
          + " WHERE dataset_key = '" + Constants.NUB_DATASET_KEY + "'" + delClause + " AND pp_synonym_fk is null)"
          + " TO STDOUT WITH NULL ''", writer);
      LOG.info("Added {} nub usages into id lookup", usages.size());
    }
    final int uCount = usages.size();

    // now load pro parte keys separately saving us from doing complex aggregations
    LOG.info("Reading existing pro parte nub usages {}from postgres ...", includeDeleted ? "incl. deleted " : "");
    try (Writer writer = new ProParteUsageWriter()) {
      cm.copyOut("COPY ("
          + "SELECT u.id, u.parent_fk, u.pp_synonym_fk, coalesce(NULLIF(trim(n.canonical_name), ''), n.scientific_name), n.authorship, n.year, u.rank, u.kingdom_fk, deleted is not null"
          + " FROM name_usage u join name n ON name_fk=n.id"
          + " WHERE dataset_key = '" + Constants.NUB_DATASET_KEY + "'" + delClause + " AND pp_synonym_fk is not null"
          + " ORDER BY pp_synonym_fk)"
          + " TO STDOUT WITH NULL ''", writer);
      LOG.info("Added {} pro parte usages into id lookup", usages.size() - uCount);
    }
    LOG.info("Loaded existing nub with {} usages and max key {} into id lookup", usages.size(), keyMax);
  }
  return this;
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:36,代码来源:IdLookupImpl.java

示例3: initNeo

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
@Override
public void initNeo(NeoUsageWriter writer) throws Exception {
  try (BaseConnection c = (BaseConnection) clb.connect()) {
    final CopyManager cm = new CopyManager(c);
    cm.copyOut("COPY ("
        + "SELECT u.id, u.parent_fk, u.basionym_fk, u.rank,"
        + " coalesce(u.status, CASE WHEN (u.is_synonym) THEN 'SYNONYM'::taxonomic_status ELSE 'ACCEPTED'::taxonomic_status END),"
        + " u.nom_status, n.scientific_name, c.citation"
        + " FROM name_usage u JOIN name n ON u.name_fk=n.id LEFT JOIN citation c ON u.name_published_in_fk=c.id"
        + " WHERE u.dataset_key = '" + key + "')"
        + " TO STDOUT WITH NULL ''", writer);
  }
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:14,代码来源:ClbSource.java

示例4: exportData

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
/**
 * Executes a COPY operation and reads the output stream to a file
 * @param dbName
 * @param sql
 * @param file
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws SQLException
 * @throws Exception
 */
private File exportData(String server, String dbName, String sql, File file) throws IOException, ClassNotFoundException, SQLException, Exception{
	//
	// Get DBUtils instance for the specified database
	//
	//ORDSPostgresDBUtils dbUtils = new ORDSPostgresDBUtils(server, dbName, user, password);

	//
	// Get QueryRunner instance for the specified database
	//
	QueryRunner qr = new QueryRunner(server, dbName);

	//
	// Create a writer for outputting the CSV to the file, and get
	// the Postgres DB connection we'll use for reading the input from
	//
	BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(file), "UTF8"));
	Connection conn = qr.getConnection();

	try {
		//
		// Obtain CopyManager from the Postgres Connection
		//
		PGConnection pg_conn = (PGConnection)conn;
		CopyManager copyManager = pg_conn.getCopyAPI();

		//
		// Copy out the data to the writer
		//
		copyManager.copyOut(sql, writer);
	} catch (Exception e) {
		file.deleteOnExit();
		throw new Exception("Error exporting table", e);
	} finally {
		//
		// Close writer
		//
		writer.close();

		//
		// Close DB connection
		//
		conn.close();
	}
	return file;
}
 
开发者ID:ox-it,项目名称:ords-database-api,代码行数:57,代码来源:PostgresCsvServiceImpl.java

示例5: testCopy100RecordsIntoFile

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
@Test
@Ignore("not used right now in read code")
public void testCopy100RecordsIntoFile() throws Exception {
    System.out.println("Starting");

    int a = 0;

    long start = System.currentTimeMillis();
    try (Connection connection = dbManager.getConnection();
         PreparedStatement ps = connection.prepareStatement(ReportingDBDao.insertMinute)) {

        String userName = "[email protected]";
        long minute = (System.currentTimeMillis() / AverageAggregatorProcessor.MINUTE) * AverageAggregatorProcessor.MINUTE;

        for (int i = 0; i < 100; i++) {
            ReportingDBDao.prepareReportingInsert(ps, userName, 1, 0, (byte) 0, 'v', minute, (double) i);
            ps.addBatch();
            minute += AverageAggregatorProcessor.MINUTE;
            a++;
        }

        ps.executeBatch();
        connection.commit();
    }

    System.out.println("Finished : " + (System.currentTimeMillis() - start)  + " millis. Executed : " + a);


    try (Connection connection = dbManager.getConnection();
         Writer gzipWriter = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(new File("/home/doom369/output.csv.gz"))), "UTF-8")) {

        CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));


        String selectQuery = "select pintype || pin, ts, value from reporting_average_minute where project_id = 1 and email = '[email protected]'";
        long res = copyManager.copyOut("COPY (" + selectQuery + " ) TO STDOUT WITH (FORMAT CSV)", gzipWriter);
        System.out.println(res);
    }


}
 
开发者ID:blynkkk,项目名称:blynk-server,代码行数:42,代码来源:DBManagerTest.java

示例6: dumpTableInformation

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
/**
 * Uses the given {@link Connection connection} to COPY the table information from the table given
 * as table name to the directory given as testDataDirectory.
 *
 * @param connection The connection over which to execute the COPY from the database.
 * @param testDataDirectory The test data directory where the result of the COPY is stored.
 * @param tableName The name of the table which is currently dumped from the database.
 *
 * @throws SQLException if the COPY command on the SQL server fails.
 * @throws IOException if the dump result could not be written successfully.
 */
private static void dumpTableInformation(
    final Connection connection, final File testDataDirectory, final String tableName)
        throws SQLException, IOException {
  final CopyManager manager = new CopyManager((BaseConnection) connection);
  try (FileWriter fw = new FileWriter(new File(testDataDirectory, tableName + ".sql"))) {
    manager.copyOut("COPY " + tableName + " TO STDOUT", fw);
  } catch (final IOException exception) {
    CUtilityFunctions.logException(exception);
  } 
}
 
开发者ID:google,项目名称:binnavi,代码行数:22,代码来源:IntegrationTestSetup.java


注:本文中的org.postgresql.copy.CopyManager.copyOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。