问:
Apache Beam: Unable to find registrar for gs
Beam is using both Google's auto/value and auto/service tools.

I want to run a pipeline with Dataflow runner and data is stored on Google Cloud Storage.

I've added a dependencies:

```<code><dependency>
    <groupId>org.apache.beam</groupId>
    <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
    <version>2.0.0</version>
</dependency>

<dependency>
    <groupId>org.apache.beam</groupId>
    <artifactId>beam-sdks-java-extensions-google-cloud-platform-core</artifactId>
    <version>2.0.0</version>
</dependency>
</code>```

I'm able to start the pipeline from the IntelliJ. But when the jar is compiled through a mvn package and run with java -jar it throws an error:

```<code>java.lang.IllegalStateException: Unable to find registrar for gs
</code>```

The fatjar is package with maven-assembly-plugin. GcsFileSystemRegistrar class is in the jar.

答:
The issue is in the way that you are building your fatjar. The maven-assembly-plugin is not handling files associated with ServiceLoader correctly. ServiceLoader relies on entries being listed within META-INF/services/org.apache.beam.sdk.io.FileSystemRegistrar for each implementation so that Java knows how to find them.

The contents of the META-INF/services/org.apache.beam.sdk.io.FileSystemRegistrar in your fatjar is likely only:

```<code>org.apache.beam.sdk.io.LocalFileSystemRegistrar
</code>```

You need to have it list (and any other implementations that you want):

```<code>org.apache.beam.sdk.io.LocalFileSystemRegistrar
org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystemRegistrar
</code>```

Your best bet is to use a tool which understands these ServiceLoader requirements like the maven-shade-plugin when configured to use the ServicesResourceTransformer to build your fatjar.

Body:
Beam is using both Google's auto/value and auto/service tools.

I want to run a pipeline with Dataflow runner and data is stored on Google Cloud Storage.

I've added a dependencies:

<dependency>
    <groupId>org.apache.beam</groupId>
    <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
    <version>2.0.0</version>
</dependency>

<dependency>
    <groupId>org.apache.beam</groupId>
    <artifactId>beam-sdks-java-extensions-google-cloud-platform-core</artifactId>
    <version>2.0.0</version>
</dependency>

I'm able to start the pipeline from the IntelliJ. But when the jar is compiled through a mvn package and run with java -jar it throws an error:

java.lang.IllegalStateException: Unable to find registrar for gs

The fatjar is package with maven-assembly-plugin. GcsFileSystemRegistrar class is in the jar.

Body:
The issue is in the way that you are building your fatjar. The maven-assembly-plugin is not handling files associated with ServiceLoader correctly. ServiceLoader relies on entries being listed within META-INF/services/org.apache.beam.sdk.io.FileSystemRegistrar for each implementation so that Java knows how to find them.

The contents of the META-INF/services/org.apache.beam.sdk.io.FileSystemRegistrar in your fatjar is likely only:

org.apache.beam.sdk.io.LocalFileSystemRegistrar

You need to have it list (and any other implementations that you want):

org.apache.beam.sdk.io.LocalFileSystemRegistrar
org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystemRegistrar

Your best bet is to use a tool which understands these ServiceLoader requirements like the maven-shade-plugin when configured to use the ServicesResourceTransformer to build your fatjar.


来源: stackexchange

答: This looks like a problem with assembly strategy, you should accumulate/merge the services for org.apache.beam.sdk.io.FileSystemRegistrar. More on similar problem here.

ContentLicense: CC BY-SA 3.0

Title: Apache Beam: Unable to find registrar for gs


问:
JDBC Spring Mockito
I want to test this method (getDetails) is part of my DaoImpl, but I do not know how to do it. I know that I have to test the database mocking it with the JDBC template:

```<code> public List<DataLoadDetail> getDetails(int fileId, String templateType, String status, int start, int end) {

    List<DataLoadDetail> list = new ArrayList<DataLoadDetail>();
    StringBuffer sql = new StringBuffer();

    sql.append("SELECT * FROM ( ")
        .append("SELECT ROW_NUMBER() OVER(ORDER BY TB_DETAIL.UPLOADITEM_SEQ_NR ASC) AS RowNum, ")
        .append("TB_DETAIL.UPLOAD_ID, TB_DETAIL.UPLOADITEM_SEQ_NR, TB_DETAIL.UPLOADITEM_ACTION_CD, ")
        .append("TB_DETAIL.UPLOADITEM_INSERT_DT, TB_DETAIL.UPLOADITEM_UPDATE_DT, TB_DETAIL.UPLOADITEM_STATUS_CD, ")
        .append("TB_DETAIL.UPLOADITEM_PAYLOAD, TB_DETAIL.UPLOADITEM_RESPONSE, TB_MESSAGE.DESCRIPTION ")
        .append("FROM DL_DETAIL TB_DETAIL LEFT JOIN DL_MESSAGE TB_MESSAGE ")
        .append("ON TB_DETAIL.UPLOAD_ID = TB_MESSAGE.UPLOAD_ID ")
        .append("AND TB_DETAIL.UPLOADITEM_SEQ_NR = TB_MESSAGE.UPLOADITEM_SEQ_NR ")
        .append("WHERE TB_DETAIL.UPLOAD_ID =:fileId ");

    if (StringUtils.equalsIgnoreCase(status, "s")) {
        sql.append(" AND TB_DETAIL.UPLOADITEM_STATUS_CD = 'S' ");
    } else if (StringUtils.equalsIgnoreCase(status, "f")) {
        sql.append(" AND TB_DETAIL.UPLOADITEM_STATUS_CD != 'S' ");
    }

    sql.append(" ) AS DT WHERE RowNum > :start ");

    if (end > 0) {
        sql.append(" AND RowNum <= :end ");
    }

    System.out.println("getDetails - File Id "+fileId+", Query --> " + sql.toString());

    Map<String, Object> props = new HashMap<String, Object>();
    props.put("fileId", fileId);
    props.put("start", start);
    props.put("end", end);

    list = npTemplate.query(sql.toString(), props, new DataLoadDetailRowMapper());
    return list;
}
</code>```

The applicationContext.xml file is:

```<code><bean id="dataLoadDetailDao" class="com.hp.it.mdm.dao.impl.DataLoadDetailDaoImpl">
    <property name="npTemplate">
        <ref bean="nameParamJdbcTemplate"/>
    </property>
    <property name="dlmdao">
        <ref bean="dlmdao"/>
    </property>
</bean>
</code>```

I have seen several posts in StackOverflow but I can not get the concept of the test.

Regards.

答:
What you can do is verify that the method npTemplate.query() was called with the specified parameters.

Your test may look like this:

```<code>private NameParamJdbcTemplate nTemplate = mock(NameParamJdbcTemplate.class);

@Test
public void test() {
  //given
  private DaoImpl daoImpl = new DaoImpl(nTemplate);
  //when
  daoImpl.getDetails(...);
  //then
  verify(nTemplate).query(any(), any(), any()); //or you can specify the exact parameters that should be passed.
}
</code>```

Title: JDBC Spring Mockito

Body:
I want to test this method (getDetails) is part of my DaoImpl, but I do not know how to do it. I know that I have to test the database mocking it with the JDBC template:

 public List<DataLoadDetail> getDetails(int fileId, String templateType, String status, int start, int end) {

    List<DataLoadDetail> list = new ArrayList<DataLoadDetail>();
    StringBuffer sql = new StringBuffer();

    sql.append("SELECT * FROM ( ")
        .append("SELECT ROW_NUMBER() OVER(ORDER BY TB_DETAIL.UPLOADITEM_SEQ_NR ASC) AS RowNum, ")
        .append("TB_DETAIL.UPLOAD_ID, TB_DETAIL.UPLOADITEM_SEQ_NR, TB_DETAIL.UPLOADITEM_ACTION_CD, ")
        .append("TB_DETAIL.UPLOADITEM_INSERT_DT, TB_DETAIL.UPLOADITEM_UPDATE_DT, TB_DETAIL.UPLOADITEM_STATUS_CD, ")
        .append("TB_DETAIL.UPLOADITEM_PAYLOAD, TB_DETAIL.UPLOADITEM_RESPONSE, TB_MESSAGE.DESCRIPTION ")
        .append("FROM DL_DETAIL TB_DETAIL LEFT JOIN DL_MESSAGE TB_MESSAGE ")
        .append("ON TB_DETAIL.UPLOAD_ID = TB_MESSAGE.UPLOAD_ID ")
        .append("AND TB_DETAIL.UPLOADITEM_SEQ_NR = TB_MESSAGE.UPLOADITEM_SEQ_NR ")
        .append("WHERE TB_DETAIL.UPLOAD_ID =:fileId ");

    if (StringUtils.equalsIgnoreCase(status, "s")) {
        sql.append(" AND TB_DETAIL.UPLOADITEM_STATUS_CD = 'S' ");
    } else if (StringUtils.equalsIgnoreCase(status, "f")) {
        sql.append(" AND TB_DETAIL.UPLOADITEM_STATUS_CD != 'S' ");
    }

    sql.append(" ) AS DT WHERE RowNum > :start ");

    if (end > 0) {
        sql.append(" AND RowNum <= :end ");
    }

    System.out.println("getDetails - File Id "+fileId+", Query --> " + sql.toString());

    Map<String, Object> props = new HashMap<String, Object>();
    props.put("fileId", fileId);
    props.put("start", start);
    props.put("end", end);

    list = npTemplate.query(sql.toString(), props, new DataLoadDetailRowMapper());
    return list;
}

The applicationContext.xml file is:

<bean id="dataLoadDetailDao" class="com.hp.it.mdm.dao.impl.DataLoadDetailDaoImpl">
    <property name="npTemplate">
        <ref bean="nameParamJdbcTemplate"/>
    </property>
    <property name="dlmdao">
        <ref bean="dlmdao"/>
    </property>
</bean>

I have seen several posts in StackOverflow but I can not get the concept of the test.

Regards.

Body:
What you can do is verify that the method npTemplate.query() was called with the specified parameters.

Your test may look like this:

private NameParamJdbcTemplate nTemplate = mock(NameParamJdbcTemplate.class);

@Test
public void test() {
  //given
  private DaoImpl daoImpl = new DaoImpl(nTemplate);
  //when
  daoImpl.getDetails(...);
  //then
  verify(nTemplate).query(any(), any(), any()); //or you can specify the exact parameters that should be passed.
}


问:
Application time out when accessing the specific report
```<code>public HashMap generateMsgFiveDaysCompltdReport(
    final SearchCriteria msgCriteria,
    String[] queueselected,
    boolean flag) throws SQLException {
    HashMap msgInitiatedData = null;

    if (logger.isDebugEnabled()) {
        logger.debug("generateMsgInitiatedReport of ReportsDelegate  - start");
    }

    logReportRun("Requested", msgCriteria.getReportName(),
            msgCriteria.getStartDate(), msgCriteria.getEndDate(),
            msgCriteria.getQueueDesc(), "", msgCriteria.getProfileId());
    TimeTracker tt = new TimeTracker();
    tt.start();
    msgInitiatedData = reportsDAO.generateMsgFiveDaysCompltdReport(msgCriteria, queueselected,flag);
    tt.stop();
    String totalTime = Long.toString(tt.getTotalTime());
    logReportRun("Completed", msgCriteria.getReportName(),
            msgCriteria.getStartDate(), msgCriteria.getEndDate(),
            msgCriteria.getQueueDesc(), totalTime, msgCriteria.getProfileId());

    if (logger.isDebugEnabled()) {
        logger.info("generateMsgInitiatedReport-End");
    }

    return msgInitiatedData;
}
</code>```

Application calling this method and once after completion of reportsDAO.generateMsgFiveDaysCompltdReport, it shows how much time it took to execute. In the logs i could see for 68-75 seconds. However it keeps calling even this methode repeatedly causing the application timeout. I know its calling repeatedly because of logger statements "Requested " and "Completed " before and after  reportsDAO.generateMsgFiveDaysCompltdReport. is it because of thread hung or DB connection issues? I am not able to replicate the same issue in SIT/UAT or DEV environemnt.

Logs:

```<code>[12/12/16 15:32:21:983 EST] 00000049 SystemOut     O 12/12/2016 15:32:21,983 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Requested the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null]
[12/12/16 15:32:28:463 EST] 0000004f SystemOut     O 12/12/2016 15:32:28,460 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Completed the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null] and total time taken is: 66.67 Sec.
[12/12/16 15:32:57:293 EST] 0000004a SystemOut     O 12/12/2016 15:32:57,292 INFO  (com.anthem.central.sm.action.ValidateUserAction:164) - User has logged on%0A+%28CustomInfo+%3A+%29%0A+%5Brequest+params%3A+none%5D%0A+%3Cuser%3A+HHarriman2642%3E+%7BsessionId%3A+cEKjYeADwPUwmrNRtAoTR5T%7D
[12/12/16 15:33:00:466 EST] 0000004a SystemOut     O 12/12/2016 15:33:00,465 INFO  (com.anthem.central.sm.dao.QuestionDAO:641) - QuestionDAO.sendClaimsMessage: ICN=ICN%23006390263 msgId=14172673 queueId=202 systemName=BXWGS patientID=LCB863763363
[12/12/16 15:33:11:959 EST] 0000004f SystemOut     O 12/12/2016 15:33:11,958 INFO  (com.anthem.central.sm.dao.QuestionDAO:641) - QuestionDAO.sendClaimsMessage: ICN=ICN%23006390267 msgId=14172677 queueId=90 systemName=NASCOPAR patientID=UGG9219580610001
[12/12/16 15:33:22:147 EST] 0000004a SystemOut     O 12/12/2016 15:33:22,147 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Requested the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null]
[12/12/16 15:33:24:478 EST] 00000049 SystemOut     O 12/12/2016 15:33:24,477 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Completed the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null] and total time taken is: 62.49 Sec.
[12/12/16 15:33:27:687 EST] 00000049 SystemOut     O 12/12/2016 15:33:27,687 INFO  (com.anthem.central.sm.dao.QuestionDAO:641) - QuestionDAO.sendClaimsMessage: ICN=ICN%23006390268 msgId=14172681 queueId=502 systemName=SEVA patientID=YRZ958M62248
[12/12/16 15:34:22:245 EST] 0000003a SystemOut     O 12/12/2016 15:34:22,244 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Requested the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null]
[12/12/16 15:34:28:404 EST] 0000004a SystemOut     O 12/12/2016 15:34:28,404 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Completed the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null] and total time taken is: 66.26 Sec.
[12/12/16 15:34:50:717 EST] 0000004f SystemOut     O 12/12/2016 15:34:50,716 INFO  (com.anthem.central.sm.action.ValidateUserMPPSSOAction:147) - prevProfileID hamde2pfs%23 found for DHamlin8008
[12/12/16 15:34:50:720 EST] 0000004f SystemOut     O 12/12/2016 15:34:50,719 INFO  (com.anthem.central.sm.action.ValidateUserMPPSSOAction:212) - User has logged on%0A+%28CustomInfo+%3A+%29%0A+%5Brequest+params%3A+TargetXML%3DPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48VXNlcj48UHJvdmlkZXJTdGF0ZT5DQTwvUHJvdmlkZXJTdGF0ZT48U1NPSWQ%2BYWthNDAwMzEzODE0MzQ8L1NTT0lkPjxIZWFsdGhQbGFuVXNlcklkPmhhbWRlMnBmczwvSGVhbHRoUGxhblVzZXJJZD48Um9sZT5VU0VSPC9Sb2xlPjxEZWVwbGlua0lkPjwvRGVlcGxpbmtJZD48L1VzZXI%2B%2C+FirstName%3DY807Mmp0%2BuxqPSZGBmCLdQ%3D%3D%2C+LastName%3D2%2Fi%2BFEH6qyKDYDHatADmNA%3D%3D%2C+Email%3DLFKtdhJnLi8tV4k6hkDnO2XTL%2F8GigkELIsfpFEoxvg%3D%5D%0A+%3Cuser%3A+DHamlin8008%3E+%7BsessionId%3A+4sf5VL9IA5I-PF8c3Wgpzw8%7D
</code>```

答:
Sorry for posting it very late. I am new to StackOverflow

Cause: I solved the issue myself but forgot to post it here, so doing it now. There is a ServerIOTimeout setting in Websphere set to 60s, which causes the webserver to initiate the request again if it has not received the response within 60s. Since my request contains the database queries which took more approximately around 70s causing the issue. Couldn't replicate the issue in lower environments as the queries were executing in 20s (data volume is very less)

Solution: increased the serverIOtimeout setting to 180s solved it.

Body:
public HashMap generateMsgFiveDaysCompltdReport(
    final SearchCriteria msgCriteria,
    String[] queueselected,
    boolean flag) throws SQLException {
    HashMap msgInitiatedData = null;

    if (logger.isDebugEnabled()) {
        logger.debug("generateMsgInitiatedReport of ReportsDelegate  - start");
    }

    logReportRun("Requested", msgCriteria.getReportName(),
            msgCriteria.getStartDate(), msgCriteria.getEndDate(),
            msgCriteria.getQueueDesc(), "", msgCriteria.getProfileId());
    TimeTracker tt = new TimeTracker();
    tt.start();
    msgInitiatedData = reportsDAO.generateMsgFiveDaysCompltdReport(msgCriteria, queueselected,flag);
    tt.stop();
    String totalTime = Long.toString(tt.getTotalTime());
    logReportRun("Completed", msgCriteria.getReportName(),
            msgCriteria.getStartDate(), msgCriteria.getEndDate(),
            msgCriteria.getQueueDesc(), totalTime, msgCriteria.getProfileId());

    if (logger.isDebugEnabled()) {
        logger.info("generateMsgInitiatedReport-End");
    }

    return msgInitiatedData;
}

Application calling this method and once after completion of reportsDAO.generateMsgFiveDaysCompltdReport, it shows how much time it took to execute. In the logs i could see for 68-75 seconds. However it keeps calling even this methode repeatedly causing the application timeout. I know its calling repeatedly because of logger statements "Requested " and "Completed " before and after  reportsDAO.generateMsgFiveDaysCompltdReport. is it because of thread hung or DB connection issues? I am not able to replicate the same issue in SIT/UAT or DEV environemnt.

Logs:

[12/12/16 15:32:21:983 EST] 00000049 SystemOut     O 12/12/2016 15:32:21,983 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Requested the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null]
[12/12/16 15:32:28:463 EST] 0000004f SystemOut     O 12/12/2016 15:32:28,460 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Completed the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null] and total time taken is: 66.67 Sec.
[12/12/16 15:32:57:293 EST] 0000004a SystemOut     O 12/12/2016 15:32:57,292 INFO  (com.anthem.central.sm.action.ValidateUserAction:164) - User has logged on%0A+%28CustomInfo+%3A+%29%0A+%5Brequest+params%3A+none%5D%0A+%3Cuser%3A+HHarriman2642%3E+%7BsessionId%3A+cEKjYeADwPUwmrNRtAoTR5T%7D
[12/12/16 15:33:00:466 EST] 0000004a SystemOut     O 12/12/2016 15:33:00,465 INFO  (com.anthem.central.sm.dao.QuestionDAO:641) - QuestionDAO.sendClaimsMessage: ICN=ICN%23006390263 msgId=14172673 queueId=202 systemName=BXWGS patientID=LCB863763363
[12/12/16 15:33:11:959 EST] 0000004f SystemOut     O 12/12/2016 15:33:11,958 INFO  (com.anthem.central.sm.dao.QuestionDAO:641) - QuestionDAO.sendClaimsMessage: ICN=ICN%23006390267 msgId=14172677 queueId=90 systemName=NASCOPAR patientID=UGG9219580610001
[12/12/16 15:33:22:147 EST] 0000004a SystemOut     O 12/12/2016 15:33:22,147 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Requested the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null]
[12/12/16 15:33:24:478 EST] 00000049 SystemOut     O 12/12/2016 15:33:24,477 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Completed the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null] and total time taken is: 62.49 Sec.
[12/12/16 15:33:27:687 EST] 00000049 SystemOut     O 12/12/2016 15:33:27,687 INFO  (com.anthem.central.sm.dao.QuestionDAO:641) - QuestionDAO.sendClaimsMessage: ICN=ICN%23006390268 msgId=14172681 queueId=502 systemName=SEVA patientID=YRZ958M62248
[12/12/16 15:34:22:245 EST] 0000003a SystemOut     O 12/12/2016 15:34:22,244 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Requested the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null]
[12/12/16 15:34:28:404 EST] 0000004a SystemOut     O 12/12/2016 15:34:28,404 INFO  (com.anthem.central.sm.delegate.ReportsDelegate:618) - Completed the report Messages+Turnaround+in+Business+Days+by+NPI+or+Queue for input criteria [ProfileId:VPurimetla2207, Start Date: 12%2F08%2F2016, End Date: 12%2F09%2F2016, Selected Queue: null] and total time taken is: 66.26 Sec.
[12/12/16 15:34:50:717 EST] 0000004f SystemOut     O 12/12/2016 15:34:50,716 INFO  (com.anthem.central.sm.action.ValidateUserMPPSSOAction:147) - prevProfileID hamde2pfs%23 found for DHamlin8008
[12/12/16 15:34:50:720 EST] 0000004f SystemOut     O 12/12/2016 15:34:50,719 INFO  (com.anthem.central.sm.action.ValidateUserMPPSSOAction:212) - User has logged on%0A+%28CustomInfo+%3A+%29%0A+%5Brequest+params%3A+TargetXML%3DPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48VXNlcj48UHJvdmlkZXJTdGF0ZT5DQTwvUHJvdmlkZXJTdGF0ZT48U1NPSWQ%2BYWthNDAwMzEzODE0MzQ8L1NTT0lkPjxIZWFsdGhQbGFuVXNlcklkPmhhbWRlMnBmczwvSGVhbHRoUGxhblVzZXJJZD48Um9sZT5VU0VSPC9Sb2xlPjxEZWVwbGlua0lkPjwvRGVlcGxpbmtJZD48L1VzZXI%2B%2C+FirstName%3DY807Mmp0%2BuxqPSZGBmCLdQ%3D%3D%2C+LastName%3D2%2Fi%2BFEH6qyKDYDHatADmNA%3D%3D%2C+Email%3DLFKtdhJnLi8tV4k6hkDnO2XTL%2F8GigkELIsfpFEoxvg%3D%5D%0A+%3Cuser%3A+DHamlin8008%3E+%7BsessionId%3A+4sf5VL9IA5I-PF8c3Wgpzw8%7D


问:
Looking for a good VBA treemap implementation
I need a VBA map object similar to C++ STL map class for use in Excel 2010. I am dreading writing one myself, and also dreading writing an XLL. Does anyone know of such an object freely available? Scripting.Dictionary will not do, since I need ordered iteration.</p>

答:
Here's a chapter from a book, hosted on MSDN, that describes creating a binary tree, might be useful to get you started at least: Implementing a Binary Tree

They do mention that there should be sample code on the cd, not sure if you'd be able to download that from there or from the publisher, nor am I sure under what license that sourcecode is provided.

ContentLicense: CC BY-SA 2.5


问:
Unable to get the tab content on right side
I have a peculiar problem of tab content not floating on right side as its tabs are on right side too. Below is the picture to get a better idea:

I have tried floating the tab content right but not working. Rather its going past right where I can't see anything. This problem exists for both Live Chat and Mail Us tabs.

Below is the codepen.

HTML Code

```<code><div class="tab-pane livechat wow animated bounceInLeft" id="chat">
     <div class="chatwidget">
                <a href="#" class="wow animated shake">Click for Chat</a>
     </div>
</div>
</code>```

CSS3

```<code>.livechat {
position: absolute;
bottom: 0px;
width: 50%;
background-color: #eee;
height: 370px;
text-align: center;
box-shadow: 0 0 20px grey;
float: right;
}
.chatwidget {
  padding: 150px;
  font-size: 24px;
 }
</code>```

答:
Before you add position: absolute to the livechat element you should add position: relative to its one of parent elements as below mentioned. Better it is to body tag. And put right: 0; instead of float: right;.

body{

```<code>position: relative;
</code>```

}

.livechat {

```<code> position: absolute;
 bottom: 0px;
 width: 50%;
 background-color: #eee;
 height: 370px;
 text-align: center;
 box-shadow: 0 0 20px grey;
 right: 0;
</code>```

}

Body:
I have a peculiar problem of tab content not floating on right side as its tabs are on right side too. Below is the picture to get a better idea:

I have tried floating the tab content right but not working. Rather its going past right where I can't see anything. This problem exists for both Live Chat and Mail Us tabs.

Below is the codepen.

HTML Code

                Click for Chat

CSS3

.livechat {
position: absolute;
bottom: 0px;
width: 50%;
background-color: #eee;
height: 370px;
text-align: center;
box-shadow: 0 0 20px grey;
float: right;
}
.chatwidget {
  padding: 150px;
  font-size: 24px;
 }

Body:
Before you add position: absolute to the livechat element you should add position: relative to its one of parent elements as below mentioned. Better it is to body tag. And put right: 0; instead of float: right;.

body{

position: relative;

}

.livechat {

 position: absolute;
 bottom: 0px;
 width: 50%;
 background-color: #eee;
 height: 370px;
 text-align: center;
 box-shadow: 0 0 20px grey;
 right: 0;

}


问:
PLSQL Need to match up nested records
I have a table with records showing when an item is put on hold or released.
Nested holds are possible. Some records have become mixed up, new logic is needed.
To fix this I need to match the release to the hold - I have a roughly drawn example below - the id column doesn't exist but is what I need to generate.

The table I'm working from has no unique identifier I can use and nothing to match the release to the hold except the order they happen in.
I've been playing with this for a while and can't nail it down.

The problem comes when I get 2 or more hold sin a row without a release. If we have hold1, hold2 and hold3 then the releases after this should be read in the order release3, release2, release1.

Any help or suggestions would be greatly appreciated.

```<code>CREATE TABLE "TBL_ACTIONS"
   ("ITEM_ID" CHAR(5 BYTE),
    "ACTION_DATE" DATE,
    "ACTION" VARCHAR2(40 BYTE)
   );

Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 01:00:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 01:12:45','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 16:00:19','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 16:12:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('20/11/16 14:52:42','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('20/11/16 16:00:10','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 17:52:49','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 21:12:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 23:12:48','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 23:32:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/11/16 14:40:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/11/16 14:40:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/11/16 19:12:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:17:59','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:17:59','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:18:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:18:40','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('01/12/16 11:03:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/12/16 08:10:51','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/12/16 11:27:06','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/12/16 11:27:11','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/12/16 07:10:07','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/12/16 07:10:07','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('16/12/16 14:37:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('16/12/16 14:37:40','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:20:52','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:20:52','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:29:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:29:39','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 10:23:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 10:23:48','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 11:52:26','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 11:52:26','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/01/17 13:47:52','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/01/17 13:47:59','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/01/17 09:42:35','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/01/17 09:42:35','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:11:24','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:11:31','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:12:20','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:12:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:01:48','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:01:48','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:02:58','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:02:58','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/02/17 16:57:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/02/17 16:57:47','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:56:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:56:47','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:57:12','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:57:21','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 16:41:54','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 16:41:54','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 17:21:53','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 17:22:04','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/02/17 16:38:35','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/02/17 16:38:43','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 07:40:05','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 07:40:13','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 23:31:52','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 23:31:52','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('11/02/17 09:16:22','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('11/02/17 09:16:23','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:48:13','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:48:13','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:49:16','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:49:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 15:42:40','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:09','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:46','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:46','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:06:59','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:06:59','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:07:10','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:07:10','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:09','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:09','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:25','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:25','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:26','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:26','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 15:07:20','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 15:10:09','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/03/17 15:35:45','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 12:17:36','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 12:17:37','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:22:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:22:55','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:23:20','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:23:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('18/03/17 07:12:27','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('18/03/17 07:12:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 16:17:54','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 17:52:44','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 18:12:49','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 23:32:45','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('01/04/17 20:32:34','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/04/17 19:53:43','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/04/17 20:52:44','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('04/04/17 21:39:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('04/04/17 21:45:23','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('05/04/17 20:54:49','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('05/04/17 21:00:19','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/04/17 17:35:13','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/04/17 11:29:33','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/04/17 21:32:44','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('18/04/17 00:40:12','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('23/04/17 09:20:35','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('23/04/17 10:52:41','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/04/17 20:40:50','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/04/17 20:52:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/04/17 01:13:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/04/17 04:32:35','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 16:12:47','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 16:20:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 16:40:32','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 18:20:19','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('01/05/17 03:12:06','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/05/17 16:58:17','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/05/17 16:58:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/05/17 15:10:28','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/05/17 15:10:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/05/17 21:14:06','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/05/17 15:41:58','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:00','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:11','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:17','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/06/17 00:30:22','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('04/06/17 06:43:33','DD/MM/YY HH24:MI:SS'),'Hold');
</code>```

答:
As per comments, I've assumed you have an ID column which can be used for ordering. I imagine there may be more efficient ways to do the following (I'd search for Last-In, First-Out or LIFO), but I wanted to see what I could come up with under my own steam:</p>

```<code>With PushPop as (
select
    nh1.Id,
    nh1.Activity,
    sum(case when nh2.Activity = 'Release' then -1 else 1 end) as PushPop
from
    NestedHolds nh1
    LEFT JOIN NestedHolds nh2 ON
        nh1.Id >= nh2.Id
group by
    nh1.Id,
    nh1.Activity
order by
    nh1.id
)

SELECT
nh.*,
NewIDs.NewID
from
NestedHolds nh
JOIN
(
SELECT
    a.Id HoldId,
    min(b.Id) as ReleaseId,
    row_number() over (order by a.Id) NewID
FROM
    PushPop a
    JOIN PushPop b ON
        a.Id < b.Id
        AND a.PushPop = b.PushPop + 1
WHERE
a.Activity = 'Hold'
AND b.Activity = 'Release'
GROUP BY
    a.Id
order by
a.Id
) NewIDs on nh.Id in (NewIDs.HoldID, NewIDs.ReleaseID)
order by nh.id
;
</code>```

Title: PLSQL Need to match up nested records

Body:
I have a table with records showing when an item is put on hold or released.
Nested holds are possible. Some records have become mixed up, new logic is needed.
To fix this I need to match the release to the hold - I have a roughly drawn example below - the id column doesn't exist but is what I need to generate.

The table I'm working from has no unique identifier I can use and nothing to match the release to the hold except the order they happen in.
I've been playing with this for a while and can't nail it down.

The problem comes when I get 2 or more hold sin a row without a release. If we have hold1, hold2 and hold3 then the releases after this should be read in the order release3, release2, release1.

Any help or suggestions would be greatly appreciated.

CREATE TABLE "TBL_ACTIONS"
   ("ITEM_ID" CHAR(5 BYTE),
    "ACTION_DATE" DATE,
    "ACTION" VARCHAR2(40 BYTE)
   );

Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 01:00:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 01:12:45','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 16:00:19','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/11/16 16:12:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('20/11/16 14:52:42','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('20/11/16 16:00:10','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 17:52:49','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 21:12:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 23:12:48','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('24/11/16 23:32:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/11/16 14:40:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/11/16 14:40:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/11/16 19:12:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:17:59','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:17:59','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:18:40','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('29/11/16 08:18:40','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('01/12/16 11:03:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/12/16 08:10:51','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/12/16 11:27:06','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/12/16 11:27:11','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/12/16 07:10:07','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/12/16 07:10:07','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('16/12/16 14:37:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('16/12/16 14:37:40','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:20:52','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:20:52','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:29:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('22/12/16 12:29:39','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 10:23:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 10:23:48','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 11:52:26','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/01/17 11:52:26','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/01/17 13:47:52','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/01/17 13:47:59','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/01/17 09:42:35','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/01/17 09:42:35','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:11:24','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:11:31','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:12:20','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/01/17 12:12:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:01:48','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:01:48','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:02:58','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/02/17 09:02:58','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/02/17 16:57:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/02/17 16:57:47','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:56:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:56:47','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:57:12','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('07/02/17 16:57:21','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 16:41:54','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 16:41:54','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 17:21:53','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/02/17 17:22:04','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/02/17 16:38:35','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('09/02/17 16:38:43','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 07:40:05','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 07:40:13','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 23:31:52','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/02/17 23:31:52','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('11/02/17 09:16:22','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('11/02/17 09:16:23','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:48:13','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:48:13','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:49:16','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/02/17 16:49:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 15:42:40','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:09','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('21/02/17 17:25:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:39','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:46','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('27/02/17 16:51:46','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:06:59','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:06:59','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:07:10','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/02/17 14:07:10','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:09','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:04:09','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:23:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('03/03/17 10:55:55','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:25','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:25','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:26','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 13:23:26','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 15:07:20','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('06/03/17 15:10:09','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('08/03/17 15:35:45','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 12:17:36','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 12:17:37','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:22:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:22:55','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:23:20','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/03/17 13:23:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('18/03/17 07:12:27','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('18/03/17 07:12:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 16:17:54','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 17:52:44','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 18:12:49','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/03/17 23:32:45','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('01/04/17 20:32:34','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/04/17 19:53:43','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/04/17 20:52:44','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('04/04/17 21:39:18','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('04/04/17 21:45:23','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('05/04/17 20:54:49','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('05/04/17 21:00:19','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('10/04/17 17:35:13','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/04/17 11:29:33','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/04/17 21:32:44','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('18/04/17 00:40:12','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('23/04/17 09:20:35','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('23/04/17 10:52:41','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/04/17 20:40:50','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('25/04/17 20:52:47','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/04/17 01:13:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/04/17 04:32:35','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 16:12:47','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 16:20:08','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 16:40:32','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/04/17 18:20:19','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('01/05/17 03:12:06','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/05/17 16:58:17','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('17/05/17 16:58:17','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/05/17 15:10:28','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('19/05/17 15:10:28','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('28/05/17 21:14:06','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('30/05/17 15:41:58','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:00','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:11','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:17','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('31/05/17 10:05:27','DD/MM/YY HH24:MI:SS'),'Hold');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('02/06/17 00:30:22','DD/MM/YY HH24:MI:SS'),'Release');
    Insert into TBL_ACTIONS (ITEM_ID,ACTION_DATE,ACTION) values ('ITEM1',to_date('04/06/17 06:43:33','DD/MM/YY HH24:MI:SS'),'Hold');

Body:
As per comments, I've assumed you have an ID column which can be used for ordering. I imagine there may be more efficient ways to do the following (I'd search for Last-In, First-Out or LIFO), but I wanted to see what I could come up with under my own steam:

With PushPop as (
select
    nh1.Id,
    nh1.Activity,
    sum(case when nh2.Activity = 'Release' then -1 else 1 end) as PushPop
from
    NestedHolds nh1
    LEFT JOIN NestedHolds nh2 ON
        nh1.Id >= nh2.Id
group by
    nh1.Id,
    nh1.Activity
order by
    nh1.id
)

SELECT
nh.*,
NewIDs.NewID
from
NestedHolds nh
JOIN
(
SELECT
    a.Id HoldId,
    min(b.Id) as ReleaseId,
    row_number() over (order by a.Id) NewID
FROM
    PushPop a
    JOIN PushPop b ON
        a.Id < b.Id
        AND a.PushPop = b.PushPop + 1
WHERE
a.Activity = 'Hold'
AND b.Activity = 'Release'
GROUP BY
    a.Id
order by
a.Id
) NewIDs on nh.Id in (NewIDs.HoldID, NewIDs.ReleaseID)
order by nh.id
;


问:
Ang2/Observables - Reading a Cookie value
Angular 2/Observables - Reading the login credentials set in cookie from Backend. Any plnkr example or anyone accomplished this ?</p>

答:
To set a cookie from the backend. send a set-cookie response header after successful authentication.

additionally, you can use javascripts cookies to set cookie manually.

and use an AuthGuard to check authentication


问:
socket.io fail to broadcast in room
I'm developing an application, which has two functions, join room and create room. When user creates a room, a random hash code(e.g.123) will be generated, which will attach to the URL and create a room with the  hash code named(e.g.123) in socket.io. This is successful so far. However, I am fail to broadcast the updated number of clients in the same room. User can click and join a room with hash code(that generated when create a room) provided. When the second user join the room, I would like to update all clients inside the room, which are the one who create room and the one who join the room. However, I can't pass the data to the client. The console states  set heartbeat timeout for client XXX something like that.

```<code>io.on('connection', function(socket){
    var roomCode = "";
    socket.on('createRoom',function(data){
        roomCode = data;
        //create route for the hash URL
          app.get('/'+roomCode, function(req, res){
            socket.join(roomCode);  //join room
            res.render('room',{roomNum:roomCode});
        });
        //response redirect to roomList.ejs
        socket.emit('redirect', "https://chess-ivanhoe0523.c9users.io:8081/"+roomCode);

      });
     socket.on('joinRoom',function(data){
         roomCode = data;
         socket.join(roomCode);
        socket.to(roomCode).emit('PlayerNum','2');
         socket.emit('redirect', "https://chess-ivanhoe0523.c9users.io:8081/"+roomCode);
        //  socket.emit('my PlayerNum', 2);
     });

})
</code>```

app.js

```<code><html>
    <head>
        <title>Chess Prototype</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <link rel="stylesheet" href="css/bootstrap-responsive.min.css">
        <link rel="stylesheet" href="css/index.css">
        <!--<script src="../socket.io/socket.io.js"></script>-->
        <script src="/socket.io/socket.io.js"></script>
        <script src="js/jquery.min.js"></script>
        <script src="js/index.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </head>
    <body>
        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel">Enter room number</h4>
              </div>
              <div class="modal-body">
                 <input type="text" class="form-control" id="roomNum">
                 <br>
                  <button type="button" class="btn btn-default" onClick="joinRoom()">Join</button>
              </div>

            </div>
          </div>
        </div>

        <div class="container">
            <div class="row">
            <div class="character-box">
                <h1>Welcome</h1>

                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Join Game</button>
                <button type="button" class="btn btn-success" onClick="createRoomReq()">Create Game</button>

                <!--</a>-->
                <script>
                    var socket = io.connect();
                    function randomHash()
                    {
                        var text = "";
                        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

                        for( var i=0; i < 5; i++ )
                            text += possible.charAt(Math.floor(Math.random() * possible.length));

                        return text;
                    }

                    function createRoomReq(){
                        var randomCode = randomHash();
                        // alert(randomCode);
                        socket.emit('createRoom', randomCode);
                    }

                    function joinRoom(){
                        var roomNum = document.getElementById("roomNum").value;
                        socket.emit('joinRoom', roomNum);
                    }

                    socket.on('redirect', function(destination) {
                        window.location.href = destination;
                    });
                </script>

                </a>

            </div>
            </div>

        </div>
    </body>
</html>
</code>```

lobby.ejs

```<code><html>
    <head><title>A room</title></head>
    <script src="/socket.io/socket.io.js"></script>
    <script>
     var socket = io.connect();
      socket.on('connectToRoom',function(data){
          document.body.innerHTML = '';
          document.write(data);
      });
       socket.on('PlayerNum',function(data){
           console.log("player num received from client: "data);
          document.getelementById("num").innerHTML = data;
      });
    </script>

    <body>
        You are in Room <%=  roomNum %>
        <br>
        Num of Players in the room:
        <div id="num"></div>
    </body>
</html>
</code>```

room.ejs

答: You want to use io.to(room).emit() instead of socket.to(room).emit()

ContentLicense: CC BY-SA 4.0

Title: socket.io fail to broadcast in room

Body:
I'm developing an application, which has two functions, join room and create room. When user creates a room, a random hash code(e.g.123) will be generated, which will attach to the URL and create a room with the  hash code named(e.g.123) in socket.io. This is successful so far. However, I am fail to broadcast the updated number of clients in the same room. User can click and join a room with hash code(that generated when create a room) provided. When the second user join the room, I would like to update all clients inside the room, which are the one who create room and the one who join the room. However, I can't pass the data to the client. The console states  set heartbeat timeout for client XXX something like that.

io.on('connection', function(socket){
    var roomCode = "";
    socket.on('createRoom',function(data){
        roomCode = data;
        //create route for the hash URL
          app.get('/'+roomCode, function(req, res){
            socket.join(roomCode);  //join room
            res.render('room',{roomNum:roomCode});
        });
        //response redirect to roomList.ejs
        socket.emit('redirect', "https://chess-ivanhoe0523.c9users.io:8081/"+roomCode);

      });
     socket.on('joinRoom',function(data){
         roomCode = data;
         socket.join(roomCode);
        socket.to(roomCode).emit('PlayerNum','2');
         socket.emit('redirect', "https://chess-ivanhoe0523.c9users.io:8081/"+roomCode);
        //  socket.emit('my PlayerNum', 2);
     });

})

app.js

        <title>Chess Prototype</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <link rel="stylesheet" href="css/bootstrap-responsive.min.css">
        <link rel="stylesheet" href="css/index.css">

                <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>

Enter room number

                 <input type="text" class="form-control" id="roomNum">

                  <button type="button" class="btn btn-default" onClick="joinRoom()">Join</button>

Welcome

                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Join Game</button>
                <button type="button" class="btn btn-success" onClick="createRoomReq()">Create Game</button>

lobby.ejs

    <title>A room</title>

        You are in Room <%=  roomNum %>

        Num of Players in the room:

room.ejs


问:
How to fix java.net.SocketException: Broken pipe?
I am using apache commons http client to call url using post method to post the parameters and it is throwing the below error rarely.

```<code>java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
        at java.io.FilterOutputStream.write(FilterOutputStream.java:80)
        at org.apache.commons.httpclient.methods.ByteArrayRequestEntity.writeRequest(ByteArrayRequestEntity.java:90)
        at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
        at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
        at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
</code>```

Can someone suggest what is causing this Exception and how to debug it?

答:
The issue could be that your deployed files are not updated with the correct RMI methods. Check to see that your RMI interface has updated parameters, or updated data structures that your client does not have. Or that your RMI client has no parameters that differ from what your server version has.

This is just an educated guess. After re-deploying my server application's class files and re-testing, the problem of "Broken pipe" went away.

OwnerDisplayName: Mani

Body:
I am using apache commons http client to call url using post method to post the parameters and it is throwing the below error rarely.

java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
        at java.io.FilterOutputStream.write(FilterOutputStream.java:80)
        at org.apache.commons.httpclient.methods.ByteArrayRequestEntity.writeRequest(ByteArrayRequestEntity.java:90)
        at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
        at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
        at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)

Can someone suggest what is causing this Exception and how to debug it?


问:
How to release memory of the responseText in an endless streaming request?
I need to use xmlHTTPRequest to fetch data from an endless motion JPEG data stream, and I heard that a nice trick that the responseText can populate data without finishing the request (it will never finish). Now I run into problem.

My request is bind with RxJS observable like this.

```<code>  postActionGivenDataBinaryStream(url:string, data:string) : Observable<any>{

    this.binary_progress_call_accum = 0 ;
    this.previous_length = 0 ;

    return Observable.create((observer)=>{
        let xhr = new XMLHttpRequest() ;

        xhr.open('POST',url,true) ;
        xhr.setRequestHeader("Content-Type","application/json;charset=utf-8");
        //this way the binary data keeps populate at state 3
        xhr.overrideMimeType('text\/plain; charset=x-user-defined');

        xhr.onreadystatechange = () =>{
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    this.binary_progress_call_accum = 0 ;
                    this.previous_length = 0 ;
                    observer.complete();
                } else {
                    this.binary_progress_call_accum = 0 ;
                    this.previous_length = 0 ;
                    observer.error(xhr.response);
                }
            }
        }
        xhr.onprogress = (event)=>{
            let outstring:string = "";
            //should preordically emit the response text

            if (this.binary_progress_call_accum > 1) {
                //just send the next piece of data
                let endCount = xhr.responseText.length ;

                //so here try to next a string

                for (let i = this.previous_length ; i < endCount; ++i ){
                    outstring += ("00" + (xhr.responseText.charCodeAt(i) & 0xFF).toString(16)).slice(-2) ;
                }

                observer.next(outstring) ;
                this.previous_length = endCount ;
            }
            else{
                for (let i = 0 ; i < xhr.responseText.length; ++i ){
                    outstring += ("00" + (xhr.responseText.charCodeAt(i) & 0xFF).toString(16)).slice(-2) ;
                }
                observer.next(outstring) ;
                this.previous_length = xhr.responseText.length ;
            }

            this.binary_progress_call_accum += 1;
        };

        xhr.send(data) ;

        //https://stackoverflow.com/a/38622923/921082
        //elegantly abort()
        return () => xhr.abort() ;
    }) ;

}
</code>```

But this piece of code has serious problem, I call this observable at a 30 seconds interval, but, it sometimes stuck. When my interval observable triggered, the request just delay for 30 seconds! Without doing anything, the console log gives nothing.

I suspect that it's the xhr.abort() takes too long to finish, before it finishes, the interval observable gives next request, which will conflict with the previous one, which causes the request-response delay. So is there any way to release the memory of responseText without using interval to reinit such xhr request observable?

答:
This seems a tough one, I actually solved it.

The answer has nothing to do with my code above, but the code calls this request observable.

I should use repeatWhen instead of IntervalObservable. Since IntervalObservable doesn't care if the request actually complete or not, it will cause request triggered before last one complete. Whereas repeatWhen ensures the last observable actually complete before the next start.

Please check this enlighten discussion, https://github.com/ReactiveX/RxJava/issues/448

Body:
I need to use xmlHTTPRequest to fetch data from an endless motion JPEG data stream, and I heard that a nice trick that the responseText can populate data without finishing the request (it will never finish). Now I run into problem.

My request is bind with RxJS observable like this.

  postActionGivenDataBinaryStream(url:string, data:string) : Observable<any>{

    this.binary_progress_call_accum = 0 ;
    this.previous_length = 0 ;

    return Observable.create((observer)=>{
        let xhr = new XMLHttpRequest() ;

        xhr.open('POST',url,true) ;
        xhr.setRequestHeader("Content-Type","application/json;charset=utf-8");
        //this way the binary data keeps populate at state 3
        xhr.overrideMimeType('text\/plain; charset=x-user-defined');

        xhr.onreadystatechange = () =>{
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    this.binary_progress_call_accum = 0 ;
                    this.previous_length = 0 ;
                    observer.complete();
                } else {
                    this.binary_progress_call_accum = 0 ;
                    this.previous_length = 0 ;
                    observer.error(xhr.response);
                }
            }
        }
        xhr.onprogress = (event)=>{
            let outstring:string = "";
            //should preordically emit the response text

            if (this.binary_progress_call_accum > 1) {
                //just send the next piece of data
                let endCount = xhr.responseText.length ;

                //so here try to next a string

                for (let i = this.previous_length ; i < endCount; ++i ){
                    outstring += ("00" + (xhr.responseText.charCodeAt(i) & 0xFF).toString(16)).slice(-2) ;
                }

                observer.next(outstring) ;
                this.previous_length = endCount ;
            }
            else{
                for (let i = 0 ; i < xhr.responseText.length; ++i ){
                    outstring += ("00" + (xhr.responseText.charCodeAt(i) & 0xFF).toString(16)).slice(-2) ;
                }
                observer.next(outstring) ;
                this.previous_length = xhr.responseText.length ;
            }

            this.binary_progress_call_accum += 1;
        };

        xhr.send(data) ;

        //https://stackoverflow.com/a/38622923/921082
        //elegantly abort()
        return () => xhr.abort() ;
    }) ;

}

But this piece of code has serious problem, I call this observable at a 30 seconds interval, but, it sometimes stuck. When my interval observable triggered, the request just delay for 30 seconds! Without doing anything, the console log gives nothing.

I suspect that it's the xhr.abort() takes too long to finish, before it finishes, the interval observable gives next request, which will conflict with the previous one, which causes the request-response delay. So is there any way to release the memory of responseText without using interval to reinit such xhr request observable?


问:
Generate list of numbers fron N to 1 in prolog
I am trying to generate a list of numbers from N to 1 without using any build-in predicated such as findall or numlist. What am I doing wrong ?

```<code>    pred(N,[H|T]):-  H is N, N1 is N-1, pred(N1,T).
    pred(1,[]).
</code>```

I keep getting ERROR: Out of global stack

答:
Switch the order of your clauses. Put the second clause first, otherwise it has no chance to contribute (i.e. to halt) and the first clause continues to count down to negative infinity.

Of course even better is to make the two clauses mutually exclusive by adding a simple test as the first goal to your first clause.

Body:
I am trying to generate a list of numbers from N to 1 without using any build-in predicated such as findall or numlist. What am I doing wrong ?

    pred(N,[H|T]):-  H is N, N1 is N-1, pred(N1,T).
    pred(1,[]).

I keep getting ERROR: Out of global stack


问:
How to fetch data dynamically from JSON file on click?
I have created an artist(artists.html) page, which includes around 15 artists. Now I am trying to create the profile of each artist through one single HTML file dynamically. So I have created another HTML file(single-artist.html) which will show the profile of an artist clicked by the visitor.

artists.html (Out of 15 artists, below are the two examples)

```<code>    <div class="all-artist" id="artists">
            <div class="col-md-4 col-sm-6 col-xs-6 artist-single" data-number="0">
                <div>
                    <a href="artist-single.html">
                        <img src="img/1.jpg" alt="">
                    </a>
                </div>
            </div>

            <div class="col-md-4 col-sm-6 col-xs-6 artist-single" data-number="1">
                <div>
                    <a href="artist-single.html">
                        <img src="img/2.jpg" alt="">
                    </a>
                </div>
            </div>

    </div>
</code>```

artist-single.html

```<code><div id="name"></div>
<div id="logo"></div>
<div id="bio"></div>
</code>```

data.json

```<code>[{

"name": "Arsh",
"logo": "img/logo.jpg",
"bio": "Arsh is a singer/songwriter"

},

{

"name": "Benz",
"logo": "img/logo.jpg",
"bio": "Benz is a singer"

}]
</code>```

main.js

```<code>  $('#all_artists artist-single').on('click',function(){
window.location.href="artist-single.html";
var num = $(this).data('number');
$.getJSON('data.json',function(data) {
    $('#name').html(data[num].name);
    $('#description').html(data[num].bio);
    $('#logo').append('<img src=data[num].logo>');
  });
});
</code>```

Now, when I click on an artist image, it redirects to artist-single.html but it's not fetching values. Maybe because I am redirecting and fetching the values on the same event. Help would be really appreciated.

答:
```<code>$(document).ready(function() {
  var num = $.cookie('num');

  $.getJSON('data.json', function(data) {
    $('#name').html(data[num].name);
    $('#description').html(data[num].bio);
    $('#logo').append('<img src=data[num].logo>');
  });

  $('#artists .artist-single').on('click', function() {
    var num = $(this).data('number');
    $.cookie('num', num);
    window.location.href = "artist-single.html";
  });

});
</code>```

Body:
I have created an artist(artists.html) page, which includes around 15 artists. Now I am trying to create the profile of each artist through one single HTML file dynamically. So I have created another HTML file(single-artist.html) which will show the profile of an artist clicked by the visitor.

artists.html (Out of 15 artists, below are the two examples)

artist-single.html

data.json

[{

"name": "Arsh",
"logo": "img/logo.jpg",
"bio": "Arsh is a singer/songwriter"

},

{

"name": "Benz",
"logo": "img/logo.jpg",
"bio": "Benz is a singer"

}]

main.js

  $('#all_artists artist-single').on('click',function(){
window.location.href="artist-single.html";
var num = $(this).data('number');
$.getJSON('data.json',function(data) {
    $('#name').html(data[num].name);
    $('#description').html(data[num].bio);
    $('#logo').append('');
  });
});

Now, when I click on an artist image, it redirects to artist-single.html but it's not fetching values. Maybe because I am redirecting and fetching the values on the same event. Help would be really appreciated.


问:
Connecting outlets in Window Based App, Objective-C
I'm reading through a beginners iPhone text book and just finished writing all the code for a route tracker app that uses Map Kit and Core Location. I have the app running with no errors on my iphone 4 device but when I tried interacting I realized that none of my IBOutlets were connected to anything. When I referenced the beginning of the tutorial in the text, all it says is to "connect the appropriate outlets".

Here's why this usually simple task has me confused. The tutorial says to create a Window Based Project, so there is no ViewController. Then, in Interface Builder, the view is built in MainWindow.xib. The only IBOutlets of the project are located in Controller.h / Controller.m files that you create and which contain mostly all of the code for the app.

I usually ctrl-drag from File's Owner to the UI in Interface Builder, but in this project there seems to be no way for me to access the IBOutlets in Controller.h / .m from the MainWindow.xib file.

I'm frustrated because it seems like this should be such an easy fix but I'm totally stumped.. any help is really appreciated. Thanks

答:
As I see it, you have two choices:

Add the outlets to the app delegate.  This is probably not the best plan.

Put an instance of your controller class in the .xib file.

I think option 2 is what you want.  If you check the Controllers section of the library, you'll see a component called "Object".  Drag one of those into your xib, then inspect it.  Select the info pane in the inspector (the circle with a white i in it) and change the Class to the name of your controller class.


问:
How to remove duplicate columns with their non-null value after join?
I have a dataframe named "A" with 300+ columns in it and i am trying to join the dataframe named "A" with its incremental data "B" with same schema as "A".

After joining the dataframes, i am getting duplicate columns. That i was avoiding by using co

```<code>val toPrint = udf((value1: String, value2: String) => if(value1 != null) {value1} else value2)
val dfClean = df1.join(df2, df1("PERIOD_TAG") === df2("PERIOD_TAG"), "fullouter").select(toPrint(df1("PERIOD_SHORT_DESCRIPTION"),df2("PERIOD_SHORT_DESCRIPTION")).alias("PERIOD_SHORT_DESCRIPTION"),toPrint(df1("PERIOD_TAG"),df2("PERIOD_TAG")).alias("PERIOD_TAG"))....so on for all the columns
</code>```

I am calling a UDF to select the most updated value(from incremental file) among the duplicate columns.
The incremental data will have few updated data which i need to add along with all new data in incremantal dataframe and also old data of dataframe "B".

Is there any another way to avoid selecting columns individually and use a for loop for it.
Or is there any way that after joining, i get the new/updated value of my incremental df and old values of dataframe "B" which are not present in dataframe "A".

答:
I'd first avoid the duplication in join column names using single-string usingColumn argument of join operator.

```<code>df1.join(df2, "PERIOD_TAG", "fullouter")
</code>```

That takes care of de-duplicating PERIOD_TAG column.

Different from other join functions, the join column will only appear once in the output, i.e. similar to SQL's JOIN USING syntax.

The last step is to use coalesce function:

coalesce(e: Column*): Column Returns the first column that is not null, or null if all inputs are null.

That looks like your case exactly and avoids dealing with 300+ columns.

```<code>val myCol = coalesce($"df1.one", $"df2.one") as "one"
df1.join(df2, "PERIOD_TAG", "inner").
  select(myCol).
  show
</code>```

So, the exercise is to build myCol-like sequence of columns using coalesce function for every column in the schema (which looks like a fairly easy programming assignment :))

Body:
I have a dataframe named "A" with 300+ columns in it and i am trying to join the dataframe named "A" with its incremental data "B" with same schema as "A".

After joining the dataframes, i am getting duplicate columns. That i was avoiding by using co

val toPrint = udf((value1: String, value2: String) => if(value1 != null) {value1} else value2)
val dfClean = df1.join(df2, df1("PERIOD_TAG") === df2("PERIOD_TAG"), "fullouter").select(toPrint(df1("PERIOD_SHORT_DESCRIPTION"),df2("PERIOD_SHORT_DESCRIPTION")).alias("PERIOD_SHORT_DESCRIPTION"),toPrint(df1("PERIOD_TAG"),df2("PERIOD_TAG")).alias("PERIOD_TAG"))....so on for all the columns

I am calling a UDF to select the most updated value(from incremental file) among the duplicate columns.
The incremental data will have few updated data which i need to add along with all new data in incremantal dataframe and also old data of dataframe "B".

Is there any another way to avoid selecting columns individually and use a for loop for it.
Or is there any way that after joining, i get the new/updated value of my incremental df and old values of dataframe "B" which are not present in dataframe "A".

Body:
I'd first avoid the duplication in join column names using single-string usingColumn argument of join operator.

df1.join(df2, "PERIOD_TAG", "fullouter")

That takes care of de-duplicating PERIOD_TAG column.

Different from other join functions, the join column will only appear once in the output, i.e. similar to SQL's JOIN USING syntax.

The last step is to use coalesce function:

coalesce(e: Column*): Column Returns the first column that is not null, or null if all inputs are null.

That looks like your case exactly and avoids dealing with 300+ columns.

val myCol = coalesce($"df1.one", $"df2.one") as "one"
df1.join(df2, "PERIOD_TAG", "inner").
  select(myCol).
  show

So, the exercise is to build myCol-like sequence of columns using coalesce function for every column in the schema (which looks like a fairly easy programming assignment :))


问:
Project Reactor async send email with retry on error
I need to send some data after user registered. I want to do first attempt in main thread, but if there are any errors, I want to retry 5 times with 10 minutes interval.

```<code>@Override
public void sendRegisterInfo(MailData data) {
    Mono.just(data)
        .doOnNext(this::send)
        .doOnError(ex -> logger.warn("Main queue {}", ex.getMessage()))
        .doOnSuccess(d -> logger.info("Send mail to {}", d.getRecipient()))
        .onErrorResume(ex -> retryQueue(data))
        .subscribe();
}

private Mono<MailData> retryQueue(MailData data) {
    return Mono.just(data)
               .delayElement(Duration.of(10, ChronoUnit.MINUTES))
               .doOnNext(this::send)
               .doOnError(ex -> logger.warn("Retry queue {}", ex.getMessage()))
               .doOnSuccess(d -> logger.info("Send mail to {}", d.getRecipient()))
               .retry(5)
               .subscribe();
}
</code>```

It works.
But I've got some questions:

Did I correct to make operation in doOnNext function?

Is it correct to use delayElement to make a delay between executions?

Did the thread blocked when waiting for delay?

And what the best practice to make a retries on error and make a delay between it?

答:
doOnXXX for logging is fine. But for the actual element processing, you must prefer using flatMap rather than doOnNext (assuming your processing is asynchronous / can be converted to returning a Flux/Mono).

This is correct. Another way is to turn the code around and start from a Flux.interval, but here delayElement is better IMO.

The delay runs on a separate thread/scheduler (by default, Schedulers.parallel()), so not blocking the main thread.

There's actually a Retry builder dedicated to that kind of use case in the reactor-extra addon: https://github.com/reactor/reactor-addons/blob/master/reactor-extra/src/main/java/reactor/retry/Retry.java

Body:
I need to send some data after user registered. I want to do first attempt in main thread, but if there are any errors, I want to retry 5 times with 10 minutes interval.

@Override
public void sendRegisterInfo(MailData data) {
    Mono.just(data)
        .doOnNext(this::send)
        .doOnError(ex -> logger.warn("Main queue {}", ex.getMessage()))
        .doOnSuccess(d -> logger.info("Send mail to {}", d.getRecipient()))
        .onErrorResume(ex -> retryQueue(data))
        .subscribe();
}

private Mono<MailData> retryQueue(MailData data) {
    return Mono.just(data)
               .delayElement(Duration.of(10, ChronoUnit.MINUTES))
               .doOnNext(this::send)
               .doOnError(ex -> logger.warn("Retry queue {}", ex.getMessage()))
               .doOnSuccess(d -> logger.info("Send mail to {}", d.getRecipient()))
               .retry(5)
               .subscribe();
}

It works.
But I've got some questions:

Did I correct to make operation in doOnNext function?

Is it correct to use delayElement to make a delay between executions?

Did the thread blocked when waiting for delay?

And what the best practice to make a retries on error and make a delay between it?