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


Java CopyManager.copyIn方法代码示例

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


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

示例1: saveAll

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
public void saveAll(PGConnection connection, Stream<TEntity> entities) throws SQLException {

        CopyManager cpManager = connection.getCopyAPI();
        CopyIn copyIn = cpManager.copyIn(getCopyCommand());

        try (PgBinaryWriter bw = new PgBinaryWriter()) {

            // Wrap the CopyOutputStream in our own Writer:
            bw.open(new PGCopyOutputStream(copyIn));

            // Insert Each Column:
            entities.forEach(entity -> this.saveEntity(bw, entity));
        }
    }
 
开发者ID:bytefish,项目名称:PgBulkInsert,代码行数:15,代码来源:PgBulkInsert.java

示例2: call

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
@Override
public Long call() throws SQLException, IOException {
  try {
    CopyManager mgr = new CopyManager((BaseConnection) conn);
    return mgr.copyIn(sql, pipeIn);
  } finally {
    try {
      pipeIn.close();
    } catch (IOException ignore) {
    }
  }
}
 
开发者ID:HashDataInc,项目名称:bireme,代码行数:13,代码来源:ChangeLoader.java

示例3: 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();
    fileReader = new FileReader(copyFile);
    copyManager.copyIn(theSql, fileReader);
}
 
开发者ID:manniwood,项目名称:cl4pg,代码行数:12,代码来源:CopyFileIn.java

示例4: load

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
/**
 *
 * @param con open postgres! connection
 * @param folder the classpath folder to scan for table data files
 * @param truncate if true first truncates the tables
 * @throws Exception
 */
public static void load(Connection con, String folder, boolean truncate) throws Exception {
    con.setAutoCommit(false);
    LOG.info("Load data from " + folder);
    CopyManager copy = ((PGConnection)con).getCopyAPI();
    List<String> tables = listTables(folder);
    if (truncate) {
        truncate(con, tables);
    }
    con.commit();

    for (String table : tables) {
        LOG.debug("Load table " + table);
        InputStreamWithoutHeader in = new InputStreamWithoutHeader(FileUtils.classpathStream(folder + "/" + table + FILE_SUFFIX), '\t', '\n');
        String header = HEADER_JOINER.join(in.header);
        copy.copyIn("COPY " + table + "(" + header + ") FROM STDOUT WITH NULL '\\N'", in);
    }
    con.commit();
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:26,代码来源:DbLoader.java

示例5: metadataToPostgres

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
private void metadataToPostgres() {
	try {
		CopyManager cpManager = new CopyManager((BaseConnection) conn);
		st.executeUpdate("TRUNCATE TABLE metadata;");
		String metaFile = this.dataDirectory + File.separator + this.metadataFile;
		this.logger.log(Level.INFO, "Importing metadata from " + metaFile);
		Long n = cpManager.copyIn("COPY metadata FROM STDIN WITH CSV", new FileReader(metaFile));
		this.logger.log(Level.INFO, n + " metadata imported");
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(1);
	}
}
 
开发者ID:tudarmstadt-lt,项目名称:newsleak-frontend,代码行数:14,代码来源:InformationExtraction2Postgres.java

示例6: testCopy

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
public static void testCopy() throws ClassNotFoundException, SQLException, IOException {
	Long start = System.nanoTime();
	Class.forName("org.postgresql.Driver");
	Connection conn = DriverManager.getConnection("jdbc:postgresql://192.168.100.8:5866/sqoop", "hive", "highgo");
	CopyManager cm = new CopyManager((BaseConnection) conn);
	Reader reader = new FileReader(new File("result"));
	cm.copyIn("copy testnumberictypes from STDIN", reader);
	Long end = System.nanoTime();
	System.out.println((end - start) / Math.pow(10, 9));
}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:11,代码来源:TestPgCopyManager.java

示例7: appendDataFromFile

import org.postgresql.copy.CopyManager; //导入方法依赖的package包/类
@Override
public void appendDataFromFile(String server, String dbName, String tableName, File file, boolean headerRow, boolean useColumnNames) throws 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);


	//
	// Define the copy operation
	//

	String sql = "COPY "+tableName;
	if (useColumnNames) {
		String names[];
		
		if (headerRow) {
			names = getColumnNames(server, dbName, tableName, file, true);
		}
		else {
			names = this.getColumnNamesFromDatabase(server, dbName, tableName);
		}
		sql += " ("+GeneralUtils.implode(",", names) + ")";
	}
	sql +=  " FROM STDIN WITH CSV ENCODING 'UTF8'";
	if ( headerRow ) {
		sql +=  " HEADER";
	}
	
	//
	// Create a reader for getting the data from the file and get
	// the Postgres DB connection we'll use for writing the output
	//
	BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(file), "UTF8"));

	Connection conn = qr.getConnection();

	try {
		//
		// Obtain CopyManager from the Postgres Connection
		//
		PGConnection pg_conn = (PGConnection)conn;
		CopyManager copyManager = pg_conn.getCopyAPI();	
		//
		// Copy in the data
		//
		copyManager.copyIn(sql, reader);
		
	}finally {
		//
		// Close writer
		//
		reader.close();

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


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