我正在阅读一些关于Java编码标准的书籍.我一直喜欢美丽而干净的代码.
但是有一些事情让我烦恼.例如,方法名称应以小写单词开头,如果它有第二个单词,则应以大写字符开头.但变量标准是一回事.我觉得这有点令人困惑.
所以我问你们,你们的Java编码标准是什么?喜欢:
我在班上使用逆向工程并得到这个:
@Entity
@Table(name = "user", catalog = "bytecode", uniqueConstraints =
@UniqueConstraint(columnNames = "email"))
public class User implements java.io.Serializable {
private Integer id;
private String email;
private String password;
private boolean type;
Run Code Online (Sandbox Code Playgroud)
数据库:
CREATE TABLE `bytecode`.`user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`type` bit(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)
但是我不想在我的属性'type'中设置'true'或'false'但是1或0.我怎么能在hibernate中做到这一点?
此致,Valter Henrique.
我用这种方式构建我的HibernateUtil:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml) config file.
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试在Eclipse中的HQL编辑器中执行HQL命令(使用Hibernate Tools)时,会出现以下错误:
为什么会这样?它不会通过ConfigureAnnotation更改AnnotationConfiguration?
UPDATE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password"><password></property>
<property name="hibernate.connection.url">jdbc:mysql://<hostname>:3306/<schema></property>
<property …Run Code Online (Sandbox Code Playgroud) 我收到一个char*缓冲区,其长度为10.但是我想在我的struct中连接整个内容,它们有一个变量char*.
typedef struct{
char *buffer;
//..
}file_entry;
file_entry real[128];
int fs_write(char *buffer, int size, int file) {
//every time this function is called buffer have 10 of lenght only
// I want to concat the whole text in my char* in my struct
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西:
real[i].buffer += buffer;
Run Code Online (Sandbox Code Playgroud)
我怎么能在C中这样做?
我正在尝试为脚本start和stop服务创建一个模板.我正在检查模板的tomcat启动和停止并查看命令RETVAL=$?.
这是做什么的?我应该保留吗?顺便说一下,我的脚本就在下面,以防万一你想看到它.
#!/bin/bash
#===================================================================================
#
#
FILE: <script-file-name>.sh
#
#
USAGE: <script-file-name>.sh [-d] [-l] [-oD logfile] [-h] [starting directories]
#
# DESCRIPTION: List and/or delete all stale links in directory trees.
#
The default starting directory is the current directory.
#
Don’t descend directories on other filesystems.
#
#
OPTIONS: see function ’usage’ below
# REQUIREMENTS: ---
#
BUGS: ---
#
NOTES: ---
#
AUTHOR: Valter Henrique, valter.henrique@<company>.com
#
COMPANY: <company>
# …Run Code Online (Sandbox Code Playgroud) 我正在监控超过300台服务器,因为我正在使用Ganglia.其中RRD用作数据库来收集和存储与每个服务器的资源相关的数据.我想有2年或更长的历史,所以阅读这篇文章,我认为我的RRA配置应该是:
RRAs "RRA:AVERAGE:0.5:1:17520"
Run Code Online (Sandbox Code Playgroud)
17520 =(365天[年] x 2)*24 [小时]
这是Ganglia默认配置,今天正在运行:
#
# Round-Robin Archives
# You can specify custom Round-Robin archives here (defaults are listed below)
#
# RRAs "RRA:AVERAGE:0.5:1:244" "RRA:AVERAGE:0.5:24:244" "RRA:AVERAGE:0.5:168:244" "RRA:AVERAGE:0.5:672:244" \
# "RRA:AVERAGE:0.5:5760:374"
#
Run Code Online (Sandbox Code Playgroud)
这是我的思维方式还是我在这里遗漏了什么?
我正在尝试使用Amazon S3 API加密和上传文件.
public class AmazonS3 {
String KmsId = "my_id_comes_here";
private TransferManager getTransferManager() {
AWSCredentials awsCredentials = new ProfileCredentialsProvider().getCredentials();
KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider(KmsId);
AmazonS3EncryptionClient s3Client = new AmazonS3EncryptionClient(awsCredentials, materialProvider,
new CryptoConfiguration().withKmsRegion(Regions.EU_CENTRAL_1)).withRegion(Regions.EU_CENTRAL_1);
s3Client.setEndpoint("s3.eu-central-1.amazonaws.com");
TransferManager transferManager = new TransferManager(s3Client);
return transferManager;
}
public void upload(String bucket, String keyName, String filePath)
throws InterruptedException, NoSuchAlgorithmException, IOException, InvalidKeySpecException {
TransferManager transferManager = getTransferManager();
// TransferManager processes all transfers asynchronously, so this call will return immediately.
Upload upload = transferManager.upload(bucket, keyName, new File(filePath));
try …Run Code Online (Sandbox Code Playgroud) 我需要在java中发送一个xml请求并捕获响应.我怎样才能做到这一点 ?
我在谷歌搜索,但直到现在还没有任何实力.
此致,Valter Henrique.
我正在尝试使用Hibernate JPA,但我需要创建我的persistence.xml(所以我可以正确使用实体管理器).我不确定要创建什么以及放置它的位置.
这是我在'Core'模式下配置hibernate.cfg.xml的方法.我正在使用:Eclipse Java EE IDE Web Developers版本:Indigo Release
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">XXXXXX</property>
<property name="hibernate.connection.url">jdbc:mysql://<hostname>/<database></property>
<property name="hibernate.connection.username">XXXXX</property>
<property name="hibernate.default_schema">XXXXXX</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud) 我试图按照这些教程(1,2)达到目标提到.但我仍然从Maven得到这个错误:
INFO] Installing /home/valter/temp-workspace/document-engine/target/application-1.0.0.CI-SNAPSHOT.jar to /home/valter/.m2/repository/com/company-solutions/application/1.0.0.CI-SNAPSHOT/application-1.0.0.CI-SNAPSHOT.jar
[INFO] Installing /home/valter/temp-workspace/document-engine/pom.xml to /home/valter/.m2/repository/com/company-solutions/application/1.0.0.CI-SNAPSHOT/application-1.0.0.CI-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ application ---
Downloading: s3://myrepo.company.solutions/snapshot/com/company-solutions/application/1.0.0.CI-SNAPSHOT/maven-metadata.xml
[WARNING] s3://myrepo.company.solutions/snapshot - Connection refused
[WARNING] Could not transfer metadata com.company-solutions:application:1.0.0.CI-SNAPSHOT/maven-metadata.xml from/to s3.snapshot (s3://myrepo.company.solutions/snapshot): Could not connect to repository
[INFO] Logged off - myrepo.company.solutions
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:31 min
[INFO] Finished at: 2015-11-16T18:36:26+01:00
[INFO] Final Memory: 181M/1289M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project …Run Code Online (Sandbox Code Playgroud)