Search in sources :

Example 16 with Account

use of com.orientechnologies.orient.test.domain.business.Account in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTestSchemaFull method synchQueryCollectionsFetch.

@Test(dependsOnMethods = "readAndBrowseDescendingAndCheckHoleUtilization")
public void synchQueryCollectionsFetch() {
    database.getLocalCache().invalidate();
    // BROWSE ALL THE OBJECTS
    Set<Integer> ids = new HashSet<Integer>(TOT_RECORDS);
    for (int i = 0; i < TOT_RECORDS; i++) ids.add(i);
    List<Account> result = database.query(new OSQLSynchQuery<Account>("select from Account").setFetchPlan("*:-1"));
    for (Account a : result) {
        if (Company.class.isAssignableFrom(a.getClass()))
            continue;
        int id = a.getId();
        Assert.assertTrue(ids.remove(id));
        Assert.assertEquals(a.getId(), id);
        Assert.assertEquals(a.getName(), "Bill");
        Assert.assertEquals(a.getSurname(), "Gates");
        Assert.assertEquals(a.getSalary(), id + 300.1f);
        Assert.assertEquals(a.getAddresses().size(), 1);
        Assert.assertEquals(a.getAddresses().get(0).getCity().getName(), rome.getName());
        Assert.assertEquals(a.getAddresses().get(0).getCity().getCountry().getName(), rome.getCountry().getName());
    }
    Assert.assertTrue(ids.isEmpty());
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Test(org.testng.annotations.Test)

Example 17 with Account

use of com.orientechnologies.orient.test.domain.business.Account in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTestSchemaFull method update.

@Test(dependsOnMethods = "mapEnumAndInternalObjects")
public void update() {
    int i = 0;
    Account a;
    for (Object o : database.browseCluster("Account").setFetchPlan("*:1")) {
        a = (Account) o;
        if (i % 2 == 0)
            a.getAddresses().set(0, new Address("work", new City(new Country("Spain"), "Madrid"), "Plaza central"));
        a.setSalary(i + 500.10f);
        database.save(a);
        i++;
    }
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) Address(com.orientechnologies.orient.test.domain.business.Address) Country(com.orientechnologies.orient.test.domain.business.Country) City(com.orientechnologies.orient.test.domain.business.City) Test(org.testng.annotations.Test)

Example 18 with Account

use of com.orientechnologies.orient.test.domain.business.Account in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTestSchemaFull method synchQueryCollectionsFetchNoLazyLoad.

@Test(dependsOnMethods = "synchQueryCollectionsFetch")
public void synchQueryCollectionsFetchNoLazyLoad() {
    database.getLocalCache().invalidate();
    database.setLazyLoading(false);
    // BROWSE ALL THE OBJECTS
    Set<Integer> ids = new HashSet<Integer>(TOT_RECORDS);
    for (int i = 0; i < TOT_RECORDS; i++) ids.add(i);
    List<Account> result = database.query(new OSQLSynchQuery<Account>("select from Account").setFetchPlan("*:2"));
    for (Account a : result) {
        if (Company.class.isAssignableFrom(a.getClass()))
            continue;
        int id = a.getId();
        Assert.assertTrue(ids.remove(id));
        Assert.assertEquals(a.getId(), id);
        Assert.assertEquals(a.getName(), "Bill");
        Assert.assertEquals(a.getSurname(), "Gates");
        Assert.assertEquals(a.getSalary(), id + 300.1f);
        Assert.assertEquals(a.getAddresses().size(), 1);
        Assert.assertEquals(a.getAddresses().get(0).getCity().getName(), rome.getName());
        Assert.assertEquals(a.getAddresses().get(0).getCity().getCountry().getName(), rome.getCountry().getName());
    }
    Assert.assertTrue(ids.isEmpty());
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Test(org.testng.annotations.Test)

Example 19 with Account

use of com.orientechnologies.orient.test.domain.business.Account in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTest method update.

@Test(dependsOnMethods = "mapEnumAndInternalObjects")
public void update() {
    int i = 0;
    Account a;
    for (Object o : database.browseClass("Account").setFetchPlan("*:1")) {
        a = (Account) o;
        if (i % 2 == 0)
            a.getAddresses().set(0, new Address("work", new City(new Country("Spain"), "Madrid"), "Plaza central"));
        a.setSalary(i + 500.10f);
        database.save(a);
        i++;
    }
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) Address(com.orientechnologies.orient.test.domain.business.Address) Country(com.orientechnologies.orient.test.domain.business.Country) City(com.orientechnologies.orient.test.domain.business.City) Test(org.testng.annotations.Test)

Example 20 with Account

use of com.orientechnologies.orient.test.domain.business.Account in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTest method testEmbeddedBinary.

@Test(enabled = false, dependsOnMethods = "testCreate")
public void testEmbeddedBinary() {
    database.getMetadata().getSchema().reload();
    Account a = new Account(0, "Chris", "Martin");
    a.setThumbnail(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
    a = database.save(a);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    Account aa = (Account) database.load((ORID) a.getRid());
    Assert.assertNotNull(a.getThumbnail());
    Assert.assertNotNull(aa.getThumbnail());
    byte[] b = aa.getThumbnail();
    for (int i = 0; i < 10; ++i) Assert.assertEquals(b[i], i);
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) ORID(com.orientechnologies.orient.core.id.ORID) Test(org.testng.annotations.Test)

Aggregations

Account (com.orientechnologies.orient.test.domain.business.Account)23 Test (org.testng.annotations.Test)21 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)5 Address (com.orientechnologies.orient.test.domain.business.Address)5 City (com.orientechnologies.orient.test.domain.business.City)4 Country (com.orientechnologies.orient.test.domain.business.Country)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 ORID (com.orientechnologies.orient.core.id.ORID)2 EnumTest (com.orientechnologies.orient.test.domain.base.EnumTest)2 Company (com.orientechnologies.orient.test.domain.business.Company)2 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)2 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)1 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)1 ArrayList (java.util.ArrayList)1