我是Neo4j的新手,正在浏览Spring-data-Neo4j文档。目前我不清楚在实体bean中定义节点关系。
我们可以在某个媒体资源上@Relationship
,direction
为INCOMING
或OUTGOING
。我们也可以@RelationshipEntity
来定义@StartNode
和@EndNode
。
如果我们在关系上有其他属性,则需要@RelationshipEntity
。但是一旦我们定义了一个关系实体,我们在关系中的任一节点上仍然需要@Relationship
吗?我们是否需要在两侧的Entity类中定义所有关系?怎么决定?定义双方的所有关系是否会影响绩效?
答案 0 :(得分:2)
使用关系实体时,SDN 4的当前版本要求您从至少开始节点实体引用它。
如果您计划持久化终端节点实体并期望关系实体也被保留,您还应该从端节点实体引用它。
建议让您的对象模型尽可能接近图形模型。 http://graphaware.com/neo4j/2015/09/03/sdn-4-object-model.html
上的示例和更多解释请注意,如果您没有关系的属性,那么您不能使用RelationshipEntity而是使用常规public static Bitmap decodeSampledBitmapFromFile(String filename,
int reqWidth, int reqHeight) {
//this gets parameters:
// reqHeight: 960, reqWidth: 1280 and filename: /data/data/my.app.project/app_photo/JPEG_20151105_092219_-1434131481.jpg
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filename, options); // this adds outHeight and outWidth to -1 (variables from options)
//this also creates a log entry: D/skia: --- SkImageDecoder::Factory returned null
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap bmp = BitmapFactory.decodeFile(filename, options);
return bmp;
}
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// BEGIN_INCLUDE (calculate_sample_size)
// Raw height and width of image
final int height = options.outHeight; //is -1
final int width = options.outWidth; //is -1
int inSampleSize = 1;
//because its obviously smaller in both statements code will not be executed so it returns 1
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
// This offers some additional logic in case the image has a strange
// aspect ratio. For example, a panorama may have a much larger
// width than height. In these cases the total pixels might still
// end up being too large to fit comfortably in memory, so we should
// be more aggressive with sample down the image (=larger inSampleSize).
long totalPixels = width * height / inSampleSize;
// Anything more than 2x the requested pixels we'll sample down further
final long totalReqPixelsCap = reqWidth * reqHeight * 2;
while (totalPixels > totalReqPixelsCap) {
inSampleSize *= 2;
totalPixels /= 2;
}
}
return inSampleSize;
// END_INCLUDE (calculate_sample_size)
}
s