我有一个文本字段,用户可以在其中输入cron表达式(例如0 */5 * * * *).然后我拆分它并构建一个javax.ejb.ScheduleExpression.
现在javax.ejb.ScheduleExpression接受不同元素的任何String而不进行验证.我可以举个例子
scheduleExpression.minute("randomText");
Run Code Online (Sandbox Code Playgroud)
并被接受.如果然后尝试使用ScheduleExpression我显然会得到错误(例如,当我尝试用它创建一个计时器时).
我开始编写代码来验证输入,但规则不是那么简短和琐碎:http://docs.oracle.com/javaee/6/api/javax/ejb/ScheduleExpression.html
是否有一种简单的方法(在Java EE中)或已经完成工作的库?
我正在开发一个使用大量AsyncTasks的应用程序.当我开始参与此应用程序的编码时,targetSdkVersion被设置为10,因此我们没有AsyncTasks的问题,因为它们都是在并行后台线程上执行的.由于我们已将targtSdkVersion设置为17,因此我们在任务中遇到了一些问题,因为它们现在在单个后台线程上执行.为了解决这个问题,我发现以下代码专门用于并行任务:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
myTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
myTask.execute();
}
Run Code Online (Sandbox Code Playgroud)
现在,因为我们有几个需要这些代码行的任务,所以我想在我们自己的Utils类中编写一个方法,以这种方式执行任务......但我无法实现这一点,因为我无法通过由于'Param |'而作为参数的方法的不同任务 进展| 结果'的东西因任务而异.有没有办法实现我们的目标?有任何想法吗?
从Java 7开始,我们可以使用try-with-resources语句:
static String readFirstLineFromFile(String path) throws IOException {
try (BufferedReader br =
new BufferedReader(new FileReader(path))) {
return br.readLine();
}
}
Run Code Online (Sandbox Code Playgroud)
如果br.readLine()和br.close() 两个抛出异常,readFirstLineFromFile将从try块抛出异常(异常),并且将禁止来自try-with-resources语句的隐式finally块(异常)的异常.br.readLine()br.close()
在这种情况下,我们可以通过从try块的异常调用方法来从隐式finally块中检索抑制的异常,如下所示:getSuppresed
try {
readFirstLineFromFile("Some path here..."); // this is the method using try-with-resources statement
} catch (IOException e) { // this is the exception from the try block
Throwable[] suppressed = e.getSuppressed();
for …Run Code Online (Sandbox Code Playgroud) #define MIN(A,B) ((A) <= (B) ? (A) : (B))
Run Code Online (Sandbox Code Playgroud)
这是宏,我被问到如果我使用以下内容会产生什么副作用:
least = MIN(*p++, b);
Run Code Online (Sandbox Code Playgroud)
注意:这是嵌入式问题
我有一个带有一个名为"libs"的元素的macrodef
<macrodef name="deploy-libs">
<element name="libs"/>
<sequential>
<copy todir="${glassfish.home}/glassfish/domains/domain1/lib">
<fileset dir="${lib}">
<libs/>
</fileset>
</copy>
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)
然后调用为
<deploy-libs>
<libs>
<include name="mysql-connector-*.jar"/>
<include name="junit-*.jar" />
<!-- .... -->
</libs>
</deploy-libs>
Run Code Online (Sandbox Code Playgroud)
然后我有另一个macrodef调用几个macrodef,包括"deploy-libs".如果这个macrodef也有一个元素"libs"会很好,但是:
<macrodef name="init-glassfish">
<element name="libs"/>
<sequential>
<!-- other stuff -->
<deploy-libs>
<libs>
<libs/>
</libs>
</deploy-libs>
<!-- other stuff -->
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)
显然不起作用(因为<libs><libs/></libs>):
Commons/ant-glassfish-server.xml:116: unsupported element include
Run Code Online (Sandbox Code Playgroud)
解决方案可能是以不同的方式命名"init-glassfish"中的元素:
<macrodef name="init-glassfish">
<element name="libraries"/>
<sequential>
<!-- other stuff -->
<deploy-libs>
<libs>
<libraries/>
</libs>
</deploy-libs>
<!-- other stuff -->
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)
有没有办法让两个macrodef以相同的方式命名元素?
我们在 Oracle 和 MySQL 中使用 Envers 没有任何问题。我们现在正在尝试 PostgreSQL,但我们遇到的问题是审计表是使用类型REVTYPE为 的列创建的TINYINT。
TINYINTPostgreSQL 不支持。
有没有办法改变类型REVTYPE?
例子:
create table AUD_SomeTable (
dbId bigint not null,
...
REV integer not null,
REVTYPE tinyint,
primary key (dbId, REV)
);
Run Code Online (Sandbox Code Playgroud)
编辑:
问题已解决:我忘记了更改 Hibernate 方言。
我正在研究DSP处理器,以便在Linux系统上使用C实现BFSK跳频机制.在程序的接收器部分,我得到一组样本的输入,我使用Goertzel算法解调,以确定接收的位是0还是1.
现在,我能够分别检测这些位.但我必须以float数组的形式返回数据进行处理.所以,我需要打包接收到的每一组32位来形成一个浮点值.对,我做的事情如下:
uint32_t i,j,curBit,curBlk;
unint32_t *outData; //this is intiallized to address of some pre-defined location in DSP memory
float *output;
for(i=0; i<num_os_bits; i++) //Loop for number of data bits
{
//Demodulate the data and set curBit=0x0000 or 0x8000
curBlk=curBlk>>1;
curBlk=curBlk|curBit;
bitsCounter+=1;
if(i!=0 && (bitsCounter%32)==0) //32-bits processed, save the data in array
{
*(outData+j)=curBlk;
j+=1;
curBlk=0;
}
}
output=(float *)outData;
Run Code Online (Sandbox Code Playgroud)
现在,output数组的值只是outData小数点后0 的数组值.例如:如果output[i]=12345`outData [i] = 12345.0000'.
但在测试程序时,我使用float数组生成位的样本测试数据
float data[] ={123.12456,45.789,297.0956};
因此在解调之后我期望浮点数组output具有与data数组相同的值.是否有其他方法可以将32位数据转换为浮点数.我应该将收到的位存储到char …
我想UIPageViewController在我的iOS 5.0应用程序中使用水平.
我唯一的问题是我不想要UIPageViewControllerTransitionStylePageCurl过渡.有没有办法获得像翻译这样的经典转型?
注意:即使是丑陋的黑客也会被接受,因为它会占用我以前的很多代码
上一个问题的后续问题:使用Hibernate 4生成SQL DB创建脚本
目标是让命令行工具能够生成具有给定持久性单元的SQL模式的文件(类似于Hibernate Tools中存在的hibernatetool-hbm2ddl Ant任务).
根据我之前的问题的答案,这可以实现org.hibernate.tool.hbm2ddl.SchemaExport.
而不是将所有实体添加到Configuration(如上一个答案中所建议的)我想指定一个PersistenceUnit.
是否可以在Hibernate中添加持久性单元Configuration?
就像是
Properties properties = new Properties();
properties.put( "hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect" );
...
EntityManagerFactory entityManagerFactory =
Persistence.createEntityManagerFactory( "persistentUnitName", properties );
Configuration configuration = new Configuration();
... missing part ...
SchemaExport schemaExport = new SchemaExport( configuration );
schemaExport.setOutputFile( "schema.sql" );
...
Run Code Online (Sandbox Code Playgroud)
按照评论中的要求编辑样本persistence.xml.每个类都注明了@Entity
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0"
>
<persistence-unit
name="doiPersistenceUnit"
transaction-type="JTA"
>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/doi</jta-data-source>
<class>ch.ethz.id.wai.doi.bo.Doi</class>
[...]
<class>ch.ethz.id.wai.doi.bo.DoiPool</class> …Run Code Online (Sandbox Code Playgroud)