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);
}
}
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();
}
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();
}
}
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);
}
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());
}
Aggregations