问:
Database multithreading with preserved sequence updates on primary key
Having a lot of data to process I was trying to make them parallel.

```<code>class Item{
    Integer id;
    String data;
}

ExecutorService executor = Executors.newFixedThreadPool(10);

for (Item item : items) {
            executor.execute(() -> putItemToDB(item));
        }
</code>```

But the problem that occurs was that in a test case i have first 6 tasks to the same primary key. The order of tasks with the same primary key(id) is important and must not be changed. Currently, I don't have guarantee of that.

Example:

```<code>items = [{id: 1, data: "a"}, {id: 1, data: "b"}, {id: 2, data: "g"}]
</code>```

I have to know that a was before b, and running all tasks in threadpool don't guarantee that. There is possibility, that a will override b.

Is there any good design pattern to solve that problem?

答:
Good design pattern for this use case is to use separate Actor instance for each id. Items are send to the corresponding actor and are kept in order in the input queue. Actor takes next items from the queue and saves in the database.
To find an actor for the key, a HashMap can be used.

If there are too many different ids and so too many actors, actor can check that if its input queue is empty for some time, then deregister itself from the HashMap.

Also such an actor can be optimized so that instead of input queue, a variable for single item can be used. If another item arrives when previous item is not yet written in the database, new item simply rewrites over previous item - anyway, writing the old item has no sense, it is going to be overwritten in the database.

A simple actor to start with can be found at https://github.com/akaigoro/CodeSamples/blob/master/src/main/java/actor/simpleactor/SimpleActor.java

Body:
Having a lot of data to process I was trying to make them parallel.

class Item{
    Integer id;
    String data;
}

ExecutorService executor = Executors.newFixedThreadPool(10);

for (Item item : items) {
            executor.execute(() -> putItemToDB(item));
        }

But the problem that occurs was that in a test case i have first 6 tasks to the same primary key. The order of tasks with the same primary key(id) is important and must not be changed. Currently, I don't have guarantee of that.

Example:

items = [{id: 1, data: "a"}, {id: 1, data: "b"}, {id: 2, data: "g"}]

I have to know that a was before b, and running all tasks in threadpool don't guarantee that. There is possibility, that a will override b.

Is there any good design pattern to solve that problem?


来源: stackexchange

问:
start and stop tomcat via command prompt
Im currently using tomcat 6.0.18.  I have installed tomcat server and set the CATALINA_HOME variable in the environment variables. Inside the tomcat installation location under the bin folder, there is no startup.bat or shutdown.bat file available. There are only two exe files: tomcat6.exe & tomcat6w.exe. I would like to know how to start the tomcat server via command prompt.

I tried executing the below command

```<code>C:\Apache Software Foundation\Tomcat6.0\bin>tomcat6.exe start
</code>```

The start command works fine. But I'm unable to stop the server using the command

```<code>C:\Apache Software Foundation\Tomcat6.0\bin>tomcat6.exe stop
</code>```

But the stop command does not stop the server. It only starts the tomcat server.

Both the commands 'tomcat6.exe start' & 'tomcat6.exe stop' starts the tomcat server. I would like to know what options should I use to stop the tomcat server via command prompt.

Any help on this is much appreciated. Thanks in Advance.

答: In your bin directory there is a file called startup which is an executable. Please execute that.</p>

ContentLicense: CC BY-SA 3.0

Body:
Im currently using tomcat 6.0.18.  I have installed tomcat server and set the CATALINA_HOME variable in the environment variables. Inside the tomcat installation location under the bin folder, there is no startup.bat or shutdown.bat file available. There are only two exe files: tomcat6.exe & tomcat6w.exe. I would like to know how to start the tomcat server via command prompt.

I tried executing the below command

C:\Apache Software Foundation\Tomcat6.0\bin>tomcat6.exe start

The start command works fine. But I'm unable to stop the server using the command

C:\Apache Software Foundation\Tomcat6.0\bin>tomcat6.exe stop

But the stop command does not stop the server. It only starts the tomcat server.

Both the commands 'tomcat6.exe start' & 'tomcat6.exe stop' starts the tomcat server. I would like to know what options should I use to stop the tomcat server via command prompt.

Any help on this is much appreciated. Thanks in Advance.


问:
Column length is returning zero when I pass the value i in the xpath using for loop in nodejs webdriver
This is the code to iterate through a dynamic table.

```<code>driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
                        console.log("NoofRowsinthetable" + rows.length);
                        var identifyvalue = "6/16/17 12:41 PM"
                        var datacount = 0;
                        for (var i = 1; i <= rows.length; i++) {
                            driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td`)).then(function (cells) {
                                    console.log("NoofColumnsinthetable" + cells.length);
                                    for (var j = 1; j <= cells.length; j++) {
                                        driver.findElement(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td[j]`)).getText().then(function (cell_text) {
                                            console.log(cell_text);
                                            if (identifyvalue === cell_text) {
                                                datacount = datacount + 1;
                                                console.log("Data count" + datacount);
                                            }
                                        })
</code>```

First Forloop:
Cells.length returns zero even if there are 9 columns.

IF I AM PASSING THE VALUE OF I AS STRING(tr["+i+"]) THEN IT IS RETURNING THE VALUE OF COLUMN.LENGTH OF FIRST ROW ONLY AND IF I DO NOT PASS THE VALUE OF ‘I’ AS STRING THEN IT IS RETURING THE COLUMN.LENGTH AS ZERO.

Second For loop:
IF I AM PASSING THE VALUE OF I AND J AS STRING(tr["+i+"]/td["+j+"]), THEN IT IS RETURNING THE VALUE OF FIRST COLUMN ONLY

答:
The problem is with single quote. you are starting the string with single quote and it should be ended with single. try the following,</p>

```<code>driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
                        console.log("NoofRowsinthetable" + rows.length);
                        var identifyvalue = "6/16/17 12:41 PM"
                        var datacount = 0;
                        for (var i = 1; i <= rows.length; i++) {
                            driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td`)).then(function (cells) {
                                    console.log("NoofColumnsinthetable" + cells.length);
                                    for (var j = 1; j <= cells.length; j++) {
                                        driver.findElement(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td[`+j+`]`)).getText().then(function (cell_text) {
                                            console.log(cell_text);
                                            if (identifyvalue === cell_text) {
                                                datacount = datacount + 1;
                                                console.log("Data count" + datacount);
                                            }
                                        })
</code>```

Body:
This is the code to iterate through a dynamic table.

driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
                        console.log("NoofRowsinthetable" + rows.length);
                        var identifyvalue = "6/16/17 12:41 PM"
                        var datacount = 0;
                        for (var i = 1; i <= rows.length; i++) {
                            driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td`)).then(function (cells) {
                                    console.log("NoofColumnsinthetable" + cells.length);
                                    for (var j = 1; j <= cells.length; j++) {
                                        driver.findElement(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td[j]`)).getText().then(function (cell_text) {
                                            console.log(cell_text);
                                            if (identifyvalue === cell_text) {
                                                datacount = datacount + 1;
                                                console.log("Data count" + datacount);
                                            }
                                        })

First Forloop:
Cells.length returns zero even if there are 9 columns.

IF I AM PASSING THE VALUE OF I AS STRING(tr["+i+"]) THEN IT IS RETURNING THE VALUE OF COLUMN.LENGTH OF FIRST ROW ONLY AND IF I DO NOT PASS THE VALUE OF ‘I’ AS STRING THEN IT IS RETURING THE COLUMN.LENGTH AS ZERO.

Second For loop:
IF I AM PASSING THE VALUE OF I AND J AS STRING(tr["+i+"]/td["+j+"]), THEN IT IS RETURNING THE VALUE OF FIRST COLUMN ONLY

Body:
The problem is with single quote. you are starting the string with single quote and it should be ended with single. try the following,

driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
                        console.log("NoofRowsinthetable" + rows.length);
                        var identifyvalue = "6/16/17 12:41 PM"
                        var datacount = 0;
                        for (var i = 1; i <= rows.length; i++) {
                            driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td`)).then(function (cells) {
                                    console.log("NoofColumnsinthetable" + cells.length);
                                    for (var j = 1; j <= cells.length; j++) {
                                        driver.findElement(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td[`+j+`]`)).getText().then(function (cell_text) {
                                            console.log(cell_text);
                                            if (identifyvalue === cell_text) {
                                                datacount = datacount + 1;
                                                console.log("Data count" + datacount);
                                            }
                                        })


问:
java.sql.SQLSyntaxErrorException: Table 'mydb.alien' doesn't exist
Alien.java(Pojo class),
this is my pojo class

```<code>  package com.me.Hive1;
  import javax.persistence.Entity;
  import javax.persistence.Id;

  @Entity
  public class Alien {
        @Id
        private int id;
        private String name;
        public int getId()
        {
            return id;
        }
        public void setId(int id)
        {
            this.id = id;
        }
        public String getName()
        {
             return name;
        }
        public void setName(String name)
        {
             this.name = name;
        }
     }
</code>```

App.java(Main Class),
this is main class.

```<code>package com.me.Hive1;
            import org.hibernate.Session;
            import org.hibernate.SessionFactory;
            import org.hibernate.Transaction;
            import org.hibernate.cfg.Configuration;
            //MAIN CLASS
            /**
             * Hello world!
             *
             */
            public class App
            {
                public static void main( String[] args )
                {
                    System.out.println( "Hello World!" );
                    Alien a = new Alien();
                    a.setId(101);
                    a.setName("bhanu");
                    try{
                    Configuration fact = new Configuration().configure().addAnnotatedClass(Alien.class);
                    SessionFactory sf = fact.buildSessionFactory();
                    Session session = sf.openSession();
                    Transaction t = session.beginTransaction();
                    session.save(a);
                    t.commit();
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }

                }
            }
</code>```

configuration file(hibernate.cfg.xml),
this is my hibernate configuration file.

```<code><?xml version="1.0" encoding="UTF-8"?><!--Configuration file-->
        <!DOCTYPE hibernate-configuration PUBLIC
                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
        <hibernate-configuration>
            <session-factory>
                <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
                <property name="hibernate.connection.password">root</property>
                <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
                <property name="hibernate.connection.username">root</property>
                <property name="hibernate.hbm2dll.auto">create</property>
                <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
                <mapping class="com.me.Hive1.Alien" resource="Alien.hbm.xml"/>
            </session-factory>
        </hibernate-configuration>
</code>```

Alien.hbm.xml(mapping file) ,
this is mapping file,is it optional ?

```<code><?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated Jul 5, 2017 1:44:20 AM by Hibernate Tools 3.5.0.Final -->
    <hibernate-mapping>
        <class name="com.me.Hive1.Alien" table="alien">
            <id name="id" type="int">
                <column name="ID" />
                <generator class="assigned" />
            </id>
            <property name="name" type="java.lang.String">
                <column name="NAME" />
            </property>
        </class>
    </hibernate-mapping>
</code>```

i am getting exception(Console output) this is the exception i am getting,
don't know i am struck

```<code>    Hello World!
    Jul 05, 2017 4:13:18 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {5.2.10.Final}
    Jul 05, 2017 4:13:18 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    Jul 05, 2017 4:13:19 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/mydb]
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001001: Connection properties: {user=root, password=****}
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001003: Autocommit mode: false
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
    INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
    Wed Jul 05 16:13:19 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
    Jul 05, 2017 4:13:19 PM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 1146, SQLState: 42S02
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: Table 'mydb.alien' doesn't exist
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
    INFO: HHH000010: On release of batch it still contained JDBC statements
    Jul 05, 2017 4:13:24 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
    ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]
    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1441)
        at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:491)
        at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3201)
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2411)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:220)
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
        at com.me.Hive1.App.main(App.java:25)
    Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3003)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3503)
        at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:589)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463)
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1435)
        ... 9 more
    Caused by: java.sql.SQLSyntaxErrorException: Table 'mydb.alien' doesn't exist
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:536)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115)
        at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983)
        at com.mysql.cj.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1826)
        at com.mysql.cj.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2034)
        at com.mysql.cj.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:1970)
        at com.mysql.cj.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5001)
        at com.mysql.cj.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1955)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
        ... 18 more
</code>```

答:
Try this one -

In your configuration file change value of this property:

```<code><property name="hibernate.hbm2ddl.auto" value="update" />
</code>```

Hope this will help you ;)

Body:
Alien.java(Pojo class),
this is my pojo class

  package com.me.Hive1;
  import javax.persistence.Entity;
  import javax.persistence.Id;

  @Entity
  public class Alien {
        @Id
        private int id;
        private String name;
        public int getId()
        {
            return id;
        }
        public void setId(int id)
        {
            this.id = id;
        }
        public String getName()
        {
             return name;
        }
        public void setName(String name)
        {
             this.name = name;
        }
     }

App.java(Main Class),
this is main class.

package com.me.Hive1;
            import org.hibernate.Session;
            import org.hibernate.SessionFactory;
            import org.hibernate.Transaction;
            import org.hibernate.cfg.Configuration;
            //MAIN CLASS
            /**
             * Hello world!
             *
             */
            public class App
            {
                public static void main( String[] args )
                {
                    System.out.println( "Hello World!" );
                    Alien a = new Alien();
                    a.setId(101);
                    a.setName("bhanu");
                    try{
                    Configuration fact = new Configuration().configure().addAnnotatedClass(Alien.class);
                    SessionFactory sf = fact.buildSessionFactory();
                    Session session = sf.openSession();
                    Transaction t = session.beginTransaction();
                    session.save(a);
                    t.commit();
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }

                }
            }

configuration file(hibernate.cfg.xml),
this is my hibernate configuration file.

<?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE hibernate-configuration PUBLIC
                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
        <hibernate-configuration>
            <session-factory>
                <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
                <property name="hibernate.connection.password">root</property>
                <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
                <property name="hibernate.connection.username">root</property>
                <property name="hibernate.hbm2dll.auto">create</property>
                <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
                <mapping class="com.me.Hive1.Alien" resource="Alien.hbm.xml"/>
            </session-factory>
        </hibernate-configuration>

Alien.hbm.xml(mapping file) ,
this is mapping file,is it optional ?

<?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping>
        <class name="com.me.Hive1.Alien" table="alien">
            <id name="id" type="int">
                <column name="ID" />
                <generator class="assigned" />
            </id>
            <property name="name" type="java.lang.String">
                <column name="NAME" />
            </property>
        </class>
    </hibernate-mapping>

i am getting exception(Console output) this is the exception i am getting,
don't know i am struck

    Hello World!
    Jul 05, 2017 4:13:18 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {5.2.10.Final}
    Jul 05, 2017 4:13:18 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    Jul 05, 2017 4:13:19 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/mydb]
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001001: Connection properties: {user=root, password=****}
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001003: Autocommit mode: false
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
    INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
    Wed Jul 05 16:13:19 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
    Jul 05, 2017 4:13:19 PM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 1146, SQLState: 42S02
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: Table 'mydb.alien' doesn't exist
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
    INFO: HHH000010: On release of batch it still contained JDBC statements
    Jul 05, 2017 4:13:24 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
    ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]
    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1441)
        at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:491)
        at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3201)
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2411)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:220)
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
        at com.me.Hive1.App.main(App.java:25)
    Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3003)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3503)
        at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:589)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463)
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1435)
        ... 9 more
    Caused by: java.sql.SQLSyntaxErrorException: Table 'mydb.alien' doesn't exist
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:536)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115)
        at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983)
        at com.mysql.cj.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1826)
        at com.mysql.cj.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2034)
        at com.mysql.cj.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:1970)
        at com.mysql.cj.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5001)
        at com.mysql.cj.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1955)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
        ... 18 more

Body:
Try this one -

In your configuration file change value of this property:

<property name="hibernate.hbm2ddl.auto" value="update" />

Hope this will help you ;)


问:
Node-red custom node, How to use the node property?
I am trying to create custom node, I am experimenting with very simple one. I need to use the node's property, the value chosen by the user from a dropdown, to send/output the value of that property with msg.payload.

This is the error msg in the debug tab:

```<code>4/7/2017 21.45.06node: lolo
msg : error
"ReferenceError: $ is not defined"
</code>```

This is the desired output:

"ppp[lolo:m2]"

I remove the line with $ in js file, because it does not recognize jQuery. I use this instead

```<code>msg.payload = msg.payload +"[" + nodeName+":"+ node.axis +"]";
</code>```

but in output the option value is undefined instead of value of one of the options from select dropdown:

```<code>5/7/2017 11.34.22node: 5aa4aa59.f9fa04
msg.payload : string[19]
"ppp[lolo:undefined]"
</code>```

This is the html file for the node:

```
</div>
</div>
</p>

<p>This is the js file for the node:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>module.exports = function(RED) {
    function helloWorld(config) {
        RED.nodes.createNode(this,config);
        //var context = this.context();
  var nodeName = this.name;
  var axis = config.axis;
        var node = this;
  //var $ = require('jQuery');
  var x = $("#node-input-axis").val();
        this.on('input', function(msg) {
   msg.payload = msg.payload +"[" + nodeName+":"+ x +"]";
   //{payload: nodeName+" "+node.axis};
   node.send(msg);
        });
  //console.log(value);
    }
    RED.nodes.registerType("Hello World",helloWorld);
};</code>```

答:
It is important to remember that the 2 separate parts of a Node-RED node run in very different locations:

The .js file runs on the backend server side of Node-RED

The .html file runs in the web browser that is accessing the Node-RED Editor on the users client machine.

This means that the .js file has no direct access to the fields in the editor configuration window and also there is no access to jquery ($) notation.

When a flow is deployed all the configuration variables are passed to the backend in the config variable. You have already accessed that value in:

```<code>var axis = config.axis;
</code>```

so rather than the var x = $("#node-input-axis").val(); you can just use the axis variable.

You can't use node.axis because you have not bound config.axis to either this.axis or node.axis before trying to use it

e.g.:

```<code>module.exports = function(RED) {
    function helloWorld(config) {
        RED.nodes.createNode(this,config);
        //var context = this.context();
        var nodeName = this.name;
        this.axis = config.axis;
        var node = this;

        this.on('input', function(msg) {
            msg.payload = msg.payload +"[" + nodeName+":"+ node.axis +"]";
            //{payload: nodeName+" "+ node.axis};
            node.send(msg);
        });
        //console.log(value);
    }
    RED.nodes.registerType("Hello World",helloWorld);
};
</code>```

Body:
I am trying to create custom node, I am experimenting with very simple one. I need to use the node's property, the value chosen by the user from a dropdown, to send/output the value of that property with msg.payload.

This is the error msg in the debug tab:

4/7/2017 21.45.06node: lolo
msg : error
"ReferenceError: $ is not defined"

This is the desired output:

"ppp[lolo:m2]"

I remove the line with $ in js file, because it does not recognize jQuery. I use this instead

msg.payload = msg.payload +"[" + nodeName+":"+ node.axis +"]";

but in output the option value is undefined instead of value of one of the options from select dropdown:

5/7/2017 11.34.22node: 5aa4aa59.f9fa04
msg.payload : string[19]
"ppp[lolo:undefined]"

This is the html file for the node:

This is the js file for the node:

module.exports = function(RED) {
    function helloWorld(config) {
        RED.nodes.createNode(this,config);
        //var context = this.context();
  var nodeName = this.name;
  var axis = config.axis;
        var node = this;
  //var $ = require('jQuery');
  var x = $("#node-input-axis").val();
        this.on('input', function(msg) {
   msg.payload = msg.payload +"[" + nodeName+":"+ x +"]";
   //{payload: nodeName+" "+node.axis};
   node.send(msg);
        });
  //console.log(value);
    }
    RED.nodes.registerType("Hello World",helloWorld);
};

Body:
It is important to remember that the 2 separate parts of a Node-RED node run in very different locations:

The .js file runs on the backend server side of Node-RED

The .html file runs in the web browser that is accessing the Node-RED Editor on the users client machine.

This means that the .js file has no direct access to the fields in the editor configuration window and also there is no access to jquery ($) notation.

When a flow is deployed all the configuration variables are passed to the backend in the config variable. You have already accessed that value in:

var axis = config.axis;

so rather than the var x = $("#node-input-axis").val(); you can just use the axis variable.

You can't use node.axis because you have not bound config.axis to either this.axis or node.axis before trying to use it

e.g.:

module.exports = function(RED) {
    function helloWorld(config) {
        RED.nodes.createNode(this,config);
        //var context = this.context();
        var nodeName = this.name;
        this.axis = config.axis;
        var node = this;

        this.on('input', function(msg) {
            msg.payload = msg.payload +"[" + nodeName+":"+ node.axis +"]";
            //{payload: nodeName+" "+ node.axis};
            node.send(msg);
        });
        //console.log(value);
    }
    RED.nodes.registerType("Hello World",helloWorld);
};


问:
transforming a matrix in R by
I want to make a new matrix B from a previous matrix A, where the length of rows and columns are the same in B and every position corresponds to a ranking of A.
In particular, for any x of a location [i,j] in A, I want to find how many values are greater than [i,j] (which sum(A>x), which I can find when x is discrete, but not for any x), followed by division by the total number of observations*variables in the matrix A.
I think using the apply function would be able to create matrix B as I wish, but I'm having trouble finding a way to apply use of "sum" for each position (i.e., sum(A>x)/# of positions in A.
I think I could use apply(A, c(1,2), FUN(X...)), but I do not know what function I can use.
Thanks for any suggestions.</p>

答:
Short version:  matrix((length(M) - rank(M))/length(M), nrow=nrow(M), ncol=ncol(M))

Long version:

length(M) will give you the number of elements in the matrix.

length(M) - rank(M) will give the number of elements greater than each element.

So you want (length(M) - rank(M)) / length(M)   but formatted into a matrix like M, so

```<code>matrix((length(M) - rank(M))/length(M), nrow=nrow(M), ncol=ncol(M))
</code>```

Title: transforming a matrix in R by

Body:
Short version:  matrix((length(M) - rank(M))/length(M), nrow=nrow(M), ncol=ncol(M))

Long version:

length(M) will give you the number of elements in the matrix.

length(M) - rank(M) will give the number of elements greater than each element.

So you want (length(M) - rank(M)) / length(M)   but formatted into a matrix like M, so

matrix((length(M) - rank(M))/length(M), nrow=nrow(M), ncol=ncol(M))


问:
Android custom circular ProgressBar direction
I have a custom Circular Progressbar. This is the drawable I have for it to be determinate:

```<code><?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/secondaryProgress">
    <shape
        android:innerRadiusRatio="6"
        android:shape="ring"
        android:thicknessRatio="20.0"
        android:useLevel="true">
     <gradient
          android:centerColor="#999999"
          android:endColor="#999999"
          android:startColor="#999999"
          android:type="sweep" />
    </shape>
  </item>
  <item android:id="@android:id/progress">
   <rotate
      android:fromDegrees="270"
      android:pivotX="50%"
      android:pivotY="50%"
      android:toDegrees="270">

  <shape
      android:innerRadiusRatio="6"
      android:shape="ring"
      android:thicknessRatio="20.0"
      android:useLevel="true">

    <rotate
        android:fromDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="0" />

    <gradient
        android:centerColor="?attr/colorAccent"
        android:endColor="?attr/colorAccent"
        android:startColor="?attr/colorAccent"
        android:type="sweep" />

      </shape>
    </rotate>
  </item>
</layer-list>
</code>```

I want it to show the progress in a clockwise direction, but now it's showing counterclockwise.

How do I change it?

答:
I'm not sure if it will work, but just try to set android:toDegrees="-360" like this :

```<code><rotate
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="-360" />
</code>```

Body:
I have a custom Circular Progressbar. This is the drawable I have for it to be determinate:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/secondaryProgress">
    <shape
        android:innerRadiusRatio="6"
        android:shape="ring"
        android:thicknessRatio="20.0"
        android:useLevel="true">
     <gradient
          android:centerColor="#999999"
          android:endColor="#999999"
          android:startColor="#999999"
          android:type="sweep" />
    </shape>
  </item>
  <item android:id="@android:id/progress">
   <rotate
      android:fromDegrees="270"
      android:pivotX="50%"
      android:pivotY="50%"
      android:toDegrees="270">

  <shape
      android:innerRadiusRatio="6"
      android:shape="ring"
      android:thicknessRatio="20.0"
      android:useLevel="true">

    <rotate
        android:fromDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="0" />

    <gradient
        android:centerColor="?attr/colorAccent"
        android:endColor="?attr/colorAccent"
        android:startColor="?attr/colorAccent"
        android:type="sweep" />

      </shape>
    </rotate>
  </item>
</layer-list>

I want it to show the progress in a clockwise direction, but now it's showing counterclockwise.

How do I change it?

Body:
I'm not sure if it will work, but just try to set android:toDegrees="-360" like this :

<rotate
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="-360" />


问:
Service worker should not cache the whole page
I register '/' (route) .css and .js file as URL that should be cached at first.

But after that I realize that it cached the whole page, which means I don't see any update on my view, event there is an update on database.

So I change it only cache my .css and .js file not route ('/') anymore , I expected that's the problem.

But after awhile, the same problem still occurred. I check on my console it did cache the whole page again, even though my Service Worker file already change like this:

```<code>var CACHE_NAME = 'cache-v2';
var urlsToCache = [
  '/assets/css/app.css',
  '/assets/js/main.js',
  '/assets/js/other.js'
];

self.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        console.log('Opened cache');
        return cache.addAll(urlsToCache);
      })
  );
});

self.addEventListener('activate', function(e) {
  console.log('[ServiceWorker] Activate');
  e.waitUntil(
    caches.keys().then(function(keyList) {
      return Promise.all(keyList.map(function(key) {
        if (key !== CACHE_NAME) {
          console.log('[ServiceWorker] Removing old cache', key);
          return caches.delete(key);
        }
      }));
    })
  );
  return self.clients.claim();
});

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        // Cache hit - return response
        if (response) {
          return response;
        }

        var fetchRequest = event.request.clone();

        return fetch(fetchRequest).then(
          function(response) {

            if(!response || response.status !== 200 || response.type !== 'basic') {
              return response;
            }

            var responseToCache = response.clone();

            caches.open(CACHE_NAME)
              .then(function(cache) {
                cache.put(event.request, responseToCache);
              });

            return response;
          }
        );
      })
    );
});
</code>```

答:
in case anyone has the same problem,
here is what i should change

```<code>self.addEventListener('fetch', function(e) {
  console.log('[ServiceWorker] Fetch', e.request.url);
  e.respondWith(
    caches.match(e.request).then(function(response) {
      return response || fetch(e.request);
    })
  );
});
</code>```

so my previous fetch looks like the problem

Body:
I register '/' (route) .css and .js file as URL that should be cached at first.

But after that I realize that it cached the whole page, which means I don't see any update on my view, event there is an update on database.

So I change it only cache my .css and .js file not route ('/') anymore , I expected that's the problem.

But after awhile, the same problem still occurred. I check on my console it did cache the whole page again, even though my Service Worker file already change like this:

var CACHE_NAME = 'cache-v2';
var urlsToCache = [
  '/assets/css/app.css',
  '/assets/js/main.js',
  '/assets/js/other.js'
];

self.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        console.log('Opened cache');
        return cache.addAll(urlsToCache);
      })
  );
});

self.addEventListener('activate', function(e) {
  console.log('[ServiceWorker] Activate');
  e.waitUntil(
    caches.keys().then(function(keyList) {
      return Promise.all(keyList.map(function(key) {
        if (key !== CACHE_NAME) {
          console.log('[ServiceWorker] Removing old cache', key);
          return caches.delete(key);
        }
      }));
    })
  );
  return self.clients.claim();
});

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        // Cache hit - return response
        if (response) {
          return response;
        }

        var fetchRequest = event.request.clone();

        return fetch(fetchRequest).then(
          function(response) {

            if(!response || response.status !== 200 || response.type !== 'basic') {
              return response;
            }

            var responseToCache = response.clone();

            caches.open(CACHE_NAME)
              .then(function(cache) {
                cache.put(event.request, responseToCache);
              });

            return response;
          }
        );
      })
    );
});

Body:
in case anyone has the same problem,
here is what i should change

self.addEventListener('fetch', function(e) {
  console.log('[ServiceWorker] Fetch', e.request.url);
  e.respondWith(
    caches.match(e.request).then(function(response) {
      return response || fetch(e.request);
    })
  );
});

so my previous fetch looks like the problem


问:
Spark OutOfMemoryError
I am experiencing OOME when I try to submit a spark job that sends a message to kafka - it sends the message to Kafka (675 bytes) - the error only shows when the executor is about to shut down.

```<code>Diagnostics: Failing this attempt. Failing the application.
  ApplicationMaster host: N/A
  ApplicationMaster RPC port: -1
  start time: 1441611385047
  final status: FAILED
</code>```

Here's the yarn logs:

(1):

```<code>INFO cluster.YarnClusterSchedulerBackend: Asking each executor to shut down
WARN thread.QueuedThreadPool: 7 threads could not be stopped
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-12"
Exception in thread "Thread-3"
</code>```

(2):

```<code>Exception in thread "shuffle-client-4" Exception in thread "shuffle-server-7"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "shuffle-client-4"
</code>```

(3):

```<code>INFO cluster.YarnClusterSchedulerBackend: Asking each executor to shut down
Exception in thread "LeaseRenewer:user@dom"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "LeaseRenewer:user@dom"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-akka.actor.default-dispatcher-16"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-akka.remote.default-remote-dispatcher-6"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-akka.remote.default-remote-dispatcher-5"
Exception in thread "Thread-3"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-3"
</code>```

On rare instances it shows as SUCCEEDED but the YARN logs still have the OOME:

```<code>INFO cluster.YarnClusterSchedulerBackend: Asking each executor to shut down
INFO scheduler.OutputCommitCoordinator$OutputCommitCoordinatorActor: OutputCommitCoordinator stopped!
INFO spark.MapOutputTrackerMasterActor: MapOutputTrackerActor stopped!
INFO storage.MemoryStore: MemoryStore cleared
INFO storage.BlockManager: BlockManager stopped
INFO storage.BlockManagerMaster: BlockManagerMaster stopped
INFO spark.SparkContext: Successfully stopped SparkContext
INFO remote.RemoteActorRefProvider$RemotingTerminator: Shutting down remote daemon.
INFO yarn.ApplicationMaster: Unregistering ApplicationMaster with SUCCEEDED
INFO remote.RemoteActorRefProvider$RemotingTerminator: Remote daemon shut down; proceeding with flushing remote transports.
Exception in thread "Thread-3"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-3"
</code>```

答: Have you tried increasing MaxPermSize like this?

Title: Spark OutOfMemoryError

Body:
I am experiencing OOME when I try to submit a spark job that sends a message to kafka - it sends the message to Kafka (675 bytes) - the error only shows when the executor is about to shut down.

Diagnostics: Failing this attempt. Failing the application.
  ApplicationMaster host: N/A
  ApplicationMaster RPC port: -1
  start time: 1441611385047
  final status: FAILED

Here's the yarn logs:

(1):

INFO cluster.YarnClusterSchedulerBackend: Asking each executor to shut down
WARN thread.QueuedThreadPool: 7 threads could not be stopped
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-12"
Exception in thread "Thread-3"

(2):

Exception in thread "shuffle-client-4" Exception in thread "shuffle-server-7"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "shuffle-client-4"

(3):

INFO cluster.YarnClusterSchedulerBackend: Asking each executor to shut down
Exception in thread "LeaseRenewer:user@dom"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "LeaseRenewer:user@dom"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-akka.actor.default-dispatcher-16"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-akka.remote.default-remote-dispatcher-6"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "sparkDriver-akka.remote.default-remote-dispatcher-5"
Exception in thread "Thread-3"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-3"

On rare instances it shows as SUCCEEDED but the YARN logs still have the OOME:

INFO cluster.YarnClusterSchedulerBackend: Asking each executor to shut down
INFO scheduler.OutputCommitCoordinator$OutputCommitCoordinatorActor: OutputCommitCoordinator stopped!
INFO spark.MapOutputTrackerMasterActor: MapOutputTrackerActor stopped!
INFO storage.MemoryStore: MemoryStore cleared
INFO storage.BlockManager: BlockManager stopped
INFO storage.BlockManagerMaster: BlockManagerMaster stopped
INFO spark.SparkContext: Successfully stopped SparkContext
INFO remote.RemoteActorRefProvider$RemotingTerminator: Shutting down remote daemon.
INFO yarn.ApplicationMaster: Unregistering ApplicationMaster with SUCCEEDED
INFO remote.RemoteActorRefProvider$RemotingTerminator: Remote daemon shut down; proceeding with flushing remote transports.
Exception in thread "Thread-3"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-3"


问:
SQL Server Conversion Failure when using INSERT
I have an existing table full of data, which can be created using

```<code>CREATE TABLE __EpisodeCost
(
    ActivityRecordID INT NOT NULL,
    ActCstID NVARCHAR(15),
    VolAmt FLOAT,
    ActCnt FLOAT,
    TotCst FLOAT,
    ResCstID NVARCHAR(50)
);
</code>```

This comes from a feed I have no control over and I want to convert this to my own version called EpisodeCost

```<code>CREATE TABLE EpisodeCostCtp
(
    ActivityRecordID INT NOT NULL,
    ActCstID NVARCHAR(6),
    ResCstID NVARCHAR(7),
    ActCnt NVARCHAR(7),
    TotCst DECIMAL(18, 8)
);
</code>```

Now, the problem I am having is with conversions. I can execute the query

```<code>SELECT
    ActivityRecordID,
    Cast(ActCstID AS NVARCHAR(6)),
    Cast(ResCstID AS NVARCHAR(7)),
    Cast(LTRIM(STR(ActCnt, 10)) AS NVARCHAR(7)),
    Cast(TotCst AS DECIMAL(18, 8))
FROM __EpisodeCostCtp;
</code>```

and it provides data, however, when I try to execute

```<code>INSERT INTO EpisodeCostCtp
    (
        ActivityRecordID,
        ActCstID,
        ResCstID,
        ActCnt,
        TotCst
    )
SELECT
    ActivityRecordID,
    Cast(ActCstID AS NVARCHAR(6)),
    Cast(ResCstID AS NVARCHAR(7)),
    Cast(LTRIM(STR(ActCnt, 10)) AS NVARCHAR(7)),
    Cast(TotCst AS DECIMAL(18, 8))
FROM __EpisodeCostCtp;
</code>```

I get

Msg 8115, Level 16, State 8, Line 102
  Arithmetic overflow error converting numeric to data type numeric.
  The statement has been terminated.

Why can I SELECT using the relevant casts, but then cannot INSERT into the target table?

Edit. I still don;t fully know what is occurring here.

As per Serg's recommendations, I have attempted to locate the problematic records but the query

```<code>SELECT
    ActivityRecordID,
    Cast(ActCstID AS NVARCHAR(6)),
    Cast(ResCstID AS NVARCHAR(7)),
    Cast(LTRIM(STR(ActCnt, 10)) AS NVARCHAR(7)),
    Cast(TotCst AS DECIMAL(18, 8))
FROM __EpisodeCostCtp
WHERE TotCst > 9.999999999999999e9;
</code>```

returns zero records. Changing to 9.999999999999999e8 does, and the conversion/cast happens with out error. I have scince changed the INSERT query to use DECIMAL(36, 18) and now the insert succeeds, but I am still none the wiser. Clearly I was hitting a limit on the cast, but why SELECT works and INSERT fails, I still don't know.

答:
as is an overflow issue you might want to try

```<code>SET ARITHABORT OFF
</code>```

from https://learn.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql

When an INSERT statement encounters an arithmetic error (overflow,
  divide by zero, or a domain error) occurring during expression
  evaluation, the Database Engine handles these errors as if SET
  ARITHABORT is set to ON. The batch is stopped, and an error message is
  returned. During expression evaluation when SET ARITHABORT and SET
  ANSI_WARNINGS are OFF, if an INSERT, DELETE or UPDATE statement
  encounters an arithmetic error, overflow, divide-by-zero, or a domain
  error, SQL Server inserts or updates a NULL value. If the target
  column is not nullable, the insert or update action fails and the user
  receives an error.

Body:
I have an existing table full of data, which can be created using

CREATE TABLE __EpisodeCost
(
    ActivityRecordID INT NOT NULL,
    ActCstID NVARCHAR(15),
    VolAmt FLOAT,
    ActCnt FLOAT,
    TotCst FLOAT,
    ResCstID NVARCHAR(50)
);

This comes from a feed I have no control over and I want to convert this to my own version called EpisodeCost

CREATE TABLE EpisodeCostCtp
(
    ActivityRecordID INT NOT NULL,
    ActCstID NVARCHAR(6),
    ResCstID NVARCHAR(7),
    ActCnt NVARCHAR(7),
    TotCst DECIMAL(18, 8)
);

Now, the problem I am having is with conversions. I can execute the query

SELECT
    ActivityRecordID,
    Cast(ActCstID AS NVARCHAR(6)),
    Cast(ResCstID AS NVARCHAR(7)),
    Cast(LTRIM(STR(ActCnt, 10)) AS NVARCHAR(7)),
    Cast(TotCst AS DECIMAL(18, 8))
FROM __EpisodeCostCtp;

and it provides data, however, when I try to execute

INSERT INTO EpisodeCostCtp
    (
        ActivityRecordID,
        ActCstID,
        ResCstID,
        ActCnt,
        TotCst
    )
SELECT
    ActivityRecordID,
    Cast(ActCstID AS NVARCHAR(6)),
    Cast(ResCstID AS NVARCHAR(7)),
    Cast(LTRIM(STR(ActCnt, 10)) AS NVARCHAR(7)),
    Cast(TotCst AS DECIMAL(18, 8))
FROM __EpisodeCostCtp;

I get

Msg 8115, Level 16, State 8, Line 102
  Arithmetic overflow error converting numeric to data type numeric.
  The statement has been terminated.

Why can I SELECT using the relevant casts, but then cannot INSERT into the target table?

Edit. I still don;t fully know what is occurring here.

As per Serg's recommendations, I have attempted to locate the problematic records but the query

SELECT
    ActivityRecordID,
    Cast(ActCstID AS NVARCHAR(6)),
    Cast(ResCstID AS NVARCHAR(7)),
    Cast(LTRIM(STR(ActCnt, 10)) AS NVARCHAR(7)),
    Cast(TotCst AS DECIMAL(18, 8))
FROM __EpisodeCostCtp
WHERE TotCst > 9.999999999999999e9;

returns zero records. Changing to 9.999999999999999e8 does, and the conversion/cast happens with out error. I have scince changed the INSERT query to use DECIMAL(36, 18) and now the insert succeeds, but I am still none the wiser. Clearly I was hitting a limit on the cast, but why SELECT works and INSERT fails, I still don't know.

Body:
as is an overflow issue you might want to try

SET ARITHABORT OFF

from https://learn.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql

When an INSERT statement encounters an arithmetic error (overflow,
  divide by zero, or a domain error) occurring during expression
  evaluation, the Database Engine handles these errors as if SET
  ARITHABORT is set to ON. The batch is stopped, and an error message is
  returned. During expression evaluation when SET ARITHABORT and SET
  ANSI_WARNINGS are OFF, if an INSERT, DELETE or UPDATE statement
  encounters an arithmetic error, overflow, divide-by-zero, or a domain
  error, SQL Server inserts or updates a NULL value. If the target
  column is not nullable, the insert or update action fails and the user
  receives an error.


问:
C# winForm Search form
Please I have a project and on one form is the database search parameters where SELECT username, password etc from databasename where value1= '"+text.text+"' etc and I need to pass the results into other text boxes in another form, how can I do this

This is the search form design:

This is the form where i what to display the result of search form:

This is the code i used in form 1

```<code>con.Open();
cmd = new SqlCommand("SELECT  surname, firstname, Sex, phone, address, dob, nameofdoctor, doctorsreport, diagnosis, drugsprescribed  FROM dbo.patient WHERE cardnumber='" + textBox1.Text + "' and dateofadmission='" + dateTimePicker1.Text + "' and dateofdischarge='" + dateTimePicker1.Text + "'", con);
sda = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
DataTable ds = new DataTable();
sda.Fill(ds);
Records rec = new Records(value, value1, value2, value3, value4, value5, value6, value7, value8, value9);
rec.ShowDialog();
</code>```

答:
first of all, you probalby shouldnt construct your sql statement that way, its very prone to sql injections, try using Sql Parameters (https://www.dotnetperls.com/sqlparameter)

for the main part of your question, you need a reference to that form and a method wich allows to set the textbox, consider you have formA where the sql statement is executed and formB where the textbox textboxB resides (the one you want to set), you will need to implement a public setter for the textbox on formB like

```<code>        public void SetTextboxB(string txt)
    {
        textboxB.Text = txt;
    }
</code>```

now you can call formB.SetTextboxB("your desired text")

if you´re unsure where to pass the forms reference you cann always use Application.OpenForms (https://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms.aspx) to find formB in formA

considering formB is already running

```<code>var b = (Application.OpenForms["formB"] as formB)
b.SetTextboxB("Desired Text");
</code>```

Title: C# winForm Search form

Body:
Please I have a project and on one form is the database search parameters where SELECT username, password etc from databasename where value1= '"+text.text+"' etc and I need to pass the results into other text boxes in another form, how can I do this

This is the search form design:

This is the form where i what to display the result of search form:

This is the code i used in form 1

con.Open();
cmd = new SqlCommand("SELECT  surname, firstname, Sex, phone, address, dob, nameofdoctor, doctorsreport, diagnosis, drugsprescribed  FROM dbo.patient WHERE cardnumber='" + textBox1.Text + "' and dateofadmission='" + dateTimePicker1.Text + "' and dateofdischarge='" + dateTimePicker1.Text + "'", con);
sda = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
DataTable ds = new DataTable();
sda.Fill(ds);
Records rec = new Records(value, value1, value2, value3, value4, value5, value6, value7, value8, value9);
rec.ShowDialog();

Body:
first of all, you probalby shouldnt construct your sql statement that way, its very prone to sql injections, try using Sql Parameters (https://www.dotnetperls.com/sqlparameter)

for the main part of your question, you need a reference to that form and a method wich allows to set the textbox, consider you have formA where the sql statement is executed and formB where the textbox textboxB resides (the one you want to set), you will need to implement a public setter for the textbox on formB like

        public void SetTextboxB(string txt)
    {
        textboxB.Text = txt;
    }

now you can call formB.SetTextboxB("your desired text")

if you´re unsure where to pass the forms reference you cann always use Application.OpenForms (https://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms.aspx) to find formB in formA

considering formB is already running

var b = (Application.OpenForms["formB"] as formB)
b.SetTextboxB("Desired Text");


问:
How to upload file by PHP cURL using ftp connection?
I am using this script to upload myfile by curl function and ftp connection.

In local it works fine but in my server file is appeared uploaded but it have zero file size.

what is wrong? Thank You.

```<code>$ch = curl_init();
$localfile = (dirname(__FILE__).'/asset/myfile.zip');
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, "ftp://$user_name:$user_pass@$server/".'myfile.zip');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
curl_close ($ch);
</code>```

and also how can I upload multiple files in this script like:

```<code>$localfile1 = (dirname(__FILE__).'/asset/myfile1.zip');
$localfile2 = (dirname(__FILE__).'/asset/myfile2.zip');
$localfile3 = (dirname(__FILE__).'/asset/myfile3.zip');
</code>```

答:
This source may helps your problem.

http://www.web-development-blog.com/archives/tutorial-ftp-upload-via-curl/

Body:
I am using this script to upload myfile by curl function and ftp connection.

In local it works fine but in my server file is appeared uploaded but it have zero file size.

what is wrong? Thank You.

$ch = curl_init();
$localfile = (dirname(__FILE__).'/asset/myfile.zip');
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, "ftp://$user_name:$user_pass@$server/".'myfile.zip');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
curl_close ($ch);

and also how can I upload multiple files in this script like:

$localfile1 = (dirname(__FILE__).'/asset/myfile1.zip');
$localfile2 = (dirname(__FILE__).'/asset/myfile2.zip');
$localfile3 = (dirname(__FILE__).'/asset/myfile3.zip');


问:
PHP function refresh page after execute (Go back to div)
I have got 2 pages:

```<code>Fun.php
Class.fun.php
</code>```

In class.fun.php I got functions, for example, select posts/upvote post/downvote post.

In Fun.php I'm displaying all posts (Like facebook posts) : Image

When I upvote/downvote post, it calls function in class.fun.php and refreshes page, but goes back to top. : Image

But I want page to stay or go back to same post, where I clicked upvote , so I could scroll forward.

My Upvote function:

```<code>public function upvotePost(){
    try
    {

        if(isset($_SESSION['user_session'])){
            $user_id = $_SESSION['user_session'];

            $stmt = $this->runQuery("SELECT * FROM users WHERE id=:id");
            $stmt->execute(array(":id"=>$user_id));

            $myRow=$stmt->fetch(PDO::FETCH_ASSOC);

        }

        $id = $_GET['image_id'];
        $user_id = $myRow['id'];

        $stmt2 = $this->conn->prepare("SELECT count(*) FROM fun_post_upvotes WHERE image_id=('$id') AND user_id=('$user_id')");
        $stmt2->execute();
        $result2 = $stmt2->fetchColumn();

        if($result2 == 0){

            $stmt3 = $this->conn->prepare("INSERT INTO fun_post_upvotes (image_id,user_id) VALUES(:image_id,:user_id)");

            $stmt3->bindparam(":image_id", $id);
            $stmt3->bindparam(":user_id", $user_id);

            $stmt3->execute();

            $stmt4 = $this->conn->prepare("SELECT * FROM fun_posts WHERE id=('$id')");
            $stmt4->execute();
            $result4 = $stmt4->fetchAll();

            foreach($result4 as $post){
                $newUpvotes = $post['upvotes']+1;

                $stmt5 = $this->conn->prepare("UPDATE fun_posts SET upvotes=$newUpvotes WHERE id=('$id')");
                $stmt5->execute();

                $_SESSION["result"]='You have succesfully liked this post!';

            }
            }else{

            $_SESSION["error"]='You have already liked this post!';

            }

            $stmt6 = $this->conn->prepare("SELECT count(*) FROM fun_post_downvotes WHERE image_id=('$id') AND user_id=('$user_id')");
            $stmt6->execute();
            $result6 = $stmt6->fetchColumn();

            if($result6 > 0){
                $stmt7 = $this->conn->prepare("DELETE FROM fun_post_downvotes WHERE image_id=('$id') AND user_id=('$user_id')");
                $stmt7->execute();

                $stmt8 = $this->conn->prepare("SELECT * FROM fun_posts WHERE id=('$id')");
                $stmt8->execute();
                $result8 = $stmt8->fetchAll();

                foreach($result8 as $post){

                    $newDownvotes = $post['downvotes'] - 1;

                    $stmt9 = $this->conn->prepare("UPDATE fun_posts SET downvotes=$newDownvotes WHERE id=('$id')");
                    $stmt9->execute();

                }
            }
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
}
</code>```

答:
Take a look at HTML anchors for a very simple solution, assuming you are using a hyperlink for voting.
You would need the container of each post to have it's own unique ID attribute, which you then refer to in your upvote/downvote href attribute, creating an anchor which the browser will jump to. See https://www.w3schools.com/html/html_links.asp
For example -

```<code><div id="post_1">
    Post content is here
    <a href="yoururl.com/posts#post_1">UPVOTE</a>
    <a href="yoururl.com/posts#post_1">DOWNVOTE</a>
</div>
<div id="post_2">
    Post content is here
    <a href="yoururl.com/posts#post_2">UPVOTE</a>
    <a href="yoururl.com/posts#post_2">DOWNVOTE</a>
</div>
</code>```

Alternatively look into using javascript ajax to post the data without reloading the page and therefore no need to scroll at all. See https://www.w3schools.com/xml/ajax_intro.asp for an introduction, or check out a JS library like jQuery.

Body:
I have got 2 pages:

Fun.php
Class.fun.php

In class.fun.php I got functions, for example, select posts/upvote post/downvote post.

In Fun.php I'm displaying all posts (Like facebook posts) : Image

When I upvote/downvote post, it calls function in class.fun.php and refreshes page, but goes back to top. : Image

But I want page to stay or go back to same post, where I clicked upvote , so I could scroll forward.

My Upvote function:

public function upvotePost(){
    try
    {

        if(isset($_SESSION['user_session'])){
            $user_id = $_SESSION['user_session'];

            $stmt = $this->runQuery("SELECT * FROM users WHERE id=:id");
            $stmt->execute(array(":id"=>$user_id));

            $myRow=$stmt->fetch(PDO::FETCH_ASSOC);

        }

        $id = $_GET['image_id'];
        $user_id = $myRow['id'];

        $stmt2 = $this->conn->prepare("SELECT count(*) FROM fun_post_upvotes WHERE image_id=('$id') AND user_id=('$user_id')");
        $stmt2->execute();
        $result2 = $stmt2->fetchColumn();

        if($result2 == 0){

            $stmt3 = $this->conn->prepare("INSERT INTO fun_post_upvotes (image_id,user_id) VALUES(:image_id,:user_id)");

            $stmt3->bindparam(":image_id", $id);
            $stmt3->bindparam(":user_id", $user_id);

            $stmt3->execute();

            $stmt4 = $this->conn->prepare("SELECT * FROM fun_posts WHERE id=('$id')");
            $stmt4->execute();
            $result4 = $stmt4->fetchAll();

            foreach($result4 as $post){
                $newUpvotes = $post['upvotes']+1;

                $stmt5 = $this->conn->prepare("UPDATE fun_posts SET upvotes=$newUpvotes WHERE id=('$id')");
                $stmt5->execute();

                $_SESSION["result"]='You have succesfully liked this post!';

            }
            }else{

            $_SESSION["error"]='You have already liked this post!';

            }

            $stmt6 = $this->conn->prepare("SELECT count(*) FROM fun_post_downvotes WHERE image_id=('$id') AND user_id=('$user_id')");
            $stmt6->execute();
            $result6 = $stmt6->fetchColumn();

            if($result6 > 0){
                $stmt7 = $this->conn->prepare("DELETE FROM fun_post_downvotes WHERE image_id=('$id') AND user_id=('$user_id')");
                $stmt7->execute();

                $stmt8 = $this->conn->prepare("SELECT * FROM fun_posts WHERE id=('$id')");
                $stmt8->execute();
                $result8 = $stmt8->fetchAll();

                foreach($result8 as $post){

                    $newDownvotes = $post['downvotes'] - 1;

                    $stmt9 = $this->conn->prepare("UPDATE fun_posts SET downvotes=$newDownvotes WHERE id=('$id')");
                    $stmt9->execute();

                }
            }
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
}

Body:
Take a look at HTML anchors for a very simple solution, assuming you are using a hyperlink for voting.
You would need the container of each post to have it's own unique ID attribute, which you then refer to in your upvote/downvote href attribute, creating an anchor which the browser will jump to. See https://www.w3schools.com/html/html_links.asp
For example -

<div id="post_1">
    Post content is here
    <a href="yoururl.com/posts#post_1">UPVOTE</a>
    <a href="yoururl.com/posts#post_1">DOWNVOTE</a>
</div>
<div id="post_2">
    Post content is here
    <a href="yoururl.com/posts#post_2">UPVOTE</a>
    <a href="yoururl.com/posts#post_2">DOWNVOTE</a>
</div>

Alternatively look into using javascript ajax to post the data without reloading the page and therefore no need to scroll at all. See https://www.w3schools.com/xml/ajax_intro.asp for an introduction, or check out a JS library like jQuery.


问:
Training locally with ML Engine & GCloud
I would like to train my model locally using this command:

```<code>gcloud ml-engine local train
  --module-name cloud_runner
  --job-dir ./tmp/output
</code>```

The issue is that it complains that --job-dir: Must be of form gs://bucket/object.

This is a local train so I'm wondering why it wants the output to be a gs storage bucket rather than a local directory.

答:
Local training tries to emulate what happens when you run using the Cloud because the point of local training is to detect problems before submitting your job to the service.

Using a local job-dir when using the CMLE service is an error because the output wouldn't persist after the job finishes.

So local training with gcloud also requires that job-dir be a GCS location.

If you want to run locally and not use GCS you can just run your TensorFlow program directly and not use gcloud.

Body:
I would like to train my model locally using this command:

gcloud ml-engine local train
  --module-name cloud_runner
  --job-dir ./tmp/output

The issue is that it complains that --job-dir: Must be of form gs://bucket/object.

This is a local train so I'm wondering why it wants the output to be a gs storage bucket rather than a local directory.


问:
React Native getInitialState() syntax error (unexpected token)
I can't seem to figure out why this code gives me a syntax/unexpected token error on line 14. Any help would be greatly appreciated.

I'm pretty sure that getInitialState() is set up correctly and not sure why it's throwing an error.

```<code>import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

export default class Test extends Component {
  getInitialState() {
    return {
      test: ''
    };
  },

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          {this.state.test}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

AppRegistry.registerComponent('Test', () => Test);
</code>```

答:
You are mixing ES5 way of writing react components with ES6(ES2015) way of writing react components. Read more about it here https://facebook.github.io/react/docs/react-without-es6.html

To Fix your code, modify as below

```<code>import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

export default class Test extends Component {
  constructor(props) {
    super(props);
    this.state =  {
      test: ''
    };
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          {this.state.test}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

AppRegistry.registerComponent('Test', () => Test);
</code>```

Body:
I can't seem to figure out why this code gives me a syntax/unexpected token error on line 14. Any help would be greatly appreciated.

I'm pretty sure that getInitialState() is set up correctly and not sure why it's throwing an error.

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

export default class Test extends Component {
  getInitialState() {
    return {
      test: ''
    };
  },

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          {this.state.test}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

AppRegistry.registerComponent('Test', () => Test);

Body:
You are mixing ES5 way of writing react components with ES6(ES2015) way of writing react components. Read more about it here https://facebook.github.io/react/docs/react-without-es6.html

To Fix your code, modify as below

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

export default class Test extends Component {
  constructor(props) {
    super(props);
    this.state =  {
      test: ''
    };
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          {this.state.test}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

AppRegistry.registerComponent('Test', () => Test);


问:
How Run A Stored Procedure (with Parameters - Has A return Value) From Code Behind?
How can I use a stored procedure (with parameters - has a return value of type int) from code behind?

My stored procedure looks like this :

```<code>ALTER Procedure [dbo].[sp_Noskheh_SumOfTotalPay]
    @Co_ID int
AS
-----------------
Declare @Sum bigint
-----------------
BEGIN
    SELECT
       @Sum = SUM(TotalPay)
    FROM Noskheh
    WHERE
       (Co_ID = @Co_ID)

    RETURN @Sum
END
</code>```

I want to use @Sum in code behind ...

Would you please show me a way for doing that ?

Thanks in advance

best regards

答: There is no shortage of tutorials on this subject.</p>

Body:
How can I use a stored procedure (with parameters - has a return value of type int) from code behind?

My stored procedure looks like this :

ALTER Procedure [dbo].[sp_Noskheh_SumOfTotalPay]
    @Co_ID int
AS
-----------------
Declare @Sum bigint
-----------------
BEGIN
    SELECT
       @Sum = SUM(TotalPay)
    FROM Noskheh
    WHERE
       (Co_ID = @Co_ID)

    RETURN @Sum
END

I want to use @Sum in code behind ...

Would you please show me a way for doing that ?

Thanks in advance

best regards

ContentLicense: CC BY-SA 2.5


问:
Invalid JPEG data, size 43 error in building part of retraining inceptionv3 of tensorflow for poets
I am trying to train my model of image recognition using tensorflow for poets .
It is getting build for the example case of flower data and generates bottle necks too but when i try to retrain it for another test case (where i made four folders namely Chandler,Darth,Ross,Joey in a folder named tf_files this folder is present in my home)

when i run this command

```<code>python tensorflow/examples/image_retraining/retrain.py \
--bottleneck_dir=/tf_files/bottlenecks \
--how_many_training_steps 500 \
--model_dir=/tf_files/inception \
--output_graph=/tf_files/retrained_graph.pb \
--output_labels=/tf_files/retrained_labels.txt \
--image_dir /tf_files
</code>```

I am getting this error

```<code>InvalidArgumentError (see above for traceback): Invalid JPEG data, size
43[[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3,
dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false,
_device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg
/contents_0)]]
</code>```

and many warning

But when i run the above command just for flower standard example

```<code>python tensorflow/examples/image_retraining/retrain.py \
--bottleneck_dir=/tf_files/bottlenecks \
--how_many_training_steps 500 \
--model_dir=/tf_files/inception \
--output_graph=/tf_files/retrained_graph.pb \
--output_labels=/tf_files/retrained_labels.txt \
--image_dir /flower_photos
</code>```

I am not getting any error .My model gets retrained and i get a prediction

Being very new in this field please guide where i am wrong be its installation mistake or something

答:
The error that you get is because there might be a few images in your dataset that are of png format. On the other hand, the flower dataset has all images of jpeg format.

Also, the retrain.py is written to handle images of jpeg format. You might want to follow this thread to know more about handling png images

Body:
I am trying to train my model of image recognition using tensorflow for poets .
It is getting build for the example case of flower data and generates bottle necks too but when i try to retrain it for another test case (where i made four folders namely Chandler,Darth,Ross,Joey in a folder named tf_files this folder is present in my home)

when i run this command

python tensorflow/examples/image_retraining/retrain.py \
--bottleneck_dir=/tf_files/bottlenecks \
--how_many_training_steps 500 \
--model_dir=/tf_files/inception \
--output_graph=/tf_files/retrained_graph.pb \
--output_labels=/tf_files/retrained_labels.txt \
--image_dir /tf_files

I am getting this error

InvalidArgumentError (see above for traceback): Invalid JPEG data, size
43[[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3,
dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false,
_device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg
/contents_0)]]

and many warning

But when i run the above command just for flower standard example

python tensorflow/examples/image_retraining/retrain.py \
--bottleneck_dir=/tf_files/bottlenecks \
--how_many_training_steps 500 \
--model_dir=/tf_files/inception \
--output_graph=/tf_files/retrained_graph.pb \
--output_labels=/tf_files/retrained_labels.txt \
--image_dir /flower_photos

I am not getting any error .My model gets retrained and i get a prediction

Being very new in this field please guide where i am wrong be its installation mistake or something


问:
Need XML from parent and child table from Oracle SQL query
In a project on which i am working on, we need to create an XML and pass it on to an interface and i am facing issues while creating an XML containing data from parent table and its subsequent child table.

parent table :- Department should be like

```<code>dept_id     dept_name
1           History
2           Biology
</code>```

CHild table :- employee should be like

```<code>emp_id      emp_name     dept_id
1           Helen         1
2           Martha        1
3           John          1
4           Carol         2
</code>```

So the resulting XML should be like for department id=1

```<code>`<department>
<dept_id>1</dept_id>
<dept_name>History</dept_name>
</department>
<employee>
<emp_id>1</emp_id>
<emp_name>Helen</emp_name>
</employee>
<employee>
<emp_id>2</emp_id>
<emp_name>Martha</emp_name>
</employee>
<employee>
<emp_id>3</emp_id>
<emp_name>John</emp_name>
</employee>'
</code>```

If anyone knows a better way of doing this then it would be of great help.
Thanks in advance

答:
Something like this (with the employee nodes in the department node so it is not a fragment):</p>

```<code>SELECT XMLELEMENT(
         "department",
         XMLFOREST(
           e.dept_id AS "dept_id",
           d.dept_name AS "dept_name"
         ),
         XMLAGG(
           XMLELEMENT(
             "employee",
             XMLFOREST(
               emp_id AS "emp_id",
               emp_name AS "emp_name"
             )
           )
         )
       )
FROM   employees e
       INNER JOIN departments d
       on ( e.dept_id = d.dept_id )
WHERE  e.dept_id = 1
GROUP BY e.dept_id, d.dept_name;
</code>```

Body:
In a project on which i am working on, we need to create an XML and pass it on to an interface and i am facing issues while creating an XML containing data from parent table and its subsequent child table.

parent table :- Department should be like

dept_id     dept_name
1           History
2           Biology

CHild table :- employee should be like

emp_id      emp_name     dept_id
1           Helen         1
2           Martha        1
3           John          1
4           Carol         2

So the resulting XML should be like for department id=1

`<department>
<dept_id>1</dept_id>
<dept_name>History</dept_name>
</department>
<employee>
<emp_id>1</emp_id>
<emp_name>Helen</emp_name>
</employee>
<employee>
<emp_id>2</emp_id>
<emp_name>Martha</emp_name>
</employee>
<employee>
<emp_id>3</emp_id>
<emp_name>John</emp_name>
</employee>'

If anyone knows a better way of doing this then it would be of great help.
Thanks in advance

Body:
Something like this (with the employee nodes in the department node so it is not a fragment):

SELECT XMLELEMENT(
         "department",
         XMLFOREST(
           e.dept_id AS "dept_id",
           d.dept_name AS "dept_name"
         ),
         XMLAGG(
           XMLELEMENT(
             "employee",
             XMLFOREST(
               emp_id AS "emp_id",
               emp_name AS "emp_name"
             )
           )
         )
       )
FROM   employees e
       INNER JOIN departments d
       on ( e.dept_id = d.dept_id )
WHERE  e.dept_id = 1
GROUP BY e.dept_id, d.dept_name;


问:
Why does Java writeBytes method send only one byte in first TCP packet and write method does not?
I have developing a simple client in java (I use a Windows 7 machine) to communicate with a server. The problem was that the server never understood my request. So I have analysed the communication with Wireshark and have noticed that only one byte is send in a first TCP packet, and 40ms after the remaining bytes are send in a other packet.

In fact, we communicate with binary frames, so all the frames must begin with the total length of the frame on 2 bytes. So it is normal that the server will never understand me. All my frames never exceed 10 bytes, so it's a insignificant amount of data. I know that TCP packets can be segmented, but for me it has no sense to segment a tiny frame after only one byte.

After unsuccessful hours of research, I tried casually to send bytes in a other way using write method instead of writeBytes method. Now I send all the data in only one TCP packet and the communication works fine, but I have never find the explanation. If someone knows, I will be happy to learn it.

Here is my code :

```<code>import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Client {

public static void main(String argv[]) {

    try {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("10.2.1.1", 1003), 1000);
        DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());
        DataInputStream inFromServer = new DataInputStream(socket.getInputStream());

        // Hexadecimal frame to send to server
        String hexFrame = "0004FF9D3175";

        // Build bytes frame
        String bytesFrame = "";
        for (int i=0; i<hexFrame.length()/2; i++) {
            bytesFrame += (char) Integer.parseInt(hexFrame.substring(i*2, (i+1)*2), 16);
        }

        // This generates 2 TCP packets
        // outToServer.writeBytes(bytesFrame);
        // This generates only 1 TCP packet
        outToServer.write(bytesFrame.getBytes());

        // Read answer from server
        hexFrame = "";
        short frame_length = inFromServer.readShort();
        for (int i=0; i<frame_length; i++) {
            hexFrame += String.format("%2s", Integer.toHexString(inFromServer.readUnsignedByte())).replace(" ", "0");
        }

        System.out.println("Receive : " + hexFrame);

        socket.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
</code>```

}

答:
Neither Java nor TCP makes any guarantees about this. TCP can segment the data any way it likes, and you have no business relying on any two bytes being delivered consecutively. The problem here is really at the reading end, that makes incorrect assumptions.

In fact, we communicate with binary frames

In fact you are communicating over a byte-stream protocol. No frames, no message boundaries, nothing.

However, if you want a little more control over this you should use a BufferedOutputStream between the DataOutputStream and the socket output stream, and similarly a BufferedInputStream at the receiving end. Flush the stream when you want the data to be sent, typically just before the next read.

Body:
I have developing a simple client in java (I use a Windows 7 machine) to communicate with a server. The problem was that the server never understood my request. So I have analysed the communication with Wireshark and have noticed that only one byte is send in a first TCP packet, and 40ms after the remaining bytes are send in a other packet.

In fact, we communicate with binary frames, so all the frames must begin with the total length of the frame on 2 bytes. So it is normal that the server will never understand me. All my frames never exceed 10 bytes, so it's a insignificant amount of data. I know that TCP packets can be segmented, but for me it has no sense to segment a tiny frame after only one byte.

After unsuccessful hours of research, I tried casually to send bytes in a other way using write method instead of writeBytes method. Now I send all the data in only one TCP packet and the communication works fine, but I have never find the explanation. If someone knows, I will be happy to learn it.

Here is my code :

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Client {

public static void main(String argv[]) {

    try {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("10.2.1.1", 1003), 1000);
        DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());
        DataInputStream inFromServer = new DataInputStream(socket.getInputStream());

        // Hexadecimal frame to send to server
        String hexFrame = "0004FF9D3175";

        // Build bytes frame
        String bytesFrame = "";
        for (int i=0; i<hexFrame.length()/2; i++) {
            bytesFrame += (char) Integer.parseInt(hexFrame.substring(i*2, (i+1)*2), 16);
        }

        // This generates 2 TCP packets
        // outToServer.writeBytes(bytesFrame);
        // This generates only 1 TCP packet
        outToServer.write(bytesFrame.getBytes());

        // Read answer from server
        hexFrame = "";
        short frame_length = inFromServer.readShort();
        for (int i=0; i<frame_length; i++) {
            hexFrame += String.format("%2s", Integer.toHexString(inFromServer.readUnsignedByte())).replace(" ", "0");
        }

        System.out.println("Receive : " + hexFrame);

        socket.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

}


问:
Node.js leaking path info, how to solve it?
I have a webserver running... and if I curl from another server.  Something like that:

```<code>curl http://myserver.com/../../../../../etc/rsyslog.conf
</code>```

then I can see the server info.

Is that a known problem?

UPDATE
here is my server code:

```<code>app = express.createServer(
            gzip.staticGzip(__dirname + '/public', {maxAge:5000 }),
            express.cookieParser(),
            express.bodyParser()

        );
</code>```

got a fix like that:

```<code>var urlSecurity = function () {
    return function (req, res, next) {
        if (req.url.indexOf('../') >=0) {
            res.send('<div>Server Error</div>' , 500);
        } else if (req.url.indexOf('/..') >=0) {
            res.send('<div>Server Error</div>' , 500);
        } else {
            next();
        }
    }
}
app = express.createServer(
urlSecurity (),
            gzip.staticGzip(__dirname + '/public', {maxAge:5000 }),
            express.cookieParser(),
            express.bodyParser()

        );
</code>```

is this good enough?

答:
The simplest solution is insecureFileName.split('/').pop() will always returns only fileName.

```<code>'index.html'.split('/').pop() => 'index.html'
'../../../index.html'.split('/').pop() => 'index.html'
</code>```

Body:
I have a webserver running... and if I curl from another server.  Something like that:

curl http://myserver.com/../../../../../etc/rsyslog.conf

then I can see the server info.

Is that a known problem?

UPDATE
here is my server code:

app = express.createServer(
            gzip.staticGzip(__dirname + '/public', {maxAge:5000 }),
            express.cookieParser(),
            express.bodyParser()

        );

got a fix like that:

var urlSecurity = function () {
    return function (req, res, next) {
        if (req.url.indexOf('../') >=0) {
            res.send('
Server Error
' , 500);
        } else if (req.url.indexOf('/..') >=0) {
            res.send('
Server Error
' , 500);
        } else {
            next();
        }
    }
}
app = express.createServer(
urlSecurity (),
            gzip.staticGzip(__dirname + '/public', {maxAge:5000 }),
            express.cookieParser(),
            express.bodyParser()

        );

is this good enough?

Body:
The simplest solution is insecureFileName.split('/').pop() will always returns only fileName.

'index.html'.split('/').pop() => 'index.html'
'../../../index.html'.split('/').pop() => 'index.html'


问:
Proper error handling with windows service that loads external assembly/dll
I have a windows service that loads a bunch of 'plugins' that are just .dll files.  It uses reflection to do this:

```<code>try
{
   Assembly assembly = Assembly.LoadFile("myPlugin.dll");
   Type[] types = assembly.GetTypes();
   foreach (Type t in types)
   {
      Type[] ifaces = t.GetInterfaces();

      foreach (Type f in ifaces)
      {
          if (f.Name == "MyPlugin")
          {
              pType = t;
              break;
          }
      }
      if (pType != null)
          break;
   }
}
catch
{
   AddToLog("Failed");
}
obj = Activator.CreateInstance(pType);

object[] Parameters = new object[1];
Parameters[0] = _pluginName;

try
{
    pType.InvokeMember("InitializePlugin",
                      BindingFlags.Default | BindingFlags.InvokeMethod,
                      null,
                      obj,
                      Parameters);

}
catch (Exception ex)
{
    AddToLog(_pluginName + " - InitializePlugin error: " + ex.Message);
}
</code>```

Problem I am having is that if the 'InitializePlugin' method with the external dll fails, it is not caught with the try/catch in the code above and ends up crashing the whole service.  Is there a better way to handle errors that occur in an externally loaded assembly like this?

答:
just use a catch block with no exception.  Not all exceptions have a type.</p>

```<code>try
{

}
catch(Exception ex)
{

}
catch
{
}
finally
{
}
</code>```

Body:
I have a windows service that loads a bunch of 'plugins' that are just .dll files.  It uses reflection to do this:

try
{
   Assembly assembly = Assembly.LoadFile("myPlugin.dll");
   Type[] types = assembly.GetTypes();
   foreach (Type t in types)
   {
      Type[] ifaces = t.GetInterfaces();

      foreach (Type f in ifaces)
      {
          if (f.Name == "MyPlugin")
          {
              pType = t;
              break;
          }
      }
      if (pType != null)
          break;
   }
}
catch
{
   AddToLog("Failed");
}
obj = Activator.CreateInstance(pType);

object[] Parameters = new object[1];
Parameters[0] = _pluginName;

try
{
    pType.InvokeMember("InitializePlugin",
                      BindingFlags.Default | BindingFlags.InvokeMethod,
                      null,
                      obj,
                      Parameters);

}
catch (Exception ex)
{
    AddToLog(_pluginName + " - InitializePlugin error: " + ex.Message);
}

Problem I am having is that if the 'InitializePlugin' method with the external dll fails, it is not caught with the try/catch in the code above and ends up crashing the whole service.  Is there a better way to handle errors that occur in an externally loaded assembly like this?

Body:
just use a catch block with no exception.  Not all exceptions have a type.

try
{

}
catch(Exception ex)
{

}
catch
{
}
finally
{
}


问:
How to resolve rename error during npm install
I opened the cmd window as administrator and ran npm install on a folder, got this error at one point:

npm ERR! Error: EPERM: operation not permitted, rename 'MyFolder\node_modules\.staging\@angular\common-54da66e9' -> 'MyFolder\node_modules\@angular\common'
npm ERR!     at destStatted (C:\Program Files\nodejs\node_modules\npm\lib\install\action\finalize.js:25:7)
npm ERR!     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:264:29
npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)
```

Same seems to work on other machines!

Can someone help me fix this?

答: Running npm cache clean, deleting the node_modules folder in the project and then running npm install again fixed this!

ContentLicense: CC BY-SA 4.0

Body:
I opened the cmd window as administrator and ran npm install on a folder, got this error at one point:

npm ERR! Error: EPERM: operation not permitted, rename 'MyFolder\node_modules\.staging\@angular\common-54da66e9' -> 'MyFolder\node_modules\@angular\common'
npm ERR!     at destStatted (C:\Program Files\nodejs\node_modules\npm\lib\install\action\finalize.js:25:7)
npm ERR!     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:264:29
npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)

Same seems to work on other machines!

Can someone help me fix this?


问:
Does Scala run on the JamVM
Does Scala 2.8 run on the JamVM? </p>

答: Yeah, it works. I just wrote a small program on it, and it was fine. Under stress I guess is a separate issue.</p>

Title: Does Scala run on the JamVM

Body: Does Scala 2.8 run on the JamVM?