Search in sources :

Example 11 with Account

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

the class CRUDObjectPhysicalTestSchemaFull method create.

@Test
public void create() {
    createBasicTestSchema();
    database.setAutomaticSchemaGeneration(true);
    database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.business");
    if (url.startsWith(OEngineRemote.NAME)) {
        database.getMetadata().reload();
    }
    database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.base");
    if (url.startsWith(OEngineRemote.NAME)) {
        database.getMetadata().reload();
    }
    database.setAutomaticSchemaGeneration(false);
    database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.whiz");
    if (url.startsWith(OEngineRemote.NAME)) {
        database.getMetadata().reload();
    }
    startRecordNumber = database.countClusterElements("Account");
    Account account;
    for (long i = startRecordNumber; i < startRecordNumber + TOT_RECORDS; ++i) {
        account = new Account((int) i, "Bill", "Gates");
        account.setBirthDate(new Date());
        account.setSalary(i + 300.10f);
        account.getAddresses().add(new Address("Residence", rome, "Piazza Navona, 1"));
        database.save(account);
    }
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) Address(com.orientechnologies.orient.test.domain.business.Address) Test(org.testng.annotations.Test)

Example 12 with Account

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

the class IndexTest method indexLinks.

public void indexLinks() {
    database.getMetadata().getSchema().getClass("Whiz").getProperty("account").createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    final List<Account> result = database.command(new OSQLSynchQuery<Account>("select * from Account limit 1")).execute();
    final OIndex<?> idx = database.getMetadata().getIndexManager().getIndex("Whiz.account");
    for (int i = 0; i < 5; i++) {
        final ODocument whiz = new ODocument("Whiz");
        whiz.field("id", i);
        whiz.field("text", "This is a test");
        whiz.field("account", result.get(0).getRid());
        whiz.save();
    }
    Assert.assertEquals(idx.getSize(), 5);
    final List<ODocument> indexedResult = database.getUnderlying().command(new OSQLSynchQuery<Profile>("select * from Whiz where account = ?")).execute(result.get(0).getRid());
    Assert.assertEquals(indexedResult.size(), 5);
    for (final ODocument resDoc : indexedResult) {
        resDoc.delete();
    }
    final ODocument whiz = new ODocument("Whiz");
    whiz.field("id", 100);
    whiz.field("text", "This is a test!");
    whiz.field("account", new ODocument("Company").field("id", 9999));
    whiz.save();
    Assert.assertTrue(((ODocument) whiz.field("account")).getIdentity().isValid());
    ((ODocument) whiz.field("account")).delete();
    whiz.delete();
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 13 with Account

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

the class TransactionConsistencyTest method testRollbackWithRemove.

/**
   * When calling .remove(o) on a collection, the row corresponding to o is deleted and not restored when the transaction is rolled
   * back.
   * 
   * Commented code after data model change to work around this problem.
   */
@SuppressWarnings("unused")
@Test
public void testRollbackWithRemove() {
    // check if the database exists and clean before running tests
    OObjectDatabaseTx database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    try {
        Account account = new Account();
        account.setName("John Grisham");
        account = database.save(account);
        Address address1 = new Address();
        address1.setStreet("Mulholland drive");
        Address address2 = new Address();
        address2.setStreet("Via Veneto");
        List<Address> addresses = new ArrayList<Address>();
        addresses.add(address1);
        addresses.add(address2);
        account.setAddresses(addresses);
        account = database.save(account);
        database.commit();
        String originalName = account.getName();
        database.begin(TXTYPE.OPTIMISTIC);
        Assert.assertEquals(account.getAddresses().size(), 2);
        // delete one of the objects in the Books collection to see how rollback behaves
        account.getAddresses().remove(1);
        Assert.assertEquals(account.getAddresses().size(), 1);
        // change an attribute to see if the change is rolled back
        account.setName("New Name");
        account = database.save(account);
        // before rollback this is fine because one of the books was removed
        Assert.assertEquals(account.getAddresses().size(), 1);
        // rollback the transaction
        database.rollback();
        // ignore cache, get a copy of author from the datastore
        account = database.reload(account, true);
        // this is fine, author still linked to 2 books
        Assert.assertEquals(account.getAddresses().size(), 2);
        // name is restored
        Assert.assertEquals(account.getName(), originalName);
        int bookCount = 0;
        for (Address b : database.browseClass(Address.class)) {
            if (b.getStreet().equals("Mulholland drive") || b.getStreet().equals("Via Veneto"))
                bookCount++;
        }
        // this fails, only 1 entry in the datastore :(
        Assert.assertEquals(bookCount, 2);
    } finally {
        database.close();
    }
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) Address(com.orientechnologies.orient.test.domain.business.Address) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 14 with Account

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

the class CRUDObjectInheritanceTest method queryByBaseType.

@Test(dependsOnMethods = "testCreate")
public void queryByBaseType() {
    final List<Account> result = database.query(new OSQLSynchQuery<Account>("select from Company where name.length() > 0"));
    Assert.assertTrue(result.size() > 0);
    Assert.assertEquals(result.size(), TOT_RECORDS);
    int companyRecords = 0;
    Account account;
    for (int i = 0; i < result.size(); ++i) {
        account = result.get(i);
        if (account instanceof Company)
            companyRecords++;
        Assert.assertNotSame(account.getName().length(), 0);
    }
    Assert.assertEquals(companyRecords, TOT_RECORDS);
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) Company(com.orientechnologies.orient.test.domain.business.Company) Test(org.testng.annotations.Test)

Example 15 with Account

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

the class CRUDObjectPhysicalTestSchemaFull method readAndBrowseDescendingAndCheckHoleUtilization.

@Test(dependsOnMethods = "testCreate")
public void readAndBrowseDescendingAndCheckHoleUtilization() {
    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);
    for (Account a : database.browseClass(Account.class)) {
        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) 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