Examples of CopyManager


Examples of org.postgresql.copy.CopyManager

            fileWriter = new BufferedWriter(new FileWriter(getExistingDataFile()), IO_BUFFER_SIZE);
            Session session = (Session) entityManager.getDelegate();
            SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory();
            ConnectionProvider cp = sfi.getConnectionProvider();
            connection = cp.getConnection();
            CopyManager copyManager = new CopyManager((BaseConnection) connection);

            if (maxResults > 0) {
                copyManager.copyOut("COPY (" + selectNativeQuery + " LIMIT " + maxResults
                    + ") TO STDOUT WITH DELIMITER '" + DELIMITER + "'", fileWriter);
            } else {
                copyManager.copyOut("COPY (" + selectNativeQuery + ") TO STDOUT WITH DELIMITER '" + DELIMITER + "'",
                    fileWriter);
            }
        } finally {
            StreamUtil.safeClose(fileWriter);
            JDBCUtil.safeClose(connection);
View Full Code Here

Examples of org.postgresql.copy.CopyManager

    throws IOException, InterruptedException {

    super.setup(context);
    conf = context.getConfiguration();
    dbConf = new DBConfiguration(conf);
    CopyManager cm = null;
    try {
      conn = dbConf.getConnection();
      cm = ((PGConnection)conn).getCopyAPI();
    } catch (ClassNotFoundException ex) {
      LOG.error("Unable to load JDBC driver class", ex);
      throw new IOException(ex);
    } catch (SQLException ex) {
      LoggingUtils.logAll(LOG, "Unable to get CopyIn", ex);
      throw new IOException(ex);
    }
    try {
      StringBuilder sql = new StringBuilder();
      sql.append("COPY ");
      sql.append(dbConf.getOutputTableName());
      sql.append(" FROM STDIN WITH (");
      sql.append(" ENCODING 'UTF-8' ");
      sql.append(", FORMAT csv ");
      sql.append(", DELIMITER ");
      sql.append("'");
      sql.append(conf.get("postgresql.input.field.delim", ","));
      sql.append("'");
      sql.append(", QUOTE ");
      sql.append("'");
      sql.append(conf.get("postgresql.input.enclosedby", "\""));
      sql.append("'");
      sql.append(", ESCAPE ");
      sql.append("'");
      sql.append(conf.get("postgresql.input.escapedby", "\""));
      sql.append("'");
      if (conf.get("postgresql.null.string") != null) {
        sql.append(", NULL ");
        sql.append("'");
        sql.append(conf.get("postgresql.null.string"));
        sql.append("'");
      }
      sql.append(")");
      LOG.debug("Starting export with copy: " + sql);
      copyin = cm.copyIn(sql.toString());
    } catch (SQLException ex) {
      LoggingUtils.logAll(LOG, "Unable to get CopyIn", ex);
      close();
      throw new IOException(ex);
    }
View Full Code Here

Examples of org.postgresql.copy.CopyManager

   * @param query the copy command to execute
   * @param reader the containing the data to be copied
   */
  private void executeCopyIn(String query, Reader reader){
    Connection con = null;
    CopyManager manager = null;
    try {
      con = this.getConnection();
      con.setAutoCommit(false);
      if(con instanceof com.jolbox.bonecp.ConnectionHandle){
        ConnectionHandle handle = (ConnectionHandle)con;
        manager = new CopyManager(
            (BaseConnection) handle.getInternalConnection());
      } else {
        manager = new CopyManager((BaseConnection) con);
      }
     
      manager.copyIn(query, reader);
      con.commit();
    } catch (Exception e) {
      if(log.isErrorEnabled()){
        log.error(query, e);
      }
View Full Code Here

Examples of org.postgresql.copy.CopyManager

    Hiber.commit();

    s.doWork(new Work() {
      public void execute(Connection con) throws SQLException {
        try {
          CopyManager cm = new CopyManager(con
              .unwrap(BaseConnection.class));
          String[][] mddArray = {
              { "gsp_group", "GSP_Group" },
              { "pc", "Profile_Class" },
              { "market_role", "Market_Role" },
              { "participant", "Market_Participant" },
              { "party", "Market_Participant_Role-party" },
              { "provider", "Market_Participant_Role-provider" },
              { "dno", "Market_Participant_Role-dno" },
              { "llfc", "Line_Loss_Factor_Class" },
              { "meter_type", "MTC_Meter_Type" },
              { "meter_payment_type", "MTC_Payment_Type" },
              { "mtc", "Meter_Timeswitch_Class" },
              { "tpr", "Time_Pattern_Regime" },
              { "clock_interval", "Clock_Interval" },
              { "ssc", "Standard_Settlement_Configuration" },
              { "measurement_requirement",
                  "Measurement_Requirement" } };
          for (String[] impArray : mddArray) {
            cm.copyIn(
                "COPY " + impArray[0]
                    + " FROM STDIN CSV HEADER",
                context.getResource(
                    "/WEB-INF/mdd/" + impArray[1] + ".csv")
                    .openStream());
View Full Code Here

Examples of org.postgresql.copy.CopyManager

        StringReader reader = new StringReader(builder.toString());
        providerAccessSpi.run(
                entityManager,
                connection -> {
                    try {
                        CopyManager copyManager = new CopyManager((BaseConnection) connectionAccessor
                                .getRawConnection(connection));
                        copyManager.copyIn("copy " + getEntityName(entityList) + "(" + fieldNames + ") from stdin",
                                reader);
                    } catch (Exception e) {
                        logger.trace("Command passed: copy {} ( {} ) from stdin {}", getEntityName(entityList),
                                fieldNames, builder);
                        throw Throwables.propagate(e);
View Full Code Here

Examples of org.postgresql.copy.CopyManager

        StringReader reader = new StringReader(builder.toString());
        providerAccessSpi.run(
                entityManager,
                connection -> {
                    try {
                        CopyManager copyManager = new CopyManager((BaseConnection) connectionAccessor
                                .getRawConnection(connection));
                        long t1 = System.currentTimeMillis();
                        copyManager.copyIn("copy " + getEntityName(entityList) + "(" + fieldNames + ") from stdin",
                                reader);
                        long elapsedTime = System.currentTimeMillis() - t1;
                        logger.debug("Wrote {} inserts in {} seconds", entityList.size(),
                                Math.round(elapsedTime / 10.0) / 100.0);
                    } catch (Exception e) {
View Full Code Here

Examples of org.postgresql.copy.CopyManager

        StringReader reader = new StringReader(builder.toString());
        providerAccessSpi.run(
                entityManager,
                connection -> {
                    try {
                        CopyManager copyManager = new CopyManager((BaseConnection) connectionAccessor
                                .getRawConnection(connection));
                        long t1 = System.currentTimeMillis();
                        copyManager.copyIn("copy " + getEntityName(entityList) + "(" + fieldNames + ") from stdin",
                                reader);
                        long elapsedTime = System.currentTimeMillis() - t1;
                        logger.debug("Wrote {} inserts in {} seconds", entityList.size(),
                                Math.round(elapsedTime / 10.0) / 100.0);
                    } catch (Exception e) {
View Full Code Here

Examples of org.postgresql.copy.CopyManager

        StringReader reader = new StringReader(builder.toString());
        providerAccessSpi.run(
                entityManager,
                connection -> {
                    try {
                        CopyManager copyManager = new CopyManager((BaseConnection) connectionAccessor
                                .getRawConnection(connection));
                        long t1 = System.currentTimeMillis();
                        copyManager.copyIn("copy " + getEntityName(entityList) + "(" + fieldNames + ") from stdin",
                                reader);
                        long elapsedTime = System.currentTimeMillis() - t1;
                        logger.debug("Wrote {} inserts in {} seconds", entityList.size(),
                                Math.round(elapsedTime / 10.0) / 100.0);
                    } catch (Exception e) {
View Full Code Here

Examples of org.postgresql.copy.CopyManager

        StringReader reader = new StringReader(builder.toString());
        providerAccessSpi.run(
                entityManager,
                connection -> {
                    try {
                        CopyManager copyManager = new CopyManager((BaseConnection) connectionAccessor
                                .getRawConnection(connection));
                        long t1 = System.currentTimeMillis();
                        copyManager.copyIn("copy " + getEntityName(entityList) + "(" + fieldNames + ") from stdin",
                                reader);
                        long elapsedTime = System.currentTimeMillis() - t1;
                        logger.debug("Wrote {} inserts in {} seconds", entityList.size(),
                                Math.round(elapsedTime / 10.0) / 100.0);
                    } catch (Exception e) {
View Full Code Here

Examples of org.postgresql.copy.CopyManager

    public <E extends Serializable> void insert(EntityManager entityManager, CopyList<E> entityList) {
        providerAccessSpi.run(
                entityManager,
                connection -> {
                    try {
                        CopyManager copyManager = new CopyManager((BaseConnection) connectionAccessor
                                .getRawConnection(connection));
                        if (entityList.size() != 0) {
                            copyManager.copyIn("copy " + getEntityName(entityList) + "(" + getFieldNames(entityList)
                                    + ") from stdin", new CopyListReader<E>(entityList));
                        }
                    } catch (Exception e) {
                        throw Throwables.propagate(e);
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.