use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class AttributeLoaderIT method assertLobDbEntities.
private void assertLobDbEntities() {
DbEntity blobEnt = getDbEntity("BLOB_TEST");
assertNotNull(blobEnt);
DbAttribute blobAttr = getDbAttribute(blobEnt, "BLOB_COL");
assertNotNull(blobAttr);
assertTrue(msgForTypeMismatch(Types.BLOB, blobAttr), Types.BLOB == blobAttr.getType() || Types.VARBINARY == blobAttr.getType() || Types.LONGVARBINARY == blobAttr.getType());
DbEntity clobEnt = getDbEntity("CLOB_TEST");
assertNotNull(clobEnt);
DbAttribute clobAttr = getDbAttribute(clobEnt, "CLOB_COL");
assertNotNull(clobAttr);
assertTrue(msgForTypeMismatch(Types.CLOB, clobAttr), Types.CLOB == clobAttr.getType() || Types.VARCHAR == clobAttr.getType() || Types.LONGVARCHAR == clobAttr.getType());
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class ExportedKeyLoaderIT method testExportedKeyLoad.
@Test
public void testExportedKeyLoad() throws Exception {
boolean supportsFK = accessStackAdapter.supportsFKConstraints();
if (!supportsFK) {
return;
}
createEntity(nameForDb("ARTIST"));
createEntity(nameForDb("GALLERY"));
createEntity(nameForDb("PAINTING"));
DbEntity artist = getDbEntity("ARTIST");
DbAttribute artistId = new DbAttribute("ARTIST_ID");
artist.addAttribute(artistId);
DbEntity gallery = getDbEntity("GALLERY");
DbAttribute galleryId = new DbAttribute("GALLERY_ID");
gallery.addAttribute(galleryId);
DbEntity painting = getDbEntity("PAINTING");
DbAttribute paintingId = new DbAttribute("PAINTING_ID");
DbAttribute paintingArtistId = new DbAttribute("ARTIST_ID");
DbAttribute paintingGalleryId = new DbAttribute("GALLERY_ID");
painting.addAttribute(paintingId);
painting.addAttribute(paintingArtistId);
painting.addAttribute(paintingGalleryId);
ExportedKeyLoader loader = new ExportedKeyLoader(EMPTY_CONFIG, new DefaultDbLoaderDelegate());
loader.load(connection.getMetaData(), store);
assertEquals(2, store.getExportedKeysEntrySet().size());
ExportedKey artistIdFk = findArtistExportedKey();
assertNotNull(artistIdFk);
assertEquals("ARTIST", artistIdFk.getPk().getTable().toUpperCase());
assertEquals("ARTIST_ID", artistIdFk.getPk().getColumn().toUpperCase());
assertEquals("PAINTING", artistIdFk.getFk().getTable().toUpperCase());
assertEquals("ARTIST_ID", artistIdFk.getFk().getColumn().toUpperCase());
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class PrimaryKeyLoaderIT method testPrimaryKeyLoad.
@Test
public void testPrimaryKeyLoad() throws Exception {
createDbEntities();
DbEntity artist = getDbEntity(nameForDb("ARTIST"));
DbAttribute artistId = new DbAttribute(nameForDb("ARTIST_ID"));
DbAttribute artistName = new DbAttribute(nameForDb("ARTIST_NAME"));
DbAttribute artistId1 = new DbAttribute(nameForDb("ARTIST_ID1"));
artist.addAttribute(artistId);
artist.addAttribute(artistName);
artist.addAttribute(artistId1);
assertFalse(artistId.isPrimaryKey());
assertFalse(artistName.isPrimaryKey());
assertFalse(artistId1.isPrimaryKey());
PrimaryKeyLoader loader = new PrimaryKeyLoader(EMPTY_CONFIG, new DefaultDbLoaderDelegate());
loader.load(connection.getMetaData(), store);
assertTrue(artistId.isPrimaryKey());
assertFalse(artistId1.isPrimaryKey());
assertFalse(artistName.isPrimaryKey());
Collection<DbAttribute> pk = artist.getPrimaryKeys();
assertEquals(1, pk.size());
assertEquals(artistId, pk.iterator().next());
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class DefaultValueTransformerFactory method getJavaType.
// TODO: calculating Java type of ObjAttribute may become unneeded per
// CAY-1752, as DbAttribute will have it.
protected String getJavaType(DbAttribute a) {
DbEntity dbEntity = a.getEntity();
DataMap dataMap = dbEntity.getDataMap();
Collection<String> javaTypes = new HashSet<>();
for (ObjEntity objEntity : dataMap.getMappedEntities(dbEntity)) {
for (ObjAttribute oa : objEntity.getAttributes()) {
// TODO: this won't pick up flattened attributes
if (a.getName().equals(oa.getDbAttributePath())) {
javaTypes.add(oa.getType());
}
}
}
if (javaTypes.size() != 1) {
String javaType = TypesMapping.getJavaBySqlType(a.getType());
String attributeName = dbEntity.getName() + "." + a.getName();
String msg = javaTypes.size() > 1 ? "ObjAttributes with different java types" : "No ObjAttributes";
// Warn user about this problem as there is nothing else we can do
logger.warn(msg + " bound to DbAttribute '" + attributeName + "', " + javaType + " type will be used.");
return javaType;
}
return javaTypes.iterator().next();
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class DefaultValueTransformerFactoryIT method testGetJavaType.
@Test
public void testGetJavaType() {
DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING");
assertEquals("java.lang.String", f.getJavaType(t1_ct));
DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES");
assertEquals("byte[]", f.getJavaType(t2_cb));
DbEntity fakeEntity = mock(DbEntity.class);
when(fakeEntity.getDataMap()).thenReturn(t1.getDataMap());
DbAttribute fakeA1 = mock(DbAttribute.class);
when(fakeA1.getName()).thenReturn("fake1");
when(fakeA1.getEntity()).thenReturn(fakeEntity);
when(fakeA1.getType()).thenReturn(Types.VARBINARY);
assertEquals("byte[]", f.getJavaType(fakeA1));
DbAttribute fakeA2 = mock(DbAttribute.class);
when(fakeA2.getName()).thenReturn("fake2");
when(fakeA2.getEntity()).thenReturn(fakeEntity);
when(fakeA2.getType()).thenReturn(Types.VARCHAR);
assertEquals("java.lang.String", f.getJavaType(fakeA2));
}
Aggregations