/** * Initialize. * * @param entityMetadata * the entity metadata * @return the map */ private Map<String, Object> initialize(EntityMetadata entityMetadata) { Map<String, Object> relationMap = null; if (entityMetadata.getRelationNames() != null && !entityMetadata.getRelationNames().isEmpty()) { relationMap = new HashMap<String, Object>(); } return relationMap; }
/** * Returns true, if associated entity holds relational references(e.g. @OneToMany * etc.) else false. * * @param m * entity metadata * * @return true, if holds relation else false */ private boolean isRelational(EntityMetadata m) { // if related via join table OR contains relations. return m.isRelationViaJoinTable() || (m.getRelationNames() != null && (!m.getRelationNames().isEmpty())); }
/** * Finds a {@link List} of entities from database. * * @param <E> * the element type * @param entityClass * the entity class * @param columnsToSelect * TODO * @param rowIds * the row ids * @return the list */ public <E> List<E> findAll(Class<E> entityClass, String[] columnsToSelect, Object... rowIds) { EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass); List<E> results = new ArrayList<E>(); results = find(entityClass, entityMetadata.getRelationNames(), entityMetadata.getRelationNames() != null && !entityMetadata.getRelationNames().isEmpty(), entityMetadata, rowIds); return results.isEmpty() ? null : results; }
/** * Finds an entiry from database. * * @param entityClass * the entity class * @param rowId * the row id * @return the object */ public Object find(Class entityClass, Object rowId) { EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass); List<String> relationNames = entityMetadata.getRelationNames(); return find(entityClass, entityMetadata, rowId, relationNames); }
/** * on check relation event, invokes populate entities and set relational * entities, in case relations are present. */ private void onCheckRelation() { try { results = populateEntities(entityMetadata, client); if (entityMetadata.isRelationViaJoinTable() || (entityMetadata.getRelationNames() != null && !(entityMetadata.getRelationNames().isEmpty()))) { query.setRelationalEntities(results, client, entityMetadata); } } catch (Exception e) { throw new PersistenceException("Error while scrolling over results, Caused by :.", e); } }
public List findByRelation(String colName, Object colValue, Class entityClazz) { EntityMetadata m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz); String tableName = m.getTableName(); // Suffixing the UNDERSCORE instead of prefix as Oracle 11g complains // about invalid characters error while executing the request. StringBuilder queryBuilder = new StringBuilder("Select "); queryBuilder.append("* "); queryBuilder.append("From "); queryBuilder.append(getFromClause(m.getSchema(), tableName)); queryBuilder.append(" "); queryBuilder.append(" Where "); queryBuilder.append(colName); queryBuilder.append(" = "); queryBuilder.append("'"); queryBuilder.append(colValue); queryBuilder.append("'"); s = getStatelessSession(); List results = find(queryBuilder.toString(), m.getRelationNames(), m); return populateEnhanceEntities(m, m.getRelationNames(), results); }
/** * Sets the entities in result. * * @param m * the m * @param results * the results * @param array * the array */ private void setEntitiesInResult(EntityMetadata m, List results, JsonArray array) { for (JsonElement element : array) { String id = element.getAsJsonObject().get("value").getAsJsonObject() .get(((AbstractAttribute) m.getIdAttribute()).getJPAColumnName()).getAsString(); Object entityFromJson = CouchDBObjectMapper.getEntityFromJson(m.getEntityClazz(), m, element .getAsJsonObject().get("value").getAsJsonObject(), m.getRelationNames(), kunderaMetadata); if (entityFromJson != null && (m.getTableName().concat(id)).equals(element.getAsJsonObject().get("id").getAsString())) { results.add(entityFromJson); } } }
@Override public E next() { if (!checkOnFetchSize() || scrollComplete) { throw new NoSuchElementException("Nothing to scroll further for:" + entityMetadata.getEntityClazz()); } E result = (E) handler.next(entityMetadata, columns); if (!entityMetadata.isRelationViaJoinTable() && (entityMetadata.getRelationNames() == null || (entityMetadata.getRelationNames().isEmpty()))) { return result; } else { return result = setRelationEntities(result, client, entityMetadata); } }
@Override public E next() { if (!checkOnFetchSize() || scrollComplete) { throw new NoSuchElementException("Nothing to scroll further for:" + entityMetadata.getEntityClazz()); } E result = (E) handler.next(entityMetadata); if (!entityMetadata.isRelationViaJoinTable() && (entityMetadata.getRelationNames() == null || (entityMetadata.getRelationNames().isEmpty()))) { return result; } else { return result = setRelationEntities(result, client, entityMetadata); } }
/** * On association using lucene. * * @param m * the m * @param client * the client * @param ls * the ls * @return the list */ protected List<EnhanceEntity> onAssociationUsingLucene(EntityMetadata m, Client client, List<EnhanceEntity> ls) { Set<String> rSet = fetchDataFromLucene(m.getEntityClazz(), client); List resultList = client.findAll(m.getEntityClazz(), null, rSet.toArray(new String[] {})); return m.getRelationNames() != null && !m.getRelationNames().isEmpty() ? resultList : transform(m, ls, resultList); }
selectQueryBuilder.delete(selectQueryBuilder.lastIndexOf(CQLTranslator.AND_CLAUSE), selectQueryBuilder.length()); return this.executeQuery(clazz, m.getRelationNames(), dataHandler, true, false, selectQueryBuilder.toString());
public Object next(EntityMetadata m) { Object entity = null; HBaseData result = ((HBaseReader) hbaseReader).next(); List<HBaseData> results = new ArrayList<HBaseData>(); List output = new ArrayList(); results.add(result); try { output = onRead(m.getSchema(), m.getEntityClazz(), m, output, gethTable(m.getSchema()), entity, m.getRelationNames(), results); } catch (IOException e) { log.error("Error during finding next record, Caused by: .", e); throw new KunderaException(e); } return output != null && !output.isEmpty() ? output.get(0) : output; }
@Override public EnhanceEntity findById(Object primaryKey, EntityMetadata m, Client client) { List<String> relationNames = m.getRelationNames(); if (relationNames != null && !relationNames.isEmpty()) { Set<String> keys = new HashSet<String>(1); keys.add(primaryKey.toString()); String query = getSqlQueryFromJPA(m, relationNames, keys); List<EnhanceEntity> results = populateEnhanceEntities(m, relationNames, client, query); return results != null && !results.isEmpty() ? results.get(0) : null; } else { Object o; try { o = client.find(m.getEntityClazz(), primaryKey); } catch (Exception e) { throw new PersistenceException(e); } return o != null ? new EnhanceEntity(o, getId(o, m), null) : null; } // return super.findById(primaryKey, m, client); }
Map<String, Object> relationValue = null; relationValue = handler.getEntityFromDocument(m.getEntityClazz(), entityFromDocument, m, document, m.getRelationNames(), relationValue, persistenceDelegator.getKunderaMetadata()); if (!m.isRelationViaJoinTable() && (m.getRelationNames() == null || (m.getRelationNames().isEmpty())))
EntityMetadata subEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, subEntity.getJavaType()); result = populate(clazz, subEntityMetadata, rowId, subEntityMetadata.getRelationNames(), metaModel); if (result != null && !result.isEmpty()) { break;
@Override public Iterator iterate() { if (kunderaQuery.isNative()) { throw new UnsupportedOperationException("Iteration not supported over native queries"); } initializeReader(); EntityMetadata m = getEntityMetadata(); Client client = persistenceDelegeator.getClient(m); return new ResultIterator((HibernateClient) client, m, persistenceDelegeator, getFetchSize() != null ? getFetchSize() : this.maxResult, ((RDBMSEntityReader) getReader()).getSqlQueryFromJPA(m, m.getRelationNames(), null)); }
@Override public List readDataByRange(String tableName, Class clazz, EntityMetadata m, byte[] startRow, byte[] endRow, String[] columns, FilterList f) throws IOException { List output = new ArrayList(); HTableInterface hTable = null; Object entity = null; List<String> relationNames = m.getRelationNames(); Filter filter = getFilter(m.getTableName()); if (filter != null) { if (f == null) { f = new FilterList(); } f.addFilter(filter); } // Load raw data from HBase hTable = gethTable(tableName); List<HBaseData> results = hbaseReader.loadAll(hTable, f, startRow, endRow, m.getTableName(), null, columns); output = onRead(tableName, clazz, m, output, hTable, entity, relationNames, results); return output; }
List<String> relations = m.getRelationNames(); if (relations != null)
protected List findUsingLucene(EntityMetadata m, Client client) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit()); boolean useInvertedIndex = CassandraIndexHelper.isInvertedIndexingApplicable(m, MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata())); Map<Boolean, List<IndexClause>> ixClause = prepareIndexClause(m, useInvertedIndex); List<Object> result = new ArrayList<Object>(); if (((CassandraClientBase) client).isCql3Enabled(m)) { result = ((CassandraClientBase) client).executeQuery(m.getEntityClazz(), m.getRelationNames(), false, onQueryOverCQL3(m, client, metaModel, m.getRelationNames())); } else { result = ((CassandraEntityReader) getReader()).handleFindByRange(m, client, result, ixClause, true, getColumnList(m, metaModel, getKunderaQuery().getResult(), null), isSingleResult ? 1 : this.maxResult); } return result; }
/** * * @param kunderaQuery * @return */ private String parseAndCreateCqlQuery(KunderaQuery kunderaQuery, EntityManagerFactory emf, EntityManager em, String puName, Class entityClass, Integer maxResult) { Method getpd = null; try { getpd = EntityManagerImpl.class.getDeclaredMethod("getPersistenceDelegator"); } catch (Exception e) { log.error("Error during execution, Caused by : ",e.getMessage()); } getpd.setAccessible(true); PersistenceDelegator pd = getPersistenceDelegator(em, getpd); KunderaMetadata kunderaMetadata = ((EntityManagerFactoryImpl) emf).getKunderaMetadataInstance(); CassQuery query = new CassQuery(kunderaQuery, pd, kunderaMetadata); query.setMaxResults(maxResult); EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass); Metamodel metaModel = KunderaMetadataManager.getMetamodel(kunderaMetadata, puName); Client<CassQuery> client = pd.getClient(metadata); String cqlQuery = query.onQueryOverCQL3(metadata, client, (MetamodelImpl) metaModel, metadata.getRelationNames()); return cqlQuery; }