Skip to content

Commit

Permalink
add module: lealone-main
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Feb 28, 2016
1 parent 6f062e9 commit a05467f
Show file tree
Hide file tree
Showing 21 changed files with 1,717 additions and 34 deletions.
5 changes: 1 addition & 4 deletions assembly.xml
Expand Up @@ -34,10 +34,7 @@
<moduleSets>
<moduleSet>
<includes>
<include>org.lealone:lealone-client</include>
<include>org.lealone:lealone-server</include>
<include>org.lealone:lealone-sql</include>
<include>org.lealone:lealone-mvstore</include>
<include>org.lealone:lealone-main</include>
</includes>
<binaries>
<unpack>false</unpack>
Expand Down
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lealone.common.exceptions;

public class ConfigurationException extends RequestValidationException {
public ConfigurationException(String msg) {
super(ExceptionCode.CONFIG_ERROR, msg);
}

public ConfigurationException(String msg, Throwable e) {
super(ExceptionCode.CONFIG_ERROR, msg, e);
}

protected ConfigurationException(ExceptionCode code, String msg) {
super(code, msg);
}
}
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lealone.common.exceptions;

public class RequestExecutionException extends LealoneException {
protected RequestExecutionException(ExceptionCode code, String msg) {
super(code, msg);
}

protected RequestExecutionException(ExceptionCode code, String msg, Throwable e) {
super(code, msg, e);
}
}
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lealone.common.exceptions;

public class RequestValidationException extends LealoneException {
protected RequestValidationException(ExceptionCode code, String msg) {
super(code, msg);
}

protected RequestValidationException(ExceptionCode code, String msg, Throwable e) {
super(code, msg, e);
}
}
Expand Up @@ -460,4 +460,9 @@ public static void copyFiles(String original, String copy) throws IOException {
copyAndClose(in, out);
}

public static byte[] toByteArray(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(in, out);
return out.toByteArray();
}
}
46 changes: 46 additions & 0 deletions lealone-common/src/main/java/org/lealone/common/util/Utils.java
Expand Up @@ -26,6 +26,7 @@

import org.lealone.api.ErrorCode;
import org.lealone.api.JavaObjectSerializer;
import org.lealone.common.exceptions.ConfigurationException;
import org.lealone.common.exceptions.DbException;
import org.lealone.db.SysProperties;

Expand Down Expand Up @@ -871,4 +872,49 @@ public static boolean getProperty(String key, boolean defaultValue) {
return defaultValue;
}

/**
* @return The Class for the given name.
* @param classname Fully qualified classname.
* @param readable Descriptive noun for the role the class plays.
* @throws ConfigurationException If the class cannot be found.
*/
@SuppressWarnings("unchecked")
public static <T> Class<T> classForName(String classname, String readable) throws ConfigurationException {
try {
return (Class<T>) Class.forName(classname);
} catch (ClassNotFoundException | NoClassDefFoundError e) {
throw new ConfigurationException(String.format("Unable to find %s class '%s'", readable, classname), e);
}
}

/**
* Constructs an instance of the given class, which must have a no-arg or default constructor.
* @param classname Fully qualified classname.
* @param readable Descriptive noun for the role the class plays.
* @throws ConfigurationException If the class cannot be found.
*/
public static <T> T construct(String classname, String readable) throws ConfigurationException {
Class<T> cls = Utils.classForName(classname, readable);
return construct(cls, classname, readable);
}

public static <T> T construct(Class<T> cls, String classname, String readable) throws ConfigurationException {
try {
return cls.newInstance();
} catch (IllegalAccessException e) {
throw new ConfigurationException(String.format("Default constructor for %s class '%s' is inaccessible.",
readable, classname));
} catch (InstantiationException e) {
throw new ConfigurationException(
String.format("Cannot use abstract class '%s' as %s.", classname, readable));
} catch (Exception e) {
// Catch-all because Class.newInstance()
// "propagates any exception thrown by the nullary constructor, including a checked exception".
if (e.getCause() instanceof ConfigurationException)
throw (ConfigurationException) e.getCause();
throw new ConfigurationException(String.format("Error instantiating %s class '%s'.", readable, classname),
e);
}
}

}
Expand Up @@ -5,6 +5,7 @@
*/
package org.lealone.storage.fs;

import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -368,4 +369,12 @@ public static void writeFully(FileChannel channel, ByteBuffer src) throws IOExce
} while (src.remaining() > 0);
}

public static void closeQuietly(Closeable c) {
try {
if (c != null)
c.close();
} catch (Exception e) {
}
}

}
73 changes: 73 additions & 0 deletions lealone-main/pom.xml
@@ -0,0 +1,73 @@
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.lealone</groupId>
<artifactId>lealone</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>lealone-main</artifactId>
<packaging>jar</packaging>
<version>3.0.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.lealone</groupId>
<artifactId>lealone-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.lealone</groupId>
<artifactId>lealone-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.lealone</groupId>
<artifactId>lealone-sql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.lealone</groupId>
<artifactId>lealone-mvstore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.11</version>
</dependency>
</dependencies>
</project>

0 comments on commit a05467f

Please sign in to comment.