Cast Date to Timestamp

CAST (<mydate> AS TIMESTAMP)

Create user

CREATE USER 'new_user' IDENTIFIED BY 'my_password';
GRANT ALL ON my_database TO 'new_user';

GRANT SELECT, INSERT ON other_database TO 'new_user';

Convert Date or Timestamp to UTC format

(SYS_EXTRACT_UTC(<mydate>)

Get the first non-null value

COALESCE (<value1>, <value2>)

is equivalent to:

CASE WHEN <value1>IS NOT NULL THEN <value1> ELSE <value2> END

 

 

1. Add jersey-server maven dependency to your Java Project

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.19</version>
    <scope>compile</scope>
</dependency>

2. Run your test server

public static void main(String[] args) {
        HttpServer server;
        try {
            /**
             * start jersey server.
             */
            server = HttpServerFactory.create("http://localhost:8042/");
            server.start();
        } catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }

3. Created Resource class with REST methods is added to the server automatically

@Path("/") public class TestResource {

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response testMethod(){

...

After adding of the MongoDB cartridge to your application, you will get a message like this:

mongodb-2.4 (MongoDB 2.4)
-------------------------
  Gears:          1 small
  Connection URL: mongodb://$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT/
  Database Name:  <your_application_name>
  Password:       <generated_password>
  Username:       admin

The problem is to find the value of OPENSHIFT_MONGODB_DB_HOST and OPENSHIFT_MONGODB_DB_PORT.

Follow steps will help you:

1. Build connection to your application:

rhc app ssh -a <your_application_name>

2. show environment variables, which names contain MONGODB

env | grep MONGODB

Create your Job execution class

@Component
public class ScheduledTasks {

    public void performService() {}

Create a scheduling configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/task
            http://www.springframework.org/schema/task/spring-task-3.1.xsd">
 
    <!-- Spring's scheduling support -->
    <task:scheduled-tasks scheduler="taskScheduler">
        <task:scheduled ref="cronService" method="performService" cron="0 */2 * * * *"/>
    </task:scheduled-tasks>
 
    <!-- The bean that does the actual work -->
    <bean id="cronService" class="your.package.job.ScheduledTasks" />
 
    <!-- Defines a ThreadPoolTaskScheduler instance with configurable pool size. -->
    <task:scheduler id="taskScheduler" pool-size="1"/>
 
</beans>

Import this file to spring-config xml file:

<beans>

<!-- Scheduling config -->
    <import resource="scheduling.xml" />

...
</beans>

Open \.openshift\express.conf file and change:

# Your OpenShift login name
default_rhlogin=Diese E-Mail-Adresse ist vor Spambots geschützt! Zur Anzeige muss JavaScript eingeschaltet sein!