Search in sources :

Example 16 with Profile

use of com.orientechnologies.orient.test.domain.whiz.Profile in project orientdb by orientechnologies.

the class IndexTest method testIndexInMajorSelect.

@Test(dependsOnMethods = "populateIndexDocuments")
public void testIndexInMajorSelect() {
    if (database.getStorage() instanceof OStorageProxy) {
        return;
    }
    final boolean oldRecording = Orient.instance().getProfiler().isRecording();
    if (!oldRecording) {
        Orient.instance().getProfiler().startRecording();
    }
    long indexQueries = Orient.instance().getProfiler().getCounter("db.demo.query.indexUsed");
    if (indexQueries < 0) {
        indexQueries = 0;
    }
    final List<Profile> result = database.command(new OSQLSynchQuery<Profile>("select * from Profile where nick > 'ZZZJayLongNickIndex3'")).execute();
    final List<String> expectedNicks = new ArrayList<String>(Arrays.asList("ZZZJayLongNickIndex4", "ZZZJayLongNickIndex5"));
    if (!oldRecording) {
        Orient.instance().getProfiler().stopRecording();
    }
    Assert.assertEquals(result.size(), 2);
    for (Profile profile : result) {
        expectedNicks.remove(profile.getNick());
    }
    Assert.assertEquals(expectedNicks.size(), 0);
    long newIndexQueries = Orient.instance().getProfiler().getCounter("db.demo.query.indexUsed");
    Assert.assertEquals(newIndexQueries, indexQueries + 1);
}
Also used : OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest) OrientTest(com.orientechnologies.orient.test.database.base.OrientTest)

Example 17 with Profile

use of com.orientechnologies.orient.test.domain.whiz.Profile in project orientdb by orientechnologies.

the class IndexTest method testDuplicatedIndexOnUnique.

public void testDuplicatedIndexOnUnique() {
    Profile jayMiner = new Profile("Jay", "Jay", "Miner", null);
    database.save(jayMiner);
    Profile jacobMiner = new Profile("Jay", "Jacob", "Miner", null);
    try {
        database.save(jacobMiner);
        // IT SHOULD GIVE ERROR ON DUPLICATED KEY
        Assert.assertTrue(false);
    } catch (ORecordDuplicatedException e) {
        Assert.assertTrue(true);
    }
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) Profile(com.orientechnologies.orient.test.domain.whiz.Profile)

Example 18 with Profile

use of com.orientechnologies.orient.test.domain.whiz.Profile in project orientdb by orientechnologies.

the class ObjectTreeTest method testCityEquality.

@Test(dependsOnMethods = "testCitySaving")
public void testCityEquality() {
    List<Profile> resultset = database.query(new OSQLSynchQuery<Object>("select from profile where location.city.name = 'Rome'"));
    Assert.assertEquals(resultset.size(), 2);
    Profile p1 = resultset.get(0);
    Profile p2 = resultset.get(1);
    Assert.assertNotSame(p1, p2);
    Assert.assertSame(OObjectEntitySerializer.getDocument((Proxy) p1.getLocation().getCity()), OObjectEntitySerializer.getDocument((Proxy) p2.getLocation().getCity()));
}
Also used : Proxy(javassist.util.proxy.Proxy) OSchemaProxyObject(com.orientechnologies.orient.object.metadata.schema.OSchemaProxyObject) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test)

Example 19 with Profile

use of com.orientechnologies.orient.test.domain.whiz.Profile in project orientdb by orientechnologies.

the class ObjectTreeTest method testSaveCircularLink.

@Test(dependsOnMethods = "testCityEquality")
public void testSaveCircularLink() {
    Profile winston = database.newInstance(Profile.class, "WChurcill", "Winston", "Churcill", null);
    winston.setLocation(database.newInstance(Address.class, "Residence", database.newInstance(City.class, database.newInstance(Country.class, "England"), "London"), "unknown"));
    Profile nicholas = database.newInstance(Profile.class, "NChurcill", "Nicholas ", "Churcill", winston);
    nicholas.setLocation(winston.getLocation());
    nicholas.setInvitedBy(winston);
    winston.setInvitedBy(nicholas);
    database.save(nicholas);
}
Also used : Address(com.orientechnologies.orient.test.domain.business.Address) Country(com.orientechnologies.orient.test.domain.business.Country) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test)

Example 20 with Profile

use of com.orientechnologies.orient.test.domain.whiz.Profile in project orientdb by orientechnologies.

the class ObjectTreeTest method iteratorShouldTerminate.

@Test
public void iteratorShouldTerminate() {
    OObjectDatabaseTx db = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    try {
        db.getEntityManager().registerEntityClass(Profile.class);
        db.begin();
        Profile person = new Profile();
        person.setNick("Guy1");
        person.setName("Guy");
        person.setSurname("Ritchie");
        person = db.save(person);
        db.commit();
        db.begin();
        db.delete(person);
        db.commit();
        db.begin();
        Profile person2 = new Profile();
        person2.setNick("Guy2");
        person2.setName("Guy");
        person2.setSurname("Brush");
        person2 = db.save(person2);
        OObjectIteratorClass<Profile> it = db.browseClass(Profile.class);
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        db.commit();
    } finally {
        db.close();
    }
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test)

Aggregations

Profile (com.orientechnologies.orient.test.domain.whiz.Profile)50 Test (org.testng.annotations.Test)46 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)14 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)14 Address (com.orientechnologies.orient.test.domain.business.Address)10 Country (com.orientechnologies.orient.test.domain.business.Country)10 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)9 City (com.orientechnologies.orient.test.domain.business.City)6 ORecordId (com.orientechnologies.orient.core.id.ORecordId)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 EnumTest (com.orientechnologies.orient.test.domain.base.EnumTest)4 OLazyObjectSetInterface (com.orientechnologies.orient.core.db.object.OLazyObjectSetInterface)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)2 Account (com.orientechnologies.orient.test.domain.business.Account)2 Proxy (javassist.util.proxy.Proxy)2 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)1 OSchemaProxyObject (com.orientechnologies.orient.object.metadata.schema.OSchemaProxyObject)1