Search in sources :

Example 6 with Address

use of com.orientechnologies.orient.test.domain.business.Address 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 7 with Address

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

the class ObjectDetachingTestSchemaFull method testReloadAndDetachAll.

@Test(dependsOnMethods = "testDetachAllNonProxied")
public void testReloadAndDetachAll() {
    // DELETE PREVIOUS TEST DATA
    database.command(new OCommandSQL("delete from Profile where nick = 'Jack'")).execute();
    // Open db
    // Create the address without country
    Address anAddress = new Address("Godewaersvelde");
    anAddress = database.save(anAddress);
    Address realAddress = database.detachAll(anAddress, true);
    // Create the person
    Profile aPerson = new Profile("Jack", "Jack", "Black", null);
    aPerson.setLocation(realAddress);
    aPerson = database.save(aPerson);
    // Update the address by another way (another process for example)
    City aCity = new City("Paris");
    aCity = database.save(aCity);
    String command = "update " + anAddress.getId() + " set city = " + database.getIdentity(aCity);
    database.command(new OCommandSQL(command)).execute();
    realAddress = database.reload(anAddress, true);
    Assert.assertNotNull(realAddress.getCity());
    // At this point, in OrientDB Studio everything is fine
    // The address has the good country @rid, with version +1
    // Now reload and detachAll the person
    Profile newPerson = database.reload(aPerson, "*:-1", true);
    Profile finalPerson = database.detachAll(newPerson, true);
    // But with the reload, the country is null
    // out = null
    Assert.assertNotNull(finalPerson.getLocation().getCity());
    // Same problem with query and detachAll
    String query = "select from Profile where name = 'Jack' and surname = 'Black'";
    newPerson = (Profile) database.query(new OSQLSynchQuery<Object>(query), new Object[0]).get(0);
    finalPerson = database.detachAll(newPerson, true);
    // out = null
    Assert.assertNotNull(finalPerson.getLocation().getCity());
// Close db
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Address(com.orientechnologies.orient.test.domain.business.Address) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) City(com.orientechnologies.orient.test.domain.business.City) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 8 with Address

use of com.orientechnologies.orient.test.domain.business.Address 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 9 with Address

use of com.orientechnologies.orient.test.domain.business.Address 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 10 with Address

use of com.orientechnologies.orient.test.domain.business.Address 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)

Aggregations

Address (com.orientechnologies.orient.test.domain.business.Address)11 Test (org.testng.annotations.Test)10 City (com.orientechnologies.orient.test.domain.business.City)6 Account (com.orientechnologies.orient.test.domain.business.Account)5 Country (com.orientechnologies.orient.test.domain.business.Country)4 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)4 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 Company (com.orientechnologies.orient.test.domain.business.Company)2 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)1 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)1 EnumTest (com.orientechnologies.orient.test.domain.base.EnumTest)1 ArrayList (java.util.ArrayList)1