snipt

Ctrl+h for KB shortcuts

Java

Hibernate Criteria And Or

1
2
3
4
5
6
Criteria criteria = getSession().createCriteria(clazz); 
Criterion rest1= Restrictions.and(Restrictions.eq("A", "X"), 
           Restrictions.in("B", Arrays.asList("X","Y")));
Criterion rest2= Restrictions.and(Restrictions.eq("A", "Y"), 
           Restrictions.eq("B", "Z"));
criteria.add(Restrictions.or(rest1, rest2));
https://snipt.net/embed/8aceb2963b54dee89d38c00f771b1477/
/raw/8aceb2963b54dee89d38c00f771b1477/
8aceb2963b54dee89d38c00f771b1477
java
Java
6
2019-06-22T19:48:20
True
False
False
May 02, 2014 at 04:16 PM
/api/public/snipt/134696/
hibernate-criteria-and-or-d04f6474
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">Criteria</span> <span class="n">criteria</span> <span class="o">=</span> <span class="n">getSession</span><span class="o">().</span><span class="na">createCriteria</span><span class="o">(</span><span class="n">clazz</span><span class="o">);</span> </span><span id="L-2"><a name="L-2"></a><span class="n">Criterion</span> <span class="n">rest1</span><span class="o">=</span> <span class="n">Restrictions</span><span class="o">.</span><span class="na">and</span><span class="o">(</span><span class="n">Restrictions</span><span class="o">.</span><span class="na">eq</span><span class="o">(</span><span class="s">&quot;A&quot;</span><span class="o">,</span> <span class="s">&quot;X&quot;</span><span class="o">),</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">Restrictions</span><span class="o">.</span><span class="na">in</span><span class="o">(</span><span class="s">&quot;B&quot;</span><span class="o">,</span> <span class="n">Arrays</span><span class="o">.</span><span class="na">asList</span><span class="o">(</span><span class="s">&quot;X&quot;</span><span class="o">,</span><span class="s">&quot;Y&quot;</span><span class="o">)));</span> </span><span id="L-4"><a name="L-4"></a><span class="n">Criterion</span> <span class="n">rest2</span><span class="o">=</span> <span class="n">Restrictions</span><span class="o">.</span><span class="na">and</span><span class="o">(</span><span class="n">Restrictions</span><span class="o">.</span><span class="na">eq</span><span class="o">(</span><span class="s">&quot;A&quot;</span><span class="o">,</span> <span class="s">&quot;Y&quot;</span><span class="o">),</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">Restrictions</span><span class="o">.</span><span class="na">eq</span><span class="o">(</span><span class="s">&quot;B&quot;</span><span class="o">,</span> <span class="s">&quot;Z&quot;</span><span class="o">));</span> </span><span id="L-6"><a name="L-6"></a><span class="n">criteria</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">Restrictions</span><span class="o">.</span><span class="na">or</span><span class="o">(</span><span class="n">rest1</span><span class="o">,</span> <span class="n">rest2</span><span class="o">));</span> </span></pre></div> </td></tr></table>
criteria, hibernate, java

JavaScript

Sleep function

1
2
3
4
5
6
7
8
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
https://snipt.net/embed/96d28bd420f3f3b132986ec996fbad67/
/raw/96d28bd420f3f3b132986ec996fbad67/
96d28bd420f3f3b132986ec996fbad67
js
JavaScript
8
2019-06-24T02:43:56
True
False
False
Apr 14, 2014 at 05:21 AM
/api/public/snipt/129781/
sleep-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">sleep</span><span class="p">(</span><span class="nx">milliseconds</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">start</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">().</span><span class="nx">getTime</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="nx">e7</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">if</span> <span class="p">((</span><span class="k">new</span> <span class="nb">Date</span><span class="p">().</span><span class="nx">getTime</span><span class="p">()</span> <span class="o">-</span> <span class="nx">start</span><span class="p">)</span> <span class="o">&gt;</span> <span class="nx">milliseconds</span><span class="p">){</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">break</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
javascript, sleep

Java

Date to XMLGregorianCalendar

1
2
3
4
GregorianCalendar gregorianCalendar = new GregorianCalendar();
Date date = new Date();
gregorianCalendar.setTime(date);
XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
https://snipt.net/embed/31c7f51c792da0ab15b0e65d68c2b262/
/raw/31c7f51c792da0ab15b0e65d68c2b262/
31c7f51c792da0ab15b0e65d68c2b262
java
Java
4
2019-06-21T23:10:15
True
False
False
Nov 15, 2013 at 12:50 AM
/api/public/snipt/94290/
date-to-xmlgregoriancalendar
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">GregorianCalendar</span> <span class="n">gregorianCalendar</span> <span class="o">=</span> <span class="k">new</span> <span class="n">GregorianCalendar</span><span class="o">();</span> </span><span id="L-2"><a name="L-2"></a><span class="n">Date</span> <span class="n">date</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Date</span><span class="o">();</span> </span><span id="L-3"><a name="L-3"></a><span class="n">gregorianCalendar</span><span class="o">.</span><span class="na">setTime</span><span class="o">(</span><span class="n">date</span><span class="o">);</span> </span><span id="L-4"><a name="L-4"></a><span class="n">XMLGregorianCalendar</span> <span class="n">xmlGregorianCalendar</span> <span class="o">=</span> <span class="n">DatatypeFactory</span><span class="o">.</span><span class="na">newInstance</span><span class="o">().</span><span class="na">newXMLGregorianCalendar</span><span class="o">(</span><span class="n">gregorianCalendar</span><span class="o">);</span> </span></pre></div> </td></tr></table>
"gregorian calendar", "xml gregorian calendar", date, java