@Override public Class<Collection<E>> getJavaType() { return super.getBoundJavaType(); }
private String getActualColumnName(Attribute attribute) { if (attribute instanceof DefaultSingularAttribute) { DefaultSingularAttribute dsAttribute = (DefaultSingularAttribute) attribute; if (dsAttribute.isId()) { return "_id"; } else { return dsAttribute.getJPAColumnName(); } } else if (attribute instanceof AbstractAttribute) { return ((AbstractAttribute) attribute).getJPAColumnName(); } else { return attribute.getName(); } }
/** * Determined TTL for a given column. * * @param columnTTLs * the column tt ls * @param attribute * the attribute * @return the TTL for column */ private int getTTLForColumn(Object columnTTLs, Attribute attribute) { Integer ttl = null; if (columnTTLs != null) { if (columnTTLs instanceof Map) { ttl = (Integer) (columnTTLs == null ? 0 : ((Map) columnTTLs).get(((AbstractAttribute) attribute) .getJPAColumnName())); } else if (columnTTLs instanceof Integer) { ttl = (Integer) columnTTLs; } } return ttl == null ? 0 : ttl; }
/** * getOrderByColumn method return order by value of the column * * @param String * [] orderByColumns * * @param Attribute * column * * @return orderColumnValue. */ private String getOrderByColumn(String[] orderByColumns, Attribute column) { if (orderByColumns != null) { for (String orderColumn : orderByColumns) { String[] orderValue = orderColumn.split("\\s"); String orderColumnName = orderValue[0].substring(orderValue[0].lastIndexOf('.') + 1); String orderColumnValue = orderValue[1]; if (orderColumnName.equals(((AbstractAttribute) column).getName()) || orderColumnName.equals(((AbstractAttribute) column).getJPAColumnName())) { return orderColumnValue; } } } return null; }
private static Class getValueType(EntityType entity, String fieldName) { Class valueClazz = null; if (fieldName != null) { valueClazz = ((AbstractAttribute) entity.getAttribute(fieldName)).getBindableJavaType(); } return valueClazz; }
@Test public void testGetType() { Assert.assertEquals(AttributeType.SET,AttributeType.getType(Set.class)); Assert.assertEquals(AttributeType.LIST,AttributeType.getType(List.class)); Assert.assertEquals(AttributeType.ENUM,AttributeType.getType(Day.class)); Assert.assertEquals(AttributeType.MAP,AttributeType.getType(Map.class)); Assert.assertEquals(AttributeType.POINT,AttributeType.getType(Point.class)); Assert.assertEquals(AttributeType.PRIMITIVE,AttributeType.getType(int.class)); }
@Override public boolean isOptional() { boolean isNullable = true; if (!isId()) { Column anno = member.getAnnotation(Column.class); if (anno != null) { isNullable = anno.nullable(); } } else { isNullable = false; } return isNullable; }
/** * Checks if is id col. * * @param m * the m * @param colName * the col name * @return true, if is id col */ private boolean isIdCol(EntityMetadata m, String colName) { return ((AbstractAttribute) m.getIdAttribute()).getJPAColumnName().equals(colName); }
/** * Gets the compound key. * * @param attribute * the attribute * @param entity * the entity * @return the compound key * @throws InstantiationException * the instantiation exception * @throws IllegalAccessException * the illegal access exception */ private Object getCompoundKey(Attribute attribute, Object entity) throws InstantiationException, IllegalAccessException { Object compoundKeyObject = null; if (entity != null) { compoundKeyObject = PropertyAccessorHelper.getObject(entity, (Field) attribute.getJavaMember()); if (compoundKeyObject == null) { compoundKeyObject = ((AbstractAttribute) attribute).getBindableJavaType().newInstance(); } } return compoundKeyObject; }
@Override public Class<Map<K, V>> getJavaType() { return super.getBoundJavaType(); }
if (column.equals(((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName()))
/** * Gets the key as string. * * @param id * the id * @param metadata * the metadata * @param metaModel * the meta model * @return the key as string */ private String getKeyAsString(Object id, EntityMetadata metadata, MetamodelImpl metaModel) { if (metaModel.isEmbeddable(((AbstractAttribute) metadata.getIdAttribute()).getBindableJavaType())) { return KunderaCoreUtils.prepareCompositeKey(metadata, id); } return id.toString(); }
@Override public Class<List<E>> getJavaType() { return super.getBoundJavaType(); } }
@Override public void writeColumn(HTableInterface htable, String columnFamily, Object rowKey, Attribute column, Object columnObj) throws IOException { Put p = new Put(HBaseUtils.getBytes(rowKey)); p.add(Bytes.toBytes(columnFamily), Bytes.toBytes(((AbstractAttribute) column).getJPAColumnName()), Bytes.toBytes(columnObj.toString())); htable.put(p); }
@Override public Class<Set<E>> getJavaType() { return super.getBoundJavaType(); } }
/** * Gets the object from json. * * @param jsonObj * the json obj * @param clazz * the clazz * @param columns * the columns * @return the object from json */ static Object getObjectFromJson(JsonObject jsonObj, Class clazz, Set<Attribute> columns) { Object obj = KunderaCoreUtils.createNewInstance(clazz); for (Attribute column : columns) { JsonElement value = jsonObj.get(((AbstractAttribute) column).getJPAColumnName()); setFieldValue(obj, column, value); } return obj; }
/** * Creates the columns field map. * * @param m * the m * @param superColumn * the super column * @return the map */ public static Map<String, Field> createColumnsFieldMap(EntityMetadata m, EmbeddableType superColumn) { Map<String, Field> columnNameToFieldMap = new HashMap<String, Field>(); Set<Attribute> attributes = superColumn.getAttributes(); for (Attribute column : attributes) { columnNameToFieldMap.put(((AbstractAttribute) column).getJPAColumnName(), (Field) column.getJavaMember()); } return columnNameToFieldMap; }
/** * Create "Proxy" nodes into Neo4J. Proxy nodes are defined as nodes in * Neo4J that refer to a record in some other database. They cater to * polyglot persistence cases. */ public Node createProxyNode(Object sourceNodeId, Object targetNodeId, GraphDatabaseService graphDb, EntityMetadata sourceEntityMetadata, EntityMetadata targetEntityMetadata) { String sourceNodeIdColumnName = ((AbstractAttribute) sourceEntityMetadata.getIdAttribute()).getJPAColumnName(); String targetNodeIdColumnName = ((AbstractAttribute) targetEntityMetadata.getIdAttribute()).getJPAColumnName(); Node node = graphDb.createNode(); node.setProperty(PROXY_NODE_TYPE_KEY, PROXY_NODE_VALUE); node.setProperty(sourceNodeIdColumnName, sourceNodeId); node.setProperty(targetNodeIdColumnName, targetNodeId); return node; }
/** * Find GRIDFSDBFile. * * @param entityMetadata * the entity metadata * @param key * the key * @return the grid fsdb file */ private GridFSDBFile findGridFSDBFile(EntityMetadata entityMetadata, Object key) { String id = ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName(); DBObject query = new BasicDBObject("metadata." + id, key); KunderaGridFS gfs = new KunderaGridFS(mongoDb, entityMetadata.getTableName()); return gfs.findOne(query); }
@Override public Object[] findIdsByColumn(String schemaName, String tableName, String pKeyName, String columnName, Object columnValue, Class entityClazz) { EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz); return getColumnsById(schemaName, tableName, columnName, ((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName(), columnValue, metadata.getIdAttribute().getBindableJavaType()).toArray(); }