使用Hibernate对多个属性进行动态查询(Dynamic Query on multiple properties with Hibernate)
我有一个有几个属性的模型。 属性可以是原始(String)或复杂(Object)。 用户可以对每个原始属性进行查询。 我想知道是否有一种简单的方法来动态构建查询。 我使用Java和Hibernate。
该模型
public class Model { String prop1; Point prop2; List<Shape> prop3; }
Point
和Shape
是可以包含基元或对象的对象。 查询的示例将是prop1 =“A”且坐标为x = 3且y = 8并且其中一个形状为圆的所有实例。prop1 =“A”和prop2.x = 3和prop2.y和prop3.get(i).type =“Circle”; 我们必须迭代prop3的所有实例。
我的第一个想法是不可维护和低效的。 它包括对所有基本属性进行查询,然后合并结果。
- 获取prop1 =“A”的所有实例
- 获取prop2.x = 3和prop3 = y的所有实例;
- 获取其中一个Shape.type =“Circle”的所有实例;
- 得到所有3集的交集
是否有任何现有的库或算法能够以更好(更聪明)的方式解决这个问题?
谢谢
I have a model that has several properties. The properties can be primitive (String) or complex (Object). The user can make a query on each primitive property. I would like to know if there is an easy way to build dynamically the query. I use Java and Hibernate.
The model
public class Model { String prop1; Point prop2; List<Shape> prop3; }
Point
andShape
are object that can contains primitives or objects. An example of a query would be all instances where prop1 = "A" and the coordinates are x = 3 and y = 8 and one of the shape is a circle.prop1 = "A" and prop2.x = 3 and prop2.y and prop3.get(i).type = "Circle"; we would have to iterate on all instances of prop3.
My first idea was unmaintainable and inefficient. It consists in doing queries on all the primitive properties and then merge the results.
- Get all instances where prop1 = "A"
- Get all instances where prop2.x = 3 and prop3 = y;
- Get all instances where one of the Shape.type = "Circle";
- Get the intersection of all 3 sets
Is there any existing library or algorithm that can solve this problem in a better (smarter) way?
Thanks
原文:https://stackoverflow.com/questions/3463813
最满意答案
当我将其保存为.png文件时,我得到了更好的数字。
fig = plt.figure(figsize=(20, 222)) plt.subplots_adjust(top=.9, bottom=0.1, wspace=0.2, hspace=0.2) for i in range(1, 65): print 'E', i, ':' plt.subplot(64, 2, i) plt.ylabel('E%s' % str(i)) i += 1 print E[0+j:127+j] plt.plot(E[0+j:127+j]) j += 128 plt.savefig('foo.png', bbox_inches='tight') plt.show()
虽然我相信有更好的解决方案。
I got a better figure when I saved it as .png file.
fig = plt.figure(figsize=(20, 222)) plt.subplots_adjust(top=.9, bottom=0.1, wspace=0.2, hspace=0.2) for i in range(1, 65): print 'E', i, ':' plt.subplot(64, 2, i) plt.ylabel('E%s' % str(i)) i += 1 print E[0+j:127+j] plt.plot(E[0+j:127+j]) j += 128 plt.savefig('foo.png', bbox_inches='tight') plt.show()
Though I believe there is a better solution.
相关问答
更多-
这比我预想的要容易,我只是这样做了: pylab.subplot(4,4,10) ,它工作。 It was easier than I expected, I just did: pylab.subplot(4,4,10) and it worked.
-
你可以使用gridspec和figure : import numpy as np import matplotlib.pyplot as plt from matplotlib import gridspec # generate some data x = np.arange(0, 10, 0.2) y = np.sin(x) # plot it fig = plt.figure(figsize=(8, 6)) gs = gridspec.GridSpec(1, 2, width_ratios= ...
-
如果figure是一个Figure实例,你可以通过它获取其中的轴 allaxes = fig.get_axes() 这个( allaxes )的返回是图中所有轴的列表。 在此列表中,您需要从图中或其他来源了解哪个子图。 If figure is a Figure instance you can get the axes inside it via allaxes = fig.get_axes() The return of this (allaxes) is a list of all the axe ...
-
首先,当您将Axes对象作为您的处置时,您正在使用调用plt 。 那条路会导致疼痛。 其次, imshow将轴刻度的纵横比设置为1.这就是为什么轴很窄的原因。 知道这一切,你的榜样变成: import numpy as np import matplotlib.pyplot as plt data = np.random.rand(10,4) #creating a wide figure with 2 subplots in 1 row fig, axes = plt.subplots(1, 2, f ...
-
_subplots是axes的子模块: https : //github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_subplots.py 它不应被操纵,正如其领先的下划线所暗示的那样。 看一下源代码,我猜你的AxesSubplot是一个用subplot_class_factory创建的类。 _subplots is a submodule of axes: https://github.com/matplotlib/matplot ...
-
当我将其保存为.png文件时,我得到了更好的数字。 fig = plt.figure(figsize=(20, 222)) plt.subplots_adjust(top=.9, bottom=0.1, wspace=0.2, hspace=0.2) for i in range(1, 65): print 'E', i, ':' plt.subplot(64, 2, i) plt.ylabel('E%s' % str(i)) i += 1 print E[0 ...
-
plt.*设置通常适用于matplotlib的当前图; 与plt.subplot ,你开始一个新的情节,因此设置不再适用于它。 你可以通过与图表相关联的Axes对象( 见这里的例子 )共享标签,蜱等,但是恕我直言,这会在这里矫枉过正。 相反,我会建议将常用的“样式”放入一个函数中,并根据每个图表调用它: def applyPlotStyle(): plt.xlabel('Size') plt.ylabel('Time(s)'); plt.title('Matrix multiplic ...
-
plt.subplot返回一个子对象,它是一种plt.subplot对象。 它有两种添加轴标签的方法: set_xlabel和set_ylabel : ax = plt.subplot('111') ax.set_xlabel('X Axis') ax.set_ylabel('Y Axis') 您也可以调用plt.xlabel和plt.ylabel (就像您以前所做的那样),并指定要将标签应用到的轴。 ax = plt.subplot('111') plt.xlabel('X Axis', axes=ax ...
-
如果使用GridSpec这可能会容易GridSpec : import numpy as np import matplotlib.pylab as pl import matplotlib.gridspec as gridspec # Create 2x2 sub plots gs = gridspec.GridSpec(2, 2) pl.figure() ax = pl.subplot(gs[0, 0]) # row 0, col 0 pl.plot([0,1]) ax = pl.subplot( ...
-
Matplotlib:重新排序子图(Matplotlib: reorder subplots)[2022-08-14]
当然,只要你重新定位它们后你就不会使用tight_layout (因此也tight_layout )(之前你可以安全地使用它)。 基本上,只需执行以下操作: import matplotlib.pyplot as plt # Create something similar to your pickled figure...... fig, (ax1, ax2) = plt.subplots(ncols=2) ax1.plot(range(10), 'r^-') ax1.set(title='Origin ...