List of usage examples for java.util Calendar JANUARY
int JANUARY
To view the source code for java.util Calendar JANUARY.
Click Source Link
From source file:org.polymap.kaps.ui.filter.VertraegeStalaAgrarFilter.java
protected Query<VertragComposite> createFilterQuery(final IFilterEditorSite site, final KapsRepository repository) { Integer quartal = Integer.parseInt((String) site.getFieldValue("Quartal")); Integer jahr = Integer.parseInt((String) site.getFieldValue("Jahr")); Calendar lowerCal = new GregorianCalendar(); lowerCal.set(Calendar.YEAR, jahr); lowerCal.set(Calendar.DAY_OF_MONTH, 1); lowerCal.set(Calendar.HOUR_OF_DAY, 0); lowerCal.set(Calendar.MINUTE, 0); lowerCal.set(Calendar.SECOND, 0); lowerCal.set(Calendar.MILLISECOND, 0); Calendar upperCal = new GregorianCalendar(); upperCal.setTime(lowerCal.getTime()); switch (quartal) { case 1:/* ww w. j a v a 2s . co m*/ lowerCal.set(Calendar.MONTH, Calendar.JANUARY); upperCal.set(Calendar.MONTH, Calendar.APRIL); break; case 2: lowerCal.set(Calendar.MONTH, Calendar.APRIL); upperCal.set(Calendar.MONTH, Calendar.JULY); break; case 3: lowerCal.set(Calendar.MONTH, Calendar.JULY); upperCal.set(Calendar.MONTH, Calendar.OCTOBER); break; case 4: lowerCal.set(Calendar.MONTH, Calendar.OCTOBER); upperCal.roll(Calendar.YEAR, true); upperCal.set(Calendar.MONTH, Calendar.JANUARY); break; default: throw new IllegalStateException("Quartal " + quartal + " unbekannt!"); } FlurstueckComposite flurstueckTemplate = QueryExpressions.templateFor(FlurstueckComposite.class); VertragComposite vertragTemplate = QueryExpressions.templateFor(VertragComposite.class); BooleanExpression dExpr = null; BooleanExpression vExpr = null; { Query<VertragComposite> vertraege = repository().findEntities(VertragComposite.class, QueryExpressions.and(QueryExpressions.ge(vertragTemplate.vertragsDatum(), lowerCal.getTime()), QueryExpressions.lt(vertragTemplate.vertragsDatum(), upperCal.getTime())), 0, -1); for (VertragComposite kv : vertraege) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.vertrag(), kv); if (vExpr == null) { vExpr = newExpr; } else { vExpr = QueryExpressions.or(vExpr, newExpr); } } } // falls keine Vertrge gefunden werden, wrden spter alle Flurstcke // selektiert -> StackOverFlow if (vExpr != null) { BooleanExpression nExpr = null; { Query<NutzungComposite> nutzungen = repository().findEntities(NutzungComposite.class, null, 0, -1); for (NutzungComposite nutzung : nutzungen) { if (nutzung.isAgrar().get() != null && nutzung.isAgrar().get() == Boolean.TRUE) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.nutzung(), nutzung); if (nExpr == null) { nExpr = newExpr; } else { nExpr = QueryExpressions.or(nExpr, newExpr); } } } } GemeindeComposite gemeinde = (GemeindeComposite) site.getFieldValue("gemeinde"); BooleanExpression gExpr = null; if (gemeinde != null) { GemarkungComposite gemarkungTemplate = QueryExpressions.templateFor(GemarkungComposite.class); Query<GemarkungComposite> gemarkungen = repository().findEntities(GemarkungComposite.class, QueryExpressions.eq(gemarkungTemplate.gemeinde(), gemeinde), 0, -1); for (GemarkungComposite gemarkung : gemarkungen) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.gemarkung(), gemarkung); if (gExpr == null) { gExpr = newExpr; } else { gExpr = QueryExpressions.or(gExpr, newExpr); } } } BooleanExpression expr = QueryExpressions.gt(flurstueckTemplate.verkaufteFlaeche(), 1000d); if (vExpr != null) { expr = QueryExpressions.and(expr, vExpr); } if (nExpr != null) { expr = QueryExpressions.and(expr, nExpr); } if (gExpr != null) { expr = QueryExpressions.and(expr, gExpr); } Query<FlurstueckComposite> allFlurstuecke = repository().findEntities(FlurstueckComposite.class, expr, 0, getMaxResults()); for (FlurstueckComposite flurstueck : allFlurstuecke) { BooleanExpression newExpr = QueryExpressions.eq(vertragTemplate.identity(), flurstueck.vertrag().get().identity().get()); if (dExpr == null) { dExpr = newExpr; } else { dExpr = QueryExpressions.or(dExpr, newExpr); } } // flurstcksfilter angegeben und keine flurstcke gefunden if (dExpr == null) { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } } else { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } BooleanExpression geeignetExpr = QueryExpressions.eq(vertragTemplate.fuerAuswertungGeeignet(), Boolean.TRUE); if (dExpr != null) { dExpr = QueryExpressions.and(dExpr, geeignetExpr); } else { dExpr = geeignetExpr; } return repository().findEntities(VertragComposite.class, dExpr, 0, getMaxResults()); }
From source file:org.polymap.kaps.ui.filter.VertraegeStalaBaulandFilter.java
protected Query<VertragComposite> createFilterQuery(final IFilterEditorSite site, final KapsRepository repository) { Integer quartal = Integer.parseInt((String) site.getFieldValue("Quartal")); Integer jahr = Integer.parseInt((String) site.getFieldValue("Jahr")); Calendar lowerCal = new GregorianCalendar(); lowerCal.set(Calendar.YEAR, jahr); lowerCal.set(Calendar.DAY_OF_MONTH, 1); lowerCal.set(Calendar.HOUR_OF_DAY, 0); lowerCal.set(Calendar.MINUTE, 0); lowerCal.set(Calendar.SECOND, 0); lowerCal.set(Calendar.MILLISECOND, 0); Calendar upperCal = new GregorianCalendar(); upperCal.setTime(lowerCal.getTime()); switch (quartal) { case 1:/* w w w .j a va 2 s . co m*/ lowerCal.set(Calendar.MONTH, Calendar.JANUARY); upperCal.set(Calendar.MONTH, Calendar.APRIL); break; case 2: lowerCal.set(Calendar.MONTH, Calendar.APRIL); upperCal.set(Calendar.MONTH, Calendar.JULY); break; case 3: lowerCal.set(Calendar.MONTH, Calendar.JULY); upperCal.set(Calendar.MONTH, Calendar.OCTOBER); break; case 4: lowerCal.set(Calendar.MONTH, Calendar.OCTOBER); upperCal.roll(Calendar.YEAR, true); upperCal.set(Calendar.MONTH, Calendar.JANUARY); break; default: throw new IllegalStateException("Quartal " + quartal + " unbekannt!"); } FlurstueckComposite flurstueckTemplate = QueryExpressions.templateFor(FlurstueckComposite.class); VertragComposite vertragTemplate = QueryExpressions.templateFor(VertragComposite.class); BooleanExpression dExpr = null; BooleanExpression vExpr = null; { Query<VertragComposite> vertraege = repository().findEntities(VertragComposite.class, QueryExpressions.and(QueryExpressions.ge(vertragTemplate.vertragsDatum(), lowerCal.getTime()), QueryExpressions.lt(vertragTemplate.vertragsDatum(), upperCal.getTime())), 0, -1); for (VertragComposite kv : vertraege) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.vertrag(), kv); if (vExpr == null) { vExpr = newExpr; } else { vExpr = QueryExpressions.or(vExpr, newExpr); } } } // falls keine Vertrge gefunden werden, wrden spter alle Flurstcke // selektiert -> StackOverFlow if (vExpr != null) { BooleanExpression nExpr = null; { Query<NutzungComposite> nutzungen = repository().findEntities(NutzungComposite.class, null, 0, -1); for (NutzungComposite nutzung : nutzungen) { if (nutzung.isAgrar().get() == null || nutzung.isAgrar().get() == Boolean.FALSE) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.nutzung(), nutzung); if (nExpr == null) { nExpr = newExpr; } else { nExpr = QueryExpressions.or(nExpr, newExpr); } } } } GemeindeComposite gemeinde = (GemeindeComposite) site.getFieldValue("gemeinde"); BooleanExpression gExpr = null; if (gemeinde != null) { GemarkungComposite gemarkungTemplate = QueryExpressions.templateFor(GemarkungComposite.class); Query<GemarkungComposite> gemarkungen = repository().findEntities(GemarkungComposite.class, QueryExpressions.eq(gemarkungTemplate.gemeinde(), gemeinde), 0, -1); for (GemarkungComposite gemarkung : gemarkungen) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.gemarkung(), gemarkung); if (gExpr == null) { gExpr = newExpr; } else { gExpr = QueryExpressions.or(gExpr, newExpr); } } } BooleanExpression expr = QueryExpressions.gt(flurstueckTemplate.verkaufteFlaeche(), 100d); if (vExpr != null) { expr = QueryExpressions.and(expr, vExpr); } if (nExpr != null) { expr = QueryExpressions.and(expr, nExpr); } if (gExpr != null) { expr = QueryExpressions.and(expr, gExpr); } Query<FlurstueckComposite> allFlurstuecke = repository().findEntities(FlurstueckComposite.class, expr, 0, getMaxResults()); for (FlurstueckComposite flurstueck : allFlurstuecke) { BooleanExpression newExpr = QueryExpressions.eq(vertragTemplate.identity(), flurstueck.vertrag().get().identity().get()); if (dExpr == null) { dExpr = newExpr; } else { dExpr = QueryExpressions.or(dExpr, newExpr); } } // flurstcksfilter angegeben und keine flurstcke gefunden if (dExpr == null) { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } } else { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } BooleanExpression geeignetExpr = QueryExpressions.eq(vertragTemplate.fuerAuswertungGeeignet(), Boolean.TRUE); if (dExpr != null) { dExpr = QueryExpressions.and(dExpr, geeignetExpr); } else { dExpr = geeignetExpr; } return repository().findEntities(VertragComposite.class, dExpr, 0, getMaxResults()); }
From source file:org.pentaho.metaverse.api.MetaverseLogicalIdGeneratorTest.java
@Test public void testGenerateLogicalId_escapedCharacters() throws Exception { when(node.getProperty("name")).thenReturn("john\ndoe"); when(node.getProperty("age")).thenReturn(30); when(node.getProperty("address")).thenReturn("1234 Pentaho Way\\Orlando, FL 12345"); Calendar cal = GregorianCalendar.getInstance(); cal.set(1976, Calendar.JANUARY, 1, 0, 0, 0); when(node.getProperty("birthday")).thenReturn(cal.getTime()); when(node.getPropertyKeys()).thenReturn(new HashSet<String>() { {/* ww w .j a v a 2 s . c om*/ add("address"); add("age"); add("birthday"); add("name"); } }); // make sure there is no logicalid on the node initially assertNull(node.getProperty(DictionaryConst.PROPERTY_LOGICAL_ID)); String logicalId = idGenerator.generateId(node); // it should come out in alphabetical order by key assertEquals( "{\"address\":\"1234 Pentaho Way\\\\Orlando, FL 12345\",\"age\":\"30\",\"birthday\":\"1976-01-01 00:00:00\",\"name\":\"john\\ndoe\"}", logicalId); // make sure the json string is parseable JsonNode jsonObject = objectMapper.readTree(logicalId); JsonNode address = jsonObject.get("address"); assertEquals("1234 Pentaho Way\\Orlando, FL 12345", address.textValue()); JsonNode name = jsonObject.get("name"); assertEquals("john\ndoe", name.textValue()); System.out.println(jsonObject.toString()); // make sure a call was made to add the logical id as a property verify(node).setProperty(DictionaryConst.PROPERTY_LOGICAL_ID, logicalId); }
From source file:org.lockss.servlet.TestDaemonStatus.java
public void testConvertDisplayString() throws Exception { // test null//ww w. j a v a 2 s . c o m Object testObj = null; assertEquals("", format(testObj, ColumnDescriptor.TYPE_STRING)); // test standard numbers testObj = new Integer(123); assertEquals("123", format(testObj, ColumnDescriptor.TYPE_INT)); testObj = new Float(123321); assertEquals(testObj.toString(), format(testObj, ColumnDescriptor.TYPE_FLOAT)); // check proper 'big int' formatting testObj = new Long(12345678); assertEquals("12,345,678", format(testObj, ColumnDescriptor.TYPE_INT)); // test string testObj = "test string"; assertEquals("test string", format(testObj, ColumnDescriptor.TYPE_STRING)); // Issue 1901: verify that there is no encoding bias testObj = "<>&'\"\n"; String res = format(testObj, ColumnDescriptor.TYPE_STRING); assertEquals("Expected \"" + StringEscapeUtils.escapeJava(testObj.toString()) + "\" but got \"" + StringEscapeUtils.escapeJava(res) + "\"; encoding bias?", "<>&'\"\n", res); // test percentage testObj = new Double(.453); assertEquals("45%", format(testObj, ColumnDescriptor.TYPE_PERCENT)); // test agreement testObj = new Double(.453); assertEquals("45.30%", format(testObj, ColumnDescriptor.TYPE_AGREEMENT)); testObj = new Double(.999999); assertEquals("99.99%", format(testObj, ColumnDescriptor.TYPE_AGREEMENT)); // test date Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DATE, 1); cal.set(Calendar.HOUR_OF_DAY, 15); cal.set(Calendar.MINUTE, 15); testObj = cal.getTime(); assertEquals(new DisplayConverter().getTableDateFormat().format(testObj), format(testObj, ColumnDescriptor.TYPE_DATE)); // test IPAddr testObj = IPAddr.getLocalHost(); assertEquals(IPAddr.getLocalHost().getHostAddress(), format(testObj, ColumnDescriptor.TYPE_IP_ADDRESS)); // test time interval long timeInt = Constants.HOUR + Constants.MINUTE; testObj = new Long(timeInt); assertEquals(StringUtil.timeIntervalToString(timeInt), format(testObj, ColumnDescriptor.TYPE_TIME_INTERVAL)); // test unknown testObj = "unknown string"; assertEquals("unknown string", format(testObj, -1)); }
From source file:nu.nethome.home.items.web.GraphServlet.java
/** * This is the main enterence point of the class. This is called when a http request is * routed to this servlet./* w ww . j av a 2s .co m*/ */ public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletOutputStream p = res.getOutputStream(); Date startTime = null; Date stopTime = null; // Analyse arguments String fileName = req.getParameter("file"); if (fileName != null) fileName = getFullFileName(fromURL(fileName)); String startTimeString = req.getParameter("start"); String stopTimeString = req.getParameter("stop"); try { if (startTimeString != null) { startTime = m_Format.parse(startTimeString); } if (stopTimeString != null) { stopTime = m_Format.parse(stopTimeString); } } catch (ParseException e1) { e1.printStackTrace(); } String look = req.getParameter("look"); if (look == null) look = ""; TimeSeries timeSeries = new TimeSeries("Data", Minute.class); // Calculate time window Calendar cal = Calendar.getInstance(); Date currentTime = cal.getTime(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date startOfDay = cal.getTime(); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date startOfWeek = cal.getTime(); cal.set(Calendar.DAY_OF_MONTH, 1); Date startOfMonth = cal.getTime(); cal.set(Calendar.MONTH, Calendar.JANUARY); Date startOfYear = cal.getTime(); // if (startTime == null) startTime = startOfWeek; if (stopTime == null) stopTime = currentTime; if (startTime == null) startTime = new Date(stopTime.getTime() - 1000L * 60L * 60L * 24L * 2L); try { // Open the data file File logFile = new File(fileName); Scanner fileScanner = new Scanner(logFile); Long startTimeMs = startTime.getTime(); Long month = 1000L * 60L * 60L * 24L * 30L; boolean doOptimize = true; boolean justOptimized = false; try { while (fileScanner.hasNext()) { try { // Get next log entry String line = fileScanner.nextLine(); if (line.length() > 21) { // Adapt the time format String minuteTime = line.substring(0, 16).replace('.', '-'); // Parse the time stamp Minute min = Minute.parseMinute(minuteTime); // Ok, this is an ugly optimization. If the current time position in the file // is more than a month (30 days) ahead of the start of the time window, we // quick read two weeks worth of data, assuming that there is 4 samples per hour. // This may lead to scanning past start of window if there are holes in the data // series. if (doOptimize && ((startTimeMs - min.getFirstMillisecond()) > month)) { for (int i = 0; (i < (24 * 4 * 14)) && fileScanner.hasNext(); i++) { fileScanner.nextLine(); } justOptimized = true; continue; } // Detect if we have scanned past the window start position just after an optimization scan. // If this is the case it may be because of the optimization. In that case we have to switch // optimization off and start over. if ((min.getFirstMillisecond() > startTimeMs) && doOptimize && justOptimized) { logFile = new File(fileName); fileScanner = new Scanner(logFile); doOptimize = false; continue; } justOptimized = false; // Check if value is within time window if ((min.getFirstMillisecond() > startTimeMs) && (min.getFirstMillisecond() < stopTime.getTime())) { // Parse the value double value = Double.parseDouble((line.substring(20)).replace(',', '.')); // Add the entry timeSeries.add(min, value); doOptimize = false; } } } catch (SeriesException se) { // Bad entry, for example due to duplicates at daylight saving time switch } catch (NumberFormatException nfe) { // Bad number format in a line, try to continue } } } catch (Exception e) { System.out.println(e.toString()); } finally { fileScanner.close(); } } catch (FileNotFoundException f) { System.out.println(f.toString()); } // Create a collection for plotting TimeSeriesCollection data = new TimeSeriesCollection(); data.addSeries(timeSeries); JFreeChart chart; int xSize = 750; int ySize = 450; // Customize colors and look of the Graph. if (look.equals("mobtemp")) { // Look for the mobile GUI chart = ChartFactory.createTimeSeriesChart(null, null, null, data, false, false, false); XYPlot plot = chart.getXYPlot(); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); xSize = 175; ySize = 180; } else { // Create a Chart with time range as heading SimpleDateFormat localFormat = new SimpleDateFormat(); String heading = localFormat.format(startTime) + " - " + localFormat.format(stopTime); chart = ChartFactory.createTimeSeriesChart(heading, null, null, data, false, false, false); Paint background = new Color(0x9D8140); chart.setBackgroundPaint(background); TextTitle title = chart.getTitle(); // fix title Font titleFont = title.getFont(); titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0); title.setFont(titleFont); title.setPaint(Color.darkGray); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.darkGray); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); plot.setRangeGridlinePaint(Color.darkGray); XYItemRenderer renderer = plot.getRenderer(0); renderer.setSeriesPaint(0, Color.darkGray); xSize = 750; ySize = 450; } try { res.setContentType("image/png"); res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cache"); res.setStatus(HttpServletResponse.SC_OK); ChartUtilities.writeChartAsPNG(p, chart, xSize, ySize); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } p.flush(); p.close(); return; }
From source file:com.netflix.genie.core.jpa.services.JpaJobPersistenceImplIntegrationTests.java
/** * Make sure we can delete jobs that were created before a given date. *//*from www . j a v a 2s .c o m*/ @Test public void canDeleteJobsCreatedBeforeDateWithPageLargerThanMax() { // Try to delete a all jobs from before Jan 1, 2016 final Calendar cal = Calendar.getInstance(JobConstants.UTC); cal.set(2016, Calendar.JANUARY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); final long deleted = this.jobPersistenceService.deleteBatchOfJobsCreatedBeforeDate(cal.getTime(), 1, 10); Assert.assertThat(deleted, Matchers.is(2L)); Assert.assertThat(this.jobExecutionRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRequestRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRequestMetadataRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRepository.count(), Matchers.is(1L)); Assert.assertNotNull(this.jobExecutionRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRequestRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRequestMetadataRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRepository.getOne(JOB_3_ID)); }
From source file:com.netflix.simianarmy.basic.BasicCalendar.java
/** * Load holidays.// www. j a v a 2s. c om * * @param year * the year */ protected void loadHolidays(int year) { holidays.clear(); // these aren't all strictly holidays, but days when engineers will likely // not be in the office to respond to rampaging monkeys // new years, or closest work day holidays.add(workDayInYear(year, Calendar.JANUARY, 1)); // 3rd monday == MLK Day holidays.add(dayOfYear(year, Calendar.JANUARY, Calendar.MONDAY, 3)); // 3rd monday == Presidents Day holidays.add(dayOfYear(year, Calendar.FEBRUARY, Calendar.MONDAY, 3)); // last monday == Memorial Day holidays.add(dayOfYear(year, Calendar.MAY, Calendar.MONDAY, -1)); // 4th of July, or closest work day holidays.add(workDayInYear(year, Calendar.JULY, 4)); // first monday == Labor Day holidays.add(dayOfYear(year, Calendar.SEPTEMBER, Calendar.MONDAY, 1)); // second monday == Columbus Day holidays.add(dayOfYear(year, Calendar.OCTOBER, Calendar.MONDAY, 2)); // veterans day, Nov 11th, or closest work day holidays.add(workDayInYear(year, Calendar.NOVEMBER, 11)); // 4th thursday == Thanksgiving holidays.add(dayOfYear(year, Calendar.NOVEMBER, Calendar.THURSDAY, 4)); // 4th friday == "black friday", monkey goes shopping! holidays.add(dayOfYear(year, Calendar.NOVEMBER, Calendar.FRIDAY, 4)); // christmas eve holidays.add(dayOfYear(year, Calendar.DECEMBER, 24)); // christmas day holidays.add(dayOfYear(year, Calendar.DECEMBER, 25)); // day after christmas holidays.add(dayOfYear(year, Calendar.DECEMBER, 26)); // new years eve holidays.add(dayOfYear(year, Calendar.DECEMBER, 31)); // mark the holiday set with the year, so on Jan 1 it will automatically // recalculate the holidays for next year holidays.add(year); }
From source file:com.streamsets.pipeline.stage.origin.jdbc.table.AllTypesIT.java
private static void populateRecords() { Record record = RecordCreator.create(); LinkedHashMap<String, Field> fields; AtomicInteger id_field = new AtomicInteger(0); //CHAR_AND_BINARY fields = new LinkedHashMap<>(); createIdField(fields, id_field);//from w ww. j a va2s . c o m fields.put("char1", Field.create("abcdefghij")); fields.put("varchar1", Field.create(UUID.randomUUID().toString())); fields.put("clob1", Field.create(UUID.randomUUID().toString())); fields.put("varbinary1", Field.create(UUID.randomUUID().toString().getBytes())); fields.put("blob1", Field.create(UUID.randomUUID().toString().getBytes())); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("CHAR_AND_BINARY").getRight().add(record); //Date and time record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); fields.put("date1", Field.create(Field.Type.DATE, calendar.getTime())); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.MILLISECOND, 0); fields.put("timestamp1", Field.create(Field.Type.DATETIME, calendar.getTime())); fields.put("datetime1", Field.create(Field.Type.DATETIME, calendar.getTime())); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.MILLISECOND, 0); fields.put("time1", Field.create(Field.Type.TIME, calendar.getTime())); calendar.setTimeInMillis(System.currentTimeMillis()); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DATE_AND_TIME").getRight().add(record); //DIFFERENT_INTS record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("int1", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE)); fields.put("int2", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE)); fields.put("mediumint1", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE)); fields.put("tinyint1", Field.create(Field.Type.SHORT, -128)); fields.put("smallint1", Field.create(Field.Type.SHORT, Short.MIN_VALUE)); fields.put("bigint1", Field.create(Field.Type.LONG, Long.MIN_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DIFFERENT_INTS").getRight().add(record); record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("int1", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE)); fields.put("int2", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE)); fields.put("mediumint1", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE)); fields.put("tinyint1", Field.create(Field.Type.SHORT, 127)); fields.put("smallint1", Field.create(Field.Type.SHORT, Short.MAX_VALUE)); fields.put("bigint1", Field.create(Field.Type.LONG, Long.MAX_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DIFFERENT_INTS").getRight().add(record); //FLOATING_PT_INTS record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("decimal1", Field.create(Field.Type.DECIMAL, new BigDecimal("12.345"))); fields.put("number1", Field.create(Field.Type.DECIMAL, new BigDecimal("0.12345"))); fields.put("double1", Field.create(Field.Type.DOUBLE, 123.456)); fields.put("real1", Field.create(Field.Type.FLOAT, 12.34)); fields.put("floatdouble1", Field.create(Field.Type.DOUBLE, Double.MAX_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("FLOATING_PT_INTS").getRight().add(record); record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("decimal1", Field.create(Field.Type.DECIMAL, new BigDecimal("-12.345"))); fields.put("number1", Field.create(Field.Type.DECIMAL, new BigDecimal("-0.12345"))); fields.put("double1", Field.create(Field.Type.DOUBLE, -123.456)); fields.put("real1", Field.create(Field.Type.FLOAT, -12.34)); fields.put("floatdouble1", Field.create(Field.Type.DOUBLE, Double.MIN_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("FLOATING_PT_INTS").getRight().add(record); //OTHER_TYPES record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("boolean1", Field.create(Field.Type.BOOLEAN, true)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("OTHER_TYPES").getRight().add(record); record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("boolean1", Field.create(Field.Type.BOOLEAN, false)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("OTHER_TYPES").getRight().add(record); }
From source file:org.hibernate.search.test.query.dsl.embedded.DslEmbeddedSearchTest.java
@Test @TestForIssue(jiraKey = "HSEARCH-2070") public void testSearchDateWithoutFieldBridge() throws Exception { FullTextSession fullTextSession = Search.getFullTextSession(s); QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(ContainerEntity.class) .get();/*from w w w . ja va2 s. c om*/ Query q = qb.range().onField("emb.date").above(initCalendar(2007, Calendar.JANUARY, 14).getTime()) .createQuery(); List<ContainerEntity> results = execute(fullTextSession, q); assertEquals("DSL didn't find the embedded date field.", 1, results.size()); assertEquals(initCalendar(2007, Calendar.JANUARY, 14).getTime(), results.get(0).getEmbeddedEntity().getDate()); }
From source file:org.polymap.kaps.ui.filter.VertraegeStabuFilter.java
protected Query<VertragComposite> createFilterQuery(final IFilterEditorSite site, final KapsRepository repository) { Integer quartal = null;/* w ww. ja v a 2 s . c o m*/ try { quartal = Integer.parseInt((String) site.getFieldValue("Quartal")); } catch (Exception e) { showError("Quartal fehlt", "Bitte whlen Sie ein Quartal aus."); return null; } Integer jahr = null; try { jahr = Integer.parseInt((String) site.getFieldValue("Jahr")); } catch (Exception e) { showError("Jahr fehlt", "Bitte whlen Sie ein Jahr aus."); return null; } Calendar lowerCal = new GregorianCalendar(); lowerCal.set(Calendar.YEAR, jahr); lowerCal.set(Calendar.DAY_OF_MONTH, 1); lowerCal.set(Calendar.HOUR_OF_DAY, 0); lowerCal.set(Calendar.MINUTE, 0); lowerCal.set(Calendar.SECOND, 0); lowerCal.set(Calendar.MILLISECOND, 0); Calendar upperCal = new GregorianCalendar(); upperCal.setTime(lowerCal.getTime()); switch (quartal) { case 1: lowerCal.set(Calendar.MONTH, Calendar.JANUARY); upperCal.set(Calendar.MONTH, Calendar.APRIL); break; case 2: lowerCal.set(Calendar.MONTH, Calendar.APRIL); upperCal.set(Calendar.MONTH, Calendar.JULY); break; case 3: lowerCal.set(Calendar.MONTH, Calendar.JULY); upperCal.set(Calendar.MONTH, Calendar.OCTOBER); break; case 4: lowerCal.set(Calendar.MONTH, Calendar.OCTOBER); upperCal.roll(Calendar.YEAR, true); upperCal.set(Calendar.MONTH, Calendar.JANUARY); break; default: throw new IllegalStateException("Quartal " + quartal + " unbekannt!"); } FlurstueckComposite flurstueckTemplate = QueryExpressions.templateFor(FlurstueckComposite.class); VertragComposite vertragTemplate = QueryExpressions.templateFor(VertragComposite.class); BooleanExpression dExpr = null; BooleanExpression vExpr = null; { Query<VertragComposite> vertraege = repository().findEntities(VertragComposite.class, QueryExpressions.and(QueryExpressions.ge(vertragTemplate.vertragsDatum(), lowerCal.getTime()), QueryExpressions.lt(vertragTemplate.vertragsDatum(), upperCal.getTime())), 0, -1); for (VertragComposite kv : vertraege) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.vertrag(), kv); if (vExpr == null) { vExpr = newExpr; } else { vExpr = QueryExpressions.or(vExpr, newExpr); } } } // falls keine Vertrge gefunden werden, wrden spter alle Flurstcke // selektiert -> StackOverFlow if (vExpr != null) { BooleanExpression nExpr = null; { Query<NutzungComposite> nutzungen = repository().findEntities(NutzungComposite.class, null, 0, -1); for (NutzungComposite nutzung : nutzungen) { if (nutzung.isAgrar().get() == null || nutzung.isAgrar().get() == Boolean.FALSE) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.nutzung(), nutzung); if (nExpr == null) { nExpr = newExpr; } else { nExpr = QueryExpressions.or(nExpr, newExpr); } } } } GemeindeComposite gemeinde = (GemeindeComposite) site.getFieldValue("gemeinde"); BooleanExpression gExpr = null; if (gemeinde != null) { GemarkungComposite gemarkungTemplate = QueryExpressions.templateFor(GemarkungComposite.class); Query<GemarkungComposite> gemarkungen = repository().findEntities(GemarkungComposite.class, QueryExpressions.eq(gemarkungTemplate.gemeinde(), gemeinde), 0, -1); for (GemarkungComposite gemarkung : gemarkungen) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.gemarkung(), gemarkung); if (gExpr == null) { gExpr = newExpr; } else { gExpr = QueryExpressions.or(gExpr, newExpr); } } } BooleanExpression expr = vExpr; if (nExpr != null) { expr = expr == null ? nExpr : QueryExpressions.and(expr, nExpr); } if (gExpr != null) { expr = expr == null ? gExpr : QueryExpressions.and(expr, gExpr); } Query<FlurstueckComposite> allFlurstuecke = repository.findEntities(FlurstueckComposite.class, expr, 0, getMaxResults()); for (FlurstueckComposite flurstueck : allFlurstuecke) { BooleanExpression newExpr = QueryExpressions.eq(vertragTemplate.identity(), flurstueck.vertrag().get().identity().get()); if (dExpr == null) { dExpr = newExpr; } else { dExpr = QueryExpressions.or(dExpr, newExpr); } } // flurstcksfilter angegeben und keine flurstcke gefunden if (dExpr == null) { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } } else { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } BooleanExpression geeignetExpr = QueryExpressions.eq(vertragTemplate.fuerAuswertungGeeignet(), Boolean.TRUE); if (dExpr != null) { dExpr = QueryExpressions.and(dExpr, geeignetExpr); } else { dExpr = geeignetExpr; } return repository().findEntities(VertragComposite.class, dExpr, 0, getMaxResults()); }