本文整理汇总了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));
}
}
示例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) {
}
}
}
示例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);
}
示例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();
}
示例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);
}
}
示例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));
}
示例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();
}
}