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


Java PGConnection类代码示例

本文整理汇总了Java中org.postgresql.PGConnection的典型用法代码示例。如果您正苦于以下问题:Java PGConnection类的具体用法?Java PGConnection怎么用?Java PGConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: saveAll

import org.postgresql.PGConnection; //导入依赖的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: run

import org.postgresql.PGConnection; //导入依赖的package包/类
public void run()
{
    trysleep(2000);
    while (!done) {
        try {
            PGConnection pg = (PGConnection)getConnection();
            if (pg == null) {
                log.info("watcher: connection was null");
                trysleep(5000);
                continue;
            }
            PGNotification notifications[] = pg.getNotifications();
            if (notifications != null) {
                Set<String> changes = new HashSet<String>();
                for (PGNotification n : notifications) {
                    changes.add(n.getParameter());
                }
                Messenger.sendEvent(MT.DATABASE_NOTIFICATION, changes);
            }
        } catch (Throwable e) {
            log.log(Level.WARNING, "ConnectionWatcher exception: " + e, e);
        }

        trysleep(500);
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:27,代码来源:PostgresqlDatabase.java

示例3: createFile

import org.postgresql.PGConnection; //导入依赖的package包/类
@Override
public void createFile(JDBCSequentialFile file) throws SQLException {
   synchronized (connection) {
      try {
         connection.setAutoCommit(false);

         LargeObjectManager lobjManager = ((PGConnection) connection).getLargeObjectAPI();
         long oid = lobjManager.createLO();

         createFile.setString(1, file.getFileName());
         createFile.setString(2, file.getExtension());
         createFile.setLong(3, oid);
         createFile.executeUpdate();

         try (ResultSet keys = createFile.getGeneratedKeys()) {
            keys.next();
            file.setId(keys.getLong(1));
         }
         connection.commit();
      } catch (SQLException e) {
         connection.rollback();
         throw e;
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:PostgresSequentialSequentialFileDriver.java

示例4: writeToFile

import org.postgresql.PGConnection; //导入依赖的package包/类
@Override
public int writeToFile(JDBCSequentialFile file, byte[] data) throws SQLException {
   synchronized (connection) {
      LargeObjectManager lobjManager = ((PGConnection) connection).getLargeObjectAPI();
      LargeObject largeObject = null;

      Long oid = getOID(file);
      try {
         connection.setAutoCommit(false);
         largeObject = lobjManager.open(oid, LargeObjectManager.WRITE);
         largeObject.seek(largeObject.size());
         largeObject.write(data);
         largeObject.close();
         connection.commit();
      } catch (Exception e) {
         connection.rollback();
         throw e;
      }
      return data.length;
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:PostgresSequentialSequentialFileDriver.java

示例5: getPostGresLargeObjectSize

import org.postgresql.PGConnection; //导入依赖的package包/类
private int getPostGresLargeObjectSize(JDBCSequentialFile file) throws SQLException {
   LargeObjectManager lobjManager = ((PGConnection) connection).getLargeObjectAPI();

   int size = 0;
   Long oid = getOID(file);
   if (oid != null) {
      synchronized (connection) {
         try {
            connection.setAutoCommit(false);
            LargeObject largeObject = lobjManager.open(oid, LargeObjectManager.READ);
            size = largeObject.size();
            largeObject.close();
            connection.commit();
         } catch (SQLException e) {
            connection.rollback();
            throw e;
         }
      }
   }
   return size;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:PostgresSequentialSequentialFileDriver.java

示例6: execute

import org.postgresql.PGConnection; //导入依赖的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

示例7: mapColumnTypes

import org.postgresql.PGConnection; //导入依赖的package包/类
public static PGConnection mapColumnTypes(PGConnection pgConn)
{
  try
  {
    pgConn.addDataType("geometry", org.postgis.jts.JtsGeometry.class);
    pgConn.addDataType("box3d", org.postgis.PGbox3d.class);
    pgConn.addDataType("box2d", org.postgis.PGbox2d.class);
  }
  catch (SQLException e)
  {
    String errMsg = e.getMessage();
    throw new ProgrammingErrorException(errMsg, e);
  }

  return pgConn;
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:17,代码来源:PostGIS.java

示例8: load

import org.postgresql.PGConnection; //导入依赖的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

示例9: do_copy

import org.postgresql.PGConnection; //导入依赖的package包/类
private void do_copy( PGBulkLoaderMeta meta, boolean wait ) throws KettleException {
  Runtime rt = Runtime.getRuntime();

  data.db = new Database( this, meta.getDatabaseMeta() );
  String copyCmd = getCopyCommand( );
  try {
    connect();

    processTruncate();

    logBasic( "Launching command: " + copyCmd );
    pgCopyOut = new PGCopyOutputStream( (PGConnection) data.db.getConnection(), copyCmd );

  } catch ( Exception ex ) {
    throw new KettleException( "Error while preparing the COPY " + copyCmd, ex );
  }
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:18,代码来源:PGBulkLoader.java

示例10: getConnection

import org.postgresql.PGConnection; //导入依赖的package包/类
/**** XAConnection interface ****/

    public Connection getConnection() throws SQLException
    {
        if (logger.logDebug())
            debug("PGXAConnection.getConnection called");

        Connection conn = super.getConnection();

        // When we're outside an XA transaction, autocommit
        // is supposed to be true, per usual JDBC convention.
        // When an XA transaction is in progress, it should be
        // false.
        if(state == STATE_IDLE)
            conn.setAutoCommit(true);

        /*
         * Wrap the connection in a proxy to forbid application from
         * fiddling with transaction state directly during an XA transaction
         */
        ConnectionHandler handler = new ConnectionHandler(conn);
        return (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler);
    }
 
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:24,代码来源:PGXAConnection.java

示例11: receiveChangesOccursBeforStartReplication

import org.postgresql.PGConnection; //导入依赖的package包/类
public void receiveChangesOccursBeforStartReplication() throws Exception {
    PGConnection pgConnection = (PGConnection) replicationConnection;

    LogSequenceNumber lsn = getCurrentLSN();

    Statement st = connection.createStatement();
    st.execute("insert into test_logical_table(name) values('previous value')");
    st.close();

    PGReplicationStream stream =
            pgConnection
                    .getReplicationAPI()
                    .replicationStream()
                    .logical()
                    .withSlotName(SLOT_NAME)
                    .withStartPosition(lsn)
                    .withSlotOption("include-xids", true)
                    .withSlotOption("skip-empty-xacts", true)
                    .withStatusInterval(20, TimeUnit.SECONDS)
                    .start();
    ByteBuffer buffer;
    while(true)
    {
        buffer = stream.readPending();
        if (buffer == null) {
            TimeUnit.MILLISECONDS.sleep(10L);
            continue;
        }

        System.out.println( toString(buffer));
        //feedback
        stream.setAppliedLSN(stream.getLastReceiveLSN());
        stream.setFlushedLSN(stream.getLastReceiveLSN());
    }

}
 
开发者ID:davecramer,项目名称:LogicalDecode,代码行数:37,代码来源:App.java

示例12: processNotifications

import org.postgresql.PGConnection; //导入依赖的package包/类
/**
 * Processes notifications which may have been issued on channels that jpgAgent is listening on.
 *
 * @return
 */
private static void processNotifications() throws Exception
{
    try (final Statement statement = Database.INSTANCE.getListenerConnection().createStatement();
         final ResultSet result_set = statement.executeQuery(Config.INSTANCE.sql.getProperty("sql.jpgagent.dummy")))
    {
        Config.INSTANCE.logger.debug("Kill jobs begin.");
        final PGConnection pg_connection = Database.INSTANCE.getListenerConnection().unwrap(PGConnection.class);
        final PGNotification notifications[] = pg_connection.getNotifications();

        if (null != notifications)
        {
            for (PGNotification notification : notifications)
            {
                if (notification.getName().equals("jpgagent_kill_job"))
                {
                    int job_id = Integer.valueOf(notification.getParameter());
                    if (job_future_map.containsKey(job_id))
                    {
                        Config.INSTANCE.logger.info("Killing job_id: {}.", job_id);
                        job_future_map.get(job_id).cancel(true);
                    }
                    else
                    {
                        Config.INSTANCE.logger.info("Kill request for job_id: {} was submitted, but the job was not running.", job_id);
                    }
                }
            }
        }
    }
}
 
开发者ID:GoSimpleLLC,项目名称:jpgAgent,代码行数:36,代码来源:JPGAgent.java

示例13: write

import org.postgresql.PGConnection; //导入依赖的package包/类
public void write(List<TEntity> entities) throws Exception {
    // Obtain a new Connection and execute it in a try with resources block, so it gets closed properly:
    try(Connection connection = connectionFactory.invoke()) {
        // Now get the underlying PGConnection for the COPY API wrapping:
        final PGConnection pgConnection = PostgreSqlUtils.getPGConnection(connection);
        // And finally save all entities by using the COPY API:
        client.saveAll(pgConnection, entities.stream());
    }
}
 
开发者ID:bytefish,项目名称:PgBulkInsert,代码行数:10,代码来源:BulkWriteHandler.java

示例14: getPGConnection

import org.postgresql.PGConnection; //导入依赖的package包/类
public static PGConnection getPGConnection(final Connection connection) throws SQLException {
    OutParameter<PGConnection> result = new OutParameter<>();
    if(!tryGetPGConnection(connection, result)) {
        throw new PgConnectionException("Could not obtain a PGConnection");
    }
    return result.get();
}
 
开发者ID:bytefish,项目名称:PgBulkInsert,代码行数:8,代码来源:PostgreSqlUtils.java

示例15: tryGetPGConnection

import org.postgresql.PGConnection; //导入依赖的package包/类
public static boolean tryGetPGConnection(final Connection connection, OutParameter<PGConnection> result) throws SQLException {
    if(tryCastConnection(connection, result)) {
        return true;
    }
    if(tryUnwrapConnection(connection, result)) {
        return true;
    }
    return false;
}
 
开发者ID:bytefish,项目名称:PgBulkInsert,代码行数:10,代码来源:PostgreSqlUtils.java


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