Example usage for java.text SimpleDateFormat setTimeZone

List of usage examples for java.text SimpleDateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setTimeZone.

Prototype

public void setTimeZone(TimeZone zone) 

Source Link

Document

Sets the time zone for the calendar of this DateFormat object.

Usage

From source file:com.opentransport.rdfmapper.nmbs.ScrapeTrip.java

private GtfsRealtime.FeedEntity.Builder parseJson(int identifier, String fileName, boolean canceled,
        String trainName) {/*from  w  w w  . j ava 2  s .  c om*/
    GtfsRealtime.FeedEntity.Builder feedEntity = GtfsRealtime.FeedEntity.newBuilder();
    feedEntity.setId(Integer.toString(identifier));
    feedEntity.setIsDeleted(false);

    //Data that doesnt Update
    GtfsRealtime.TripUpdate.Builder tripUpdate = GtfsRealtime.TripUpdate.newBuilder();
    GtfsRealtime.VehicleDescriptor.Builder vehicleDescription = GtfsRealtime.VehicleDescriptor.newBuilder();
    GtfsRealtime.TripDescriptor.Builder tripDescription = GtfsRealtime.TripDescriptor.newBuilder();
    GtfsRealtime.TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = GtfsRealtime.TripUpdate.StopTimeUpdate
            .newBuilder();

    //Each StopTime Update contains StopTimeEvents with the stop Arrival and Departure Time 
    GtfsRealtime.TripUpdate.StopTimeEvent.Builder stopTimeArrival = GtfsRealtime.TripUpdate.StopTimeEvent
            .newBuilder();
    GtfsRealtime.TripUpdate.StopTimeEvent.Builder stopTimeDeparture = GtfsRealtime.TripUpdate.StopTimeEvent
            .newBuilder();

    JSONParser parser = new JSONParser();
    try {
        FileReader fr = new FileReader(fileName);
        JSONObject json = (JSONObject) parser.parse(fr);
        String trainId = (String) json.get("vehicle");
        //Setting the VehicleData
        String routeId = trainName;
        vehicleDescription.setId(routeId);
        vehicleDescription.setLicensePlate(trainId);

        //Handling Departure Date
        String unixSeconds = (String) json.get("timestamp");
        Long unixSec = Long.parseLong(unixSeconds);

        Date date = new Date(unixSec * 1000L); // *1000 is to convert seconds to milliseconds
        SimpleDateFormat sdfStartDate = new SimpleDateFormat("yyyyMMdd"); // the format of your date
        sdfStartDate.setTimeZone(TimeZone.getTimeZone("GMT+2")); // give a timezone reference for formating
        SimpleDateFormat sdfStartTimeHour = new SimpleDateFormat("HH:mm:ss");

        String formattedDepartureDate = sdfStartDate.format(date);
        // String formattedDepartureHour = sdfStartTimeHour.format(date);

        // Setting the Trip Description
        // tripDescription.setStartTime(formattedDepartureHour);
        //YYYYMMDD format
        tripDescription.setStartDate(formattedDepartureDate);
        tripDescription.setRouteId(routeId);

        String tripId = tr.getTripIdFromRouteId(routeId, cdr);
        tripDescription.setTripId(tripId);

        //Get Information about stops
        JSONObject rootStop = (JSONObject) json.get("stops");
        JSONArray stops = (JSONArray) rootStop.get("stop");
        String arrivalDelay = "0";
        String departureDelay = "0";
        int maxDelay = 0;

        String firstStopName = "";
        String lastStopName = "";

        boolean wholeTripCanceled = true; // True when all stoptimes since now are canceled

        for (int i = 0; i < stops.size(); i++) {
            //Information about the stops
            JSONObject stop = (JSONObject) stops.get(i);
            // String stopSeq = (String) stop.get("id");

            stopTimeUpdate.setStopSequence(i);
            try {

                JSONObject station = (JSONObject) stop.get("stationinfo");
                // tripDescription.setRouteId((String) station.get("@id"));

                String stopId = (String) station.get("id");
                stopId = stopId.replaceFirst("[^0-9]+", "") + ":";
                stopId = stopId.substring(2); // remove first '00'
                if (!stop.get("platform").equals("") && !stop.get("platform").equals("?")) {
                    stopId += stop.get("platform");
                } else {
                    stopId += "0";
                }

                stopTimeUpdate.setStopId(stopId);

                // Constructing route long name from first and last stop
                if (i == 0) {
                    firstStopName = (String) station.get("standardname");
                } else if (i == stops.size() - 1) {
                    lastStopName = (String) station.get("standardname");
                }

            } catch (Exception e) {
                errorWriter.writeError(e.toString() + fileName);
                System.out.println(fileName);
                System.out.println(e);
            }

            // delays
            arrivalDelay = (String) stop.get("arrivalDelay");
            departureDelay = (String) stop.get("departureDelay");

            int arrivalDelayInt = Integer.parseInt(arrivalDelay);
            int departureDelayInt = Integer.parseInt(departureDelay);

            if (maxDelay < arrivalDelayInt) {
                maxDelay = arrivalDelayInt;
            }
            if (maxDelay < departureDelayInt) {
                maxDelay = departureDelayInt;
            }

            long now = System.currentTimeMillis();

            //Calculate arrival times
            long scheduledArrivalTimeUnixSeconds = Long.parseLong((String) stop.get("scheduledArrivalTime"));
            java.util.Date scheduledArrivalTime = new java.util.Date(
                    (long) scheduledArrivalTimeUnixSeconds * 1000);
            // add arrivalDelay to get real arrival time
            long arrivalTimeMillis = (DateUtils.addSeconds(scheduledArrivalTime, arrivalDelayInt)).getTime();

            //Calculate departure times
            long scheduledDepartureTimeUnixSeconds = Long
                    .parseLong((String) stop.get("scheduledDepartureTime"));
            java.util.Date scheduledDepartureTime = new java.util.Date(
                    (long) scheduledDepartureTimeUnixSeconds * 1000);
            // add departureDelay to get real departure time
            long departureTimeMillis = (DateUtils.addSeconds(scheduledDepartureTime, departureDelayInt))
                    .getTime();

            // If stoptime is (partially) canceled
            String isCanceled = (String) stop.get("canceled");
            if (!isCanceled.equals("0")) {
                // Set ScheduleRelationship of stoptime to SKIPPED
                stopTimeUpdate.setScheduleRelationship(
                        GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED);
            } else {
                // If a current or future stoptime isn't canceled, the whole trip isn't canceled
                if (wholeTripCanceled && arrivalTimeMillis >= now) {
                    wholeTripCanceled = false;
                }
            }

            // Set Arrival in the object
            stopTimeArrival.setDelay(arrivalDelayInt);
            //    setTime takes parameter in seconds
            stopTimeArrival.setTime(arrivalTimeMillis / 1000);
            stopTimeUpdate.setArrival(stopTimeArrival);
            // Do the same for departure
            stopTimeDeparture.setDelay(Integer.parseInt(departureDelay));
            //    setTime takes parameter in seconds
            stopTimeDeparture.setTime(departureTimeMillis / 1000);
            stopTimeUpdate.setDeparture(stopTimeDeparture);
            tripUpdate.addStopTimeUpdate(stopTimeUpdate);
        }

        tripDescription.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
        if (wholeTripCanceled) {
            // Can be partially canceled
            tripDescription.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED);
        }

        String route_long_name = firstStopName + " - " + lastStopName;
        vehicleDescription.setLabel(route_long_name);
        tripUpdate.setTrip(tripDescription);
        tripUpdate.setVehicle(vehicleDescription);
        tripUpdate.setDelay(maxDelay);
        feedEntity.setTripUpdate(tripUpdate);

        fr.close();
    } catch (FileNotFoundException ex) {
        System.out.println(ex);
        errorWriter.writeError(ex.toString());

    } catch (IOException ex) {
        System.out.println("IO exception" + ex);

    } catch (ParseException ex) {
        System.out.println("Parse exception " + ex + " " + fileName);
    } catch (NullPointerException npe) {
        System.out.println(npe.toString());
    }

    return feedEntity;
}

From source file:com.mercandalli.android.apps.files.file.FileAddDialog.java

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public FileAddDialog(@NonNull final Activity activity, final int id_file_parent,
        @Nullable final IListener listener, @Nullable final IListener dismissListener) {
    super(activity, R.style.DialogFullscreen);
    mActivity = activity;/*  w ww  .j a  va2 s  .c  o  m*/
    mDismissListener = dismissListener;
    mFileParentId = id_file_parent;
    mListener = listener;

    setContentView(R.layout.dialog_add_file);
    setCancelable(true);

    final View rootView = findViewById(R.id.dialog_add_file_root);
    rootView.startAnimation(AnimationUtils.loadAnimation(mActivity, R.anim.dialog_add_file_open));
    rootView.setOnClickListener(this);

    findViewById(R.id.dialog_add_file_upload_file).setOnClickListener(this);
    findViewById(R.id.dialog_add_file_add_directory).setOnClickListener(this);

    findViewById(R.id.dialog_add_file_text_doc).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogUtils.prompt(mActivity, mActivity.getString(R.string.dialog_file_create_txt),
                    mActivity.getString(R.string.dialog_file_name_interrogation),
                    mActivity.getString(R.string.dialog_file_create),
                    new DialogUtils.OnDialogUtilsStringListener() {
                        @Override
                        public void onDialogUtilsStringCalledBack(String text) {
                            //TODO create a online txt with content
                            Toast.makeText(getContext(), getContext().getString(R.string.not_implemented),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }, mActivity.getString(android.R.string.cancel), null);
            FileAddDialog.this.dismiss();
        }
    });

    findViewById(R.id.dialog_add_file_scan).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            // Ensure that there's a camera activity to handle the intent
            if (takePictureIntent.resolveActivity(mActivity.getPackageManager()) != null) {
                // Create the File where the photo should go
                ApplicationActivity.sPhotoFile = createImageFile();
                // Continue only if the File was successfully created
                if (ApplicationActivity.sPhotoFile != null) {
                    if (listener != null) {
                        ApplicationActivity.sPhotoFileListener = listener;
                    }
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                            Uri.fromFile(ApplicationActivity.sPhotoFile.getFile()));
                    mActivity.startActivityForResult(takePictureIntent, ApplicationActivity.REQUEST_TAKE_PHOTO);
                }
            }
            FileAddDialog.this.dismiss();
        }
    });

    findViewById(R.id.dialog_add_file_add_timer).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Calendar currentTime = Calendar.getInstance();

            DialogDatePicker dialogDate = new DialogDatePicker(mActivity,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, final int year, final int monthOfYear,
                                final int dayOfMonth) {

                            Calendar currentTime = Calendar.getInstance();

                            DialogTimePicker dialogTime = new DialogTimePicker(mActivity,
                                    new TimePickerDialog.OnTimeSetListener() {
                                        @Override
                                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                                            Log.d("TIme Picker", hourOfDay + ":" + minute);

                                            final SimpleDateFormat dateFormatGmt = new SimpleDateFormat(
                                                    "yyyy-MM-dd HH:mm:ss", Locale.US);
                                            dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));
                                            final SimpleDateFormat dateFormatLocal = new SimpleDateFormat(
                                                    "yyyy-MM-dd HH:mm:ss", Locale.US);

                                            String nowAsISO = dateFormatGmt.format(new Date());

                                            final JSONObject json = new JSONObject();
                                            try {
                                                json.put("type", "timer");
                                                json.put("date_creation", nowAsISO);
                                                json.put("timer_date",
                                                        "" + dateFormatGmt.format(dateFormatLocal.parse(year
                                                                + "-" + (monthOfYear + 1) + "-" + dayOfMonth
                                                                + " " + hourOfDay + ":" + minute + ":00")));

                                                final SimpleDateFormat dateFormatGmtTZ = new SimpleDateFormat(
                                                        "yyyy-MM-dd'T'HH-mm'Z'", Locale.US);
                                                dateFormatGmtTZ.setTimeZone(TimeZone.getTimeZone("UTC"));
                                                nowAsISO = dateFormatGmtTZ.format(new Date());

                                                final List<StringPair> parameters = new ArrayList<>();
                                                parameters.add(new StringPair("content", json.toString()));
                                                parameters.add(new StringPair("name", "TIMER_" + nowAsISO));
                                                parameters.add(
                                                        new StringPair("id_file_parent", "" + id_file_parent));
                                                new TaskPost(mActivity,
                                                        Constants.URL_DOMAIN + Config.ROUTE_FILE,
                                                        new IPostExecuteListener() {
                                                            @Override
                                                            public void onPostExecute(JSONObject json,
                                                                    String body) {
                                                                if (listener != null) {
                                                                    listener.execute();
                                                                }
                                                            }
                                                        }, parameters).execute();
                                            } catch (JSONException | ParseException e) {
                                                Log.e(getClass().getName(), "Failed to convert Json", e);
                                            }

                                        }
                                    }, currentTime.get(Calendar.HOUR_OF_DAY), currentTime.get(Calendar.MINUTE),
                                    true);
                            dialogTime.show();

                        }
                    }, currentTime.get(Calendar.YEAR), currentTime.get(Calendar.MONTH),
                    currentTime.get(Calendar.DAY_OF_MONTH));
            dialogDate.show();

            FileAddDialog.this.dismiss();
        }
    });

    findViewById(R.id.dialog_add_file_article).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogCreateArticle dialogCreateArticle = new DialogCreateArticle(mActivity, listener);
            dialogCreateArticle.show();
            FileAddDialog.this.dismiss();
        }
    });

    FileAddDialog.this.show();
}

From source file:de.phillme.PhotoSorter.java

private String generateNewFileName(PhotoFile photoFile) {
    if (photoFile.getPhotoDate() != null) {

        SimpleDateFormat sdf = new SimpleDateFormat(this.dateFormatPhotos);
        sdf.setTimeZone(this.timeZone);

        String newFileName = sdf.format(photoFile.getPhotoDate()) + "_" + this.photoNumberInEvent;
        String fileExt = getFileExt(photoFile.getFilePath().getFileName().toString());

        if (fileExt != null) {
            newFileName = newFileName + "." + fileExt;
            return newFileName;
        }//from   w ww.ja  va2  s. c  o m
    }

    return null;
}

From source file:de.phillme.PhotoSorter.java

private void movePhotoToEvent(PhotoFile photoFile, Date eventStartDate) throws IOException {
    SimpleDateFormat sdfEurope = new SimpleDateFormat(this.dateFormatFolders);
    sdfEurope.setTimeZone(this.timeZone);
    String sDateinEurope = sdfEurope.format(eventStartDate) + this.eventFileSuffix;

    String eventPath = this.photosPath + File.separator + sDateinEurope;
    File eventFile = new File(eventPath);

    if (!eventFile.exists() && this.write) {
        boolean success = (new File(eventPath)).mkdirs();
    }//from   w  ww  .j a  v a2s.c  o  m

    moveRelevantFiles(eventPath, photoFile);

}

From source file:com.mb.framework.util.DateTimeUtil.java

/**
 * This method is used for convert date into another time zone.
 * //from w ww  .  j  av  a2s.c  om
 * @param date
 * @param timeZone
 * @return Date
 * @throws ParseException
 */
public static Date convertTimeZoneOfDate(Date date, String timeZone) throws ParseException {
    String dateStr = null;
    Date d = null;

    if (null != date && null != timeZone) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
        dateStr = formatter.format(date);

        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        d = formatter1.parse(dateStr);
    }
    return d;
}

From source file:info.archinnov.achilles.it.TestDSLEntityWithClusterings.java

@Test
public void should_dsl_select_slice_with_clustering_IN_same_partition() throws Exception {
    //Given//from w w  w  .j a  va  2 s .c  o  m
    final Map<String, Object> values = new HashMap<>();
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    values.put("id1", id);
    values.put("id2", id);
    values.put("id3", id);
    values.put("id4", id);
    values.put("id5", id);

    final UUID uuid1 = new UUID(0L, 0L);
    final UUID uuid2 = new UUID(0L, 1L);

    values.put("uuid1", uuid1);
    values.put("uuid2", uuid1);
    values.put("uuid3", uuid1);
    values.put("uuid4", uuid2);
    values.put("uuid5", uuid2);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date date3 = dateFormat.parse("2015-10-03 00:00:00 GMT");
    final Date date5 = dateFormat.parse("2015-10-05 00:00:00 GMT");

    values.put("date1", "'2015-10-01 00:00:00+0000'");
    values.put("date2", "'2015-10-02 00:00:00+0000'");
    values.put("date3", "'2015-10-03 00:00:00+0000'");
    values.put("date4", "'2015-10-04 00:00:00+0000'");
    values.put("date5", "'2015-10-05 00:00:00+0000'");

    scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values);

    /*
    Data are ordered as:
            
    uuid1, date3,
    uuid1, date2,
    uuid1, date1,
    uuid2, date5,
    uuid2, date4
            
    because date is ORDERED BY DESC natively
     */

    //When
    final List<EntityWithClusteringColumns> list = manager.dsl().select().uuid().date().value().fromBaseTable()
            .where().id_Eq(id).uuid_IN(uuid1, uuid2).date_Gte_And_Lte(date3, date5).getList();

    //Then
    assertThat(list).hasSize(3);

    assertThat(list.stream().map(EntityWithClusteringColumns::getValue).sorted().collect(toList()))
            .containsExactly("val3", "val4", "val5");
}

From source file:info.archinnov.achilles.it.TestDSLEntityWithClusterings.java

@Test
public void should_dsl_select_slice_with_clusterings_IN_same_partition() throws Exception {
    //Given//from www . jav  a 2 s.  c  o  m
    final Map<String, Object> values = new HashMap<>();
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    values.put("id1", id);
    values.put("id2", id);
    values.put("id3", id);
    values.put("id4", id);
    values.put("id5", id);

    final UUID uuid1 = new UUID(0L, 0L);
    final UUID uuid2 = new UUID(0L, 1L);

    values.put("uuid1", uuid1);
    values.put("uuid2", uuid1);
    values.put("uuid3", uuid1);
    values.put("uuid4", uuid2);
    values.put("uuid5", uuid2);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date date3 = dateFormat.parse("2015-10-03 00:00:00 GMT");
    final Date date5 = dateFormat.parse("2015-10-05 00:00:00 GMT");

    values.put("date1", "'2015-10-01 00:00:00+0000'");
    values.put("date2", "'2015-10-02 00:00:00+0000'");
    values.put("date3", "'2015-10-03 00:00:00+0000'");
    values.put("date4", "'2015-10-04 00:00:00+0000'");
    values.put("date5", "'2015-10-05 00:00:00+0000'");

    scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values);

    /*
    Data are ordered as:
            
    uuid1, date3,
    uuid1, date2,
    uuid1, date1,
    uuid2, date5,
    uuid2, date4
            
    because date is ORDERED BY DESC natively
     */

    //When
    final List<EntityWithClusteringColumns> list = manager.dsl().select().uuid().date().value().fromBaseTable()
            .where().id_Eq(id).uuid_IN(uuid1, uuid2).date_IN(date3, date5).getList();

    //Then
    assertThat(list).hasSize(2);

    assertThat(list.stream().map(EntityWithClusteringColumns::getValue).sorted().collect(toList()))
            .containsExactly("val3", "val5");
}

From source file:info.archinnov.achilles.it.TestDSLEntityWithClusterings.java

@Test
public void should_dsl_select_slice_with_different_partitions() throws Exception {
    //Given/*from   w w w  .ja  va2 s .co m*/
    final Map<String, Object> values = new HashMap<>();
    final long id1 = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final long id2 = RandomUtils.nextLong(0L, Long.MAX_VALUE);

    values.put("id1", id1);
    values.put("id2", id1);
    values.put("id3", id1);
    values.put("id4", id2);
    values.put("id5", id2);

    final UUID uuid = new UUID(0L, 0L);

    values.put("uuid1", uuid);
    values.put("uuid2", uuid);
    values.put("uuid3", uuid);
    values.put("uuid4", uuid);
    values.put("uuid5", uuid);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date date3 = dateFormat.parse("2015-10-03 00:00:00 GMT");
    final Date date5 = dateFormat.parse("2015-10-05 00:00:00 GMT");

    values.put("date1", "'2015-10-01 00:00:00+0000'");
    values.put("date2", "'2015-10-02 00:00:00+0000'");
    values.put("date3", "'2015-10-03 00:00:00+0000'");
    values.put("date4", "'2015-10-04 00:00:00+0000'");
    values.put("date5", "'2015-10-05 00:00:00+0000'");

    scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values);

    /*
    Data are ordered as:
            
    id1, uuid, date3,
    id1, uuid, date2,
    id1, uuid, date1,
    id2, uuid, date5,
    id2, uuid, date4
            
    because date is ORDERED BY DESC natively
     */

    //When
    final List<EntityWithClusteringColumns> list = manager.dsl().select().uuid().date().value().fromBaseTable()
            .where().id_IN(id1, id2).uuid_Eq(uuid).date_IN(date3, date5).getList();

    //Then
    assertThat(list).hasSize(2);

    assertThat(list.stream().map(EntityWithClusteringColumns::getValue).sorted().collect(toList()))
            .containsExactly("val3", "val5");
}

From source file:info.archinnov.achilles.it.TestDSLEntityWithClusterings.java

@Test
public void should_dsl_update_multiple_partitions() throws Exception {
    //Given/*ww w  .  j  a  v a  2 s.c  o  m*/
    final Map<String, Object> values = new HashMap<>();
    final long id1 = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final long id2 = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    values.put("id1", id1);
    values.put("id2", id1);
    values.put("id3", id1);
    values.put("id4", id2);
    values.put("id5", id2);

    final UUID uuid = new UUID(0L, 0L);

    values.put("uuid1", uuid);
    values.put("uuid2", uuid);
    values.put("uuid3", uuid);
    values.put("uuid4", uuid);
    values.put("uuid5", uuid);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date date1 = dateFormat.parse("2015-10-01 00:00:00 GMT");

    values.put("date1", "'2015-10-01 00:00:00+0000'");
    values.put("date2", "'2015-10-02 00:00:00+0000'");
    values.put("date3", "'2015-10-03 00:00:00+0000'");
    values.put("date4", "'2015-10-01 00:00:00+0000'");
    values.put("date5", "'2015-10-02 00:00:00+0000'");

    scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values);

    /*
    Data are ordered as:
            
    id1, uuid, date3,
    id1, uuid, date2,
    id1, uuid, date1,
    id2, uuid, date2,
    id2, uuid, date1
            
    because date is ORDERED BY DESC natively
     */

    //When
    manager.dsl().update().fromBaseTable().value_Set("new_value").where().id_IN(id1, id2).uuid_Eq(uuid)
            .date_Eq(date1).execute();

    //Then
    final List<Row> actuals = session.execute("SELECT value FROM entity_with_clusterings WHERE id IN (" + id1
            + "," + id2 + ") AND uuid = " + uuid + " AND date = '2015-10-01 00:00:00+0000'").all();

    assertThat(actuals).hasSize(2);
    assertThat(actuals.get(0).getString("value")).isEqualTo("new_value");
    assertThat(actuals.get(1).getString("value")).isEqualTo("new_value");
}

From source file:info.archinnov.achilles.it.TestDSLEntityWithClusterings.java

@Test
public void should_dsl_delete_multiple_partitions() throws Exception {
    //Given//from ww  w.j a v a2 s  .co  m
    final Map<String, Object> values = new HashMap<>();
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    values.put("id1", id);
    values.put("id2", id);
    values.put("id3", id);
    values.put("id4", id);
    values.put("id5", id);

    final UUID uuid = new UUID(0L, 0L);

    values.put("uuid1", uuid);
    values.put("uuid2", uuid);
    values.put("uuid3", uuid);
    values.put("uuid4", uuid);
    values.put("uuid5", uuid);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date date2 = dateFormat.parse("2015-10-02 00:00:00 GMT");

    values.put("date1", "'2015-10-01 00:00:00+0000'");
    values.put("date2", "'2015-10-02 00:00:00+0000'");
    values.put("date3", "'2015-10-03 00:00:00+0000'");
    values.put("date4", "'2015-10-04 00:00:00+0000'");
    values.put("date5", "'2015-10-05 00:00:00+0000'");

    scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values);

    /*
    Data are ordered as:
            
    uuid, date5,
    uuid, date4,
    uuid, date3,
    uuid, date2,
    uuid, date1
            
    because date is ORDERED BY DESC natively
     */

    //When
    manager.dsl().delete().value().fromBaseTable().where().id_Eq(id).uuid_Eq(uuid).date_Eq(date2).execute();

    //Then
    final List<Row> actuals = session
            .execute("SELECT value FROM entity_with_clusterings WHERE id = " + id + " AND uuid = " + uuid)
            .all();

    assertThat(actuals).hasSize(5);
    assertThat(actuals.get(0).getString("value")).isEqualTo("val5");
    assertThat(actuals.get(1).getString("value")).isEqualTo("val4");
    assertThat(actuals.get(2).getString("value")).isEqualTo("val3");
    assertThat(actuals.get(3).isNull("value")).isTrue();
    assertThat(actuals.get(4).getString("value")).isEqualTo("val1");
}