Package com.impetus.client.crud

Examples of com.impetus.client.crud.PersonCassandra


     */
    @Test
    public void onInsertBlobImageCassandra() throws Exception
    {

        PersonCassandra personWithKey = new PersonCassandra();
        personWithKey.setPersonId("111");

        BufferedImage originalImage = ImageIO.read(new File("src/test/resources/nature.jpg"));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(originalImage, "jpg", baos);
        baos.flush();
        byte[] imageInByte = baos.toByteArray();

        baos.close();

        personWithKey.setA(imageInByte);
        em.persist(personWithKey);

        em.clear();

        String qry = "Select p from PersonCassandra p where p.personId = 111";
        Query q = em.createQuery(qry);
        List<PersonCassandra> persons = q.getResultList();
        PersonCassandra person = persons.get(0);

        InputStream in = new ByteArrayInputStream(person.getA());
        BufferedImage bImageFromConvert = ImageIO.read(in);

        ImageIO.write(bImageFromConvert, "jpg", new File("src/test/resources/nature-test.jpg"));

        Assert.assertNotNull(person.getA());
        Assert.assertEquals(new File("src/test/resources/nature.jpg").getTotalSpace(), new File(
                "src/test/resources/nature-test.jpg").getTotalSpace());
        Assert.assertEquals(String.valueOf(Hex.encodeHex((byte[]) imageInByte)),
                String.valueOf(Hex.encodeHex((byte[]) person.getA())));

    }
View Full Code Here


            File file = new File("src/test/resources/persistence.pdf");

            byte[] bFile = new byte[(int) file.length()];

            PersonCassandra personWithKey = new PersonCassandra();
            personWithKey.setPersonId("111");
            // convert file into array of bytes
            fileInputStream = new FileInputStream(file);
            fileInputStream.read(bFile);
            fileInputStream.close();

            personWithKey.setA(bFile);
            em.persist(personWithKey);
            em.clear();

            String qry = "Select p from PersonCassandra p where p.personId = 111";
            Query q = em.createQuery(qry);
            List<PersonCassandra> persons = q.getResultList();
            PersonCassandra person = persons.get(0);

            // convert array of bytes into file
            FileOutputStream fileOuputStream = new FileOutputStream("src/test/resources/persistence-test.pdf");
            fileOuputStream.write(person.getA());
            fileOuputStream.close();

            Assert.assertNotNull(person.getA());
            Assert.assertEquals(new File("src/test/resources/persistence.pdf").getTotalSpace(), new File(
                    "src/test/resources/persistence-test.pdf").getTotalSpace());
            Assert.assertTrue(isFileBinaryEqual(new File("src/test/resources/persistence.pdf"), new File(
                    "src/test/resources/persistence-test.pdf")));
            Assert.assertEquals(String.valueOf(Hex.encodeHex((byte[]) bFile)),
                    String.valueOf(Hex.encodeHex((byte[]) person.getA())));

        }
        catch (Exception e)
        {
View Full Code Here

    private List<PersonCassandra> prepareData(Integer noOfRecords)
    {
        List<PersonCassandra> persons = new ArrayList<PersonCassandra>();
        for (int i = 1; i <= noOfRecords; i++)
        {
            PersonCassandra o = new PersonCassandra();
            o.setPersonId(i + "");
            o.setPersonName("vivek" + i);
            o.setAge(10);
            persons.add(o);
        }

        return persons;
    }
View Full Code Here

        entityManager.persist(p1);
        entityManager.persist(p2);
        entityManager.persist(p3);

        PersonCassandra personWithKey = new PersonCassandra();
        personWithKey.setPersonId("111");
        entityManager.persist(personWithKey);
        col.put("1", p1);
        col.put("2", p2);
        col.put("3", p3);

        entityManager.clear();
        PersonCassandra p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("vivek", p.getPersonName());
        Assert.assertEquals(Day.thursday, p.getDay());

        entityManager.clear();
        Query q;
        List<PersonCassandra> persons = queryOverRowkey();

        assertFindByName(entityManager, "PersonCassandra", PersonCassandra.class, "vivek", "personName");
        assertFindByNameAndAge(entityManager, "PersonCassandra", PersonCassandra.class, "vivek", "10", "personName");
        assertFindByNameAndAgeGTAndLT(entityManager, "PersonCassandra", PersonCassandra.class, "vivek", "10", "20",
                "personName");
        assertFindByNameAndAgeBetween(entityManager, "PersonCassandra", PersonCassandra.class, "vivek", "10", "15",
                "personName");
        assertFindByRange(entityManager, "PersonCassandra", PersonCassandra.class, "1", "2", "personId", true);
        assertFindWithoutWhereClause(entityManager, "PersonCassandra", PersonCassandra.class, true);

        // perform merge after query.
        for (PersonCassandra person : persons)
        {
            person.setPersonName("'after merge'");
            entityManager.merge(person);
        }

        entityManager.clear();

        p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("'after merge'", p.getPersonName());

        String updateQuery = "update PersonCassandra p set p.personName=''KK MISHRA'' where p.personId=1";
        q = entityManager.createQuery(updateQuery);
        q.executeUpdate();

        entityManager.clear();
        p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("'KK MISHRA'", p.getPersonName());

        testCountResult();
        // Delete without WHERE clause.

        String deleteQuery = "DELETE from PersonCassandra";
View Full Code Here

        entityManager.clear();
        col.put("1", p1);
        col.put("2", p2);
        col.put("3", p3);
        PersonCassandra p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("vivek", p.getPersonName());
        Assert.assertEquals(Month.APRIL, p.getMonth());
        // modify record.
        p.setPersonName("newvivek");
        entityManager.merge(p);

        assertOnMerge(entityManager, "PersonCassandra", PersonCassandra.class, "vivek", "newvivek", "personName");
    }
View Full Code Here

        entityManager.persist(p3);

        col.put("1", p1);
        col.put("2", p2);
        col.put("3", p3);
        PersonCassandra p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("vivek", p.getPersonName());
        entityManager.remove(p);
        entityManager.clear();

        TypedQuery<PersonCassandra> query = entityManager.createQuery("Select p from PersonCassandra p",
                PersonCassandra.class);
View Full Code Here

        Object p3 = prepareData("3", 15);
        entityManager.persist(p1);
        entityManager.persist(p2);
        entityManager.persist(p3);
        entityManager.clear();
        PersonCassandra person = entityManager.find(PersonCassandra.class, "1");
        entityManager.remove(person);
        entityManager.clear(); // just to make sure that not to be picked up
                               // from cache.
        TypedQuery<PersonCassandra> query = entityManager.createQuery("Select p from PersonCassandra p",
                PersonCassandra.class);
View Full Code Here

        entityManager.persist(p1);
        entityManager.persist(p2);
        entityManager.persist(p3);

        PersonCassandra personWithKey = new PersonCassandra();
        personWithKey.setPersonId("111");
        entityManager.persist(personWithKey);
        col.put("1", p1);
        col.put("2", p2);
        col.put("3", p3);

        entityManager.clear();
        PersonCassandra p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("vivek", p.getPersonName());
        Assert.assertEquals(Day.thursday, p.getDay());

        entityManager.clear();
        Query q;
        List<PersonCassandra> persons = queryOverRowkey();

        assertFindByName(entityManager, PersonCassandra.class, PersonCassandra.class, "vivek", "personName");
        assertFindByNameAndAge(entityManager, PersonCassandra.class, PersonCassandra.class, "vivek", "10", "personName");
        assertFindByNameAndAgeGTAndLT(entityManager, PersonCassandra.class, PersonCassandra.class, "vivek", "10", "20",
                "personName");
        assertFindByNameAndAgeBetween(entityManager, PersonCassandra.class, PersonCassandra.class, "vivek", "10", "15",
                "personName");
        assertFindByRange(entityManager, PersonCassandra.class, PersonCassandra.class, "1", "2", "personId", true);
        assertFindWithoutWhereClause(entityManager, PersonCassandra.class, PersonCassandra.class, true);

        // perform merge after query.
        for (PersonCassandra person : persons)
        {
            person.setPersonName("'after merge'");
            entityManager.merge(person);
        }

        entityManager.clear();

        p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("'after merge'", p.getPersonName());

        String updateQuery = "update PersonCassandra p set p.personName=''KK MISHRA'' where p.personId=1";
        q = entityManager.createQuery(updateQuery);
        q.executeUpdate();

        entityManager.clear();
        p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("'KK MISHRA'", p.getPersonName());

       
        // Delete without WHERE clause.

        String deleteQuery = "DELETE from PersonCassandra";
View Full Code Here

        entityManager.clear();
        col.put("1", p1);
        col.put("2", p2);
        col.put("3", p3);
        PersonCassandra p = findById(PersonCassandra.class, "1", entityManager);
        Assert.assertNotNull(p);
        Assert.assertEquals("vivek", p.getPersonName());
        Assert.assertEquals(Month.APRIL, p.getMonth());
        // modify record.
        p.setPersonName("newvivek");
        entityManager.merge(p);

        assertOnMerge(entityManager, PersonCassandra.class, PersonCassandra.class, "vivek", "newvivek", "personName");
    }
View Full Code Here

TOP

Related Classes of com.impetus.client.crud.PersonCassandra

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.