├── .gitignore ├── README.md ├── com.vispractice.amoeba.base ├── META-INF │ └── MANIFEST.MF ├── build.xml ├── release │ ├── conf │ │ └── config.ini │ ├── restart.sh │ ├── startup.bat │ ├── startup.sh │ └── stop.sh └── src │ ├── com │ ├── meidusa │ │ └── amoeba │ │ │ ├── bean │ │ │ ├── FieldDictionary.java │ │ │ ├── ObjectAccessException.java │ │ │ ├── OrderRetainingMap.java │ │ │ ├── PureJavaReflectionProvider.java │ │ │ └── ReflectionProvider.java │ │ │ ├── config │ │ │ ├── BeanObjectEntityConfig.java │ │ │ ├── ConfigEntity.java │ │ │ ├── ConfigUtil.java │ │ │ ├── DBServerConfig.java │ │ │ ├── ParameterMapping.java │ │ │ ├── PropertyTransfer.java │ │ │ ├── ProxyServerConfig.java │ │ │ ├── UserConfig.java │ │ │ └── loader │ │ │ │ ├── AmoebaContextLoader.java │ │ │ │ ├── ConfigModifiedAwareLoader.java │ │ │ │ ├── ConfigModifiedEventHandler.java │ │ │ │ ├── DBServerConfigLoader.java │ │ │ │ ├── IpAccessListLoader.java │ │ │ │ ├── RuleFunctionMapLoader.java │ │ │ │ ├── SqlFunctionMapLoader.java │ │ │ │ ├── TableRuleLoader.java │ │ │ │ └── UserLoader.java │ │ │ ├── context │ │ │ ├── ContextChangedListener.java │ │ │ ├── ProxyRuntimeContext.java │ │ │ ├── RefreshConfigLock.java │ │ │ └── RuntimeContext.java │ │ │ ├── data │ │ │ ├── AuthCodes.java │ │ │ ├── ConMgrStats.java │ │ │ └── Constants.java │ │ │ ├── exception │ │ │ ├── AmoebaRuntimeException.java │ │ │ ├── ConfigurationException.java │ │ │ ├── IllegalRequestParameterException.java │ │ │ ├── InitialisationException.java │ │ │ ├── LoadTableRuleRuntimeException.java │ │ │ ├── UpdateDBServerRuntimeException.java │ │ │ └── UpdateIpRuleRuntimeException.java │ │ │ ├── heartbeat │ │ │ ├── HeartbeatDelayed.java │ │ │ ├── HeartbeatManager.java │ │ │ ├── Status.java │ │ │ └── TaskProperty.java │ │ │ ├── jdbc │ │ │ ├── ClassWrapperUtil.java │ │ │ ├── ConnectionWrapper.java │ │ │ ├── DriverWrapper.java │ │ │ ├── JdbcConnectionFactory.java │ │ │ ├── PoolableJdbcConnection.java │ │ │ ├── ResultSetHandler.java │ │ │ └── StringCharsetIOHandler.java │ │ │ ├── log4j │ │ │ └── DOMConfigurator.java │ │ │ ├── monitor │ │ │ ├── Command.java │ │ │ ├── MonitorConstant.java │ │ │ ├── MonitorServer.java │ │ │ ├── ShutdownClient.java │ │ │ ├── io │ │ │ │ └── MonitorPacketInputStream.java │ │ │ ├── net │ │ │ │ ├── MonitorClientConnection.java │ │ │ │ └── MonitorClientConnectionFactory.java │ │ │ └── packet │ │ │ │ ├── MonitorCommandPacket.java │ │ │ │ └── MonitorPacketBuffer.java │ │ │ ├── net │ │ │ ├── AbstractConnectionFactory.java │ │ │ ├── AuthResponseData.java │ │ │ ├── Authenticator.java │ │ │ ├── AuthingableConnection.java │ │ │ ├── AuthingableConnectionFactory.java │ │ │ ├── AuthingableConnectionManager.java │ │ │ ├── BackendConnectionFactory.java │ │ │ ├── Connection.java │ │ │ ├── ConnectionFactory.java │ │ │ ├── ConnectionManager.java │ │ │ ├── ConnectionObserver.java │ │ │ ├── DatabaseConnection.java │ │ │ ├── FrontendConnectionFactory.java │ │ │ ├── IdleChecker.java │ │ │ ├── MessageHandler.java │ │ │ ├── MultiConnectionManagerWrapper.java │ │ │ ├── NetEventHandler.java │ │ │ ├── PacketHandler.java │ │ │ ├── PoolableConnectionFactory.java │ │ │ ├── ServerableConnectionManager.java │ │ │ ├── SessionMessageHandler.java │ │ │ ├── Sessionable.java │ │ │ ├── SocketChannelFactory.java │ │ │ ├── io │ │ │ │ ├── PacketInputStream.java │ │ │ │ └── PacketOutputStream.java │ │ │ ├── packet │ │ │ │ ├── AbstractPacket.java │ │ │ │ ├── AbstractPacketBuffer.java │ │ │ │ ├── AbstractPacketFactory.java │ │ │ │ ├── Packet.java │ │ │ │ ├── PacketBuffer.java │ │ │ │ ├── PacketFactory.java │ │ │ │ └── Response.java │ │ │ └── poolable │ │ │ │ ├── GenericObjectPool.java │ │ │ │ ├── MultipleLoadBalanceObjectPool.java │ │ │ │ ├── ObjectPool.java │ │ │ │ ├── PoolableObject.java │ │ │ │ ├── PoolableObjectFactoryWapper.java │ │ │ │ └── PoolableObjectPool.java │ │ │ ├── parser │ │ │ ├── AmoebaSqlHintPropNames.java │ │ │ ├── ParseException.java │ │ │ ├── Parser.java │ │ │ ├── dbobject │ │ │ │ ├── Column.java │ │ │ │ ├── DBObjectBase.java │ │ │ │ ├── GlobalSeqColumn.java │ │ │ │ ├── Schema.java │ │ │ │ └── Table.java │ │ │ ├── expression │ │ │ │ ├── AndExpression.java │ │ │ │ ├── BaseExpressionList.java │ │ │ │ ├── ColumnExpression.java │ │ │ │ ├── ComparisonExpression.java │ │ │ │ ├── ConstantExpression.java │ │ │ │ ├── Expression.java │ │ │ │ ├── FunctionExpression.java │ │ │ │ ├── OrExpression.java │ │ │ │ └── ParameterExpression.java │ │ │ ├── function │ │ │ │ ├── AbstractFunction.java │ │ │ │ ├── Add.java │ │ │ │ ├── And.java │ │ │ │ ├── Ascii.java │ │ │ │ ├── BulkValFuntion.java │ │ │ │ ├── Concat.java │ │ │ │ ├── ConcatWs.java │ │ │ │ ├── CurrentDate.java │ │ │ │ ├── Divide.java │ │ │ │ ├── Function.java │ │ │ │ ├── Insert.java │ │ │ │ ├── Instr.java │ │ │ │ ├── LastInsertId.java │ │ │ │ ├── Modulus.java │ │ │ │ ├── Multiply.java │ │ │ │ ├── Now.java │ │ │ │ ├── Procedure.java │ │ │ │ ├── RealtimeCalculator.java │ │ │ │ ├── Sub.java │ │ │ │ ├── Substring.java │ │ │ │ ├── ThreadLocalSettingFunction.java │ │ │ │ ├── TimeConverter.java │ │ │ │ ├── TimeForType.java │ │ │ │ ├── ToDate.java │ │ │ │ ├── UnixTimestamp.java │ │ │ │ └── UnknowableFunction.java │ │ │ └── statement │ │ │ │ ├── AbstractStatement.java │ │ │ │ ├── BeginStatement.java │ │ │ │ ├── CallStatement.java │ │ │ │ ├── CommitCMD.java │ │ │ │ ├── CommitStatement.java │ │ │ │ ├── DMLStatement.java │ │ │ │ ├── DeleteStatement.java │ │ │ │ ├── HelpStatement.java │ │ │ │ ├── InsertStatement.java │ │ │ │ ├── PropertyStatement.java │ │ │ │ ├── RollbackCMD.java │ │ │ │ ├── RollbackStatement.java │ │ │ │ ├── SelectStatement.java │ │ │ │ ├── ShowStatement.java │ │ │ │ ├── StartTansactionStatement.java │ │ │ │ ├── Statement.java │ │ │ │ ├── UpdateStatement.java │ │ │ │ ├── XACommitStatement.java │ │ │ │ ├── XAEndStatement.java │ │ │ │ ├── XAPrepareStatement.java │ │ │ │ ├── XARecoverStatement.java │ │ │ │ ├── XARollBackStatement.java │ │ │ │ ├── XAStartStatement.java │ │ │ │ ├── XAStatement.java │ │ │ │ └── ddl │ │ │ │ ├── DDLAlertTableStatement.java │ │ │ │ ├── DDLCreateSequenceStatenment.java │ │ │ │ ├── DDLCreateTableStatement.java │ │ │ │ ├── DDLDropSequenceStatement.java │ │ │ │ ├── DDLDropStatement.java │ │ │ │ ├── DDLRenameTableStatement.java │ │ │ │ ├── DDLStatement.java │ │ │ │ └── DDLTruncateTableStatement.java │ │ │ ├── route │ │ │ ├── AbstractQueryRouter.java │ │ │ ├── QueryRouter.java │ │ │ ├── Request.java │ │ │ ├── Rule.java │ │ │ ├── RuleResult.java │ │ │ ├── SqlBaseQueryRouter.java │ │ │ ├── SqlQueryObject.java │ │ │ └── TableRule.java │ │ │ ├── runtime │ │ │ ├── PriorityShutdownHook.java │ │ │ └── Shutdowner.java │ │ │ ├── server │ │ │ ├── AuthenticateFilter.java │ │ │ ├── DummyAuthenticator.java │ │ │ ├── IPAccessController.java │ │ │ └── MultipleServerPool.java │ │ │ ├── service │ │ │ └── Service.java │ │ │ ├── sqljep │ │ │ ├── ASTArray.java │ │ │ ├── ASTConstant.java │ │ │ ├── ASTFunNode.java │ │ │ ├── ASTStart.java │ │ │ ├── ASTVarNode.java │ │ │ ├── BaseJEP.java │ │ │ ├── JJTParserState.java │ │ │ ├── JavaCharStream.java │ │ │ ├── JepRuntime.java │ │ │ ├── Node.java │ │ │ ├── ParseException.java │ │ │ ├── Parser.java │ │ │ ├── Parser.jj │ │ │ ├── Parser.jjt │ │ │ ├── ParserConstants.java │ │ │ ├── ParserDumpColumns.java │ │ │ ├── ParserDumpVisitor.java │ │ │ ├── ParserTokenManager.java │ │ │ ├── ParserTreeConstants.java │ │ │ ├── ParserVisitor.java │ │ │ ├── ResultSetJEP.java │ │ │ ├── RowJEP.java │ │ │ ├── SimpleNode.java │ │ │ ├── Token.java │ │ │ ├── TokenMgrError.java │ │ │ ├── function │ │ │ │ ├── Abs.java │ │ │ │ ├── Add.java │ │ │ │ ├── AddDate.java │ │ │ │ ├── AddMonths.java │ │ │ │ ├── AddTime.java │ │ │ │ ├── And.java │ │ │ │ ├── Between.java │ │ │ │ ├── Case.java │ │ │ │ ├── Ceil.java │ │ │ │ ├── Comparative.java │ │ │ │ ├── ComparativeAND.java │ │ │ │ ├── ComparativeBaseList.java │ │ │ │ ├── ComparativeComparator.java │ │ │ │ ├── ComparativeEQ.java │ │ │ │ ├── ComparativeGE.java │ │ │ │ ├── ComparativeGT.java │ │ │ │ ├── ComparativeIsNotNull.java │ │ │ │ ├── ComparativeIsNull.java │ │ │ │ ├── ComparativeLE.java │ │ │ │ ├── ComparativeLT.java │ │ │ │ ├── ComparativeNE.java │ │ │ │ ├── ComparativeOR.java │ │ │ │ ├── ComparativeRange.java │ │ │ │ ├── Concat.java │ │ │ │ ├── Datediff.java │ │ │ │ ├── Day.java │ │ │ │ ├── DayName.java │ │ │ │ ├── DayOfWeek.java │ │ │ │ ├── DayOfYear.java │ │ │ │ ├── Declare.java │ │ │ │ ├── Decode.java │ │ │ │ ├── Divide.java │ │ │ │ ├── Floor.java │ │ │ │ ├── Hash.java │ │ │ │ ├── HashParttion.java │ │ │ │ ├── Hour.java │ │ │ │ ├── IfElse.java │ │ │ │ ├── In.java │ │ │ │ ├── IndistinctMatching.java │ │ │ │ ├── Initcap.java │ │ │ │ ├── Instr.java │ │ │ │ ├── Intersector.java │ │ │ │ ├── LastDay.java │ │ │ │ ├── Length.java │ │ │ │ ├── Like.java │ │ │ │ ├── LogicalAND.java │ │ │ │ ├── LogicalNOT.java │ │ │ │ ├── LogicalOR.java │ │ │ │ ├── Lower.java │ │ │ │ ├── Lpad.java │ │ │ │ ├── Ltrim.java │ │ │ │ ├── MakeDate.java │ │ │ │ ├── MakeTime.java │ │ │ │ ├── Microsecond.java │ │ │ │ ├── Minute.java │ │ │ │ ├── Modulus.java │ │ │ │ ├── Month.java │ │ │ │ ├── MonthName.java │ │ │ │ ├── MonthsBetween.java │ │ │ │ ├── Multiply.java │ │ │ │ ├── NextDay.java │ │ │ │ ├── NotLike.java │ │ │ │ ├── Nvl.java │ │ │ │ ├── OracleDateFormat.java │ │ │ │ ├── OracleNumberFormat.java │ │ │ │ ├── OracleTimeFormat.java │ │ │ │ ├── OracleTimestampFormat.java │ │ │ │ ├── PostfixCommand.java │ │ │ │ ├── PostfixCommandI.java │ │ │ │ ├── Power.java │ │ │ │ ├── Range.java │ │ │ │ ├── Replace.java │ │ │ │ ├── Round.java │ │ │ │ ├── Rpad.java │ │ │ │ ├── Rtrim.java │ │ │ │ ├── Second.java │ │ │ │ ├── Sign.java │ │ │ │ ├── SqlQueryCommand.java │ │ │ │ ├── StringHash.java │ │ │ │ ├── SubDate.java │ │ │ │ ├── SubTime.java │ │ │ │ ├── Substring.java │ │ │ │ ├── Subtract.java │ │ │ │ ├── ToChar.java │ │ │ │ ├── ToDate.java │ │ │ │ ├── ToLong.java │ │ │ │ ├── ToNumber.java │ │ │ │ ├── Translate.java │ │ │ │ ├── Trim.java │ │ │ │ ├── Trunc.java │ │ │ │ ├── UMinus.java │ │ │ │ ├── Upper.java │ │ │ │ ├── Var.java │ │ │ │ ├── WeekOfYear.java │ │ │ │ └── Year.java │ │ │ └── variable │ │ │ │ └── Variable.java │ │ │ └── util │ │ │ ├── BasicRunQueue.java │ │ │ ├── ByteUtil.java │ │ │ ├── CmdLineParser.java │ │ │ ├── ConcurrentHashSet.java │ │ │ ├── ConsistentHash.java │ │ │ ├── Crontab.java │ │ │ ├── DateTimeUtils.java │ │ │ ├── EnumCode.java │ │ │ ├── HashFunction.java │ │ │ ├── Histogram.java │ │ │ ├── IPRule.java │ │ │ ├── Initialisable.java │ │ │ ├── Invoker.java │ │ │ ├── JVM.java │ │ │ ├── LoopingThread.java │ │ │ ├── MappedByteBufferUtil.java │ │ │ ├── NamableThreadFactory.java │ │ │ ├── NameableRunner.java │ │ │ ├── ObjectUtil.java │ │ │ ├── OptionType.java │ │ │ ├── Queue.java │ │ │ ├── Reporter.java │ │ │ ├── RunQueue.java │ │ │ ├── SoftCache.java │ │ │ ├── SqlUtil.java │ │ │ ├── StaticString.java │ │ │ ├── StringFillFormat.java │ │ │ ├── StringUtil.java │ │ │ ├── ThreadLocalMap.java │ │ │ ├── TimeUtil.java │ │ │ └── Tuple.java │ └── vispractice │ │ └── amoeba │ │ └── base │ │ └── Activator.java │ └── log4j.properties ├── com.vispractice.amoeba.loader.file ├── META-INF │ └── MANIFEST.MF ├── OSGI-INF │ ├── AmoebaContextFileLoader.xml │ ├── DBServerConfigFileLoader.xml │ ├── IpAccessListFileLoader.xml │ ├── RuleFunctionMapFileLoader.xml │ ├── SqlFunctionMapFileLoader.xml │ ├── TableRuleFileLoader.xml │ └── UserFileLoader.xml ├── release │ └── conf │ │ ├── access_list.conf │ │ ├── amoeba.xml │ │ ├── dbServers.xml │ │ ├── rule.xml │ │ ├── ruleFunctionMap.xml │ │ ├── seq.properties │ │ ├── sqlFunctionMap.xml │ │ └── users.xml └── src │ └── com │ ├── meidusa │ └── amoeba │ │ ├── config │ │ └── loader │ │ │ ├── AmoebaContextFileLoader.java │ │ │ ├── DBServerConfigFileLoader.java │ │ │ ├── FunctionFileLoader.java │ │ │ ├── IpAccessListFileLoader.java │ │ │ ├── RuleFunctionMapFileLoader.java │ │ │ ├── SqlFunctionMapFileLoader.java │ │ │ ├── TableRuleFileLoader.java │ │ │ ├── UserFileLoader.java │ │ │ └── util │ │ │ └── ConfigLoaderUtil.java │ │ ├── xml │ │ ├── amoeba.dtd │ │ ├── dbserver.dtd │ │ ├── function.dtd │ │ ├── objectMap.dtd │ │ ├── rule.dtd │ │ ├── table.dtd │ │ └── user.dtd │ │ └── xmltable │ │ ├── Condition.java │ │ ├── XmlColumn.java │ │ ├── XmlRow.java │ │ ├── XmlTable.java │ │ └── XmlTableLoader.java │ └── vispractice │ └── amoeba │ └── loader │ └── file │ └── Activator.java ├── com.vispractice.amoeba.mysql ├── META-INF │ └── MANIFEST.MF └── src │ └── com │ ├── meidusa │ └── amoeba │ │ └── mysql │ │ ├── context │ │ └── MysqlRuntimeContext.java │ │ ├── filter │ │ ├── AbstractIOFilter.java │ │ ├── FilterInvocation.java │ │ ├── IOFilter.java │ │ ├── PacketFilterInvocation.java │ │ └── PacketIOFilter.java │ │ ├── handler │ │ ├── CommandMessageHandler.java │ │ ├── CommandQueue.java │ │ ├── CommitCommand.java │ │ ├── CommitStatementHandler.java │ │ ├── MySqlCommandDispatcher.java │ │ ├── PrepareExecuteCommand.java │ │ ├── PrepareQueryCommand.java │ │ ├── PreparedStatmentConnectionStatuts.java │ │ ├── PreparedStatmentExecuteConnectionStatuts.java │ │ ├── PreparedStatmentExecuteMessageHandler.java │ │ ├── PreparedStatmentInfo.java │ │ ├── PreparedStatmentMessageHandler.java │ │ ├── PropertyCommand.java │ │ ├── QueryCommand.java │ │ ├── QueryCommandMessageHandler.java │ │ ├── RollbackCommand.java │ │ ├── RollbackStatementHandler.java │ │ ├── StickyForTransactionHandler.java │ │ └── session │ │ │ ├── CommandStatus.java │ │ │ ├── ConnectionStatuts.java │ │ │ └── SessionStatus.java │ │ ├── io │ │ ├── CompressedInputStream.java │ │ ├── Constants.java │ │ ├── MySqlPacketConstant.java │ │ ├── MysqlFramedInputStream.java │ │ └── MysqlFramingOutputStream.java │ │ ├── jdbc │ │ ├── IsolationLevels.java │ │ ├── LocalizedErrorMessages.properties │ │ ├── Messages.java │ │ └── MysqlDefs.java │ │ ├── net │ │ ├── CommandInfo.java │ │ ├── CommandListener.java │ │ ├── MysqlClientConnection.java │ │ ├── MysqlClientConnectionFactory.java │ │ ├── MysqlConnection.java │ │ ├── MysqlServerConnection.java │ │ ├── MysqlServerConnectionFactory.java │ │ └── packet │ │ │ ├── AbstractPacket.java │ │ │ ├── AbstractResultPacket.java │ │ │ ├── AuthenticationPacket.java │ │ │ ├── BindValue.java │ │ │ ├── BlockedPacketIO.java │ │ │ ├── CommandPacket.java │ │ │ ├── ConstantPacketBuffer.java │ │ │ ├── EOFPacket.java │ │ │ ├── ErrorPacket.java │ │ │ ├── ExecutePacket.java │ │ │ ├── FieldPacket.java │ │ │ ├── HandshakePacket.java │ │ │ ├── LongDataPacket.java │ │ │ ├── MysqlPacketBuffer.java │ │ │ ├── MysqlPingPacket.java │ │ │ ├── OKforPreparedStatementPacket.java │ │ │ ├── OkPacket.java │ │ │ ├── PacketUtil.java │ │ │ ├── ParameterPacket.java │ │ │ ├── PreparedStatmentClosePacket.java │ │ │ ├── QueryCommandPacket.java │ │ │ ├── ResultSetHeaderPacket.java │ │ │ ├── RowDataPacket.java │ │ │ ├── Scramble323Packet.java │ │ │ └── result │ │ │ ├── ErrorResultPacket.java │ │ │ ├── MysqlResultSetPacket.java │ │ │ ├── MysqlSimpleResultPacket.java │ │ │ ├── PreparedResultPacket.java │ │ │ └── ResultPacket.java │ │ ├── parser │ │ ├── MysqlParser.jjt │ │ ├── MysqlQueryRouter.java │ │ ├── MysqlSyntaxConstants.java │ │ ├── data │ │ │ └── MysqlSimpleNode.java │ │ └── sql │ │ │ ├── JJTMysqlParserState.java │ │ │ ├── MysqlParser.java │ │ │ ├── MysqlParser.jj │ │ │ ├── MysqlParserConstants.java │ │ │ ├── MysqlParserTokenManager.java │ │ │ ├── MysqlParserTreeConstants.java │ │ │ ├── Node.java │ │ │ ├── ParseException.java │ │ │ ├── SimpleCharStream.java │ │ │ ├── Token.java │ │ │ └── TokenMgrError.java │ │ ├── server │ │ └── MysqlClientAuthenticator.java │ │ └── util │ │ ├── CharsetMapping.java │ │ ├── MysqlStringUtil.java │ │ ├── Security.java │ │ ├── SingleByteCharsetConverter.java │ │ └── Util.java │ └── vispractice │ └── amoeba │ └── mysql │ └── Activator.java ├── com.vispractice.amoeba.seq.fetcher ├── META-INF │ └── MANIFEST.MF ├── OSGI-INF │ └── SeqFetcherComp.xml └── src │ └── com │ ├── meidusa │ └── amoeba │ │ └── seq │ │ └── fetcher │ │ ├── SeqConstants.java │ │ ├── SeqFetchService.java │ │ ├── SeqOperationResult.java │ │ └── SeqProvider.java │ └── vispractice │ └── amoeba │ └── seq │ └── fetcher │ └── Activator.java ├── com.vispractice.amoeba.seq.provider ├── META-INF │ └── MANIFEST.MF ├── OSGI-INF │ └── SeqProviderComp.xml ├── lib │ ├── curator-client-1.3.3.jar │ ├── curator-framework-1.3.3.jar │ ├── curator-recipes-1.3.3.jar │ ├── guava-14.0.1.jar │ ├── jline-0.9.94.jar │ ├── log4j-1.2.15.jar │ ├── netty-3.2.2.Final.jar │ ├── slf4j-api-1.6.1.jar │ ├── slf4j-log4j12-1.6.1.jar │ └── zookeeper-3.4.5.jar └── src │ └── com │ ├── meidusa │ └── amoeba │ │ └── seq │ │ └── provider │ │ ├── DummySeqProvider.java │ │ ├── SeqProviderBasedOnZK.java │ │ └── utils │ │ └── Utils.java │ └── vispractice │ └── amoeba │ └── seq │ └── provider │ └── Activator.java ├── com.vispractice.amoeba.startup ├── META-INF │ └── MANIFEST.MF └── src │ └── com │ ├── meidusa │ └── amoeba │ │ └── server │ │ └── AmoebaProxyServer.java │ └── vispractice │ └── amoeba │ └── startup │ └── Activator.java ├── plugins ├── com.alibaba.china.jdbc_proxy_1.1.0.jar ├── com.springsource.javassist-3.15.0.GA.jar ├── com.springsource.javax.xml.stream-1.0.1.jar ├── com.springsource.org.apache.commons.collections-3.2.1.jar ├── com.springsource.org.apache.commons.lang-2.4.0.jar ├── com.springsource.org.dom4j-1.6.1.jar ├── com.springsource.org.ognl-2.7.3.jar ├── com.springsource.slf4j.api-1.5.6.jar ├── com.springsource.slf4j.log4j-1.5.6.jar ├── log4j.osgi-1.2.15-SNAPSHOT.jar ├── org.apache.servicemix.bundles.asm-3.3_2.jar ├── org.apache.servicemix.bundles.commons-pool-1.5.4_1.jar ├── org.eclipse.equinox.ds_1.1.1.R35x_v20090806.jar ├── org.eclipse.equinox.event_1.2.100.v20110502.jar ├── org.eclipse.equinox.util_1.0.100.v20090520-1800.jar ├── org.eclipse.osgi.services_3.3.0.v20110513.jar ├── org.eclipse.osgi.util_3.2.200.v20110110.jar └── org.eclipse.osgi_3.7.1.R37x_v20110808-1106.jar └── release ├── amoeba-plus-mysql-1.0-RC1.tar.gz └── amoeba-plus-mysql-1.0-RC1.zip /.gitignore: -------------------------------------------------------------------------------- 1 | *target* 2 | *.war 3 | *.ear 4 | *.class 5 | 6 | # eclipse specific git ignore 7 | *.pydevproject 8 | .project 9 | .metadata 10 | bin/** 11 | tmp/** 12 | tmp/**/* 13 | *.tmp 14 | *.bak 15 | *.swp 16 | *~.nib 17 | local.properties 18 | .classpath 19 | .settings/ 20 | .loadpath 21 | 22 | # External tool builders 23 | .externalToolBuilders/ 24 | 25 | # Locally stored "Eclipse launch configurations" 26 | *.launch 27 | 28 | .svn 29 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/release/restart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sh stop.sh 4 | if [ $? != 0 ]; 5 | then 6 | exit $?; 7 | fi 8 | sh startup.sh 9 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/release/startup.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | java -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar module/libs/org.eclipse.osgi_3.7.1.R37x_v20110808-1106.jar -configuration conf -console 3 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/release/startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -f cc.pid ]; 4 | then 5 | echo 'cc.pid already exist.'; 6 | exit 1; 7 | fi 8 | 9 | echo 'Starting......' 10 | java -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m -jar module/libs/org.eclipse.osgi_3.7.1.R37x_v20110808-1106.jar -configuration conf & 11 | echo $! > cc.pid 12 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/release/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -f cc.pid ]; 4 | then 5 | echo 'not found pid file.'; 6 | exit 1; 7 | fi 8 | 9 | pid=`cat cc.pid` 10 | 11 | if (kill -0 $pid 2>/dev/null) 12 | then 13 | echo -n "Shutting down #$pid " 14 | kill $pid 1>/dev/null 15 | else 16 | echo "process #$pid is not running!" 17 | rm -rf cc.pid 18 | exit 0 19 | fi 20 | 21 | process="$pid" 22 | 23 | while test ! -z $process ;do 24 | sleep 1 25 | process=`ps -ef | grep -v grep | grep -v "stop.sh" | grep -w $pid | sed -n '1P' | awk '{print $2}'` 26 | echo -n '.' 27 | done 28 | 29 | rm -rf cc.pid 30 | 31 | echo '[ok]' 32 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/bean/ObjectAccessException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.bean; 13 | 14 | /** 15 | * 16 | * @author Struct chen 17 | * 18 | */ 19 | public class ObjectAccessException extends RuntimeException { 20 | private static final long serialVersionUID = 1L; 21 | 22 | public ObjectAccessException(String message) { 23 | super(message); 24 | } 25 | 26 | public ObjectAccessException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/ConfigEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.config; 13 | 14 | import java.io.Serializable; 15 | 16 | import org.apache.commons.lang.builder.ToStringBuilder; 17 | 18 | /** 19 | * 20 | * @author Struct chen 21 | * @version $Id: ConfigEntity.java 3597 2006-11-23 08:11:58Z struct $ 22 | */ 23 | public class ConfigEntity implements Serializable{ 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | public String toString() { 28 | return ToStringBuilder.reflectionToString(this); 29 | } 30 | 31 | public int hashCode(){ 32 | return 2101; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/PropertyTransfer.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config; 2 | 3 | public interface PropertyTransfer { 4 | T transfer(String inputString); 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/UserConfig.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config; 2 | 3 | public class UserConfig { 4 | private String username; 5 | private String password; 6 | private boolean isAdmin = false; 7 | 8 | 9 | public UserConfig(String username, String password) { 10 | super(); 11 | this.username = username; 12 | this.password = password; 13 | } 14 | public String getUsername() { 15 | return username; 16 | } 17 | public void setUsername(String username) { 18 | this.username = username; 19 | } 20 | public String getPassword() { 21 | return password; 22 | } 23 | public void setPassword(String password) { 24 | this.password = password; 25 | } 26 | public boolean isAdmin() { 27 | return isAdmin; 28 | } 29 | public void setAdmin(boolean isAdmin) { 30 | this.isAdmin = isAdmin; 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/AmoebaContextLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import com.meidusa.amoeba.config.ProxyServerConfig; 4 | import com.meidusa.amoeba.context.ProxyRuntimeContext; 5 | 6 | public interface AmoebaContextLoader { 7 | public ProxyServerConfig loadConfig(); 8 | public void setAmoebaContext(ProxyRuntimeContext amoebaContext); 9 | } 10 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/ConfigModifiedAwareLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | public interface ConfigModifiedAwareLoader { 4 | public void startObserve(); 5 | public void setConfigModifiedEventHandler(ConfigModifiedEventHandler handler); 6 | } 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/ConfigModifiedEventHandler.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | public interface ConfigModifiedEventHandler { 4 | public void doOnConfigModified(); 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/DBServerConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.meidusa.amoeba.config.DBServerConfig; 7 | 8 | public interface DBServerConfigLoader { 9 | public static final String DEFAULT_REAL_POOL_CLASS = "com.meidusa.amoeba.net.poolable.PoolableObjectPool"; 10 | public static final String DEFAULT_VIRTUAL_POOL_CLASS = "com.meidusa.amoeba.server.MultipleServerPool"; 11 | Map loadConfig(); 12 | Map loadConfig(List ids); 13 | } 14 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/IpAccessListLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.List; 4 | 5 | public interface IpAccessListLoader { 6 | public List loadIPRule(); 7 | public List reLoadIPRule(); 8 | } 9 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/RuleFunctionMapLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.Map; 4 | 5 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 6 | 7 | public interface RuleFunctionMapLoader { 8 | public void loadFunctionMap(Map funMap); 9 | 10 | public boolean needLoad(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/SqlFunctionMapLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.Map; 4 | 5 | import com.meidusa.amoeba.parser.function.Function; 6 | 7 | public interface SqlFunctionMapLoader { 8 | public void loadFunctionMap(Map funMap); 9 | 10 | public boolean needLoad(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/TableRuleLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.meidusa.amoeba.parser.dbobject.Table; 7 | import com.meidusa.amoeba.route.TableRule; 8 | 9 | public interface TableRuleLoader { 10 | Map loadRule(); 11 | Map reLoadRule(); 12 | 13 | boolean needLoad(); 14 | Map loadRule(List ids); 15 | } 16 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/config/loader/UserLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.Map; 4 | 5 | import com.meidusa.amoeba.config.UserConfig; 6 | 7 | public interface UserLoader { 8 | public void loadUser(); 9 | } 10 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/context/ContextChangedListener.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.context; 2 | 3 | public interface ContextChangedListener { 4 | public void doChange(); 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/context/RefreshConfigLock.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.context; 2 | 3 | public class RefreshConfigLock { 4 | public final static Object lock = new Object(); 5 | 6 | private RefreshConfigLock() { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/data/AuthCodes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.data; 13 | 14 | /** 15 | * Basic authentication response codes. 16 | */ 17 | public interface AuthCodes 18 | { 19 | /** A code indicating that no user exists with the specified 20 | * username. */ 21 | public static final String NO_SUCH_USER = "m.no_such_user"; 22 | 23 | /** A code indicating that the supplied password was invalid. */ 24 | public static final String INVALID_PASSWORD = "m.invalid_password"; 25 | 26 | /** A code indicating that an internal server error occurred while 27 | * trying to log the user on. */ 28 | public static final String SERVER_ERROR = "m.server_error"; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/data/ConMgrStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.data; 13 | 14 | import java.util.concurrent.atomic.AtomicLong; 15 | 16 | 17 | /** 18 | * Used to track and report stats on the connection manager. 19 | * @author Struct chen 20 | */ 21 | public class ConMgrStats implements Cloneable 22 | { 23 | 24 | /** The number of connection events since the server started up. */ 25 | public AtomicLong connects = new AtomicLong(0); 26 | 27 | /** The number of disconnection events since the server started up. */ 28 | public AtomicLong disconnects = new AtomicLong(0); 29 | 30 | @Override // from Object 31 | public Object clone () 32 | { 33 | try { 34 | return super.clone(); 35 | } catch (CloneNotSupportedException cnse) { 36 | throw new RuntimeException(cnse); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/data/Constants.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.data; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public final class Constants { 7 | 8 | public final static String NORMAL = "X"; 9 | 10 | public final static Map sqlReadKeyWord = new HashMap(); 11 | static { 12 | sqlReadKeyWord.put("show", null); 13 | sqlReadKeyWord.put("print", null); 14 | sqlReadKeyWord.put("help", null); 15 | sqlReadKeyWord.put("explain", null); 16 | sqlReadKeyWord.put("describe", null); 17 | sqlReadKeyWord.put("select", null); 18 | } 19 | 20 | 21 | private Constants(){ 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/exception/IllegalRequestParameterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.exception; 13 | 14 | public class IllegalRequestParameterException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | public IllegalRequestParameterException() { 19 | } 20 | 21 | public IllegalRequestParameterException(String message) { 22 | super(message); 23 | } 24 | 25 | public IllegalRequestParameterException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | public IllegalRequestParameterException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/exception/LoadTableRuleRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.exception; 2 | 3 | public class LoadTableRuleRuntimeException extends AmoebaRuntimeException { 4 | 5 | 6 | private static final long serialVersionUID = 1L; 7 | private String tableName; 8 | 9 | public String getTableName() { 10 | return tableName; 11 | } 12 | 13 | public void setTableName(String tableName) { 14 | this.tableName = tableName; 15 | } 16 | 17 | public LoadTableRuleRuntimeException(String tableName, String s, Throwable cause) { 18 | super(s); 19 | this.throwable = cause; 20 | this.tableName = tableName; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/exception/UpdateDBServerRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.exception; 2 | 3 | public class UpdateDBServerRuntimeException extends AmoebaRuntimeException{ 4 | private static final long serialVersionUID = 1L; 5 | private String poolName; 6 | 7 | public UpdateDBServerRuntimeException(String poolName, String s, Throwable cause) { 8 | super(s); 9 | this.throwable = cause; 10 | this.poolName = poolName; 11 | } 12 | 13 | public String getPoolName() { 14 | return poolName; 15 | } 16 | 17 | public void setPoolName(String poolName) { 18 | this.poolName = poolName; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/exception/UpdateIpRuleRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.exception; 2 | 3 | public class UpdateIpRuleRuntimeException extends AmoebaRuntimeException{ 4 | private static final long serialVersionUID = 1L; 5 | private String ipRule; 6 | 7 | public UpdateIpRuleRuntimeException(String ipRule, String s, Throwable cause) { 8 | super(s); 9 | this.throwable = cause; 10 | this.ipRule = ipRule; 11 | } 12 | 13 | public String getIpRule() { 14 | return ipRule; 15 | } 16 | 17 | public void setIpRule(String ipRule) { 18 | this.ipRule = ipRule; 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/heartbeat/Status.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.heartbeat; 2 | 3 | /** 4 | * 5 | * @author Struct 6 | * 7 | */ 8 | public enum Status { 9 | INVALID, VALID 10 | }; -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/heartbeat/TaskProperty.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.heartbeat; 2 | 3 | 4 | public final class TaskProperty { 5 | //时间单位为毫秒 6 | 7 | // IP 过滤地址刷新时间和重试次数 8 | public final static int IPRULE_MAX_RETRY_TIMES = 10; 9 | public final static Long IPRULE_RELOAD_DELAY = 8000l; 10 | 11 | private TaskProperty(){ 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/jdbc/ClassWrapperUtil.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.jdbc; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public class ClassWrapperUtil { 6 | @SuppressWarnings("unchecked") 7 | public static T invoke(Object obje,Class returnClass ,String methodName,Object[] parameters,Class... parameterTypes){ 8 | try { 9 | Method method = obje.getClass().getMethod(methodName, parameterTypes); 10 | return (T)method.invoke(obje, parameters); 11 | } catch (Exception e) { 12 | throw new UnsupportedOperationException(e); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/jdbc/ResultSetHandler.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.jdbc; 2 | 3 | import com.meidusa.amoeba.net.DatabaseConnection; 4 | 5 | public interface ResultSetHandler { 6 | 7 | public boolean needHandle(int jdbcType); 8 | 9 | public T serverToClient(DatabaseConnection conn, T object); 10 | 11 | public T clientToServer(DatabaseConnection conn, T object); 12 | } 13 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/jdbc/StringCharsetIOHandler.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.jdbc; 2 | 3 | public class StringCharsetIOHandler { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/monitor/Command.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.monitor; 2 | 3 | import java.io.Serializable; 4 | 5 | public enum Command implements Serializable{ 6 | SHUTDOWN,OK,PING,PONG 7 | } 8 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/monitor/MonitorConstant.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.monitor; 2 | 3 | public interface MonitorConstant { 4 | String APPLICATION_NAME = ".Amoeba"; 5 | int HEADER_SIZE = 5; 6 | 7 | byte FUN_TYPE_OBJECT = 1; 8 | byte FUN_TYPE_PING = 2; 9 | byte FUN_TYPE_OK = 3; 10 | 11 | byte FUN_TYPE_DBSERVER_ADD = 4; 12 | byte FUN_TYPE_DBSERVER_DELETE = 5; 13 | byte FUN_TYPE_DBSERVER_UPDATE = 6; 14 | byte FUN_TYPE_DBSERVER_DSIABLE = 7; 15 | byte FUN_TYPE_DBSERVER_ENABLE = 8; 16 | 17 | byte FUN_TYPE_RULE_UPDATE = 9; 18 | byte FUN_TYPE_RULE_ADD = 10; 19 | byte FUN_TYPE_RULE_DELETE = 11; 20 | byte FUN_TYPE_AMOEBA_RELOAD = 21; 21 | byte FUN_TYPE_AMOEBA_SHUTDOWN = 22; 22 | 23 | byte[] HEADER_PAD = new byte[HEADER_SIZE]; 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/monitor/io/MonitorPacketInputStream.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.monitor.io; 2 | 3 | import com.meidusa.amoeba.monitor.MonitorConstant; 4 | import com.meidusa.amoeba.net.io.PacketInputStream; 5 | 6 | public class MonitorPacketInputStream extends PacketInputStream implements MonitorConstant{ 7 | 8 | protected int decodeLength() { 9 | /** 10 | * 判断一下我们当前已经读取的数据包的数据是否比包头长,如果是:则可以计算整个包的长度,否则返回-1 11 | */ 12 | if (_have < getHeaderSize()) { 13 | return -1; 14 | } 15 | 16 | //_buffer.rewind(); 17 | 18 | /** 19 | * mysql 数据部分+包头=整个数据包长度 20 | */ 21 | int length = (_buffer.get(0) & 0xff) 22 | | ((_buffer.get(1) & 0xff) << 8) 23 | | ((_buffer.get(2) & 0xff) << 16) 24 | | ((_buffer.get(3) & 0xff) << 24); 25 | 26 | return length; 27 | } 28 | 29 | public int getHeaderSize() { 30 | return HEADER_SIZE; 31 | } 32 | 33 | protected byte[] readPacket(){ 34 | byte[] msg = new byte[_length]; 35 | int position = _buffer.position(); 36 | _buffer.position(0); 37 | _buffer.get(msg, 0, _length); 38 | try{ 39 | _buffer.limit(_have); 40 | 41 | _buffer.compact(); 42 | _buffer.position(position - _length); 43 | _have -= _length; 44 | _length = this.decodeLength(); 45 | }catch(IllegalArgumentException e){ 46 | throw new IllegalArgumentException("old position="+_buffer.position()+", new position="+_length+",old limit="+_buffer.limit() +", have(new limit)="+_have,e); 47 | } 48 | return msg; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/monitor/net/MonitorClientConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.monitor.net; 2 | 3 | import java.nio.channels.SocketChannel; 4 | 5 | import com.meidusa.amoeba.net.AbstractConnectionFactory; 6 | import com.meidusa.amoeba.net.Connection; 7 | 8 | public class MonitorClientConnectionFactory extends AbstractConnectionFactory { 9 | 10 | @Override 11 | protected Connection newConnectionInstance(SocketChannel channel, 12 | long createStamp) { 13 | return new MonitorClientConnection(channel,createStamp); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/AuthResponseData.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.net; 15 | 16 | /** 17 | * @author Struct chen 18 | */ 19 | public class AuthResponseData { 20 | 21 | /** The constant used to indicate a successful authentication. */ 22 | public static final String SUCCESS = "success"; 23 | public static final String ERROR = "error"; 24 | 25 | public String message; 26 | 27 | /** 28 | * Either the {@link #SUCCESS} constant or a reason code indicating why the authentication failed. 29 | */ 30 | public String code; 31 | } 32 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/AuthingableConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net; 2 | 3 | import java.io.IOException; 4 | import java.nio.channels.SocketChannel; 5 | 6 | import org.apache.log4j.Logger; 7 | 8 | import com.meidusa.amoeba.context.ProxyRuntimeContext; 9 | 10 | /** 11 | * 需要等待验证得连接工厂 12 | * @author struct 13 | * 14 | */ 15 | public abstract class AuthingableConnectionFactory extends AbstractConnectionFactory { 16 | 17 | private static Logger logger = Logger.getLogger(AuthingableConnectionFactory.class); 18 | 19 | public Connection createConnection(SocketChannel channel, long createStamp) throws IOException { 20 | Connection connection = (Connection) super.createConnection(channel, createStamp); 21 | waitforAuthenticate(connection); 22 | 23 | if (logger.isDebugEnabled()) { 24 | logger.debug("make backend connection success, connection=" + connection ); 25 | } 26 | 27 | return connection; 28 | } 29 | 30 | 31 | 32 | protected void waitforAuthenticate(Connection connection){ 33 | if(connection instanceof AuthingableConnection){ 34 | AuthingableConnection authconn = (AuthingableConnection)connection; 35 | 36 | // 验证超时时间 37 | long authTimeOut = ProxyRuntimeContext.getInstance().getRuntimeContext().getAuthTimeOut() * 1000; 38 | 39 | if( authTimeOut >0 ){ 40 | authconn.isAuthenticatedWithBlocked(authTimeOut); 41 | } 42 | }else{ 43 | connection.getConnectionManager().notifyObservers(ConnectionManager.CONNECTION_ESTABLISHED, connection, null); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/AuthingableConnectionManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.net; 15 | 16 | import java.io.IOException; 17 | 18 | /** 19 | * 支持Connection 身份验证流程的 ConnectionManager 20 | * 21 | * @author Struct chen 22 | */ 23 | public class AuthingableConnectionManager extends ConnectionManager { 24 | protected Authenticator _author; 25 | 26 | public AuthingableConnectionManager() throws IOException{ 27 | } 28 | 29 | public AuthingableConnectionManager(String managerName) throws IOException{ 30 | super(managerName); 31 | } 32 | 33 | public void setAuthenticator(Authenticator author) { 34 | _author = author; 35 | } 36 | 37 | public Authenticator getAuthenticator() { 38 | return _author; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net; 13 | 14 | import java.io.IOException; 15 | import java.nio.channels.SocketChannel; 16 | 17 | /** 18 | * Connection Factory interface 19 | * 连接工厂接口 20 | * @author Struct chen 21 | * 22 | */ 23 | public interface ConnectionFactory { 24 | 25 | /** 26 | * @param channel 27 | * @param createStamp 28 | * @return 29 | * @throws IOException 30 | */ 31 | public Connection createConnection(SocketChannel channel,long createStamp) throws IOException; 32 | } 33 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/ConnectionObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net; 13 | 14 | /** 15 | * 16 | * @see ConnectionManager 17 | * @see Connection 18 | * 19 | * @author Struct chen 20 | * 21 | */ 22 | public interface ConnectionObserver { 23 | 24 | public void connectionEstablished(Connection conn); 25 | 26 | public void connectionFailed(Connection conn, Exception fault); 27 | 28 | public void connectionClosed(Connection conn); 29 | } 30 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/FrontendConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 作为前端数据库连接工厂 7 | * @author struct 8 | * 9 | */ 10 | public abstract class FrontendConnectionFactory extends AbstractConnectionFactory { 11 | 12 | protected void initConnection(Connection connection) throws IOException{ 13 | super.initConnection(connection); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/IdleChecker.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net; 2 | 3 | public interface IdleChecker { 4 | 5 | /** 6 | * 检查是否以及处于idle,如果返回true,则需要关闭. 7 | * @param now 8 | * @return 9 | */ 10 | public boolean checkIdle(long now); 11 | } 12 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/MessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net; 13 | 14 | 15 | /** 16 | * 17 | * 网络数据处理接口 18 | * 19 | * @author Struct chen 20 | * 21 | */ 22 | public interface MessageHandler { 23 | 24 | /** 25 | * 26 | * 处理一个完整的数据包消息 27 | * 28 | * @param conn 表示该数据是从当前conn 发送过来的 29 | * 30 | * @param message 当前handle 的消息数据 31 | */ 32 | public void handleMessage(Connection conn); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/NetEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net; 13 | 14 | import java.io.IOException; 15 | import java.nio.channels.SelectionKey; 16 | 17 | /** 18 | * net Event handler 19 | * @author Struct chen 20 | * 21 | */ 22 | public interface NetEventHandler extends IdleChecker{ 23 | 24 | /** 25 | * 此时handler需要处理 when 时刻 所 handle 的网络事件。 26 | * 27 | * @param when 28 | * @return 29 | */ 30 | public int handleEvent (long when); 31 | 32 | public SelectionKey getSelectionKey(); 33 | 34 | public void setSelectionKey(SelectionKey selkey); 35 | 36 | public boolean doWrite() throws IOException; 37 | } 38 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/PacketHandler.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net; 2 | 3 | import com.meidusa.amoeba.net.packet.Packet; 4 | 5 | public interface PacketHandler extends MessageHandler { 6 | public void handlePacket(T packet); 7 | } 8 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/SessionMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net; 13 | 14 | 15 | /** 16 | * 17 | * 网络数据处理接口 18 | * 19 | * @author Struct chen 20 | * 21 | */ 22 | public interface SessionMessageHandler extends IdleChecker{ 23 | 24 | /** 25 | * 26 | * 处理一个完整的数据包消息 27 | * 28 | * @param conn 表示该数据是从当前conn 发送过来的 29 | * 30 | * @param message 当前handle 的消息数据 31 | */ 32 | public void handleMessage(Connection conn,byte[] message); 33 | 34 | public void forceEndSession(String cause); 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/Sessionable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net; 13 | 14 | public interface Sessionable extends IdleChecker{ 15 | 16 | public void startSession() throws Exception; 17 | public boolean isMultiplayer(); 18 | public void endSession(boolean force, Exception trigger); 19 | public boolean isStarted(); 20 | public boolean isEnded(); 21 | public boolean isSuccess(); 22 | } 23 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/SocketChannelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net; 13 | 14 | import java.io.IOException; 15 | import java.nio.channels.SocketChannel; 16 | 17 | /** 18 | * 非阻塞模式的SocketChannel 工厂 19 | * 20 | * @author Struct chen 21 | * 22 | */ 23 | public interface SocketChannelFactory { 24 | 25 | /** 26 | * 创建一个非阻塞模式的SocketChannel 27 | * @return 28 | * @throws IOException 29 | */ 30 | public SocketChannel createSokectChannel() throws IOException; 31 | } 32 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/packet/AbstractPacketFactory.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net.packet; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import com.meidusa.amoeba.net.Connection; 6 | 7 | public abstract class AbstractPacketFactory implements PacketFactory { 8 | private static final Logger logger = Logger.getLogger(AbstractPacketFactory.class); 9 | public T createPacket(Connection conn, byte[] buffer) { 10 | try { 11 | T packet = getPacketClass(buffer).newInstance(); 12 | V packetBuffer = getPacketBufferClass(buffer).newInstance(); 13 | packet.init(packetBuffer); 14 | return packet; 15 | } catch (Exception e) { 16 | logger.error("instance of packet Error",e); 17 | return null; 18 | } 19 | } 20 | 21 | protected abstract Class getPacketClass(byte[] buffer); 22 | 23 | protected abstract Class getPacketBufferClass(byte[] buffer); 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/packet/Packet.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.net.packet; 15 | 16 | import java.nio.ByteBuffer; 17 | 18 | import com.meidusa.amoeba.net.Connection; 19 | 20 | /** 21 | * @author Struct chen 22 | */ 23 | public interface Packet extends Cloneable { 24 | 25 | /** 26 | * 从buffer(含包头) 中初始化数据包。 27 | * 28 | * @param buffer buffer是从socketChannel的流读取头n个字节计算数据包长度 并且读取相应的长度所形成的buffer 29 | */ 30 | public void init(byte[] buffer, Connection conn); 31 | 32 | /** 33 | * 将数据包转化成ByteBuffer,byteBuffer中包含有包头信息 34 | * 35 | * @return 36 | */ 37 | public ByteBuffer toByteBuffer(Connection conn); 38 | } 39 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/packet/PacketBuffer.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net.packet; 2 | 3 | import java.io.InputStream; 4 | import java.io.OutputStream; 5 | import java.nio.ByteBuffer; 6 | 7 | /** 8 | * 9 | * @author struct 10 | * 11 | */ 12 | public interface PacketBuffer { 13 | 14 | /** 15 | * 16 | * @return 17 | */ 18 | public ByteBuffer toByteBuffer(); 19 | 20 | public byte readByte(); 21 | 22 | public byte readByte(int postion); 23 | 24 | public int readBytes(byte[] ab, int offset, int len); 25 | 26 | public void reset(); 27 | /** 28 | * current remain, but the buffer can expands itself. when the large bytes written; 29 | * @return 30 | */ 31 | int remaining(); 32 | /** 33 | * 34 | * @param bte 35 | */ 36 | public void writeByte(byte bte); 37 | 38 | /** 39 | * 40 | * @param btes 41 | */ 42 | public int writeBytes(byte[] btes); 43 | 44 | /** 45 | * 46 | * @return 47 | */ 48 | public int getPacketLength(); 49 | 50 | 51 | /** 52 | * 53 | * @return 54 | */ 55 | public int getPosition(); 56 | 57 | /** 58 | * Set the current position to write to/ read from 59 | * 60 | * @param position 61 | * the position (0-based index) 62 | */ 63 | public void setPosition(int positionToSet); 64 | 65 | public InputStream asInputStream(); 66 | 67 | public OutputStream asOutputStream(); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/packet/PacketFactory.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net.packet; 2 | 3 | import com.meidusa.amoeba.net.Connection; 4 | 5 | /** 6 | * 由Packet 工厂负责创建 Packet 7 | * @author struct 8 | * 9 | */ 10 | public interface PacketFactory { 11 | 12 | /** 13 | * 14 | * @param conn 数据包的来源Connection 15 | * @param buffer 数据包字节 16 | * @return Packet 目标数据包 17 | */ 18 | T createPacket(Connection conn,byte[] buffer); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/packet/Response.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.net.packet; 2 | 3 | /** 4 | * 对原有packet的封装 5 | * @author WangFei 6 | * 7 | */ 8 | public class Response { 9 | 10 | public boolean isSuccess; 11 | 12 | public int errno; 13 | 14 | /** 15 | * 5个字节 16 | */ 17 | public String sqlstate; 18 | 19 | /** 20 | * 错误信息 21 | */ 22 | public String serverErrorMessage; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/net/poolable/PoolableObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.net.poolable; 13 | 14 | /** 15 | * 16 | * @author Struct chen 17 | * 18 | */ 19 | public interface PoolableObject { 20 | 21 | public void setObjectPool(ObjectPool pool); 22 | 23 | public ObjectPool getObjectPool(); 24 | 25 | public void setActive(boolean isactive); 26 | 27 | public boolean isRemovedFromPool(); 28 | 29 | public boolean isActive(); 30 | } 31 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/AmoebaSqlHintPropNames.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser; 2 | 3 | public class AmoebaSqlHintPropNames { 4 | public final static String IS_READ_HINT = "isRead"; 5 | public final static String IS_PROCEDURE_HINT = "isProcedure"; 6 | public final static String PARAMS_COUNT_HINT = "params"; 7 | public final static String POOLS_HINT = "pools"; 8 | } 9 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/ParseException.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.parser; 15 | 16 | /** 17 | * @author Struct chen 18 | */ 19 | public class ParseException extends Exception { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | public ParseException(String message, Exception e){ 24 | super(message, e); 25 | } 26 | 27 | public ParseException(Exception e){ 28 | super(e); 29 | } 30 | 31 | public ParseException(String message){ 32 | super(message); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/Parser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser; 13 | 14 | import java.util.Map; 15 | 16 | import com.meidusa.amoeba.parser.function.Function; 17 | import com.meidusa.amoeba.parser.dbobject.Schema; 18 | import com.meidusa.amoeba.parser.statement.Statement; 19 | 20 | /** 21 | * 22 | * @author Struct chen 23 | * 24 | */ 25 | public interface Parser { 26 | public Statement doParse() throws ParseException; 27 | public void setDefaultSchema(Schema schema); 28 | public void setFunctionMap(Map funMap); 29 | public void setUserName(String userName); 30 | } 31 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/dbobject/DBObjectBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.dbobject; 13 | 14 | /** 15 | * 16 | * @author Struct chen 17 | * 18 | */ 19 | public interface DBObjectBase { 20 | public String getSql(); 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/dbobject/GlobalSeqColumn.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.dbobject; 2 | 3 | public class GlobalSeqColumn { 4 | private T seqObject; 5 | private String seqName; 6 | private Long seqValue; 7 | private int seqTokenEndColumn; 8 | 9 | 10 | public GlobalSeqColumn(T seqObject, String seqName, Long seqValue, int seqTokenEndColumn) { 11 | super(); 12 | this.seqObject = seqObject; 13 | this.seqName = seqName; 14 | this.seqValue = seqValue; 15 | this.seqTokenEndColumn = seqTokenEndColumn; 16 | } 17 | 18 | public T getSeqObject() { 19 | return seqObject; 20 | } 21 | 22 | public void setSeqObject(T seqObject) { 23 | this.seqObject = seqObject; 24 | } 25 | 26 | public String getSeqName() { 27 | return seqName; 28 | } 29 | 30 | public void setSeqName(String seqName) { 31 | this.seqName = seqName; 32 | } 33 | 34 | public Long getSeqValue() { 35 | return seqValue; 36 | } 37 | 38 | public void setSeqValue(Long seqValue) { 39 | this.seqValue = seqValue; 40 | } 41 | 42 | public int getSeqTokenEndColumn() { 43 | return seqTokenEndColumn; 44 | } 45 | 46 | public void setSeqTokenEndColumn(int seqTokenEndColumn) { 47 | this.seqTokenEndColumn = seqTokenEndColumn; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return seqObject.toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/expression/AndExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.expression; 13 | 14 | /** 15 | * And Expression 16 | * @author Struct chen 17 | * 18 | */ 19 | public class AndExpression extends BaseExpressionList { 20 | 21 | public AndExpression(){ 22 | } 23 | 24 | public AndExpression(Expression node){ 25 | super(node); 26 | } 27 | 28 | @SuppressWarnings("unchecked") 29 | public Comparable evaluate(Object[] parameters) { 30 | for (Expression e : eList) { 31 | if (!((Boolean) e.evaluate(parameters))) { 32 | return Boolean.FALSE; 33 | } 34 | } 35 | return Boolean.TRUE; 36 | } 37 | 38 | protected BaseExpressionList getReverseObject() { 39 | return new OrExpression(null); 40 | } 41 | 42 | protected void toString(StringBuilder builder) { 43 | this.toString(builder, " AND "); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/expression/Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.expression; 13 | 14 | 15 | /** 16 | * 表达式基类 17 | * 18 | * @author Struct chen 19 | * 20 | */ 21 | public abstract class Expression { 22 | 23 | public Expression(){ 24 | } 25 | 26 | public boolean canEvaluate() { 27 | return true; 28 | } 29 | 30 | /** 31 | * 表达式取反 32 | */ 33 | public abstract Expression reverse(); 34 | 35 | protected abstract void toString(StringBuilder builder); 36 | 37 | /** 38 | * 表示该表达式是否需要实时计算 39 | */ 40 | public abstract boolean isRealtime(); 41 | 42 | /** 43 | * 表达式计算 44 | */ 45 | @SuppressWarnings("unchecked") 46 | public abstract Comparable evaluate(Object[] parameters); 47 | 48 | public String toString() { 49 | StringBuilder builder = new StringBuilder(); 50 | this.toString(builder); 51 | return builder.toString(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/expression/OrExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.expression; 13 | 14 | /** 15 | * OR expression 16 | * @author Struct chen 17 | * 18 | */ 19 | public class OrExpression extends BaseExpressionList { 20 | 21 | public OrExpression(){ 22 | 23 | } 24 | 25 | public OrExpression(Expression node) { 26 | super(node); 27 | } 28 | 29 | @SuppressWarnings("unchecked") 30 | public Comparable evaluate(Object[] parameters) { 31 | for(Expression e :eList){ 32 | if((Boolean)e.evaluate(parameters)){ 33 | return Boolean.TRUE; 34 | } 35 | } 36 | return Boolean.FALSE; 37 | } 38 | 39 | protected BaseExpressionList getReverseObject(){ 40 | return new AndExpression(null); 41 | } 42 | 43 | protected void toString(StringBuilder builder){ 44 | this.toString(builder, " OR "); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Ascii.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.List; 4 | 5 | import com.meidusa.amoeba.parser.expression.Expression; 6 | import com.meidusa.amoeba.sqljep.ParseException; 7 | import com.meidusa.amoeba.util.StringUtil; 8 | 9 | public class Ascii extends AbstractFunction { 10 | 11 | @SuppressWarnings("unchecked") 12 | public Comparable evaluate(List list, Object[] parameters) 13 | throws ParseException { 14 | if(list.size()==0){ 15 | return null; 16 | } 17 | 18 | Comparable param = list.get(0).evaluate(parameters); 19 | if(param == null){ 20 | return null; 21 | } 22 | String str = String.valueOf(param); 23 | if(StringUtil.isEmpty(str)){ 24 | return 0; 25 | }else{ 26 | } 27 | return (int)str.charAt(0); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/BulkValFuntion.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.List; 4 | 5 | import com.meidusa.amoeba.parser.dbobject.Table; 6 | import com.meidusa.amoeba.parser.expression.Expression; 7 | import com.meidusa.amoeba.sqljep.ParseException; 8 | 9 | public class BulkValFuntion extends AbstractFunction{ 10 | 11 | private Table table; 12 | 13 | public Table getTable() { 14 | return table; 15 | } 16 | 17 | public void setTable(Table table) { 18 | this.table = table; 19 | } 20 | 21 | public String getSql() { 22 | return (table == null ? name : table.getSql() + "." + name); 23 | } 24 | 25 | public void toString(List list,StringBuilder builder) { 26 | 27 | if(list == null){ 28 | builder.append(getSql()); 29 | builder.append("("); 30 | builder.append(")"); 31 | }else{ 32 | int current = 0; 33 | builder.append(getSql()); 34 | builder.append("("); 35 | for(Expression e:list){ 36 | builder.append(e); 37 | current ++; 38 | if(current != list.size()){ 39 | builder.append(","); 40 | } 41 | } 42 | builder.append(")"); 43 | } 44 | } 45 | 46 | @Override 47 | public Comparable evaluate(List list, Object[] parameters) throws ParseException { 48 | throw new UnsupportedOperationException("evaluate is not supported in class="+ this.getClass().getName()); 49 | } 50 | 51 | public String toString() { 52 | return getSql(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/CurrentDate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.function; 13 | 14 | import java.util.Calendar; 15 | import java.util.List; 16 | 17 | import com.meidusa.amoeba.parser.expression.Expression; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | /** 21 | * 22 | * @author Struct chen 23 | * 24 | */ 25 | public class CurrentDate extends AbstractFunction implements RealtimeCalculator{ 26 | 27 | @SuppressWarnings("unchecked") 28 | public Comparable evaluate(List list, Object[] parameters) 29 | throws ParseException { 30 | Calendar cal = Calendar.getInstance(); 31 | return cal.get(Calendar.DATE); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Divide.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.function; 13 | 14 | import java.util.Iterator; 15 | import java.util.List; 16 | 17 | import com.meidusa.amoeba.parser.expression.Expression; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | public class Divide extends AbstractFunction { 21 | 22 | @SuppressWarnings("unchecked") 23 | public Comparable evaluate(List list, Object[] parameters) 24 | throws ParseException { 25 | Comparable param1 = null; 26 | if(list.size()>=2){ 27 | Iterator it =list.iterator(); 28 | param1 = it.next().evaluate(parameters); 29 | Comparable param2 = it.next().evaluate(parameters); 30 | param1 = com.meidusa.amoeba.sqljep.function.Divide.div(param1, param2); 31 | } 32 | return param1; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.function; 13 | 14 | import java.util.List; 15 | 16 | import com.meidusa.amoeba.parser.expression.Expression; 17 | import com.meidusa.amoeba.sqljep.ParseException; 18 | 19 | /** 20 | * 21 | * @author Struct chen 22 | * 23 | */ 24 | public interface Function{ 25 | 26 | @SuppressWarnings("unchecked") 27 | Comparable evaluate(List list,Object[] parameters) throws ParseException; 28 | 29 | /** 30 | * 获得函数名称 31 | * @return 32 | */ 33 | public String getName(); 34 | 35 | /** 36 | * 设置函数名称 37 | * @param name 38 | */ 39 | public void setName(String name); 40 | 41 | void toString(List list,StringBuilder builder); 42 | } 43 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Insert.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.List; 4 | 5 | import com.meidusa.amoeba.parser.expression.Expression; 6 | import com.meidusa.amoeba.sqljep.ParseException; 7 | 8 | public class Insert extends AbstractFunction { 9 | 10 | @SuppressWarnings("unchecked") 11 | public Comparable evaluate(List list, Object[] parameters) 12 | throws ParseException { 13 | if(list.size() != 4){ 14 | return null; 15 | } 16 | String param1 = (String)list.get(0).evaluate(parameters); 17 | Long param2 = (Long)list.get(1).evaluate(parameters); 18 | Long param3 = (Long)list.get(2).evaluate(parameters); 19 | String param4 = (String)list.get(3).evaluate(parameters); 20 | if(param1 == null){ 21 | return null; 22 | } 23 | 24 | return insert(param1,param2.intValue(),param3.intValue(),param4); 25 | } 26 | 27 | 28 | public static String insert(String param1,int pos, int length,String newStr){ 29 | if(param1 == null){ 30 | return null; 31 | } 32 | 33 | 34 | if(pos<=0) return param1; 35 | pos = pos>param1.length()?param1.length():pos; 36 | //length = length >= param1.length() - pos-1?param1.length() - pos-1:length; 37 | String str1 = param1.substring(0,pos-1); 38 | String str2 = null; 39 | if(length + pos -1 <= param1.length()){ 40 | str2 = param1.substring(pos+length-1,param1.length()); 41 | } 42 | StringBuilder builder = new StringBuilder(); 43 | builder.append(str1); 44 | builder.append(newStr); 45 | if(str2 != null){ 46 | builder.append(str2); 47 | } 48 | return builder.toString(); 49 | } 50 | 51 | public static void main(String args[]){ 52 | System.out.println(insert("Quadratic", 3, 4, "What")); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Instr.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.List; 4 | 5 | import com.meidusa.amoeba.parser.expression.Expression; 6 | import com.meidusa.amoeba.sqljep.ParseException; 7 | 8 | public class Instr extends AbstractFunction { 9 | 10 | @SuppressWarnings("unchecked") 11 | public Comparable evaluate(List list, Object[] parameters) 12 | throws ParseException { 13 | if(list.size() != 2){ 14 | return null; 15 | } 16 | 17 | String param1 = (String)list.get(0).evaluate(parameters); 18 | String param2 = (String)list.get(1).evaluate(parameters); 19 | 20 | if(param1 == null || param2 == null){ 21 | return 0; 22 | } 23 | 24 | return param1.indexOf(param2) +1; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/LastInsertId.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.List; 4 | 5 | import com.meidusa.amoeba.parser.expression.Expression; 6 | import com.meidusa.amoeba.sqljep.ParseException; 7 | import com.meidusa.amoeba.util.ThreadLocalMap; 8 | 9 | public class LastInsertId extends AbstractFunction implements ThreadLocalSettingFunction { 10 | 11 | public Comparable evaluate(List list, Object[] parameters) 12 | throws ParseException { 13 | return null; 14 | } 15 | 16 | public void invoke() { 17 | ThreadLocalMap.put(LastInsertId.class.getName(), Boolean.TRUE); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Modulus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.function; 13 | 14 | import java.util.Iterator; 15 | import java.util.List; 16 | 17 | import com.meidusa.amoeba.parser.expression.Expression; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | public class Modulus extends AbstractFunction { 21 | 22 | @SuppressWarnings("unchecked") 23 | public Comparable evaluate(List list, Object[] parameters) 24 | throws ParseException { 25 | Comparable param1 = null; 26 | if(list.size()>=2){ 27 | Iterator it =list.iterator(); 28 | param1 = it.next().evaluate(parameters); 29 | Comparable param2 = it.next().evaluate(parameters); 30 | param1 = com.meidusa.amoeba.sqljep.function.Modulus.remainder(param1, param2); 31 | } 32 | return param1; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Multiply.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.function; 13 | 14 | import java.util.List; 15 | 16 | import com.meidusa.amoeba.parser.expression.Expression; 17 | import com.meidusa.amoeba.sqljep.ParseException; 18 | 19 | public class Multiply extends AbstractFunction { 20 | 21 | @SuppressWarnings("unchecked") 22 | public Comparable evaluate(List list, Object[] parameters) 23 | throws ParseException { 24 | Expression param1 = list.get(0); 25 | Expression param2 = list.get(1); 26 | return com.meidusa.amoeba.sqljep.function.Multiply.mul(param1.evaluate(parameters), param2.evaluate(parameters)); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Now.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.function; 13 | 14 | import java.sql.Timestamp; 15 | import java.util.List; 16 | 17 | import com.meidusa.amoeba.parser.expression.Expression; 18 | 19 | /** 20 | * 21 | * @author Struct chen 22 | * 23 | */ 24 | public class Now extends AbstractFunction implements RealtimeCalculator{ 25 | 26 | @SuppressWarnings("unchecked") 27 | public Comparable evaluate(List list,Object[] parameters) { 28 | return new Timestamp(System.currentTimeMillis()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/Procedure.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.meidusa.amoeba.exception.InitialisationException; 8 | import com.meidusa.amoeba.parser.dbobject.Column; 9 | import com.meidusa.amoeba.parser.dbobject.Table; 10 | import com.meidusa.amoeba.parser.expression.Expression; 11 | import com.meidusa.amoeba.sqljep.ParseException; 12 | import com.meidusa.amoeba.util.Initialisable; 13 | 14 | /** 15 | * 16 | * @author Struct 17 | * 18 | */ 19 | public class Procedure extends AbstractFunction implements Initialisable{ 20 | private Table table; 21 | private Map columnMap = new HashMap(); 22 | private String tableName; 23 | private String params; 24 | 25 | @Override 26 | public Comparable evaluate(List list, Object[] parameters) 27 | throws ParseException { 28 | 29 | return null; 30 | } 31 | 32 | @Override 33 | public void init() throws InitialisationException { 34 | 35 | } 36 | 37 | public String getTableName() { 38 | return tableName; 39 | } 40 | 41 | public void setTableName(String tableName) { 42 | this.tableName = tableName; 43 | } 44 | 45 | public String getParams() { 46 | return params; 47 | } 48 | 49 | public void setParams(String params) { 50 | this.params = params; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/RealtimeCalculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.function; 13 | 14 | /** 15 | * 用于表示实时计算的方法或者表达式 16 | * @author Struct chen 17 | * 18 | */ 19 | public interface RealtimeCalculator { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/ThreadLocalSettingFunction.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | public interface ThreadLocalSettingFunction { 4 | public void invoke(); 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/UnixTimestamp.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.List; 4 | 5 | import com.meidusa.amoeba.parser.expression.Expression; 6 | import com.meidusa.amoeba.sqljep.ParseException; 7 | 8 | public class UnixTimestamp extends AbstractFunction { 9 | 10 | public Comparable evaluate(List list, Object[] parameters) 11 | throws ParseException { 12 | return System.currentTimeMillis() /1000; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/function/UnknowableFunction.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.function; 2 | 3 | import java.util.List; 4 | 5 | import com.meidusa.amoeba.parser.expression.Expression; 6 | import com.meidusa.amoeba.sqljep.ParseException; 7 | 8 | /** 9 | * 未知的函数,如果想要让sqlparser正常工作,但是又不希望实现,则可以采用该函数 10 | * @author struct 11 | * 12 | */ 13 | public class UnknowableFunction extends AbstractFunction { 14 | 15 | @SuppressWarnings("unchecked") 16 | public Comparable evaluate(List list, Object[] parameters) 17 | throws ParseException { 18 | return null; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/AbstractStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | import java.util.Map; 4 | 5 | import com.meidusa.amoeba.parser.dbobject.Table; 6 | 7 | 8 | public abstract class AbstractStatement implements Statement { 9 | protected Table[] tables; 10 | private int parameterCount; 11 | 12 | private boolean isPrepared; 13 | 14 | private boolean isExplain; 15 | 16 | private Map hintParamsMap; 17 | 18 | 19 | public int getParameterCount() { 20 | return parameterCount; 21 | } 22 | 23 | public String getSql() { 24 | return null; 25 | } 26 | 27 | public void setParameterCount(int count) { 28 | this.parameterCount = count; 29 | } 30 | 31 | public Table[] getTables() { 32 | return tables; 33 | } 34 | 35 | public void setTables(Table[] tables) { 36 | this.tables = tables; 37 | } 38 | 39 | public boolean isPrepared() { 40 | return isPrepared; 41 | } 42 | 43 | public void setPrepared(boolean isPrepared) { 44 | this.isPrepared = isPrepared; 45 | } 46 | 47 | public String getType() { 48 | return this.getClass().getSimpleName(); 49 | } 50 | 51 | public boolean isRead() { 52 | return false; 53 | } 54 | 55 | @Override 56 | public boolean isExplain() { 57 | return isExplain; 58 | } 59 | 60 | @Override 61 | public void setExplain(boolean isExplain) { 62 | this.isExplain = isExplain; 63 | } 64 | 65 | @Override 66 | public void setHintParams(Map hintParamsMap) { 67 | this.hintParamsMap = hintParamsMap; 68 | } 69 | 70 | @Override 71 | public Map getHintParams() { 72 | return hintParamsMap; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/BeginStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | import com.meidusa.amoeba.parser.expression.Expression; 4 | 5 | public class BeginStatement extends AbstractStatement { 6 | 7 | public Expression getExpression() { 8 | return null; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/CallStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | import java.util.Map; 4 | 5 | import com.meidusa.amoeba.parser.dbobject.Column; 6 | import com.meidusa.amoeba.parser.dbobject.Table; 7 | import com.meidusa.amoeba.sqljep.function.Comparative; 8 | 9 | public class CallStatement extends DMLStatement { 10 | public CallStatement(){ 11 | this.setProcedure(true); 12 | } 13 | 14 | @Override 15 | public Map> evaluate(Object[] parameters) { 16 | return null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/CommitCMD.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | public interface CommitCMD { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/CommitStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | import com.meidusa.amoeba.parser.expression.Expression; 15 | 16 | public class CommitStatement extends AbstractStatement implements CommitCMD{ 17 | 18 | public Expression getExpression() { 19 | return null; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/DeleteStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | 15 | /** 16 | * 17 | * @author Struct chen 18 | * 19 | */ 20 | public class DeleteStatement extends DMLStatement { 21 | public DeleteStatement(){ 22 | this.setRead(false); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/HelpStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | import com.meidusa.amoeba.parser.expression.Expression; 4 | 5 | public class HelpStatement extends AbstractStatement{ 6 | 7 | @Override 8 | public Expression getExpression() { 9 | return null; 10 | } 11 | 12 | public boolean isRead() { 13 | return true; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/InsertStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | 15 | /** 16 | * 17 | * @author Struct chen 18 | * 19 | */ 20 | public class InsertStatement extends DMLStatement { 21 | 22 | public InsertStatement(){ 23 | this.setRead(false); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/PropertyStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | import com.meidusa.amoeba.parser.expression.Expression; 18 | 19 | /** 20 | * 用于设置连接属性的query语句(比如:mysql的“set names utf8”之类的语句) 21 | * @author Struct chen 22 | * 23 | */ 24 | public class PropertyStatement extends AbstractStatement { 25 | private Map properties = new HashMap(); 26 | 27 | public void addProperty(String key,Expression value){ 28 | 29 | this.properties.put(key==null?null:key.toLowerCase(), value); 30 | } 31 | 32 | public Expression getExpression() { 33 | return null; 34 | } 35 | 36 | public Expression getValue(String key){ 37 | return this.properties.get(key==null?null:key.toLowerCase()); 38 | } 39 | 40 | public Map getProperties() { 41 | return properties; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/RollbackCMD.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | public interface RollbackCMD { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/RollbackStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | import com.meidusa.amoeba.parser.expression.Expression; 15 | 16 | public class RollbackStatement extends AbstractStatement implements RollbackCMD{ 17 | 18 | public Expression getExpression() { 19 | // TODO Auto-generated method stub 20 | return null; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/SelectStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | /** 15 | * 16 | * @author Struct chen 17 | * 18 | */ 19 | public class SelectStatement extends DMLStatement { 20 | private boolean queryLastInsertId; 21 | 22 | public SelectStatement(){ 23 | this.setRead(true); 24 | } 25 | public void setQueryLastInsertId(boolean queryLastInsertId) { 26 | this.queryLastInsertId = queryLastInsertId; 27 | } 28 | public boolean isQueryLastInsertId(){ 29 | return queryLastInsertId; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ShowStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of the 3 | * GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 4 | * of the License, or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 7 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8 | * AFFERO GENERAL PUBLIC LICENSE for more details. You should have received a copy of the GNU AFFERO 9 | * GENERAL PUBLIC LICENSE along with this program; if not, write to the Free Software Foundation, 10 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | import com.meidusa.amoeba.parser.expression.Expression; 15 | 16 | public class ShowStatement extends AbstractStatement { 17 | public static ShowStatement STATMENT = new ShowStatement(); 18 | private Expression expression; 19 | private boolean isMultiple = false; 20 | 21 | public Expression getExpression() { 22 | return expression; 23 | } 24 | 25 | public void setExpression(Expression expression) { 26 | this.expression = expression; 27 | } 28 | 29 | public boolean isMultiple() { 30 | return isMultiple; 31 | } 32 | 33 | public void setMultiple(boolean isMultiple) { 34 | this.isMultiple = isMultiple; 35 | } 36 | 37 | public boolean isRead() { 38 | return true; 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/StartTansactionStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | import com.meidusa.amoeba.parser.expression.Expression; 15 | 16 | public class StartTansactionStatement extends AbstractStatement { 17 | 18 | public Expression getExpression() { 19 | // TODO Auto-generated method stub 20 | return null; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/Statement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | 15 | import java.util.Map; 16 | 17 | import com.meidusa.amoeba.parser.expression.Expression; 18 | 19 | /** 20 | * 21 | * @author Struct chen 22 | * 23 | */ 24 | public interface Statement { 25 | public boolean isPrepared(); 26 | public Expression getExpression(); 27 | 28 | public void setParameterCount(int count); 29 | public int getParameterCount(); 30 | 31 | public String getSql(); 32 | public String getType(); 33 | 34 | public boolean isRead(); 35 | 36 | public boolean isExplain(); 37 | public void setExplain(boolean isExplain); 38 | 39 | // 设置sql hint 40 | public void setHintParams(Map hintParamsMap); 41 | // 从语句中获取sql hint 42 | public Map getHintParams(); 43 | } 44 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/UpdateStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.parser.statement; 13 | 14 | /** 15 | * 16 | * @author Struct chen 17 | * 18 | */ 19 | public class UpdateStatement extends DMLStatement { 20 | 21 | public UpdateStatement(){ 22 | this.setRead(false); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/XACommitStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | 4 | public class XACommitStatement extends XAStatement implements CommitCMD{ 5 | 6 | } 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/XAEndStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | 4 | public class XAEndStatement extends XAStatement { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/XAPrepareStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | 4 | public class XAPrepareStatement extends XAStatement { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/XARecoverStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | 4 | public class XARecoverStatement extends XAStatement { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/XARollBackStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | 4 | public class XARollBackStatement extends XAStatement implements RollbackCMD{ 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/XAStartStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | 4 | public class XAStartStatement extends XAStatement{ 5 | 6 | } 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/XAStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement; 2 | 3 | import com.meidusa.amoeba.parser.expression.Expression; 4 | 5 | public class XAStatement extends AbstractStatement { 6 | 7 | @Override 8 | public Expression getExpression() { 9 | return null; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLAlertTableStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | public class DDLAlertTableStatement extends DDLStatement{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLCreateSequenceStatenment.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | import com.meidusa.amoeba.parser.dbobject.Schema; 4 | 5 | public class DDLCreateSequenceStatenment extends DDLStatement{ 6 | private long startWith = 1; 7 | private long offset = 1; 8 | 9 | private Schema schema; 10 | private String seqName; 11 | 12 | public long getStartWith() { 13 | return startWith; 14 | } 15 | public void setStartWith(long startWith) { 16 | this.startWith = startWith; 17 | } 18 | public long getOffset() { 19 | return offset; 20 | } 21 | public void setOffset(long offset) { 22 | this.offset = offset; 23 | } 24 | 25 | public Schema getSchema() { 26 | return schema; 27 | } 28 | public void setSchema(Schema schema) { 29 | this.schema = schema; 30 | } 31 | 32 | public String getSeqName() { 33 | return seqName; 34 | } 35 | public void setSeqName(String seqName) { 36 | this.seqName = seqName; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLCreateTableStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | public class DDLCreateTableStatement extends DDLStatement{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLDropSequenceStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | import com.meidusa.amoeba.parser.dbobject.Schema; 4 | 5 | public class DDLDropSequenceStatement extends DDLStatement{ 6 | private Schema schema; 7 | private String seqName; 8 | 9 | public Schema getSchema() { 10 | return schema; 11 | } 12 | public void setSchema(Schema schema) { 13 | this.schema = schema; 14 | } 15 | public String getSeqName() { 16 | return seqName; 17 | } 18 | public void setSeqName(String seqName) { 19 | this.seqName = seqName; 20 | } 21 | 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLDropStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | public class DDLDropStatement extends DDLStatement { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLRenameTableStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | public class DDLRenameTableStatement extends DDLStatement { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | import com.meidusa.amoeba.parser.expression.Expression; 4 | import com.meidusa.amoeba.parser.statement.AbstractStatement; 5 | 6 | public abstract class DDLStatement extends AbstractStatement { 7 | 8 | private String targetName; 9 | private String targetValue; 10 | private String operate; 11 | 12 | @Override 13 | public Expression getExpression() { 14 | // TODO Auto-generated method stub 15 | return null; 16 | } 17 | 18 | public void setTargetName(String targetName) { 19 | this.targetName = targetName; 20 | } 21 | 22 | public void setTargetValue(String targetValue) { 23 | this.targetValue = targetValue; 24 | } 25 | 26 | public String getTargetName() { 27 | return targetName; 28 | } 29 | 30 | public String getTargetValue() { 31 | return targetValue; 32 | } 33 | 34 | public String getOperate() { 35 | return operate; 36 | } 37 | 38 | public void setOperate(String operate) { 39 | this.operate = operate; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/parser/statement/ddl/DDLTruncateTableStatement.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.parser.statement.ddl; 2 | 3 | public class DDLTruncateTableStatement extends DDLStatement{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/route/QueryRouter.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.route; 15 | 16 | import java.util.List; 17 | 18 | import com.meidusa.amoeba.net.Connection; 19 | import com.meidusa.amoeba.net.poolable.ObjectPool; 20 | import com.meidusa.amoeba.parser.ParseException; 21 | import com.meidusa.amoeba.parser.statement.Statement; 22 | 23 | /** 24 | * @author struct 25 | */ 26 | public interface QueryRouter { 27 | 28 | public ObjectPool[] doRoute(T connection, V queryObjct, Statement statement) throws ParseException; 29 | 30 | public ObjectPool[] getDefaultObjectPool(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/route/Request.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.route; 2 | 3 | public interface Request { 4 | public boolean isRead(); 5 | public boolean isPrepared(); 6 | public boolean isUseStatement(); 7 | } 8 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/route/Rule.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.route; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import com.meidusa.amoeba.parser.dbobject.Column; 10 | import com.meidusa.amoeba.sqljep.RowJEP; 11 | 12 | public class Rule implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | public String name; 17 | public String group; 18 | public boolean ignoreArray; 19 | public boolean isSwitch; 20 | public RuleResult result = RuleResult.BOOLEAN; 21 | 22 | public Map parameterMap = new HashMap(); 23 | public List excludes = new ArrayList(); 24 | public Map cloumnMap = new HashMap(); 25 | 26 | public String expression; 27 | public transient RowJEP rowJep; 28 | 29 | public String[] defaultPools; 30 | public String[] readPools; 31 | public String[] writePools; 32 | 33 | public boolean isEnable; 34 | } 35 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/route/RuleResult.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.route; 2 | 3 | public enum RuleResult { 4 | POOLNAME,BOOLEAN,INDEX 5 | } 6 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/route/SqlQueryObject.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.route; 2 | 3 | import com.meidusa.amoeba.util.SqlUtil; 4 | import com.meidusa.amoeba.util.StringUtil; 5 | 6 | public class SqlQueryObject implements Request{ 7 | public boolean isPrepared; 8 | public String sql; 9 | public Object[] parameters; 10 | public boolean isRead; 11 | @Override 12 | public boolean isPrepared() { 13 | return isPrepared; 14 | } 15 | 16 | @Override 17 | public boolean isRead() { 18 | return isRead; 19 | } 20 | 21 | @Override 22 | public boolean isUseStatement() { 23 | return SqlUtil.isUseStatement(sql); 24 | } 25 | 26 | public String toString(){ 27 | StringBuffer buffer = new StringBuffer(); 28 | buffer.append("{sql=[").append(sql).append("]").append(", parameter="); 29 | buffer.append(StringUtil.toString(parameters)).append("}"); 30 | return buffer.toString(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/route/TableRule.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.meidusa.amoeba.route; 5 | 6 | import java.io.Serializable; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import com.meidusa.amoeba.parser.dbobject.Table; 11 | 12 | public class TableRule implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | public List ruleList = new ArrayList(); 16 | public Table table; 17 | public boolean isEnable = false; 18 | public String[] defaultPools; 19 | public String[] readPools; 20 | public String[] writePools; 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/runtime/Shutdowner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.runtime; 13 | 14 | /** 15 | * 实现该接口,并且需要调用 {@link PriorityShutdownHook#addShutdowner(Shutdowner)} 当系统shutdown的时候将会被通知到 16 | * 17 | * @author Struct chen 18 | * 19 | */ 20 | public interface Shutdowner { 21 | 22 | /** 23 | * 获取组件关闭的时候优先级别,该定义跟线程优先级别一致 24 | * @see Thread#getPriority() 25 | * 26 | * @return 27 | */ 28 | public int getShutdownPriority(); 29 | 30 | /** 31 | * Called when the server is shutting down. 32 | */ 33 | public void shutdown(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/server/AuthenticateFilter.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.server; 2 | 3 | import com.meidusa.amoeba.net.AuthResponseData; 4 | import com.meidusa.amoeba.net.AuthingableConnection; 5 | 6 | /** 7 | * @author struct 8 | */ 9 | public interface AuthenticateFilter { 10 | public boolean doFilte(AuthingableConnection conn, AuthResponseData rdata); 11 | } 12 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/service/Service.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.service; 2 | 3 | import com.meidusa.amoeba.exception.InitialisationException; 4 | import com.meidusa.amoeba.runtime.Shutdowner; 5 | import com.meidusa.amoeba.util.Initialisable; 6 | import com.meidusa.amoeba.util.Reporter; 7 | 8 | /** 9 | * 10 | * @author Struct 11 | * 12 | */ 13 | public interface Service extends Initialisable,Shutdowner,Reporter{ 14 | 15 | public int getPriority(); 16 | /** 17 | * after Properties setted 18 | */ 19 | public void init() throws InitialisationException; 20 | 21 | /** 22 | * start Service 23 | */ 24 | public void start(); 25 | 26 | /** 27 | * destroy service 28 | */ 29 | public void shutdown(); 30 | } 31 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/ASTArray.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JJTree: Do not edit this line. ASTArray.java */ 2 | 3 | package com.meidusa.amoeba.sqljep; 4 | 5 | 6 | /** 7 | * This class is used only for IN (exp,exp,...) predicate. 8 | * All children of node with type ASTArray are items of an array. 9 | * @see com.meidusa.amoeba.sqljep.function.In 10 | */ 11 | public class ASTArray extends SimpleNode { 12 | public ASTArray(int id) { 13 | super(id); 14 | } 15 | 16 | public ASTArray(Parser p, int id) { 17 | super(p, id); 18 | } 19 | 20 | /** Accept the visitor. **/ 21 | public Object jjtAccept(ParserVisitor visitor, Object data) throws ParseException { 22 | return visitor.visit(this, data); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/ASTConstant.java: -------------------------------------------------------------------------------- 1 | 2 | /* Generated By:JJTree: Do not edit this line. ASTInteger.java */ 3 | package com.meidusa.amoeba.sqljep; 4 | 5 | 6 | /** 7 | * Constant Node 8 | */ 9 | class ASTConstant extends SimpleNode { 10 | Comparable value; 11 | 12 | public ASTConstant(int id) { 13 | super(id); 14 | } 15 | 16 | public ASTConstant(Parser p, int id) { 17 | super(p, id); 18 | } 19 | 20 | /** Accept the visitor. **/ 21 | public Object jjtAccept(ParserVisitor visitor, Object data) throws ParseException 22 | { 23 | return visitor.visit(this, data); 24 | } 25 | 26 | public String toString() { 27 | return "Constant: " + value; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/ASTFunNode.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JJTree: Do not edit this line. ASTFunNode.java */ 2 | package com.meidusa.amoeba.sqljep; 3 | 4 | 5 | import com.meidusa.amoeba.sqljep.function.PostfixCommandI; 6 | 7 | /** 8 | * Function Node 9 | */ 10 | public class ASTFunNode extends SimpleNode { 11 | 12 | /** The function class used to evaluate the node */ 13 | private PostfixCommandI pfmc; 14 | 15 | /** Name of the function */ 16 | private String name; 17 | 18 | /** 19 | * Creates a new ASTFunNode 20 | */ 21 | public ASTFunNode(int id) { 22 | super(id); 23 | } 24 | 25 | /** 26 | * Creates a new ASTFunNode 27 | */ 28 | public ASTFunNode(Parser p, int id) { 29 | super(p, id); 30 | } 31 | 32 | /** 33 | * Accept the visitor. 34 | */ 35 | public Object jjtAccept(ParserVisitor visitor, Object data) throws ParseException { 36 | return visitor.visit(this, data); 37 | } 38 | 39 | /** 40 | * Sets the function for a node. A name and function class must 41 | * be specified. 42 | */ 43 | public void setFunction(String name_in, PostfixCommandI pfmc_in) { 44 | name = name_in; 45 | pfmc = pfmc_in; 46 | } 47 | 48 | /** 49 | * Returns a string containing the function name. 50 | */ 51 | public String toString() { 52 | return "Function \"" + name + "\""; 53 | } 54 | 55 | /** 56 | * Returns the math command class associated with this node. 57 | */ 58 | public PostfixCommandI getPFMC() { 59 | return pfmc; 60 | } 61 | 62 | /** 63 | * Returns the name of the node (operator symbol or function name). 64 | */ 65 | public String getName() { 66 | return name; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/ASTStart.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JJTree: Do not edit this line. ASTStart.java */ 2 | package com.meidusa.amoeba.sqljep; 3 | 4 | 5 | /** 6 | * Start Node 7 | */ 8 | public class ASTStart extends SimpleNode { 9 | public ASTStart(int id) { 10 | super(id); 11 | } 12 | 13 | public ASTStart(Parser p, int id) { 14 | super(p, id); 15 | } 16 | 17 | /** Accept the visitor. **/ 18 | public Object jjtAccept(ParserVisitor visitor, Object data) throws ParseException 19 | { 20 | return visitor.visit(this, data); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/ASTVarNode.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JJTree: Do not edit this line. ASTVarNode.java */ 2 | 3 | package com.meidusa.amoeba.sqljep; 4 | 5 | import java.util.Map; 6 | 7 | import com.meidusa.amoeba.sqljep.variable.Variable; 8 | 9 | 10 | /** 11 | * It is public and fields index and variable are public 12 | * because it is possible to change values outside from SQLJEP. 13 | * @see com.meidusa.amoeba.sqljep.BaseJEP#getTopNode() 14 | */ 15 | public class ASTVarNode extends SimpleNode { 16 | public int index; // index of column in a Row 17 | public Variable variable; 18 | public String ident; 19 | 20 | public ASTVarNode(int id) { 21 | super(id); 22 | } 23 | 24 | public ASTVarNode(Parser p, int id) { 25 | super(p, id); 26 | } 27 | 28 | /** 29 | * Accept the visitor. 30 | */ 31 | public Object jjtAccept(ParserVisitor visitor, Object data) throws ParseException { 32 | return visitor.visit(this, data); 33 | } 34 | 35 | /** 36 | * Creates a string containing the variable's name and value 37 | */ 38 | public String toString() { 39 | if (variable == null) { 40 | return "Column: "+index; 41 | } else { 42 | return "Variable: \"" + (variable == null ? "null" : variable.getValue().toString())+ "\""; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/Node.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JJTree: Do not edit this line. Node.java */ 2 | 3 | package com.meidusa.amoeba.sqljep; 4 | 5 | 6 | /* All AST nodes must implement this interface. It provides basic 7 | machinery for constructing the parent and child relationships 8 | between nodes. */ 9 | 10 | public interface Node { 11 | 12 | /** This method is called after the node has been made the current 13 | node. It indicates that child nodes can now be added to it. */ 14 | public void jjtOpen(); 15 | 16 | /** This method is called after all the child nodes have been 17 | added. */ 18 | public void jjtClose(); 19 | 20 | /** This pair of methods are used to inform the node of its 21 | parent. */ 22 | public void jjtSetParent(Node n); 23 | public Node jjtGetParent(); 24 | 25 | /** This method tells the node to add its argument to the node's 26 | list of children. */ 27 | public void jjtAddChild(Node n, int i); 28 | 29 | /** This method returns a child node. The children are numbered 30 | from zero, left to right. */ 31 | public Node jjtGetChild(int i); 32 | 33 | /** Return the number of children the node has. */ 34 | public int jjtGetNumChildren(); 35 | 36 | /** Accept the visitor. **/ 37 | public Object jjtAccept(ParserVisitor visitor, Object data) throws ParseException; 38 | } 39 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/ParserTreeConstants.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JavaCC: Do not edit this line. ParserTreeConstants.java Version 4.1d1 */ 2 | package com.meidusa.amoeba.sqljep; 3 | 4 | public interface ParserTreeConstants 5 | { 6 | public int JJTSTART = 0; 7 | public int JJTVOID = 1; 8 | public int JJTFUNNODE = 2; 9 | public int JJTVARNODE = 3; 10 | public int JJTARRAY = 4; 11 | public int JJTCONSTANT = 5; 12 | 13 | 14 | public String[] jjtNodeName = { 15 | "Start", 16 | "void", 17 | "FunNode", 18 | "VarNode", 19 | "Array", 20 | "Constant", 21 | }; 22 | } 23 | /* JavaCC - OriginalChecksum=22da27626797a5d3757afdebb5bfe0ec (do not edit this line) */ 24 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/ParserVisitor.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JavaCC: Do not edit this line. ParserVisitor.java Version 4.1d1 */ 2 | package com.meidusa.amoeba.sqljep; 3 | 4 | public interface ParserVisitor 5 | { 6 | public Object visit(SimpleNode node, Object data) throws ParseException; 7 | public Object visit(ASTStart node, Object data) throws ParseException; 8 | public Object visit(ASTFunNode node, Object data) throws ParseException; 9 | public Object visit(ASTVarNode node, Object data) throws ParseException; 10 | public Object visit(ASTArray node, Object data) throws ParseException; 11 | public Object visit(ASTConstant node, Object data) throws ParseException; 12 | } 13 | /* JavaCC - OriginalChecksum=78049580ff25fabdceb758a89080b84e (do not edit this line) */ 14 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/ComparativeAND.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import java.util.Comparator; 4 | 5 | public class ComparativeAND extends ComparativeBaseList{ 6 | 7 | public ComparativeAND(int function, Comparable value) { 8 | super(function, value); 9 | } 10 | 11 | public ComparativeAND(){ 12 | } 13 | 14 | public ComparativeAND(Comparative item){ 15 | super(item); 16 | } 17 | 18 | @SuppressWarnings("unchecked") 19 | public boolean intersect(int function,Comparable other,Comparator comparator){ 20 | for(Comparative source :list){ 21 | if(!source.intersect(function, other, comparator)){ 22 | return false; 23 | } 24 | } 25 | return true; 26 | } 27 | 28 | @Override 29 | public boolean intersect(Comparative other, Comparator comparator) { 30 | for(Comparative source :list){ 31 | if(!source.intersect(other, comparator)){ 32 | return false; 33 | } 34 | } 35 | return true; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/ComparativeIsNotNull.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 16 | import com.meidusa.amoeba.sqljep.ASTFunNode; 17 | import com.meidusa.amoeba.sqljep.JepRuntime; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | public final class ComparativeIsNotNull extends PostfixCommand { 21 | final public int getNumberOfParameters() { 22 | return 1; 23 | } 24 | 25 | public boolean isAutoBox() { 26 | return false; 27 | } 28 | 29 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) 30 | throws ParseException { 31 | node.childrenAccept(runtime.ev, null); 32 | 33 | Comparable param = runtime.stack.pop(); 34 | return new Comparable[] { param }; 35 | } 36 | 37 | public Comparable getResult(Comparable... comparables) 38 | throws ParseException { 39 | if (comparables[0] instanceof Comparative) { 40 | return (((Comparative) comparables[0]).getValue() != null); 41 | } else { 42 | return (comparables[0] != null); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/ComparativeIsNull.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 16 | import com.meidusa.amoeba.sqljep.ASTFunNode; 17 | import com.meidusa.amoeba.sqljep.JepRuntime; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | public class ComparativeIsNull extends PostfixCommand { 21 | final public int getNumberOfParameters() { 22 | return 1; 23 | } 24 | 25 | public boolean isAutoBox() { 26 | return false; 27 | } 28 | 29 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) 30 | throws ParseException { 31 | node.childrenAccept(runtime.ev, null); 32 | 33 | Comparable param = runtime.stack.pop(); 34 | return new Comparable[] { param }; 35 | } 36 | 37 | public Comparable getResult(Comparable... comparables) 38 | throws ParseException { 39 | if (comparables[0] instanceof Comparative) { 40 | return (((Comparative) comparables[0]).getValue() == null); 41 | } else { 42 | return (comparables[0] == null); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/ComparativeOR.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import java.util.Comparator; 4 | 5 | public class ComparativeOR extends ComparativeBaseList{ 6 | 7 | public ComparativeOR(int function, Comparable value) { 8 | super(function, value); 9 | } 10 | 11 | public ComparativeOR(){}; 12 | 13 | public ComparativeOR(Comparative item){ 14 | super(item); 15 | } 16 | 17 | @SuppressWarnings("unchecked") 18 | public boolean intersect(int function,Comparable other,Comparator comparator){ 19 | Comparative param2 = new Comparative(function,other); 20 | for(Comparative source :list){ 21 | 22 | /*if(ComparativeComparator.intersect(source, param2)){ 23 | return true; 24 | }*/ 25 | if(source.intersect(function, other, comparator)){ 26 | return true; 27 | } 28 | } 29 | return false; 30 | } 31 | 32 | @SuppressWarnings("unchecked") 33 | public boolean intersect(Comparative other, Comparator comparator) { 34 | for(Comparative source :list){ 35 | if(source.intersect(other, comparator)){ 36 | return true; 37 | } 38 | } 39 | return false; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/ComparativeRange.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import java.util.Comparator; 4 | 5 | public class ComparativeRange extends ComparativeBaseList { 6 | 7 | @Override 8 | public boolean intersect(int function, Comparable other, 9 | Comparator comparator) { 10 | Comparative left = this.list.get(0); 11 | Comparative right = this.list.get(1); 12 | return left.intersect(function, other, comparator) 13 | && right.intersect(function, other, comparator); 14 | } 15 | 16 | @Override 17 | public boolean intersect(Comparative other, Comparator comparator) { 18 | 19 | if(other instanceof ComparativeBaseList){ 20 | ComparativeBaseList target = (ComparativeBaseList)other; 21 | return target.intersect(this, comparator); 22 | }else{ 23 | Comparative left = this.list.get(0); 24 | Comparative right = this.list.get(1); 25 | return left.intersect(other, comparator) 26 | && right.intersect(other, comparator); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Declare.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import com.meidusa.amoeba.sqljep.JepRuntime; 4 | 5 | public interface Declare { 6 | public void declare(JepRuntime runtime,Comparable comparable); 7 | } 8 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Hash.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 4 | import com.meidusa.amoeba.sqljep.ASTFunNode; 5 | import com.meidusa.amoeba.sqljep.JepRuntime; 6 | import com.meidusa.amoeba.sqljep.ParseException; 7 | 8 | /** 9 | * 10 | * @author struct 11 | * 12 | */ 13 | public class Hash extends PostfixCommand { 14 | final public int getNumberOfParameters() { 15 | return 1; 16 | } 17 | 18 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 19 | node.childrenAccept(runtime.ev, null); 20 | Comparable param = runtime.stack.pop(); 21 | return new Comparable[]{param}; 22 | } 23 | 24 | public static Comparable hash(Comparable param) throws ParseException { 25 | if (param == null) { 26 | return null; 27 | } 28 | 29 | return param.hashCode(); 30 | } 31 | 32 | public Comparable getResult(Comparable... comparables) 33 | throws ParseException { 34 | return hash(comparables[0]); 35 | } 36 | 37 | 38 | public static void main(String[] args){ 39 | String dd = "624265432"; 40 | int off = 0; 41 | char val[] = dd.toCharArray(); 42 | int len = val.length; 43 | int h = 0; 44 | for (int i = 0; i < len; i++) { 45 | h = 31*h + val[off++]; 46 | } 47 | 48 | try { 49 | System.out.println(hash((dd))); 50 | } catch (ParseException e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/IfElse.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import com.meidusa.amoeba.sqljep.ASTFunNode; 4 | import com.meidusa.amoeba.sqljep.JepRuntime; 5 | import com.meidusa.amoeba.sqljep.ParseException; 6 | 7 | public class IfElse extends PostfixCommand { 8 | 9 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) 10 | throws ParseException { 11 | node.childrenAccept(runtime.ev, null); 12 | Comparable limit2 = runtime.stack.pop(); 13 | Comparable limit1 = runtime.stack.pop(); 14 | Comparable source = runtime.stack.pop(); 15 | return new Comparable[] { source, limit1, limit2 }; 16 | } 17 | 18 | public int getNumberOfParameters() { 19 | return 3; 20 | } 21 | 22 | public boolean isAutoBox() { 23 | return false; 24 | } 25 | 26 | public Comparable getResult(Comparable... comparables) 27 | throws ParseException { 28 | Comparable limit2 = comparables[2]; 29 | Comparable limit1 = comparables[1]; 30 | Comparable source = comparables[0]; 31 | if (source == null) { 32 | return (Boolean.FALSE); 33 | }else{ 34 | Comparable value = source; 35 | if(source instanceof Comparative){ 36 | value = ((Comparative) source).getValue(); 37 | } 38 | if(Boolean.valueOf(value.toString())){ 39 | return limit1; 40 | }else{ 41 | return limit2; 42 | } 43 | } 44 | 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Length.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 16 | import com.meidusa.amoeba.sqljep.ASTFunNode; 17 | import com.meidusa.amoeba.sqljep.JepRuntime; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | public class Length extends PostfixCommand { 21 | final public int getNumberOfParameters() { 22 | return 1; 23 | } 24 | 25 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 26 | node.childrenAccept(runtime.ev, null); 27 | Comparable param = runtime.stack.pop(); 28 | return new Comparable[]{param}; 29 | } 30 | 31 | public static Integer length(Comparable param) throws ParseException { 32 | if (param == null) { 33 | return null; 34 | } 35 | return param.toString().length(); 36 | } 37 | 38 | public Comparable getResult(Comparable... comparables) 39 | throws ParseException { 40 | return length(comparables[0]); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/LogicalNOT.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | 16 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 17 | import com.meidusa.amoeba.sqljep.ASTFunNode; 18 | import com.meidusa.amoeba.sqljep.JepRuntime; 19 | import com.meidusa.amoeba.sqljep.ParseException; 20 | 21 | public final class LogicalNOT extends PostfixCommand { 22 | final public int getNumberOfParameters() { 23 | return 1; 24 | } 25 | 26 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 27 | node.childrenAccept(runtime.ev, null); 28 | Comparable param = runtime.stack.pop(); 29 | return new Comparable[]{param}; 30 | } 31 | 32 | public static Boolean not(Comparable param) throws ParseException { 33 | if (param == null) { 34 | return null; 35 | } 36 | if (param instanceof Boolean) { 37 | return ((Boolean)param).booleanValue() ? Boolean.TRUE : Boolean.FALSE; 38 | } 39 | throw new ParseException(WRONG_TYPE+" not "+param.getClass()); 40 | } 41 | 42 | public Comparable getResult(Comparable... comparables) 43 | throws ParseException { 44 | return not(comparables[0]); 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Lower.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | 16 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 17 | import com.meidusa.amoeba.sqljep.ASTFunNode; 18 | import com.meidusa.amoeba.sqljep.JepRuntime; 19 | import com.meidusa.amoeba.sqljep.ParseException; 20 | 21 | public class Lower extends PostfixCommand { 22 | final public int getNumberOfParameters() { 23 | return 1; 24 | } 25 | 26 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 27 | node.childrenAccept(runtime.ev, null); 28 | Comparable param = runtime.stack.pop(); 29 | return new Comparable[]{param}; 30 | } 31 | 32 | public static String lower(Comparable param) throws ParseException { 33 | if (param == null) { 34 | return null; 35 | } 36 | return param.toString().toLowerCase(); 37 | } 38 | 39 | public Comparable getResult(Comparable... comparables) 40 | throws ParseException { 41 | return lower(comparables[0]); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Microsecond.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | import java.sql.Timestamp; 16 | 17 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 18 | import com.meidusa.amoeba.sqljep.ASTFunNode; 19 | import com.meidusa.amoeba.sqljep.JepRuntime; 20 | import com.meidusa.amoeba.sqljep.ParseException; 21 | 22 | public class Microsecond extends PostfixCommand { 23 | final public int getNumberOfParameters() { 24 | return 1; 25 | } 26 | 27 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 28 | node.childrenAccept(runtime.ev, null); 29 | Comparable param = runtime.stack.pop(); 30 | return new Comparable[]{param}; 31 | } 32 | 33 | 34 | public static Long microsecond(Comparable param) throws ParseException { 35 | if (param == null) { 36 | return null; 37 | } 38 | if (param instanceof Timestamp) { 39 | Timestamp ts = (Timestamp)param; 40 | return new Long(ts.getTime()); 41 | } 42 | throw new ParseException(WRONG_TYPE+" microsecond("+param.getClass()+")"); 43 | } 44 | 45 | public Comparable getResult(Comparable... comparables) 46 | throws ParseException { 47 | return microsecond(comparables[0]); 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/NotLike.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | 16 | import com.meidusa.amoeba.sqljep.function.Like; 17 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 18 | import com.meidusa.amoeba.sqljep.ASTFunNode; 19 | import com.meidusa.amoeba.sqljep.JepRuntime; 20 | import com.meidusa.amoeba.sqljep.ParseException; 21 | 22 | public final class NotLike extends PostfixCommand { 23 | final public int getNumberOfParameters() { 24 | return 2; 25 | } 26 | 27 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 28 | node.childrenAccept(runtime.ev, null); 29 | Comparable param2 = runtime.stack.pop(); 30 | Comparable param1 = runtime.stack.pop(); 31 | return new Comparable[]{param1,param2}; 32 | } 33 | 34 | public Comparable getResult(Comparable... comparables) 35 | throws ParseException { 36 | return !Like.like(comparables[0], comparables[1]); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Nvl.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | 16 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 17 | import com.meidusa.amoeba.sqljep.ASTFunNode; 18 | import com.meidusa.amoeba.sqljep.JepRuntime; 19 | import com.meidusa.amoeba.sqljep.ParseException; 20 | 21 | public class Nvl extends PostfixCommand { 22 | final public int getNumberOfParameters() { 23 | return 2; 24 | } 25 | 26 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 27 | node.childrenAccept(runtime.ev, null); 28 | Comparable param2 = runtime.stack.pop(); 29 | Comparable param1 = runtime.stack.pop(); 30 | return new Comparable[]{param1,param2}; 31 | } 32 | 33 | public static Comparable nvl(Comparable param1, Comparable param2) { 34 | return (param1 == null) ? param2 : param1; 35 | } 36 | 37 | public Comparable getResult(Comparable... comparables) 38 | throws ParseException { 39 | return nvl(comparables[0],comparables[1]); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/PostfixCommandI.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | import com.meidusa.amoeba.sqljep.ASTFunNode; 15 | import com.meidusa.amoeba.sqljep.JepRuntime; 16 | import com.meidusa.amoeba.sqljep.ParseException; 17 | 18 | /** 19 | * All function classes must implement this interface to ensure that the run() 20 | * method is implemented. 21 | */ 22 | public interface PostfixCommandI { 23 | /** 24 | * Run the function on the stack. Pops the arguments from the stack, and 25 | * pushes the result on the top of the stack. 26 | */ 27 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException; 28 | 29 | public boolean isAutoBox(); 30 | 31 | public Comparable getResult(Comparable ...comparables) throws ParseException; 32 | 33 | /** 34 | * Returns the number of required parameters, or -1 if any number of 35 | * parameters is allowed. 36 | */ 37 | public int getNumberOfParameters(); 38 | 39 | public boolean isDeclare(); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/StringHash.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import com.meidusa.amoeba.sqljep.ASTFunNode; 4 | import com.meidusa.amoeba.sqljep.JepRuntime; 5 | import com.meidusa.amoeba.sqljep.ParseException; 6 | 7 | /** 8 | * 针对String的hash算法 9 | * 10 | * @author hexianmao 11 | * @version 2008-10-27 下午05:49:02 12 | */ 13 | public class StringHash extends PostfixCommand { 14 | 15 | private static final int _hash_len = 8; 16 | private static final int _bit_len = 5; 17 | 18 | private static final long _unknown = -1L; 19 | 20 | public int getNumberOfParameters() { 21 | return 1; 22 | } 23 | 24 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 25 | node.childrenAccept(runtime.ev, null); 26 | Comparable param = runtime.stack.pop(); 27 | return new Comparable[] { param }; 28 | } 29 | 30 | public Comparable getResult(Comparable... comparables) throws ParseException { 31 | if (comparables[0] != null && comparables[0] instanceof String) { 32 | return hash((String) comparables[0]); 33 | } 34 | return _unknown; 35 | } 36 | 37 | /** 38 | *
39 |      * 字符串hash算法:s[0]*31ˆ(n-1) + s[1]*31ˆ(n-2) + ... + s[n-1]
40 |      * 其中s[]为字符串的字符数组,换算成程序的表达式为:
41 |      * h = 31*h + s.charAt(i); => h = (h << 5) - h + s.charAt(i);
42 |      * 注:对hash的字符串做了长度限定,保证其结果不会超出数据类型的范围。
43 |      * 
44 | */ 45 | private static long hash(String s) { 46 | long h = 0; 47 | for (int i = 0; (i < _hash_len && i < s.length()); i++) { 48 | h = (h << _bit_len) - h + s.charAt(i); 49 | } 50 | return h; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/ToLong.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import com.meidusa.amoeba.sqljep.ParseException; 4 | 5 | public class ToLong extends ToNumber { 6 | 7 | public Comparable getResult(Comparable... comparables) 8 | throws ParseException { 9 | if (comparables.length == 1) { 10 | return ((Number)to_number(comparables[0])).longValue(); 11 | } else { 12 | return ((Number)to_number(comparables[0], comparables[1])).longValue(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Trim.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | package com.meidusa.amoeba.sqljep.function; 13 | 14 | 15 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 16 | import com.meidusa.amoeba.sqljep.ASTFunNode; 17 | import com.meidusa.amoeba.sqljep.JepRuntime; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | public class Trim extends PostfixCommand { 21 | final public int getNumberOfParameters() { 22 | return 1; 23 | } 24 | 25 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 26 | node.childrenAccept(runtime.ev, null); 27 | Comparable param = runtime.stack.pop(); 28 | return new Comparable[]{param}; 29 | } 30 | 31 | public static String trim(Comparable param) throws ParseException { 32 | if (param == null) { 33 | return null; 34 | } 35 | return param.toString().trim(); 36 | } 37 | 38 | public Comparable getResult(Comparable... comparables) 39 | throws ParseException { 40 | return trim(comparables[0]); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Upper.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | SQLJEP - Java SQL Expression Parser 0.2 3 | November 1 2006 4 | (c) Copyright 2006, Alexey Gaidukov 5 | SQLJEP Author: Alexey Gaidukov 6 | 7 | SQLJEP is based on JEP 2.24 (http://www.singularsys.com/jep/) 8 | (c) Copyright 2002, Nathan Funk 9 | 10 | See LICENSE.txt for license information. 11 | *****************************************************************************/ 12 | 13 | package com.meidusa.amoeba.sqljep.function; 14 | 15 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 16 | import com.meidusa.amoeba.sqljep.ASTFunNode; 17 | import com.meidusa.amoeba.sqljep.JepRuntime; 18 | import com.meidusa.amoeba.sqljep.ParseException; 19 | 20 | public class Upper extends PostfixCommand { 21 | final public int getNumberOfParameters() { 22 | return 1; 23 | } 24 | 25 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException { 26 | node.childrenAccept(runtime.ev, null); 27 | Comparable param = runtime.stack.pop(); 28 | return new Comparable[]{param}; 29 | } 30 | 31 | public static String upper(Comparable param) throws ParseException { 32 | if (param == null) { 33 | return null; 34 | } 35 | return param.toString().toUpperCase(); 36 | } 37 | 38 | public Comparable getResult(Comparable... comparables) 39 | throws ParseException { 40 | return upper(comparables[0]); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/function/Var.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.function; 2 | 3 | import com.meidusa.amoeba.sqljep.ASTFunNode; 4 | import com.meidusa.amoeba.sqljep.JepRuntime; 5 | import com.meidusa.amoeba.sqljep.ParseException; 6 | 7 | public class Var extends PostfixCommand implements Declare{ 8 | private String identity; 9 | public Var(String identity){ 10 | this.identity = identity; 11 | } 12 | 13 | public Comparable[] evaluate(ASTFunNode node, JepRuntime runtime) 14 | throws ParseException { 15 | node.childrenAccept(runtime.ev, null); 16 | Comparable param = runtime.stack.pop(); 17 | return new Comparable[]{param}; 18 | } 19 | 20 | public int getNumberOfParameters() { 21 | return 1; 22 | } 23 | 24 | public Comparable getResult(Comparable... comparables) 25 | throws ParseException { 26 | return comparables[0]; 27 | } 28 | 29 | public boolean isDeclare(){ 30 | return true; 31 | } 32 | 33 | public void declare(JepRuntime runtime,Comparable comparable) { 34 | runtime.vars.put(identity, comparable); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/sqljep/variable/Variable.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.sqljep.variable; 2 | 3 | /** 4 | * 5 | * @author Struct chen 6 | * 7 | */ 8 | public interface Variable { 9 | public Comparable getValue(); 10 | } 11 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/EnumCode.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.util; 2 | 3 | import java.util.EnumMap; 4 | 5 | public class EnumCode { 6 | public enum ErrorCode { 7 | TABLE_NUM_LIMIT, 8 | RECORDS_IN_SINGLE_TABLE_LIMIT, 9 | USER_RULE_LIMIT, 10 | UNKNOWN_FATAL_ERROR, 11 | OK 12 | }; 13 | 14 | public final static EnumMap errNoMapping = new EnumMap(ErrorCode.class); 15 | 16 | static { 17 | errNoMapping.put(ErrorCode.TABLE_NUM_LIMIT, 11002); 18 | errNoMapping.put(ErrorCode.RECORDS_IN_SINGLE_TABLE_LIMIT, 11003); 19 | errNoMapping.put(ErrorCode.USER_RULE_LIMIT, 11004); 20 | 21 | errNoMapping.put(ErrorCode.UNKNOWN_FATAL_ERROR, 11001); 22 | errNoMapping.put(ErrorCode.OK, 11000); 23 | } 24 | 25 | 26 | public final static EnumMap errMsgMapping = new EnumMap(ErrorCode.class); 27 | 28 | static { 29 | errMsgMapping.put(ErrorCode.TABLE_NUM_LIMIT, "Number of created table beyond the SLA limit"); 30 | errMsgMapping.put(ErrorCode.RECORDS_IN_SINGLE_TABLE_LIMIT, "Records beyond the SLA limit in single table"); 31 | errMsgMapping.put(ErrorCode.USER_RULE_LIMIT, "Don't have the authority for the operation"); 32 | errMsgMapping.put(ErrorCode.UNKNOWN_FATAL_ERROR, "Unknown fatal error!"); 33 | } 34 | 35 | public static int getErrorNo(ErrorCode code) { 36 | return errNoMapping.get(code) != null ? errNoMapping.get(code) : 0; 37 | } 38 | 39 | public static String getErrorMsg(ErrorCode code) { 40 | return errMsgMapping.get(code) != null ? errMsgMapping.get(code) : ""; 41 | } 42 | 43 | private EnumCode(){ 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/HashFunction.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.util; 2 | 3 | public interface HashFunction { 4 | 5 | long hash(Object string); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/Initialisable.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.util; 15 | 16 | import com.meidusa.amoeba.exception.InitialisationException; 17 | 18 | public interface Initialisable { 19 | 20 | public void init() throws InitialisationException; 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/NameableRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.util; 13 | 14 | public interface NameableRunner extends Runnable { 15 | 16 | public String getRunnerName(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/OptionType.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.util; 2 | public enum OptionType{ 3 | String,Long,Int,Double,Boolean 4 | } -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/Reporter.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.util; 15 | 16 | import org.apache.log4j.Level; 17 | 18 | /** 19 | * @author Struct chen 20 | */ 21 | public interface Reporter { 22 | 23 | /** 24 | * @param buffer 组装report信息的 StringBuilder 25 | * @param now report 任务开始产生report的当时时间,单位ms 26 | * @param sinceLast 上一次report的时间 27 | * @param reset 是否需要重新统计 28 | */ 29 | public void appendReport(StringBuilder buffer, long now, long sinceLast, boolean reset, Level level); 30 | 31 | // public void alertStartReport(); 32 | 33 | public static interface SubReporter { 34 | 35 | public void appendReport(StringBuilder buffer, long now, long sinceLast, boolean reset, Level level); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/RunQueue.java: -------------------------------------------------------------------------------- 1 | /** 2 | *
 3 |  * 	This program is free software; you can redistribute it and/or modify it under the terms of 
 4 |  * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 
 5 |  * or (at your option) any later version. 
 6 |  * 
 7 |  * 	This program is distributed in the hope that it will be useful, 
 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 9 |  * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
10 |  * 	You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 
11 |  * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
12 |  * 
13 | */ 14 | package com.meidusa.amoeba.util; 15 | 16 | /** 17 | * An interface for a service that queues up execution of Runnables. 18 | */ 19 | public interface RunQueue { 20 | 21 | /** 22 | * Post the specified Runnable to be run on the RunQueue. 23 | */ 24 | public void postRunnable(Runnable r); 25 | 26 | /** 27 | * @return true if the calling thread is the RunQueue dispatch thread. 28 | */ 29 | public boolean isDispatchThread(); 30 | 31 | public int size(); 32 | } 33 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/SqlUtil.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.util; 2 | 3 | 4 | public class SqlUtil { 5 | 6 | public static boolean isUseStatement(String sql){ 7 | 8 | if (!StringUtil.isEmpty(sql)) { 9 | 10 | sql = sql.trim(); 11 | String[] words = sql.split("\\s+"); 12 | 13 | if (!StringUtil.isEmpty(words[0]) && words[0].toLowerCase().equals("use")) { 14 | return true; 15 | } 16 | } 17 | 18 | return false; 19 | } 20 | 21 | 22 | public static String getUseSchema(String sql){ 23 | 24 | String schema = null; 25 | 26 | if (isUseStatement(sql)) { 27 | if (!StringUtil.isEmpty(sql)) { 28 | sql = sql.trim(); 29 | String[] words = sql.split("\\s+"); 30 | 31 | if (words != null && words.length >= 2) { 32 | if (!StringUtil.isEmpty(words[1])) { 33 | schema = words[1].trim(); 34 | } 35 | } 36 | } 37 | } 38 | 39 | return schema; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/meidusa/amoeba/util/StaticString.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.util; 2 | 3 | public interface StaticString { 4 | 5 | public static final String DATE_FORMAT_SYMBOLS = "DATE_FORMAT_SYMBOLS"; 6 | public static final String CALENDAR = "CALENDAR"; 7 | public static final String JEP_RUNTIME = "JEP_RUNTIME"; 8 | public static final String HANDLER = "_HANDLER_"; 9 | } 10 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/com/vispractice/amoeba/base/Activator.java: -------------------------------------------------------------------------------- 1 | package com.vispractice.amoeba.base; 2 | 3 | import org.osgi.framework.BundleActivator; 4 | import org.osgi.framework.BundleContext; 5 | 6 | 7 | public class Activator implements BundleActivator { 8 | 9 | public static BundleContext bundleContext; 10 | 11 | /* 12 | * (non-Javadoc) 13 | * 14 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) 15 | */ 16 | public void start(BundleContext context) throws Exception { 17 | Activator.bundleContext = context; 18 | } 19 | 20 | /* 21 | * (non-Javadoc) 22 | * 23 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) 24 | */ 25 | public void stop(BundleContext context) throws Exception { 26 | Activator.bundleContext = null; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.base/src/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=ERROR,Console,R 2 | 3 | log4j.logger.com.vispractice=DEBUG 4 | log4j.logger.com.meidusa=INFO 5 | log4j.logger.com.meidusa.amoeba.mysql=INFO 6 | log4j.logger.com.meidusa.amoeba.base=INFO 7 | 8 | log4j.appender.Console=org.apache.log4j.ConsoleAppender 9 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.Console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c:%L]-[%p] %m%n 11 | 12 | log4j.appender.R=org.apache.log4j.RollingFileAppender 13 | log4j.appender.R.File=./log/log4j.log 14 | log4j.appender.R.MaxFileSize=500KB 15 | log4j.appender.R.MaxBackupIndex=10 16 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 17 | log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] [%c:%L] [%p] - %m%n 18 | 19 | ### reporter logger ### 20 | #log4j.logger.report=DEBUG,ReportAppender 21 | #log4j.additivity.report=false 22 | #log4j.appender.ReportAppender=org.apache.log4j.DailyRollingFileAppender 23 | #log4j.appender.ReportAppender.File=./log/report.log 24 | #log4j.appender.ReportAppender.layout=org.apache.log4j.PatternLayout 25 | #log4j.appender.ReportAppender.layout.ConversionPattern=%d %-5p %c{2} - %m%n 26 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: File 4 | Bundle-SymbolicName: com.vispractice.amoeba.loader.file 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Activator: com.vispractice.amoeba.loader.file.Activator 7 | Bundle-Vendor: VISPRACTICE 8 | Bundle-RequiredExecutionEnvironment: JavaSE-1.7 9 | Import-Package: org.osgi.framework;version="1.3.0" 10 | Bundle-ActivationPolicy: lazy 11 | Service-Component: OSGI-INF/AmoebaContextFileLoader.xml, 12 | OSGI-INF/DBServerConfigFileLoader.xml, 13 | OSGI-INF/UserFileLoader.xml, 14 | OSGI-INF/TableRuleFileLoader.xml, 15 | OSGI-INF/RuleFunctionMapFileLoader.xml, 16 | OSGI-INF/SqlFunctionMapFileLoader.xml, 17 | OSGI-INF/IpAccessListFileLoader.xml 18 | Require-Bundle: com.vispractice.amoeba.base;bundle-version="1.0.0", 19 | org.springframework.osgi.log4j.osgi;bundle-version="1.2.15", 20 | com.springsource.org.apache.commons.collections;bundle-version="3.2.1" 21 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/OSGI-INF/AmoebaContextFileLoader.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/OSGI-INF/DBServerConfigFileLoader.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/OSGI-INF/IpAccessListFileLoader.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/OSGI-INF/RuleFunctionMapFileLoader.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/OSGI-INF/SqlFunctionMapFileLoader.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/OSGI-INF/TableRuleFileLoader.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/OSGI-INF/UserFileLoader.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/release/conf/access_list.conf: -------------------------------------------------------------------------------- 1 | #配置IP访问控制 2 | # 3 | # 优先级别从上往下,前面的优先级别高,每条一行 4 | 5 | #192.*.1.236-239:yes 6 | #比如192.34.1.238则可以访问,否则将不能访问。 7 | 8 | #218.85.*.*:no 9 | #127.0.0.1:yes 10 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/release/conf/rule.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/release/conf/ruleFunctionMap.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.loader.file/release/conf/ruleFunctionMap.xml -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/release/conf/seq.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.loader.file/release/conf/seq.properties -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/release/conf/users.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/config/loader/RuleFunctionMapFileLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.Map; 4 | 5 | import com.meidusa.amoeba.config.BeanObjectEntityConfig; 6 | import com.meidusa.amoeba.sqljep.function.PostfixCommand; 7 | 8 | public class RuleFunctionMapFileLoader extends FunctionFileLoader implements RuleFunctionMapLoader{ 9 | 10 | @Override 11 | public void initBeanObject(BeanObjectEntityConfig config, PostfixCommand bean) { 12 | bean.setName(config.getName()); 13 | } 14 | 15 | @Override 16 | public void putToMap(Map map, PostfixCommand value) { 17 | map.put(value.getName(), value); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/config/loader/SqlFunctionMapFileLoader.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.config.loader; 2 | 3 | import java.util.Map; 4 | 5 | import com.meidusa.amoeba.config.BeanObjectEntityConfig; 6 | import com.meidusa.amoeba.parser.function.Function; 7 | 8 | public class SqlFunctionMapFileLoader extends FunctionFileLoader implements SqlFunctionMapLoader{ 9 | 10 | @Override 11 | public void initBeanObject(BeanObjectEntityConfig config, Function bean) { 12 | bean.setName(config.getName()); 13 | } 14 | 15 | @Override 16 | public void putToMap(Map map, Function value) { 17 | map.put(value.getName(), value); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xml/amoeba.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xml/dbserver.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xml/function.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xml/objectMap.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xml/rule.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xml/table.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xml/user.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xmltable/Condition.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.xmltable; 2 | 3 | public class Condition { 4 | public static enum TYPE {exist,match,nameMatch}; 5 | public String name; 6 | public String value; 7 | public TYPE type; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xmltable/XmlColumn.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.xmltable; 2 | 3 | public class XmlColumn { 4 | private String name; 5 | private int type; 6 | private String value; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | public int getType() { 15 | return type; 16 | } 17 | public void setType(int type) { 18 | this.type = type; 19 | } 20 | public String getValue() { 21 | return value; 22 | } 23 | public void setValue(String value) { 24 | this.value = value; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xmltable/XmlRow.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.xmltable; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.meidusa.amoeba.util.StringUtil; 7 | 8 | public class XmlRow { 9 | private Map columMap = new HashMap(); 10 | 11 | public Map getColumMap() { 12 | return columMap; 13 | } 14 | 15 | public void setColumMap(Map columMap) { 16 | this.columMap = columMap; 17 | } 18 | 19 | public void addColumn(String name,XmlColumn column){ 20 | columMap.put(name, column); 21 | } 22 | 23 | public boolean isMatch(Condition condition){ 24 | if(condition == null) return true; 25 | if(condition.type == Condition.TYPE.exist){ 26 | return columMap.get(condition.name) != null; 27 | }else if(condition.type == Condition.TYPE.match){ 28 | XmlColumn column = columMap.get(condition.name); 29 | if(column == null) return false; 30 | return StringUtil.equalsIgnoreCase(column.getValue(), condition.value); 31 | }else{ 32 | return false; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/meidusa/amoeba/xmltable/XmlTable.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.xmltable; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class XmlTable { 7 | private String name; 8 | private String schema; 9 | private List columns = new ArrayList(); 10 | private List rows = new ArrayList(); 11 | 12 | public List getColumns() { 13 | return columns; 14 | } 15 | public void setColumns(List columns) { 16 | this.columns = columns; 17 | } 18 | public List getRows() { 19 | return rows; 20 | } 21 | public void setRows(List rows) { 22 | this.rows = rows; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public String getSchema() { 33 | return schema; 34 | } 35 | 36 | public void setSchema(String schema) { 37 | this.schema = schema; 38 | } 39 | 40 | public XmlTable query(Condition condition){ 41 | XmlTable table = new XmlTable(); 42 | for(String column:columns){ 43 | table.columns.add(column); 44 | } 45 | for(XmlRow row : rows){ 46 | if(row.isMatch(condition)){ 47 | table.rows.add(row); 48 | } 49 | } 50 | return table; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.loader.file/src/com/vispractice/amoeba/loader/file/Activator.java: -------------------------------------------------------------------------------- 1 | package com.vispractice.amoeba.loader.file; 2 | 3 | import org.osgi.framework.BundleActivator; 4 | import org.osgi.framework.BundleContext; 5 | 6 | public class Activator implements BundleActivator { 7 | 8 | private static BundleContext context; 9 | 10 | static BundleContext getContext() { 11 | return context; 12 | } 13 | 14 | /* 15 | * (non-Javadoc) 16 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) 17 | */ 18 | public void start(BundleContext bundleContext) throws Exception { 19 | Activator.context = bundleContext; 20 | } 21 | 22 | /* 23 | * (non-Javadoc) 24 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) 25 | */ 26 | public void stop(BundleContext bundleContext) throws Exception { 27 | Activator.context = null; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Mysql 4 | Bundle-SymbolicName: com.vispractice.amoeba.mysql 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Activator: com.vispractice.amoeba.mysql.Activator 7 | Bundle-Vendor: VISPRACTICE 8 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 9 | Import-Package: org.osgi.framework;version="1.3.0", 10 | org.osgi.service.component;version="1.1.0" 11 | Require-Bundle: com.vispractice.amoeba.base;bundle-version="1.0.0", 12 | com.springsource.org.apache.commons.collections;bundle-version="3.2.1", 13 | com.springsource.org.apache.commons.lang;bundle-version="2.4.0", 14 | org.springframework.osgi.log4j.osgi;bundle-version="1.2.15", 15 | org.apache.servicemix.bundles.commons-pool;bundle-version="1.5.4", 16 | com.vispractice.amoeba.seq.fetcher;bundle-version="1.0.0" 17 | Export-Package: com.meidusa.amoeba.mysql.context, 18 | com.meidusa.amoeba.mysql.handler, 19 | com.meidusa.amoeba.mysql.jdbc, 20 | com.meidusa.amoeba.mysql.net, 21 | com.meidusa.amoeba.mysql.net.packet, 22 | com.meidusa.amoeba.mysql.net.packet.result, 23 | com.meidusa.amoeba.mysql.parser, 24 | com.meidusa.amoeba.mysql.util 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/filter/AbstractIOFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2108 amoeba.meidusa.com 3 | * 4 | * This program is free software; you can redistribute it and/or modify it under the terms of 5 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 6 | * or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 11 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 12 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 13 | */ 14 | package com.meidusa.amoeba.mysql.filter; 15 | 16 | import com.meidusa.amoeba.mysql.filter.FilterInvocation.Result; 17 | 18 | /** 19 | * 20 | * @author Struct chen 21 | * 22 | */ 23 | public abstract class AbstractIOFilter implements IOFilter { 24 | 25 | private byte[] resultBuffer; 26 | public void startFiltrate(){ 27 | } 28 | 29 | protected void setResultBuffer(byte[] resultBuffer) { 30 | this.resultBuffer = resultBuffer; 31 | } 32 | 33 | public void finishFiltrate(){ 34 | resultBuffer = null; 35 | } 36 | 37 | public Result doFilter(PacketFilterInvocation invocation) { 38 | return packetFilter(invocation.getByteBuffer()); 39 | } 40 | 41 | protected abstract Result packetFilter(byte[] packetBuffer); 42 | 43 | public byte[] getFiltedResult(){ 44 | return resultBuffer; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/filter/FilterInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2108 amoeba.meidusa.com 3 | * 4 | * This program is free software; you can redistribute it and/or modify it under the terms of 5 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 6 | * or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 11 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 12 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 13 | */ 14 | package com.meidusa.amoeba.mysql.filter; 15 | 16 | /** 17 | * 18 | * @author Struct chen 19 | * 20 | */ 21 | public interface FilterInvocation { 22 | enum Result{RETURN,OK,ERROR,PROCESSED,QUIT} 23 | void invoke(); 24 | Result getResultCode(); 25 | } 26 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/filter/IOFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2108 amoeba.meidusa.com 3 | * 4 | * This program is free software; you can redistribute it and/or modify it under the terms of 5 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 6 | * or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 11 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 12 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 13 | */ 14 | package com.meidusa.amoeba.mysql.filter; 15 | 16 | import com.meidusa.amoeba.mysql.filter.FilterInvocation.Result; 17 | 18 | /** 19 | * 20 | * @author Struct chen 21 | * 22 | */ 23 | public interface IOFilter { 24 | public void startFiltrate(); 25 | public Result doFilter(PacketFilterInvocation invocation); 26 | public byte[] getFiltedResult(); 27 | public void finishFiltrate(); 28 | } 29 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/handler/CommitStatementHandler.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.handler; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import com.meidusa.amoeba.mysql.net.MysqlClientConnection; 6 | import com.meidusa.amoeba.net.poolable.ObjectPool; 7 | import com.meidusa.amoeba.parser.statement.Statement; 8 | import com.meidusa.amoeba.route.Request; 9 | 10 | public class CommitStatementHandler extends StickyForTransactionHandler { 11 | public static Logger logger = Logger.getLogger(CommitStatementHandler.class); 12 | 13 | public CommitStatementHandler(MysqlClientConnection source, byte[] query, Statement statment, 14 | ObjectPool[] pools, Request request, long timeout) { 15 | super(source, query, statment, pools, request, timeout); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/handler/RollbackStatementHandler.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.handler; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | import com.meidusa.amoeba.mysql.net.MysqlClientConnection; 6 | import com.meidusa.amoeba.net.poolable.ObjectPool; 7 | import com.meidusa.amoeba.parser.statement.Statement; 8 | import com.meidusa.amoeba.route.Request; 9 | 10 | public class RollbackStatementHandler extends StickyForTransactionHandler{ 11 | public static Logger logger = Logger.getLogger(RollbackStatementHandler.class); 12 | 13 | public RollbackStatementHandler(MysqlClientConnection source, byte[] query, Statement statment, 14 | ObjectPool[] pools, Request request, long timeout) { 15 | 16 | super(source, query, statment, pools, request, timeout); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/handler/session/CommandStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.meidusa.amoeba.mysql.handler.session; 5 | 6 | public enum CommandStatus{ 7 | ConnectionNotComplete,ConnectionCompleted,AllCompleted 8 | } -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/handler/session/SessionStatus.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.handler.session; 2 | 3 | /** 4 | * 表示服务器返回的数据包所表示当前会话状态 5 | * @author Struct chen 6 | * 7 | */ 8 | public class SessionStatus{ 9 | public static final int QUERY = 1; 10 | public static final int RESULT_HEAD = 2; 11 | public static final int EOF_FIELDS = 4; 12 | public static final int EOF_ROWS = 8; 13 | public static final int OK = 16; 14 | public static final int ERROR = 32; 15 | public static final int COMPLETED = 64; 16 | } -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/jdbc/IsolationLevels.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.jdbc; 2 | 3 | public class IsolationLevels { 4 | public static final int READ_UNCOMMITTED = 1; 5 | public static final int READ_COMMITTED = 2; 6 | 7 | public static final int REPEATED_READ = 4; 8 | 9 | public static final int SERIALIZABLE = 8; 10 | } 11 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/CommandListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.mysql.net; 13 | 14 | public interface CommandListener{ 15 | public void startCommand(CommandInfo command); 16 | public void finishedCommand(CommandInfo command); 17 | } 18 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/MysqlClientConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify it under the terms of 3 | * the GNU AFFERO GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 3 of the License, 4 | * or (at your option) any later version. 5 | * 6 | * This program is distributed in the hope that it will be useful, 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | * See the GNU AFFERO GENERAL PUBLIC LICENSE for more details. 9 | * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this program; 10 | * if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 11 | */ 12 | package com.meidusa.amoeba.mysql.net; 13 | 14 | import java.nio.channels.SocketChannel; 15 | 16 | import com.meidusa.amoeba.net.Connection; 17 | import com.meidusa.amoeba.net.FrontendConnectionFactory; 18 | 19 | /** 20 | * 21 | * @author Struct chen 22 | * 23 | */ 24 | public class MysqlClientConnectionFactory extends FrontendConnectionFactory { 25 | 26 | @Override 27 | protected Connection newConnectionInstance(SocketChannel channel, 28 | long createStamp) { 29 | return new MysqlClientConnection(channel, createStamp); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/packet/ConstantPacketBuffer.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.net.packet; 2 | 3 | import com.meidusa.amoeba.mysql.net.packet.OkPacket; 4 | 5 | public class ConstantPacketBuffer { 6 | public static byte[] STATIC_OK_BUFFER; 7 | static { 8 | OkPacket ok = new OkPacket(); 9 | ok.affectedRows = 0; 10 | ok.insertId = 0; 11 | ok.packetId = 1; 12 | ok.serverStatus = 2; 13 | STATIC_OK_BUFFER = ok.toByteBuffer(null).array(); 14 | } 15 | 16 | public static final String _READ_UNCOMMITTED = "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"; 17 | 18 | public static final String _READ_COMMITTED = "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"; 19 | 20 | public static final String _REPEATED_READ = "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ"; 21 | 22 | public static final String _SERIALIZABLE = "SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"; 23 | } 24 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/packet/MysqlPingPacket.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.net.packet; 2 | 3 | /** 4 | * 5 | * @author struct 6 | * 7 | */ 8 | public class MysqlPingPacket extends CommandPacket { 9 | public MysqlPingPacket(){ 10 | command = COM_PING; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/packet/Scramble323Packet.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.net.packet; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | 5 | import com.meidusa.amoeba.mysql.util.Util; 6 | import com.meidusa.amoeba.net.packet.AbstractPacketBuffer; 7 | 8 | /** 9 | *
10 |  * By sending this very specific reply server asks us to send scrambled 
11 |  * password in old format. The reply contains scramble_323.
12 |  *
13 | * 14 | * @author Struct 15 | */ 16 | public class Scramble323Packet extends AbstractPacket { 17 | 18 | public String password; 19 | public String seed323; 20 | 21 | public void write2Buffer(AbstractPacketBuffer mybuffer) throws UnsupportedEncodingException { 22 | super.write2Buffer(mybuffer); 23 | MysqlPacketBuffer buffer = (MysqlPacketBuffer) mybuffer; 24 | buffer.writeString(Util.newCrypt(password, seed323)); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/packet/result/ErrorResultPacket.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.net.packet.result; 2 | 3 | import com.meidusa.amoeba.mysql.net.packet.ErrorPacket; 4 | import com.meidusa.amoeba.net.Connection; 5 | 6 | /** 7 | * 8 | * @author struct 9 | * 10 | */ 11 | public class ErrorResultPacket implements ResultPacket{ 12 | private boolean isError; 13 | private String errorMessage; 14 | public boolean isError() { 15 | return isError; 16 | } 17 | 18 | private int errorCode; 19 | public void setError(int errorCode,String errorMessage) { 20 | isError = true; 21 | this.errorCode = errorCode; 22 | this.errorMessage = errorMessage; 23 | } 24 | 25 | public void wirteToConnection(Connection conn) { 26 | ErrorPacket packet = new ErrorPacket(); 27 | packet.packetId = 1; 28 | packet.errno = errorCode; 29 | packet.serverErrorMessage = errorMessage; 30 | conn.postMessage(packet.toByteBuffer(conn)); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/packet/result/MysqlSimpleResultPacket.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.net.packet.result; 2 | 3 | import java.util.concurrent.atomic.AtomicLong; 4 | 5 | import com.meidusa.amoeba.mysql.net.packet.OkPacket; 6 | import com.meidusa.amoeba.net.Connection; 7 | 8 | /** 9 | * 10 | * @author struct 11 | * 12 | */ 13 | public class MysqlSimpleResultPacket extends ErrorResultPacket { 14 | 15 | private AtomicLong resultCount = new AtomicLong(); 16 | public void addResultCount(int count){ 17 | resultCount.addAndGet(count); 18 | } 19 | 20 | public void wirteToConnection(Connection conn) { 21 | if(isError()){ 22 | super.wirteToConnection(conn); 23 | return; 24 | } 25 | OkPacket packet = new OkPacket(); 26 | packet.affectedRows = resultCount.get(); 27 | packet.insertId = 0; 28 | packet.serverStatus = 2; 29 | packet.packetId = 1; 30 | conn.postMessage(packet.toByteBuffer(conn)); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/net/packet/result/ResultPacket.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.net.packet.result; 2 | 3 | import com.meidusa.amoeba.net.Connection; 4 | 5 | /** 6 | * 7 | * @author struct 8 | * 9 | */ 10 | public interface ResultPacket { 11 | 12 | public void setError(int errorCode,String errorMessage); 13 | /** 14 | * 将ResultSet这些包合并以后写到Connection 15 | * head--> fields --> eof -->rows --> eof 16 | * @param conn 17 | */ 18 | public abstract void wirteToConnection(Connection conn); 19 | 20 | } -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/parser/MysqlSyntaxConstants.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.mysql.parser; 2 | 3 | public class MysqlSyntaxConstants { 4 | // 数据库虚表的名称 5 | public final static String DUAL_TABLE_NAME = "DUAL"; 6 | } 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/meidusa/amoeba/mysql/parser/sql/MysqlParserTreeConstants.java: -------------------------------------------------------------------------------- 1 | /* Generated By:JavaCC: Do not edit this line. MysqlParserTreeConstants.java Version 5.0 */ 2 | package com.meidusa.amoeba.mysql.parser.sql; 3 | 4 | public interface MysqlParserTreeConstants 5 | { 6 | public int JJTVOID = 0; 7 | 8 | 9 | public String[] jjtNodeName = { 10 | "void", 11 | }; 12 | } 13 | /* JavaCC - OriginalChecksum=dfbb97a40f8c7240511d1c243626087a (do not edit this line) */ 14 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.mysql/src/com/vispractice/amoeba/mysql/Activator.java: -------------------------------------------------------------------------------- 1 | package com.vispractice.amoeba.mysql; 2 | 3 | import org.osgi.framework.BundleActivator; 4 | import org.osgi.framework.BundleContext; 5 | 6 | public class Activator implements BundleActivator { 7 | public static BundleContext bundleContext = null; 8 | 9 | /* 10 | * (non-Javadoc) 11 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) 12 | */ 13 | public void start(BundleContext context) throws Exception { 14 | Activator.bundleContext = context; 15 | } 16 | 17 | /* 18 | * (non-Javadoc) 19 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) 20 | */ 21 | public void stop(BundleContext context) throws Exception { 22 | Activator.bundleContext = null; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.fetcher/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Seq 4 | Bundle-SymbolicName: com.vispractice.amoeba.seq.fetcher 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Activator: com.vispractice.amoeba.seq.fetcher.Activator 7 | Bundle-Vendor: VISPRACTICE 8 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 9 | Import-Package: org.osgi.framework;version="1.3.0" 10 | Service-Component: OSGI-INF/SeqFetcherComp.xml 11 | Export-Package: com.meidusa.amoeba.seq.fetcher 12 | Require-Bundle: org.springframework.osgi.log4j.osgi;bundle-version="1.2.15" 13 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.fetcher/OSGI-INF/SeqFetcherComp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.fetcher/src/com/meidusa/amoeba/seq/fetcher/SeqConstants.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.seq.fetcher; 2 | 3 | public class SeqConstants { 4 | public final static String NEXTVAL = "NEXTVAL"; 5 | public final static String CURRVAL = "CURRVAL"; 6 | public final static String BULKVAL = "BULKVAL"; 7 | } 8 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.fetcher/src/com/meidusa/amoeba/seq/fetcher/SeqOperationResult.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.seq.fetcher; 2 | 3 | public class SeqOperationResult { 4 | private boolean isSuccessed; 5 | private String errMsg; 6 | 7 | public SeqOperationResult(boolean isSuccessed, String errMsg) { 8 | this.isSuccessed = isSuccessed; 9 | this.errMsg = errMsg; 10 | } 11 | 12 | public boolean isSuccessed() { 13 | return isSuccessed; 14 | } 15 | public void setSuccessed(boolean isSuccessed) { 16 | this.isSuccessed = isSuccessed; 17 | } 18 | public String getErrMsg() { 19 | return errMsg; 20 | } 21 | public void setErrMsg(String errMsg) { 22 | this.errMsg = errMsg; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.fetcher/src/com/meidusa/amoeba/seq/fetcher/SeqProvider.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.seq.fetcher; 2 | 3 | public abstract class SeqProvider { 4 | public abstract SeqOperationResult createSeq(String schema, String seqName, long start, long offset); 5 | public abstract long getSeqCurrVal(String schema, String seqName); 6 | public abstract long getSeqNextVal(String schema, String seqName); 7 | public abstract long batchGetSeqVal(String schema, String seqName, long count); 8 | public abstract SeqOperationResult deleteSeq(String schema, String seqName); 9 | 10 | public void init() throws Exception { 11 | 12 | } 13 | 14 | public void stop() throws Exception { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.fetcher/src/com/vispractice/amoeba/seq/fetcher/Activator.java: -------------------------------------------------------------------------------- 1 | package com.vispractice.amoeba.seq.fetcher; 2 | 3 | import org.osgi.framework.BundleActivator; 4 | import org.osgi.framework.BundleContext; 5 | 6 | public class Activator implements BundleActivator { 7 | 8 | public static BundleContext context; 9 | 10 | /* 11 | * (non-Javadoc) 12 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) 13 | */ 14 | public void start(BundleContext bundleContext) throws Exception { 15 | Activator.context = bundleContext; 16 | } 17 | 18 | /* 19 | * (non-Javadoc) 20 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) 21 | */ 22 | public void stop(BundleContext bundleContext) throws Exception { 23 | Activator.context = null; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Generator 4 | Bundle-SymbolicName: com.vispractice.amoeba.seq.provider 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Activator: com.vispractice.amoeba.seq.provider.Activator 7 | Bundle-Vendor: VISPRACTICE 8 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 9 | Import-Package: org.osgi.framework;version="1.3.0" 10 | Service-Component: OSGI-INF/SeqProviderComp.xml 11 | Require-Bundle: com.vispractice.amoeba.base;bundle-version="1.0.0", 12 | com.vispractice.amoeba.seq.fetcher;bundle-version="1.0.0" 13 | Export-Package: com.meidusa.amoeba.seq.provider 14 | Bundle-ClassPath: .,lib/jline-0.9.94.jar, 15 | lib/netty-3.2.2.Final.jar, 16 | lib/zookeeper-3.4.5.jar, 17 | lib/log4j-1.2.15.jar, 18 | lib/slf4j-api-1.6.1.jar, 19 | lib/slf4j-log4j12-1.6.1.jar, 20 | lib/curator-client-1.3.3.jar, 21 | lib/curator-framework-1.3.3.jar, 22 | lib/curator-recipes-1.3.3.jar, 23 | lib/guava-14.0.1.jar 24 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/OSGI-INF/SeqProviderComp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/curator-client-1.3.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/curator-client-1.3.3.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/curator-framework-1.3.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/curator-framework-1.3.3.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/curator-recipes-1.3.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/curator-recipes-1.3.3.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/guava-14.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/guava-14.0.1.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/jline-0.9.94.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/jline-0.9.94.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/log4j-1.2.15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/log4j-1.2.15.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/netty-3.2.2.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/netty-3.2.2.Final.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/slf4j-api-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/slf4j-api-1.6.1.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/slf4j-log4j12-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/slf4j-log4j12-1.6.1.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/lib/zookeeper-3.4.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/com.vispractice.amoeba.seq.provider/lib/zookeeper-3.4.5.jar -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/src/com/meidusa/amoeba/seq/provider/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.meidusa.amoeba.seq.provider.utils; 2 | 3 | import java.io.FileReader; 4 | import java.io.IOException; 5 | import java.util.Properties; 6 | 7 | import com.meidusa.amoeba.context.ProxyRuntimeContext; 8 | import com.meidusa.amoeba.util.StringUtil; 9 | 10 | public class Utils { 11 | 12 | public final static String SEQ_CONFIG_FILENAME = "seq.properties"; 13 | 14 | static public Properties readGlobalSeqConfigProps() throws IOException{ 15 | Properties props = new Properties(); 16 | String amoebaHomePath = ProxyRuntimeContext.getInstance().getAmoebaHomePath(); 17 | String PATH_SEPARATOR = StringUtil.PATH_SEPARATOR; 18 | String seqConfigPath = amoebaHomePath + PATH_SEPARATOR + "conf" + PATH_SEPARATOR + SEQ_CONFIG_FILENAME; 19 | FileReader reader = new FileReader(seqConfigPath); 20 | props.load(reader); 21 | return props; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.seq.provider/src/com/vispractice/amoeba/seq/provider/Activator.java: -------------------------------------------------------------------------------- 1 | package com.vispractice.amoeba.seq.provider; 2 | 3 | import org.osgi.framework.BundleActivator; 4 | import org.osgi.framework.BundleContext; 5 | 6 | public class Activator implements BundleActivator { 7 | 8 | public static BundleContext context; 9 | 10 | /* 11 | * (non-Javadoc) 12 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) 13 | */ 14 | public void start(BundleContext bundleContext) throws Exception { 15 | Activator.context = bundleContext; 16 | } 17 | 18 | /* 19 | * (non-Javadoc) 20 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) 21 | */ 22 | public void stop(BundleContext bundleContext) throws Exception { 23 | Activator.context = null; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.startup/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Startup 4 | Bundle-SymbolicName: com.vispractice.amoeba.startup 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Activator: com.vispractice.amoeba.startup.Activator 7 | Bundle-Vendor: VISPRACTICE 8 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 9 | Import-Package: org.osgi.framework;version="1.3.0" 10 | Require-Bundle: com.springsource.org.apache.commons.lang;bundle-version="2.4.0", 11 | com.springsource.org.apache.commons.collections;bundle-version="3.2.1", 12 | org.springframework.osgi.log4j.osgi;bundle-version="1.2.15", 13 | org.apache.servicemix.bundles.commons-pool;bundle-version="1.5.4", 14 | com.vispractice.amoeba.base;bundle-version="1.0.0", 15 | com.vispractice.amoeba.mysql;bundle-version="1.0.0" 16 | -------------------------------------------------------------------------------- /com.vispractice.amoeba.startup/src/com/vispractice/amoeba/startup/Activator.java: -------------------------------------------------------------------------------- 1 | package com.vispractice.amoeba.startup; 2 | 3 | 4 | import org.apache.log4j.Logger; 5 | import org.osgi.framework.BundleActivator; 6 | import org.osgi.framework.BundleContext; 7 | 8 | import com.meidusa.amoeba.exception.AmoebaRuntimeException; 9 | import com.meidusa.amoeba.server.AmoebaProxyServer; 10 | 11 | 12 | public class Activator implements BundleActivator { 13 | private static Logger logger = Logger.getLogger(Activator.class); 14 | 15 | /* 16 | * (non-Javadoc) 17 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) 18 | */ 19 | public void start(final BundleContext context) throws Exception { 20 | String[] args = {"start"}; 21 | try { 22 | AmoebaProxyServer.run(args, context); 23 | } catch (Exception e) { 24 | logger.error("start amoeba error", e); 25 | throw new AmoebaRuntimeException(e); 26 | } 27 | } 28 | 29 | /* 30 | * (non-Javadoc) 31 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) 32 | */ 33 | public void stop(BundleContext context) throws Exception { 34 | } 35 | 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /plugins/com.alibaba.china.jdbc_proxy_1.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.alibaba.china.jdbc_proxy_1.1.0.jar -------------------------------------------------------------------------------- /plugins/com.springsource.javassist-3.15.0.GA.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.javassist-3.15.0.GA.jar -------------------------------------------------------------------------------- /plugins/com.springsource.javax.xml.stream-1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.javax.xml.stream-1.0.1.jar -------------------------------------------------------------------------------- /plugins/com.springsource.org.apache.commons.collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.org.apache.commons.collections-3.2.1.jar -------------------------------------------------------------------------------- /plugins/com.springsource.org.apache.commons.lang-2.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.org.apache.commons.lang-2.4.0.jar -------------------------------------------------------------------------------- /plugins/com.springsource.org.dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.org.dom4j-1.6.1.jar -------------------------------------------------------------------------------- /plugins/com.springsource.org.ognl-2.7.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.org.ognl-2.7.3.jar -------------------------------------------------------------------------------- /plugins/com.springsource.slf4j.api-1.5.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.slf4j.api-1.5.6.jar -------------------------------------------------------------------------------- /plugins/com.springsource.slf4j.log4j-1.5.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/com.springsource.slf4j.log4j-1.5.6.jar -------------------------------------------------------------------------------- /plugins/log4j.osgi-1.2.15-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/log4j.osgi-1.2.15-SNAPSHOT.jar -------------------------------------------------------------------------------- /plugins/org.apache.servicemix.bundles.asm-3.3_2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.apache.servicemix.bundles.asm-3.3_2.jar -------------------------------------------------------------------------------- /plugins/org.apache.servicemix.bundles.commons-pool-1.5.4_1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.apache.servicemix.bundles.commons-pool-1.5.4_1.jar -------------------------------------------------------------------------------- /plugins/org.eclipse.equinox.ds_1.1.1.R35x_v20090806.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.eclipse.equinox.ds_1.1.1.R35x_v20090806.jar -------------------------------------------------------------------------------- /plugins/org.eclipse.equinox.event_1.2.100.v20110502.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.eclipse.equinox.event_1.2.100.v20110502.jar -------------------------------------------------------------------------------- /plugins/org.eclipse.equinox.util_1.0.100.v20090520-1800.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.eclipse.equinox.util_1.0.100.v20090520-1800.jar -------------------------------------------------------------------------------- /plugins/org.eclipse.osgi.services_3.3.0.v20110513.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.eclipse.osgi.services_3.3.0.v20110513.jar -------------------------------------------------------------------------------- /plugins/org.eclipse.osgi.util_3.2.200.v20110110.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.eclipse.osgi.util_3.2.200.v20110110.jar -------------------------------------------------------------------------------- /plugins/org.eclipse.osgi_3.7.1.R37x_v20110808-1106.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/plugins/org.eclipse.osgi_3.7.1.R37x_v20110808-1106.jar -------------------------------------------------------------------------------- /release/amoeba-plus-mysql-1.0-RC1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/release/amoeba-plus-mysql-1.0-RC1.tar.gz -------------------------------------------------------------------------------- /release/amoeba-plus-mysql-1.0-RC1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vispractice/Amoeba-Plus-For-MySQL/3579ddd5a569b2ac84a489709c0df1857979346b/release/amoeba-plus-mysql-1.0-RC1.zip --------------------------------------------------------------------------------